home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 568b.lha / PowerSource_v3.0 / source.lzh / source / genmenus.c < prev    next >
C/C++ Source or Header  |  1991-09-15  |  14KB  |  432 lines

  1. /*----------------------------------------------------------------------*
  2.     GenMenus.c version 3.0 - © Copyright 1991 Jaba Development
  3.  
  4.     Author : Jan van den Baard
  5.     Purpose: Generating the menu source code.
  6.  *----------------------------------------------------------------------*/
  7. extern struct ge_prefs   prefs;
  8. extern struct MyMenu    *MenuStrip;
  9. extern struct MyMenuItem dummy;
  10. extern UWORD             SubCount, ItemCount;
  11.  
  12. extern UBYTE             MenuLabel[32];
  13. extern UBYTE             ItemLabel[32];
  14. extern UBYTE             SubLabel[32];
  15.  
  16. #define STAT    (prefs.static_structures)
  17. #define NOFLAGS (prefs.no_flags)
  18.  
  19. void WriteCIText( BPTR file, struct IntuiText *itext )
  20. {
  21.     WriteFormat(file,"  %ld,%ld,",itext->FrontPen,itext->BackPen);
  22.     WriteDrMd(file,itext->DrawMode,FALSE);
  23.     WriteFormat(file,",%ld,%ld,NULL,(UBYTE *)\"%s\",NULL,\n",itext->LeftEdge,itext->TopEdge,itext->IText);
  24. }
  25.  
  26. void WriteAsmIText( BPTR file, struct IntuiText *itext, UWORD inum, BOOL sub )
  27. {
  28.     if(sub)
  29.         WriteFormat(file,"%sText%ld:\n",&SubLabel[0],inum);
  30.     else
  31.         WriteFormat(file,"%sText%ld:\n",&ItemLabel[0],inum);
  32.  
  33.     WriteFormat(file,"    DC.B    %ld,%ld,",itext->FrontPen,itext->BackPen);
  34.     if(NOFLAGS)
  35.         WriteFormat(file,"$%0.20lx,0\n",itext->DrawMode);
  36.     else {
  37.         WriteDrMd(file,itext->DrawMode,TRUE);
  38.         WriteFormat(file,",0\n");
  39.     }
  40.  
  41.     WriteFormat(file,"    DC.W    %ld,%ld\n    DC.L    0\n",itext->LeftEdge,itext->TopEdge,itext->IText);
  42.  
  43.     if(sub)
  44.         WriteFormat(file,"    DC.L    %sIText%ld,0\n\n",&SubLabel[0],inum);
  45.     else
  46.         WriteFormat(file,"    DC.L    %sIText%ld,0\n\n",&ItemLabel[0],inum);
  47.  
  48.     if(sub)
  49.         WriteFormat(file,"%sIText%ld:\n",&SubLabel[0],inum);
  50.     else
  51.         WriteFormat(file,"%sIText%ld:\n",&ItemLabel[0],inum);
  52.  
  53.     WriteFormat(file,"    DC.B    '%s',0\n",itext->IText);
  54.     WriteFormat(file,"    CNOP    0,2\n\n");
  55.  
  56. }
  57.  
  58. ULONG INum( struct MyMenu *menu )
  59. {
  60.     struct MyMenu       *tmp;
  61.     struct MyMenuItem   *it;
  62.     ULONG                inum = 0L;
  63.  
  64.     for(tmp = MenuStrip; tmp != menu; tmp = tmp->NextMenu) {
  65.         for(it = tmp->FirstItem; it; it = it->NextItem)
  66.             if(it != &dummy)
  67.                 inum++;
  68.     }
  69.     return(inum);
  70. }
  71.  
  72. ULONG SNum( struct MyMenuItem *sub )
  73. {
  74.     struct MyMenu       *tmp;
  75.     struct MyMenuItem   *it, *sb;
  76.     ULONG                snum = 0L;
  77.  
  78.     for(tmp = MenuStrip; tmp; tmp = tmp->NextMenu) {
  79.         for(it = tmp->FirstItem; it; it = it->NextItem) {
  80.             if(it->SubItem) {
  81.                 for(sb = it->SubItem; sb; sb = sb->NextItem) {
  82.                     if(sb == sub) goto gotIt;
  83.                     snum++;
  84.                 }
  85.             }
  86.         }
  87.     }
  88. gotIt:
  89.     return(snum);
  90. }
  91.  
  92. void WriteCItem( BPTR file, struct MyMenuItem *item, UWORD tnum , BOOL sub)
  93. {
  94.     struct MyMenuItem *tmp;
  95.     ULONG              flags;
  96.  
  97.     tmp   = item;
  98.     flags = (ULONG)tmp->Flags;
  99.  
  100.     if(sub) {
  101.         if(tmp->NextItem)
  102.             WriteFormat(file,"  &%s[%ld],",&SubLabel[0],tnum+1);
  103.         else
  104.             WriteFormat(file,"  NULL,");
  105.     } else {
  106.         if(tmp->NextItem)
  107.             WriteFormat(file,"  &%s[%ld],",&ItemLabel[0],tnum+1);
  108.         else
  109.             WriteFormat(file,"  NULL,");
  110.     }
  111.  
  112.     WriteFormat(file,"%ld,%ld,%ld,%ld,",tmp->LeftEdge,tmp->TopEdge,tmp->Width,tmp->Height);
  113.  
  114.     if(TestBits(flags,ITEMENABLED))
  115.         WriteFormat(file,"ITEMENABLED+");
  116.     if(TestBits(flags,HIGHNONE))
  117.         WriteFormat(file,"HIGHNONE+");
  118.     else if(TestBits(flags,HIGHCOMP))
  119.         WriteFormat(file,"HIGHCOMP+");
  120.     else
  121.         WriteFormat(file,"HIGHBOX+");
  122.     if(TestBits(flags,CHECKIT))
  123.         WriteFormat(file,"CHECKIT+");
  124.     if(TestBits(flags,ITEMTEXT))
  125.         WriteFormat(file,"ITEMTEXT+");
  126.     if(TestBits(flags,COMMSEQ))
  127.         WriteFormat(file,"COMMSEQ+");
  128.     if(TestBits(flags,MENUTOGGLE))
  129.         WriteFormat(file,"MENUTOGGLE+");
  130.     if(TestBits(flags,CHECKED))
  131.         WriteFormat(file,"CHECKED+");
  132.     Seek(file,-1L,OFFSET_CURRENT);
  133.     WriteFormat(file,",");
  134.     WriteFormat(file,"%ld,",tmp->MutualExclude);
  135.     if(sub)
  136.         WriteFormat(file,"(APTR)&%sText[%ld],",&SubLabel[0],tnum);
  137.     else
  138.         WriteFormat(file,"(APTR)&%sText[%ld],",&ItemLabel[0],tnum);
  139.     if(TestBits(flags,COMMSEQ))
  140.         WriteFormat(file,"NULL,%ld,",tmp->Command);
  141.     else
  142.         WriteFormat(file,"NULL,0,");
  143.     if(NOT sub AND item->SubItem)
  144.         WriteFormat(file,"&%s[%ld],0,\n",&SubLabel[0],SNum(item->SubItem));
  145.     else
  146.         WriteFormat(file,"NULL,0,\n");
  147. }
  148.  
  149. void WriteAsmItem( BPTR file, struct MyMenuItem *item, UWORD tnum , BOOL sub)
  150. {
  151.     struct MyMenuItem *tmp;
  152.     ULONG              flags;
  153.  
  154.     tmp   = item;
  155.     flags = (ULONG)tmp->Flags;
  156.  
  157.     if(sub) {
  158.         WriteFormat(file,"%s%ld:\n",&SubLabel[0],tnum);
  159.         if(tmp->NextItem)
  160.             WriteFormat(file,"    DC.L    %s%ld\n",&SubLabel[0],tnum+1);
  161.         else
  162.             WriteFormat(file,"    DC.L    0\n");
  163.     } else {
  164.         WriteFormat(file,"%s%ld:\n",&ItemLabel[0],tnum);
  165.         if(tmp->NextItem)
  166.             WriteFormat(file,"    DC.L    %s%ld\n",&ItemLabel[0],tnum+1);
  167.         else
  168.             WriteFormat(file,"    DC.L    0\n");
  169.     }
  170.  
  171.     WriteFormat(file,"    DC.W    %ld,%ld,%ld,%ld\n",tmp->LeftEdge,tmp->TopEdge,tmp->Width,tmp->Height);
  172.     WriteFormat(file,"    DC.W    ");
  173.     if(NOFLAGS) {
  174.         if(TestBits((ULONG)item->SpecialFlags,ITEMENABLED))
  175.             WriteFormat(file,"$%0.4lx\n",item->Flags+ITEMENABLED);
  176.         else
  177.             WriteFormat(file,"$%0.4lx\n",item->Flags);
  178.     } else {
  179.         if(TestBits(flags,ITEMENABLED))
  180.             WriteFormat(file,"ITEMENABLED+");
  181.         if(TestBits(flags,HIGHNONE))
  182.             WriteFormat(file,"HIGHNONE+");
  183.         else if(TestBits(flags,HIGHCOMP))
  184.             WriteFormat(file,"HIGHCOMP+");
  185.         else
  186.             WriteFormat(file,"HIGHBOX+");
  187.         if(TestBits(flags,CHECKIT))
  188.             WriteFormat(file,"CHECKIT+");
  189.         if(TestBits(flags,ITEMTEXT))
  190.             WriteFormat(file,"ITEMTEXT+");
  191.         if(TestBits(flags,COMMSEQ))
  192.             WriteFormat(file,"COMMSEQ+");
  193.         if(TestBits(flags,MENUTOGGLE))
  194.             WriteFormat(file,"MENUTOGGLE+");
  195.         if(TestBits(flags,CHECKED))
  196.             WriteFormat(file,"CHECKED+");
  197.         Seek(file,-1L,OFFSET_CURRENT);
  198.         WriteFormat(file,"\n");
  199.     }
  200.  
  201.     WriteFormat(file,"    DC.L    %ld\n",tmp->MutualExclude);
  202.     if(sub)
  203.         WriteFormat(file,"    DC.L    %sText%ld,0\n",&SubLabel[0],tnum);
  204.     else
  205.         WriteFormat(file,"    DC.L    %sText%ld,0\n",&ItemLabel[0],tnum);
  206.     if(TestBits(flags,COMMSEQ))
  207.         WriteFormat(file,"    DC.B    %ld,0\n",tmp->Command);
  208.     else
  209.         WriteFormat(file,"    DC.B    0,0\n");
  210.     if(NOT sub AND item->SubItem)
  211.         WriteFormat(file,"    DC.L    %s%ld\n    DC.W    0\n\n",&SubLabel[0],SNum((struct MyMenuItem *)item->SubItem));
  212.     else
  213.         WriteFormat(file,"    DC.L    0\n    DC.W    0\n\n");
  214. }
  215.  
  216. BOOL WriteCMenus( BPTR file )
  217. {
  218.     register    struct MyMenu       *menu;
  219.     register    struct MyMenuItem   *item, *sub;
  220.     register    struct IntuiText    *itext;
  221.     register    UWORD                inum, snum, mnum;
  222.  
  223.     if(SubCount) {
  224.         if(STAT)
  225.             WriteFormat(file,"static ");
  226.             WriteFormat(file,"struct IntuiText %sText[] = {\n",&SubLabel[0]);
  227.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  228.             for(item = menu->FirstItem; item; item = item->NextItem) {
  229.                 if((sub = item->SubItem)) {
  230.                     while(1) {
  231.                         WriteCIText(file,(struct IntuiText *)sub->ItemFill);
  232.                         if(NOT(sub = sub->NextItem))
  233.                             break;
  234.                     }
  235.                 }
  236.             }
  237.         }
  238.         Seek(file,-2L,OFFSET_CURRENT);
  239.         WriteFormat(file," };\n\n");
  240.     }
  241.  
  242.     if(ItemCount) {
  243.         if(STAT)
  244.             WriteFormat(file,"static ");
  245.             WriteFormat(file,"struct IntuiText %sText[] = {\n",&ItemLabel[0]);
  246.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  247.             if((item = menu->FirstItem)) {
  248.                 while(1) {
  249.                     if(item == &dummy) break;
  250.                     WriteCIText(file,(struct IntuiText *)item->ItemFill);
  251.                     if(NOT(item = item->NextItem))
  252.                         break;
  253.                 }
  254.             }
  255.         }
  256.         Seek(file,-2L,OFFSET_CURRENT);
  257.         WriteFormat(file," };\n\n");
  258.     }
  259.  
  260.     snum = NULL;
  261.  
  262.     if(SubCount) {
  263.         if(STAT)
  264.             WriteFormat(file,"static ");
  265.             WriteFormat(file,"struct MenuItem %s[] = {\n",&SubLabel[0]);
  266.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  267.             for(item = menu->FirstItem; item; item = item->NextItem) {
  268.                 if((sub = item->SubItem)) {
  269.                     while(1) {
  270.                         WriteCItem(file,sub,snum++,TRUE);
  271.                         if(NOT(sub = sub->NextItem))
  272.                             break;
  273.                     }
  274.                 }
  275.             }
  276.         }
  277.         Seek(file,-2L,OFFSET_CURRENT);
  278.         WriteFormat(file," };\n\n");
  279.     }
  280.  
  281.     inum = NULL;
  282.  
  283.     if(ItemCount) {
  284.         if(STAT)
  285.             WriteFormat(file,"static ");
  286.             WriteFormat(file,"struct MenuItem %s[] = {\n",&ItemLabel[0]);
  287.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  288.             if((item = menu->FirstItem)) {
  289.                 while(1) {
  290.                     if(item == &dummy) break;
  291.                     WriteCItem(file,item,inum++,FALSE);
  292.                     if(NOT(item = item->NextItem))
  293.                         break;
  294.                 }
  295.             }
  296.         }
  297.         Seek(file,-2L,OFFSET_CURRENT);
  298.         WriteFormat(file," };\n\n");
  299.     }
  300.  
  301.     mnum = 1;
  302.  
  303.     if(STAT)
  304.         WriteFormat(file,"static ");
  305.     WriteFormat(file,"struct Menu %s[] = {\n",&MenuLabel[0]);
  306.  
  307.     for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  308.         if(menu->NextMenu)
  309.             WriteFormat(file,"  &%s[%ld],",&MenuLabel[0],mnum++);
  310.         else
  311.             WriteFormat(file,"  NULL,");
  312.  
  313.         WriteFormat(file,"%ld,%ld,%ld,%ld,",menu->LeftEdge,menu->TopEdge,menu->Width,menu->Height);
  314.         if(TestBits((ULONG)menu->Flags,MENUENABLED))
  315.             WriteFormat(file,"MENUENABLED,");
  316.         else
  317.             WriteFormat(file,"0,");
  318.  
  319.         WriteFormat(file,"(BYTE *)\"%s\",",menu->MenuName);
  320.  
  321.         if(menu->FirstItem != &dummy)
  322.             WriteFormat(file,"&%s[%ld],0,0,0,0,\n",&ItemLabel[0],INum(menu));
  323.         else
  324.             WriteFormat(file,"NULL,0,0,0,0,\n");
  325.     }
  326.     Seek(file,-2L,OFFSET_CURRENT);
  327.     WriteFormat(file," };\n\n");
  328. }
  329.  
  330. BOOL WriteAsmMenus( BPTR file )
  331. {
  332.     register    struct MyMenu       *menu;
  333.     register    struct MyMenuItem   *item, *sub;
  334.     register    struct IntuiText    *itext;
  335.     register    UWORD                inum, snum, mnum;
  336.  
  337.     inum = 0;
  338.  
  339.     if(SubCount) {
  340.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  341.             for(item = menu->FirstItem; item; item = item->NextItem) {
  342.                 if((sub = item->SubItem)) {
  343.                     while(1) {
  344.                         WriteAsmIText(file,(struct IntuiText *)sub->ItemFill,inum++,TRUE);
  345.                         if(NOT(sub = sub->NextItem))
  346.                             break;
  347.                     }
  348.                 }
  349.             }
  350.         }
  351.     }
  352.  
  353.     inum = 0;
  354.  
  355.     if(ItemCount) {
  356.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  357.             if((item = menu->FirstItem)) {
  358.                 while(1) {
  359.                     if(item == &dummy) break;
  360.                     WriteAsmIText(file,(struct IntuiText *)item->ItemFill,inum++,FALSE);
  361.                     if(NOT(item = item->NextItem))
  362.                         break;
  363.                 }
  364.             }
  365.         }
  366.     }
  367.  
  368.     snum = NULL;
  369.  
  370.     if(SubCount) {
  371.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  372.             for(item = menu->FirstItem; item; item = item->NextItem) {
  373.                 if((sub = item->SubItem)) {
  374.                     while(1) {
  375.                         WriteAsmItem(file,sub,snum++,TRUE);
  376.                         if(NOT(sub = sub->NextItem))
  377.                             break;
  378.                     }
  379.                 }
  380.             }
  381.         }
  382.     }
  383.  
  384.     inum = NULL;
  385.  
  386.     if(ItemCount) {
  387.         for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  388.             if((item = menu->FirstItem)) {
  389.                 while(1) {
  390.                     if(item == &dummy) break;
  391.                     WriteAsmItem(file,item,inum++,FALSE);
  392.                     if(NOT(item = item->NextItem))
  393.                         break;
  394.                 }
  395.             }
  396.         }
  397.     }
  398.  
  399.     mnum = 0;
  400.  
  401.     for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  402.         WriteFormat(file,"%s%ld:\n",&MenuLabel[0],mnum);
  403.         if(menu->NextMenu)
  404.             WriteFormat(file,"    DC.L    %s%ld\n",&MenuLabel[0],mnum+1);
  405.         else
  406.             WriteFormat(file,"    DC.L    0\n");
  407.  
  408.         WriteFormat(file,"    DC.W    %ld,%ld,%ld,%ld\n",menu->LeftEdge,menu->TopEdge,menu->Width,menu->Height);
  409.         if(NOFLAGS) {
  410.             if(TestBits((ULONG)menu->Flags,MENUENABLED))
  411.                 WriteFormat(file,"    DC.W    $0001\n");
  412.             else
  413.                 WriteFormat(file,"    DC.W    $0000\n");
  414.         } else {
  415.             if(TestBits((ULONG)menu->Flags,MENUENABLED))
  416.                 WriteFormat(file,"    DC.W    MENUENABLED\n");
  417.             else
  418.                 WriteFormat(file,"    DC.W    0\n");
  419.         }
  420.  
  421.         WriteFormat(file,"    DC.L    MenuName%ld\n",mnum);
  422.  
  423.         if(menu->FirstItem != &dummy)
  424.             WriteFormat(file,"    DC.L    %s%ld\n    DC.W    0,0,0,0\n\n",&ItemLabel[0],INum(menu));
  425.         else
  426.             WriteFormat(file,"    DC.L    0\n    DC.W    0,0,0,0\n\n");
  427.  
  428.         WriteFormat(file,"MenuName%ld:\n    DC.B    '%s',0\n",mnum++,menu->MenuName);
  429.         WriteFormat(file,"    CNOP    0,2\n\n");
  430.     }
  431. }
  432.