home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / AGNUS / SRC / FLAGSET2.CPX / FLAGSET2.CC < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-01  |  5.7 KB  |  244 lines

  1. /*
  2.  *    FLAGSET.CPX
  3.  *    Lesen und Setzen von Programmflags
  4.  *
  5.  *    Autor: Volker Hemsen, 1993-97
  6.  *    Compiler: GNU C/C++
  7.  *    Librarys: xlb, gem
  8.  */
  9.  
  10. /*    Includes    */
  11. #include <aesbind.h>
  12. #include <cpx.h>
  13. #include <string.h>
  14. #include <osbind.h>
  15. #include <xlb.h>
  16. #include "resource.h"
  17.  
  18. /* Typen & Strukturen */
  19. typedef struct
  20. {
  21.     unsigned tpa_size            :    4;    /*    28..31    */
  22.     unsigned res1                    :    12;    /*    16..27    */
  23.     unsigned res2                    :    4;    /*    12..15    */
  24.     unsigned shared_text    :    1;    /*    11    */
  25.     unsigned res3                    :    3;    /*    8..10    */
  26.     unsigned memprotection:    4;    /*    4..7    */
  27.     unsigned res4                    :    1;    /*    3    */
  28.     unsigned fast_malloc    :    1;    /*    2    */
  29.     unsigned fast_program    :    1;    /*    1    */
  30.     unsigned fast_load        :    1;    /*    0    */
  31. }    HEADER_FLAGS;
  32.  
  33. /* Konstanten */
  34. #define EXTENSION_MAX    8
  35.  
  36. /*    Prototypen    */
  37. short __saveds __stdargs cpx_call(GRECT*);
  38. short dopopup(char *items[],short num,short start,short objc);
  39. boolean file_patch(boolean writemode);
  40. void load_flags();
  41.  
  42. /* Objekte in Tree DIAL */
  43. void drawobjc(short ob)
  44. {
  45.     drawobjc(DIAL,ob);
  46. }
  47. void setobstr(short ob,char* str)
  48. {
  49.     setobstr(DIAL,ob,str);
  50. }
  51. void clrobselect(short ob,boolean draw)
  52. {
  53.     setobselect(DIAL,ob,FALSE);
  54.     if (draw)
  55.         drawobjc(ob);
  56. }
  57. void setobselect(short ob,boolean state,boolean draw)
  58. {
  59.     register OBJECT *t=&DIAL[ob];
  60.     t->ob_state&=(~CROSSED);
  61.     if (state)
  62.         t->ob_state|=CROSSED;
  63.     if (draw)
  64.         drawobjc(ob);
  65. }
  66. inline void setobselect(short ob,unsigned short state,boolean draw)
  67. {
  68.     setobselect(ob,state?TRUE:FALSE,draw);
  69. }
  70.  
  71. /*    Variablen    */
  72. XCPB *xcpb;
  73. char path[PATH_MAX],validpath[PATH_MAX];
  74. char ext[EXTENSION_MAX]="*";
  75. HEADER_FLAGS flags;
  76. CPXINFO cpxinfo={cpx_call,0L,0L,0L,0L,0L,0L,0L,0L,0L};
  77. char *tpa_items[]={ "   128kB ","   256kB ","   384kB ","   512kB ","   640kB ",
  78.                                         "   768kB ","   896kB ","  1024kB ","  1152kB ","  1280kB ","  1408kB ",
  79.                                         "  1536kB ","  1664kB ","  1792kB ","  1920kB ","  2048kB " };
  80. char *memprot_items[]={ "  privat ","  global ","  super  ","  lesbar " };
  81.  
  82. extern "C" {
  83.     CPXINFO* __saveds __stdargs cpx_init(XCPB*);
  84.     CPXINFO* __saveds __stdargs cpx_init(XCPB* Xcpb)
  85.     {
  86.         if (Xcpb->booting)
  87.             return((CPXINFO*)1L);
  88.         xcpb=Xcpb;
  89.         return(&cpxinfo);
  90.     }
  91. }
  92.  
  93. short __saveds __stdargs cpx_call(GRECT *rect)
  94. {
  95.     boolean ende=FALSE;
  96.     {
  97.         register char *p=(char*)xcpb->Get_Buffer();
  98.         if (*p) {
  99.             strcpy(validpath,p);
  100.             strcpy(path,validpath);
  101.             load_flags();
  102.         } else {
  103.             path[0]=Dgetdrv()+65;
  104.             path[1]=':';
  105.             Dgetpath(&path[2],0);
  106.             strcat(path,"\\");
  107.         }
  108.     }
  109.     stcgfn(((TEDINFO*)DIAL[DATEI].ob_spec)->te_ptext,path);
  110.     setobstr(RMTPA,tpa_items[flags.tpa_size]);
  111.     setobstr(MEMPRT,memprot_items[flags.memprotection]);
  112.     DIAL[0].ob_x=rect->g_x;
  113.     DIAL[0].ob_y=rect->g_y;
  114.     objc_draw(DIAL,0,MAX_DEPTH,rect->g_x,rect->g_y,rect->g_w,rect->g_h);
  115.     do {
  116.         short msg[8],ex;
  117.         ex=xcpb->Xform_do(DIAL,0,msg);
  118.         if (ex<0) {                //    Fenster-Meldungen
  119.             switch(msg[0]) {
  120.                 case WM_CLOSED:
  121.                 case AC_CLOSE:
  122.                     ende=TRUE;
  123.                     break;
  124.             }
  125.         } else {                    //    Dialogbox-Meldungen
  126.             switch(ex) {
  127.                 case DATEI:
  128.                 case LOAD:
  129.                     if (fileselector(ext,"Datei auswählen",path))
  130.                         load_flags();
  131.                     graf_mouse(0,0L);    //keine Ahnung warum, aber is so!!!
  132.                     clrobselect(LOAD,FALSE);
  133.                     drawobjc(0);
  134.                     break;
  135.                 case FSTLD:
  136.                 case FSTLDS:
  137.                     flags.fast_load=!flags.fast_load;
  138.                     setobselect(FSTLD,flags.fast_load,TRUE);
  139.                     break;
  140.                 case FSTRMRM:
  141.                 case FSTRMRMS:
  142.                     flags.fast_malloc=!flags.fast_malloc;
  143.                     setobselect(FSTRMRM,flags.fast_malloc,TRUE);
  144.                     break;
  145.                 case FSTRMLD:
  146.                 case FSTRMLDS:
  147.                     flags.fast_program=!flags.fast_program;
  148.                     setobselect(FSTRMLD,flags.fast_program,TRUE);
  149.                     break;
  150.                 case SHRDTXT:
  151.                 case SHRDTXTS:
  152.                     flags.shared_text=!flags.shared_text;
  153.                     setobselect(SHRDTXT,flags.shared_text,TRUE);
  154.                     break;
  155.                 case RMTPA:
  156.                     {
  157.                         register short ret=dopopup(tpa_items,16,flags.tpa_size,RMTPA);
  158.                         if (ret>=0)
  159.                             flags.tpa_size=ret;
  160.                     }
  161.                     break;
  162.                 case MEMPRT:
  163.                     {
  164.                         register short ret=dopopup(memprot_items,4,flags.memprotection,MEMPRT);
  165.                         if (ret>=0)
  166.                             flags.memprotection=ret;
  167.                     }
  168.                     break;
  169.                 case SAVE:
  170.                     file_patch(TRUE);
  171.                     clrobselect(SAVE,TRUE);
  172.                     break;
  173.                 case ENDE:
  174.                     ende=TRUE;
  175.                     break;
  176.             }
  177.         }
  178.     } while (!ende);
  179.     {
  180.         register char *p=(char*)xcpb->Get_Buffer();
  181.         if (strlen(validpath)<64)
  182.             strcpy(p,validpath);
  183.         else
  184.             *p=0;
  185.     }
  186.     return(0);
  187. }
  188.  
  189. void load_flags()
  190. {
  191.     stcgfe(ext,path);
  192.     if (!*ext)
  193.         strcat(ext,"*");
  194.     if (file_patch(FALSE)) {
  195.         stcgfn(((TEDINFO*)DIAL[DATEI].ob_spec)->te_ptext,path);
  196.         setobselect(FSTLD,(short)flags.fast_load,FALSE);
  197.         setobselect(FSTRMRM,(short)flags.fast_malloc,FALSE);
  198.         setobselect(FSTRMLD,(short)flags.fast_program,FALSE);
  199.         setobselect(SHRDTXT,(short)flags.shared_text,FALSE);
  200.         setobstr(RMTPA,tpa_items[flags.tpa_size]);
  201.         setobstr(MEMPRT,memprot_items[flags.memprotection]);
  202.     }
  203. }
  204.  
  205. boolean file_patch(boolean writemode)
  206. {
  207.     register long fh;
  208.     char *p;
  209.     if (writemode==FALSE)
  210.         p=path;
  211.     else
  212.         p=validpath;
  213.     fh=Fopen(p,2);
  214.     if (fh>=0) {
  215.         if ( (stricmp(ext,"CPX")==0) || (stricmp(ext,"CPZ")==0) )
  216.             Fseek(22L+512,fh,0);
  217.         else
  218.             Fseek(22L,fh,0);
  219.         if (writemode)
  220.             Fwrite(fh,4L,&flags);
  221.         else {
  222.             strcpy(validpath,path);
  223.             Fread(fh,4L,&flags);
  224.         }
  225.         Fclose(fh);
  226.         return TRUE;
  227.     }
  228.     xcpb->XGen_Alert(FILE_NOT_FOUND);
  229.     return FALSE;
  230. }
  231.  
  232. short dopopup(char *items[],short num,short start,short objc)
  233. {
  234.     short ret;
  235.     GRECT gb,gw;
  236.     objc_xywh(DIAL,0,&gw);
  237.     objc_xywh(DIAL,objc,&gb);
  238.     ret=xcpb->Popup(items,num,start,IBM,&gb,&gw);
  239.     if (ret>=0)
  240.         setobstr(objc,items[ret]);
  241.     clrobselect(objc,TRUE);
  242.     return ret;
  243. }
  244.