home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d547 / powersource.lha / PowerSource / source.lzh / source / gensrc.c < prev    next >
C/C++ Source or Header  |  1991-09-15  |  54KB  |  1,623 lines

  1. /*----------------------------------------------------------------------*
  2.    gensrc.c Version 3.0 -  © Copyright 1990-91 Jaba Development
  3.  
  4.    Author : Jan van den Baard
  5.    Purpose: What it's all about, the writing of C or Assembler source
  6.  *----------------------------------------------------------------------*/
  7.  
  8. extern struct Window        *MainWindow;
  9. extern struct Screen        *MainScreen;
  10. extern struct FileSelector  *IODir;
  11. extern struct Menu          *MenuStrip;
  12. extern struct ge_prefs       prefs;
  13. extern struct Gadget         TextGadget;
  14. extern struct GadgetList     Gadgets;
  15. extern struct SharedList     Images;
  16. extern struct BorderList     SBorders;
  17. extern ULONG                 WindowFlags, IDCMPFlags;
  18. extern USHORT                BackFill, GadgetCount, WDBackFill;
  19. extern BOOL                  REQUESTER, WBSCREEN;
  20. extern UBYTE                 name[256], wdt[80], wlb[MAXLABEL];
  21.  
  22. extern BOOL                  gen_wd, gen_sc, gen_cl;
  23. extern BOOL                  gen_bo, gen_rt, gen_sg;
  24. extern BOOL                  gen_gd, gen_si, gen_mn;
  25.  
  26. extern UBYTE                 TextLabel[32];
  27. extern UBYTE                 BorderLabel[32];
  28. extern UBYTE                 MenuLabel[32];
  29. extern UBYTE                 SpecialLabel[32];
  30. extern UBYTE                 ScreenLabel[32];
  31. extern UBYTE                 ReqLabel[32];
  32. extern UBYTE                 ColorLabel[32];
  33. extern UBYTE                 ImageLabel[32];
  34. extern UBYTE                 SharedLabel[32];
  35.  
  36. struct GadgetList            Borders;
  37. BOOL                         GenASM, HaveGad, MultyB;
  38.  
  39. /*
  40.  * Get the exact border number.
  41.  */
  42. ULONG SBordPos( register struct Border *b )
  43. {
  44.     register struct SharedBorder    *s;
  45.     register ULONG                   pos = NULL;
  46.  
  47.     for(s = SBorders.Head; s->Border != b; s = s->Succ) {
  48.         if(s->Border->NextBorder) pos += 2;
  49.         else                      pos++;
  50.     }
  51.     return(pos);
  52. }
  53.  
  54. /*
  55.  * split up the normal and 'BORDERONLY' gadgets in seperate lists
  56.  */
  57. static void split( void )
  58. {
  59.     register struct MyGadget *tmp;
  60.  
  61.     if(! Gadgets.Head->Succ) return;
  62.  
  63.     NewList((void *)&Borders);
  64.  
  65.     while(1) {
  66.         tmp = Gadgets.Head;
  67.         while(1) {
  68.             if(TestBits((ULONG)tmp->SpecialFlags,BORDERONLY)) break;
  69.             if(! Gadgets.Head->Succ) return;
  70.             if(NOT (tmp = tmp->Succ)) return;
  71.         }
  72.         Remove((void *)tmp);
  73.         AddHead((void *)&Borders,(void *)tmp);
  74.     }
  75. }
  76.  
  77. /*
  78.  * join the normal and 'BORDERONLY' gadgets again
  79.  */
  80. static void join( void )
  81. {
  82.     register struct MyGadget *tmp;
  83.  
  84.     while((tmp = (struct MyGadget *)RemHead((void *)&Borders)))
  85.          AddTail((void *)&Gadgets,(void *)tmp);
  86. }
  87.  
  88. /*
  89.  * write the IDCMPFlags
  90.  */
  91. static VOID WriteIFlags( BPTR file )
  92. {
  93.     if(NOT IDCMPFlags) {
  94.         if(GenASM) WriteFormat(file,"0");
  95.         else       WriteFormat(file,"NULL");
  96.         return;
  97.     }
  98.     if(TestBits(IDCMPFlags,SIZEVERIFY))     WriteFormat(file,"SIZEVERIFY+");
  99.     if(TestBits(IDCMPFlags,NEWSIZE))        WriteFormat(file,"NEWSIZE+");
  100.     if(TestBits(IDCMPFlags,REFRESHWINDOW))  WriteFormat(file,"REFRESHWINDOW+");
  101.     if(TestBits(IDCMPFlags,ACTIVEWINDOW))   WriteFormat(file,"ACTIVEWINDOW+");
  102.     if(TestBits(IDCMPFlags,INACTIVEWINDOW)) WriteFormat(file,"INACTIVEWINDOW+");
  103.     if(TestBits(IDCMPFlags,GADGETDOWN))     WriteFormat(file,"GADGETDOWN+");
  104.     if(TestBits(IDCMPFlags,GADGETUP))       WriteFormat(file,"GADGETUP+");
  105.     if(TestBits(IDCMPFlags,CLOSEWINDOW))    WriteFormat(file,"CLOSEWINDOW+");
  106.     if(TestBits(IDCMPFlags,REQSET))         WriteFormat(file,"REQSET+");
  107.     if(TestBits(IDCMPFlags,REQCLEAR))       WriteFormat(file,"REQCLEAR+");
  108.     if(TestBits(IDCMPFlags,REQVERIFY))      WriteFormat(file,"REQVERIFY+");
  109.     if(TestBits(IDCMPFlags,MENUPICK))       WriteFormat(file,"MENUPICK+");
  110.     if(TestBits(IDCMPFlags,MENUVERIFY))     WriteFormat(file,"MENUVERIFY+");
  111.     if(TestBits(IDCMPFlags,MOUSEBUTTONS))   WriteFormat(file,"MOUSEBUTTONS+");
  112.     if(TestBits(IDCMPFlags,MOUSEMOVE))      WriteFormat(file,"MOUSEMOVE+");
  113.     if(TestBits(IDCMPFlags,DELTAMOVE))      WriteFormat(file,"DELTAMOVE+");
  114.     if(TestBits(IDCMPFlags,INTUITICKS))     WriteFormat(file,"INTUITICKS+");
  115.     if(TestBits(IDCMPFlags,NEWPREFS))       WriteFormat(file,"NEWPREFS+");
  116.     if(TestBits(IDCMPFlags,DISKINSERTED))   WriteFormat(file,"DISKINSERTED+");
  117.     if(TestBits(IDCMPFlags,DISKREMOVED))    WriteFormat(file,"DISKREMOVED+");
  118.     if(TestBits(IDCMPFlags,RAWKEY))         WriteFormat(file,"RAWKEY+");
  119.     if(TestBits(IDCMPFlags,VANILLAKEY))     WriteFormat(file,"VANILLAKEY+");
  120.     if(TestBits(IDCMPFlags,WBENCHMESSAGE))  WriteFormat(file,"WBENCHMESSAGE+");
  121.     if(TestBits(IDCMPFlags,LONELYMESSAGE))  WriteFormat(file,"LONELYMESSAGE+");
  122.     Seek(file,-1,OFFSET_CURRENT);
  123. }
  124.  
  125. /*
  126.  * write the window flags
  127.  */
  128. static VOID WriteWFlags( BPTR file )
  129. {
  130.     if(NOT WindowFlags) {
  131.         if(GenASM) WriteFormat(file,"0");
  132.         else       WriteFormat(file,"NULL");
  133.         return;
  134.     }
  135.     if(TestBits(WindowFlags,WINDOWSIZING))   WriteFormat(file,"WINDOWSIZING+");
  136.     if(TestBits(WindowFlags,WINDOWDRAG))     WriteFormat(file,"WINDOWDRAG+");
  137.     if(TestBits(WindowFlags,WINDOWDEPTH))    WriteFormat(file,"WINDOWDEPTH+");
  138.     if(TestBits(WindowFlags,WINDOWCLOSE))    WriteFormat(file,"WINDOWCLOSE+");
  139.     if(TestBits(WindowFlags,SIZEBRIGHT))     WriteFormat(file,"SIZEBRIGHT+");
  140.     if(TestBits(WindowFlags,SIZEBBOTTOM))    WriteFormat(file,"SIZEBBOTTOM+");
  141.     if(TestBits(WindowFlags,NOCAREREFRESH))  WriteFormat(file,"NOCAREREFRESH+");
  142.     if(TestBits(WindowFlags,SIMPLE_REFRESH)) WriteFormat(file,"SIMPLE_REFRESH+");
  143.     if(TestBits(WindowFlags,SMART_REFRESH))  WriteFormat(file,"SMART_REFRESH+");
  144.     if(TestBits(WindowFlags,SUPER_BITMAP))   WriteFormat(file,"SUPER_BITMAP+");
  145.     if(TestBits(WindowFlags,BACKDROP))       WriteFormat(file,"BACKDROP+");
  146.     if(TestBits(WindowFlags,GIMMEZEROZERO))  WriteFormat(file,"GIMMEZEROZERO+");
  147.     if(TestBits(WindowFlags,BORDERLESS))     WriteFormat(file,"BORDERLESS+");
  148.     if(TestBits(WindowFlags,ACTIVATE))       WriteFormat(file,"ACTIVATE+");
  149.     if(TestBits(WindowFlags,REPORTMOUSE))    WriteFormat(file,"REPORTMOUSE+");
  150.     if(TestBits(WindowFlags,RMBTRAP))        WriteFormat(file,"RMBTRAP+");
  151.     Seek(file,-1,OFFSET_CURRENT);
  152. }
  153.  
  154. /*
  155.  * write the gadget flags
  156.  */
  157. static VOID WriteFlags( BPTR file, struct MyGadget *gad )
  158. {
  159.     struct Gadget *gadget;
  160.     ULONG          flags;
  161.  
  162.     gadget = &gad->Gadget;
  163.     flags  = (ULONG)gadget->Flags;
  164.  
  165.     if(NOT flags) {
  166.         WriteFormat(file,"GADGHCOMP");
  167.         return;
  168.     }
  169.     if((TestBits(flags,GADGHIMAGE)) AND
  170.        (TestBits(flags,GADGHBOX)))           WriteFormat(file,"GADGHNONE+");
  171.     else if(TestBits(flags,GADGHIMAGE))      WriteFormat(file,"GADGHIMAGE+");
  172.     else if(TestBits(flags,GADGHBOX))        WriteFormat(file,"GADGHBOX+");
  173.     else                                     WriteFormat(file,"GADGHCOMP+");
  174.     if(TestBits(flags,GRELBOTTOM))           WriteFormat(file,"GRELBOTTOM+");
  175.     if(TestBits(flags,GRELRIGHT))            WriteFormat(file,"GRELRIGHT+");
  176.     if(TestBits(flags,GRELWIDTH))            WriteFormat(file,"GRELWIDTH+");
  177.     if(TestBits(flags,GRELHEIGHT))           WriteFormat(file,"GRELHEIGHT+");
  178.     if(TestBits(flags,GADGIMAGE))            WriteFormat(file,"GADGIMAGE+");
  179.     if(TestBits(flags,SELECTED))             WriteFormat(file,"SELECTED+");
  180.     if(TestBits((ULONG)gad->SpecialFlags,GADGETOFF)) WriteFormat(file,"GADGDISABLED+");
  181.     Seek(file,-1,OFFSET_CURRENT);
  182. }
  183.  
  184. /*
  185.  * write the activation gadget flags
  186.  */
  187. static VOID WriteActivation( BPTR file, struct MyGadget *gad )
  188. {
  189.     struct Gadget   *gadget;
  190.     ULONG            act;
  191.  
  192.     gadget = &gad->Gadget;
  193.     act    = (ULONG)gadget->Activation;
  194.  
  195.     if(TestBits(act,TOGGLESELECT))      WriteFormat(file,"TOGGLESELECT+");
  196.     if(NOT TestBits(gad->SpecialFlags,NOSIGNAL)) {
  197.         if(TestBits(act,RELVERIFY))     WriteFormat(file,"RELVERIFY+");
  198.         if(TestBits(act,GADGIMMEDIATE)) WriteFormat(file,"GADGIMMEDIATE+");
  199.     }
  200.     if(TestBits(act,RIGHTBORDER))       WriteFormat(file,"RIGHTBORDER+");
  201.     if(TestBits(act,LEFTBORDER))        WriteFormat(file,"LEFTBORDER+");
  202.     if(TestBits(act,TOPBORDER))         WriteFormat(file,"TOPBORDER+");
  203.     if(TestBits(act,BOTTOMBORDER))      WriteFormat(file,"BOTTOMBORDER+");
  204.     if(TestBits(act,STRINGCENTER))      WriteFormat(file,"STRINGCENTER+");
  205.     if(TestBits(act,STRINGRIGHT))       WriteFormat(file,"STRINGRIGHT+");
  206.     if(TestBits(act,LONGINT))           WriteFormat(file,"LONGINT+");
  207.     if(TestBits(act,ALTKEYMAP))         WriteFormat(file,"ALTKEYMAP+");
  208.     if(TestBits(act,BOOLEXTEND))        WriteFormat(file,"BOOLEXTEND+");
  209.     if(TestBits(act,ENDGADGET))         WriteFormat(file,"ENDGADGET+");
  210.     if(TestBits(act,FOLLOWMOUSE))       WriteFormat(file,"FOLLOWMOUSE+");
  211.     Seek(file,-1,OFFSET_CURRENT);
  212. }
  213.  
  214. /*
  215.  * write the gadget type
  216.  */
  217. static VOID WriteType( BPTR file, struct MyGadget *gad )
  218. {
  219.     struct Gadget   *gadget;
  220.     ULONG            type;
  221.  
  222.     gadget = &gad->Gadget;
  223.     type   = (ULONG)gadget->GadgetType;
  224.  
  225.     if(TestBits(type,PROPGADGET))      WriteFormat(file,"PROPGADGET+");
  226.     else if(TestBits(type,STRGADGET))  WriteFormat(file,"STRGADGET+");
  227.     else if(TestBits(type,BOOLGADGET)) WriteFormat(file,"BOOLGADGET+");
  228.     if(TestBits((ULONG)gad->SpecialFlags,GZZGADGET)) WriteFormat(file,"GZZGADGET+");
  229.     if(REQUESTER)                      WriteFormat(file,"REQGADGET+");
  230.     Seek(file,-1,OFFSET_CURRENT);
  231. }
  232.  
  233. /*
  234.  * write the draw modes
  235.  */
  236. VOID WriteDrMd( BPTR file, ULONG drmd, LONG mode )
  237. {
  238.     if(TestBits(drmd,JAM2)) {
  239.         if(mode) WriteFormat(file,"RP_JAM2+");
  240.         else     WriteFormat(file,"JAM2+");
  241.     } else if(TestBits(drmd,JAM1)) {
  242.         if(mode) WriteFormat(file,"RP_JAM1+");
  243.         else     WriteFormat(file,"JAM1+");
  244.     }
  245.  
  246.     if(TestBits(drmd,COMPLEMENT)) {
  247.         if(mode) WriteFormat(file,"RP_COMPLEMENT+");
  248.         else     WriteFormat(file,"COMPLEMENT+");
  249.     }
  250.  
  251.     if(TestBits(drmd,INVERSVID)) {
  252.         if(mode) WriteFormat(file,"RP_INVERSVID+");
  253.         else     WriteFormat(file,"INVERSVID+");
  254.     }
  255.     Seek(file,-1,OFFSET_CURRENT);
  256. }
  257.  
  258. /*
  259.  * write the propinfo flags
  260.  */
  261. static VOID WritePFlags( BPTR file, struct PropInfo *info )
  262. {
  263.     ULONG flags;
  264.  
  265.     flags = (ULONG)info->Flags;
  266.  
  267.     if(TestBits(flags,AUTOKNOB))       WriteFormat(file,"AUTOKNOB+");
  268.     if(TestBits(flags,FREEHORIZ))      WriteFormat(file,"FREEHORIZ+");
  269.     if(TestBits(flags,FREEVERT))       WriteFormat(file,"FREEVERT+");
  270.     if(TestBits(flags,PROPBORDERLESS)) WriteFormat(file,"PROPBORDERLESS+");
  271.     Seek(file,-1,OFFSET_CURRENT);
  272. }
  273.  
  274. #define RAWINC  prefs.no_flags
  275.  
  276. /*
  277.  * write the assembler image
  278.  */
  279. static VOID WriteAsmImage( BPTR file, struct Image *image, ULONG account )
  280. {
  281.     register USHORT *data;
  282.     register USHORT  i,ii;
  283.     ULONG            data_size;
  284.  
  285.     data  = image->ImageData;
  286.  
  287.     WriteFormat(file,"%sData%ld:\n",&ImageLabel[0],account);
  288.     data_size = (RASSIZE(image->Width,image->Height) * image->Depth);
  289.  
  290.     for( i = 0 ; i < (data_size >> 1) ; i+=8) {
  291.         WriteFormat(file,"    DC.W    ");
  292.         for( ii = 0; ii < 8; ii++) {
  293.             if(i+ii < (data_size >> 1))
  294.                 WriteFormat(file,"$%04lx,",data[i+ii]);
  295.         }
  296.         Seek(file,-1,OFFSET_CURRENT);
  297.         WriteFormat(file,"\n");
  298.     }
  299.     WriteFormat(file,"\n");
  300.  
  301.     WriteFormat(file,"%s%ld:\n",&ImageLabel[0],account);
  302.     WriteFormat(file,"    DC.W    %ld,%ld\n",image->LeftEdge,image->TopEdge);
  303.     WriteFormat(file,"    DC.W    %ld,%ld\n",image->Width,image->Height);
  304.     WriteFormat(file,"    DC.W    %ld\n",image->Depth);
  305.     WriteFormat(file,"    DC.L    %sData%ld\n",&ImageLabel[0],account);
  306.     WriteFormat(file,"    DC.B    $%02lx\n",image->PlanePick);
  307.     WriteFormat(file,"    DC.B    $%02lx\n",image->PlaneOnOff);
  308.     WriteFormat(file,"    DC.L    0\n\n");
  309. }
  310.  
  311. /*
  312.  * write the assembler prop info structure
  313.  */
  314. static VOID WriteAsmPinfo( BPTR file, struct MyGadget *gadget )
  315. {
  316.     struct PropInfo *info;
  317.  
  318.     info = (struct PropInfo *)gadget->Gadget.SpecialInfo;
  319.     WriteFormat(file,"%s_info:\n",&gadget->GadgetLabel);
  320.     WriteFormat(file,"    DC.W    ");
  321.  
  322.     if(RAWINC) WriteFormat(file,"$%04lx",info->Flags);
  323.     else       WritePFlags(file,info);
  324.  
  325.     WriteFormat(file,"\n    DC.W    $%04lx\n",info->HorizPot);
  326.     WriteFormat(file,"    DC.W    $%04lx\n",info->VertPot);
  327.     WriteFormat(file,"    DC.W    $%04lx\n",info->HorizBody);
  328.     WriteFormat(file,"    DC.W    $%04lx\n",info->VertBody);
  329.     WriteFormat(file,"    DC.W    0,0,0,0,0,0\n\n");
  330. }
  331.  
  332. /*
  333.  * write the assembler string info structure
  334.  */
  335. static VOID WriteAsmSinfo( BPTR file, struct MyGadget *gadget )
  336. {
  337.     struct StringInfo *info;
  338.  
  339.     info = (struct StringInfo *)gadget->Gadget.SpecialInfo;
  340.     WriteFormat(file,"%s_info:\n",&gadget->GadgetLabel);
  341.     WriteFormat(file,"    DC.L    %s_buf\n",&gadget->GadgetLabel);
  342.  
  343.     if(info->UndoBuffer) WriteFormat(file,"    DC.L    %s_ubuf\n",&gadget->GadgetLabel);
  344.     else                 WriteFormat(file,"    DC.L    0\n");
  345.  
  346.     WriteFormat(file,"    DC.W    0,%ld\n",info->MaxChars);
  347.     WriteFormat(file,"    DC.W    0,0,0,0,0,0\n");
  348.     WriteFormat(file,"    DC.L    0,0,0\n\n");
  349.     WriteFormat(file,"%s_buf:\n",&gadget->GadgetLabel);
  350.  
  351.     if(strlen(info->Buffer)) {
  352.         WriteFormat(file,"    DC.B    '%s',0\n",info->Buffer);
  353.         WriteFormat(file,"    DCB.B   %ld,0\n",info->MaxChars - strlen((char *)info->Buffer) -1);
  354.     } else
  355.         WriteFormat(file,"    DCB.B   %ld\n",info->MaxChars);
  356.     WriteFormat(file,"    CNOP    0,2\n\n");
  357.  
  358.     if(info->UndoBuffer) {
  359.         WriteFormat(file,"%s_ubuf:\n    DCB.B    %ld,0\n",&gadget->GadgetLabel,info->MaxChars);
  360.         WriteFormat(file,"    CNOP    0,2\n\n");
  361.     }
  362. }
  363.  
  364. /*
  365.  * write the assembler gadget structure
  366.  */
  367. static VOID WriteAsmGadget( BPTR file, struct MyGadget *gadget )
  368. {
  369.     struct Gadget   *gad;
  370.     struct MyGadget *next;
  371.  
  372.     gad = &gadget->Gadget;
  373.  
  374.     WriteFormat(file,"%s_ID   EQU     %ld\n\n",&gadget->GadgetLabel,gad->GadgetID);
  375.     WriteFormat(file,"%s:\n",&gadget->GadgetLabel);
  376.  
  377.     if(gadget == Gadgets.Head) {
  378.         if((TextGadget.GadgetText) OR Borders.Head->Succ) {
  379.             if(NOT REQUESTER) {
  380.                 if(gen_sg AND (gen_bo OR gen_rt))
  381.                     WriteFormat(file,"    DC.L    %s\n",&SpecialLabel[0]);
  382.                 else
  383.                     WriteFormat(file,"    DC.L    0\n");
  384.             } else
  385.                 WriteFormat(file,"    DC.L    0\n");
  386.         } else
  387.             WriteFormat(file,"    DC.L    0\n");
  388.     } else
  389.         WriteFormat(file,"    DC.L    %s\n",&(gadget->Pred->GadgetLabel));
  390.  
  391.     WriteFormat(file,"    DC.W    %ld,%ld\n",gad->LeftEdge,gad->TopEdge);
  392.     WriteFormat(file,"    DC.W    %ld,%ld\n",gad->Width,gad->Height);
  393.     WriteFormat(file,"    DC.W    ");
  394.  
  395.     if(RAWINC) WriteFormat(file,"$%04lx",gad->Flags);
  396.     else       WriteFlags(file,gadget);
  397.  
  398.     WriteFormat(file,"\n    DC.W    ");
  399.  
  400.     if(RAWINC) WriteFormat(file,"$%04lx",gad->Activation);
  401.     else       WriteActivation(file,gadget);
  402.  
  403.     WriteFormat(file,"\n    DC.W    ");
  404.  
  405.     if(RAWINC) WriteFormat(file,"$%04lx",gad->GadgetType);
  406.     else       WriteType(file,gadget);
  407.  
  408.     if(TestBits((ULONG)gad->Flags,GADGIMAGE))
  409.         WriteFormat(file,"\n    DC.L    %s%ld\n",&ImageLabel[0],bank_account(gad->GadgetRender));
  410.     else if(TestBits((ULONG)gad->GadgetType,PROPGADGET))
  411.         WriteFormat(file,"\n    DC.L    %s_image\n",&gadget->GadgetLabel);
  412.     else if(NOT TestBits((ULONG)gadget->SpecialFlags,NOBORDER))
  413.         WriteFormat(file,"\n    DC.L    %s%ld\n",&SharedLabel[0],SBordPos((struct Border *)gadget->Gadget.GadgetRender));
  414.     else
  415.         WriteFormat(file,"\n    DC.L    0\n");
  416.  
  417.     if((TestBits((ULONG)gad->Flags,GADGHIMAGE)) AND
  418.        (NOT TestBits((ULONG)gad->Flags,GADGHBOX)) AND
  419.        (NOT TestBits((ULONG)gadget->SpecialFlags,OS20HIGHBORDER)))
  420.         WriteFormat(file,"    DC.L    %s%ld\n",&ImageLabel[0],bank_account(gad->SelectRender));
  421.     else if(TestBits((ULONG)gadget->SpecialFlags,OS20HIGHBORDER))
  422.         WriteFormat(file,"    DC.L    %s%ld\n",&SharedLabel[0],SBordPos((struct Border *)gadget->Gadget.SelectRender));
  423.     else
  424.         WriteFormat(file,"    DC.L    0\n");
  425.  
  426.     if(gad->GadgetText)
  427.         WriteFormat(file,"    DC.L    %s_text0,0\n",&gadget->GadgetLabel);
  428.     else
  429.         WriteFormat(file,"    DC.L    0,0\n");
  430.  
  431.     if(gad->SpecialInfo)
  432.         WriteFormat(file,"    DC.L    %s_info\n",&gadget->GadgetLabel);
  433.     else
  434.         WriteFormat(file,"    DC.L    0\n");
  435.  
  436.     WriteFormat(file,"    DC.W    %s_ID\n    DC.L    0\n\n",&gadget->GadgetLabel);
  437. }
  438.  
  439. /*
  440.  * write the assembler IntuitText structures
  441.  */
  442. static VOID WriteAsmTexts( BPTR file, struct MyGadget *gadget )
  443. {
  444.     register struct IntuiText *itext;
  445.     register UWORD             i=0;
  446.  
  447.     if((itext = gadget->Gadget.GadgetText)) {
  448.         WriteFormat(file,"%s_text%ld:\n",&gadget->GadgetLabel,i);
  449.         while(1) {
  450.             WriteFormat(file,"    DC.B    %ld,%ld\n",itext->FrontPen,itext->BackPen);
  451.             WriteFormat(file,"    DC.B    ");
  452.  
  453.             if(RAWINC) WriteFormat(file,"$%02lx",itext->DrawMode);
  454.             else       WriteDrMd(file,itext->DrawMode,TRUE);
  455.  
  456.             WriteFormat(file,"\n    DC.W    %ld,%ld\n",itext->LeftEdge,itext->TopEdge);
  457.             WriteFormat(file,"    DC.L    0\n");
  458.             WriteFormat(file,"    DC.L    %s_itext%ld\n",&gadget->GadgetLabel,i);
  459.  
  460.             if(itext->NextText) WriteFormat(file,"    DC.L    %s_text%ld\n\n",&gadget->GadgetLabel,i+1);
  461.             else                WriteFormat(file,"    DC.L    0\n\n");
  462.  
  463.             WriteFormat(file,"%s_itext%ld:\n",&gadget->GadgetLabel,i++);
  464.             WriteFormat(file,"    DC.B    '%s',0\n",itext->IText);
  465.             WriteFormat(file,"    CNOP    0,2\n\n");
  466.  
  467.             if(!(itext = itext->NextText)) break;
  468.             WriteFormat(file,"%s_text%ld\n",&gadget->GadgetLabel,i);
  469.         }
  470.     }
  471. }
  472.  
  473. /*
  474.  * write the assembler new screen structure
  475.  */
  476. static VOID WriteAsmScreen( BPTR file )
  477. {
  478.     WriteFormat(file,"%s:\n",&ScreenLabel[0]);
  479.     WriteFormat(file,"    DC.W    0,0,%ld,%ld\n",MainScreen->Width,MainScreen->Height);
  480.     WriteFormat(file,"    DC.W    %ld\n",MainScreen->BitMap.Depth);
  481.     WriteFormat(file,"    DC.B    -1,-1\n");
  482.  
  483.     if(MainScreen->BitMap.Depth == 5) WriteFormat(file,"    DC.W    0\n");
  484.     else {
  485.         if(RAWINC) WriteFormat(file,"    DC.W    $8000\n");
  486.         else       WriteFormat(file,"    DC.W    V_HIRES\n");
  487.     }
  488.  
  489.     if(RAWINC) WriteFormat(file,"    DC.W    $0001\n");
  490.     else       WriteFormat(file,"    DC.W    CUSTOMSCREEN\n");
  491.  
  492.     WriteFormat(file,"    DC.L    0,0,0,0\n\n");
  493. }
  494.  
  495. /*
  496.  * write the assembler window/requester structure
  497.  */
  498. static VOID WriteAsmRW( BPTR file )
  499. {
  500.     if(REQUESTER) {
  501.         WriteFormat(file,"%s:\n    DC.L    0\n",&ReqLabel[0]);
  502.         WriteFormat(file,"    DC.W    %ld,%ld,",(MainWindow->LeftEdge + MainWindow->BorderLeft),
  503.                                                 (MainWindow->TopEdge + MainWindow->BorderTop));
  504.         WriteFormat(file,"%ld,%ld\n",MainWindow->GZZWidth,MainWindow->GZZHeight);
  505.  
  506.         if(HaveGad AND gen_gd)
  507.             WriteFormat(file,"    DC.W    0,0\n    DC.L    %s,",&Gadgets.TailPred->GadgetLabel);
  508.         else
  509.             WriteFormat(file,"    DC.W    0,0\n    DC.L    0");
  510.  
  511.         if(Borders.Head->Succ AND gen_bo)
  512.             WriteFormat(file,"%s0\n",&BorderLabel[0]);
  513.         else
  514.             WriteFormat(file,"0\n");
  515.  
  516.         if(TextGadget.GadgetText AND gen_rt)
  517.             WriteFormat(file,"    DC.L    %s0\n",&TextLabel[0]);
  518.         else
  519.             WriteFormat(file,"    DC.L    0\n");
  520.  
  521.         WriteFormat(file,"    DC.W    0\n    DC.B    %ld\n",BackFill);
  522.         WriteFormat(file,"    DC.L    0\n    DCB.B   32,0\n    DC.L    0,0\n    DCB.B    36,0\n\n");
  523.     } else {
  524.         WriteFormat(file,"%s:\n",&wlb);
  525.         WriteFormat(file,"    DC.W    %ld,%ld,%ld,%ld\n",MainWindow->LeftEdge,MainWindow->TopEdge,
  526.                                                          MainWindow->Width,MainWindow->Height);
  527.         WriteFormat(file,"    DC.B    %ld,%ld\n",MainWindow->DetailPen,MainWindow->BlockPen);
  528.         WriteFormat(file,"    DC.L    ");
  529.  
  530.         if(RAWINC) WriteFormat(file,"$%08lx",IDCMPFlags);
  531.         else       WriteIFlags(file);
  532.  
  533.         WriteFormat(file,"\n    DC.L    ");
  534.  
  535.         if(RAWINC) WriteFormat(file,"$%08lx",WindowFlags);
  536.         else       WriteWFlags(file);
  537.  
  538.         WriteFormat(file,"\n");
  539.  
  540.         if(HaveGad AND gen_gd)
  541.             WriteFormat(file,"    DC.L    %s,0\n",Gadgets.TailPred->GadgetLabel);
  542.         else if(Borders.Head->Succ OR TextGadget.GadgetText) {
  543.             if(gen_sg AND (gen_bo OR gen_rt))
  544.                 WriteFormat(file,"    DC.L    %s,0\n",&SpecialLabel[0]);
  545.             else
  546.                 WriteFormat(file,"    DC.L    0,0\n");
  547.         } else
  548.             WriteFormat(file,"    DC.L    0,0\n");
  549.  
  550.         if(strlen((char *)&wdt))
  551.             WriteFormat(file,"    DC.L    %s_title\n",&wlb);
  552.         else
  553.             WriteFormat(file,"    DC.L    0\n");
  554.  
  555.         WriteFormat(file,"    DC.L    0,0\n");
  556.         WriteFormat(file,"    DC.W    %ld,%ld,%ld,%ld,",MainWindow->MinWidth,
  557.                                                         MainWindow->MinHeight,
  558.                                                         MainWindow->MaxWidth,
  559.                                                         MainWindow->MaxHeight);
  560.         if(WBSCREEN) {
  561.             if(RAWINC) WriteFormat(file,"$0001\n\n");
  562.             else       WriteFormat(file,"WBENCHSCREEN\n\n");
  563.         } else {
  564.             if(RAWINC) WriteFormat(file,"$000F\n\n");
  565.             else       WriteFormat(file,"CUSTOMSCREEN\n\n");
  566.         }
  567.  
  568.         if(strlen((char *)&wdt))
  569.             WriteFormat(file,"%s_title:\n    DC.B    '%s',0\n    CNOP    0,2\n\n",&wlb,&wdt);
  570.     }
  571. }
  572.  
  573. /*
  574.  * write the assembler window/requester texts
  575.  */
  576. static VOID WriteAsmWDT( BPTR file )
  577. {
  578.     register struct IntuiText *t, *t1;
  579.     register USHORT            i = 0;
  580.  
  581.     if(NOT TextGadget.GadgetText) return;
  582.  
  583.     t = t1 = TextGadget.GadgetText;
  584.     WriteFormat(file,"%s%ld:\n",&TextLabel[0],i);
  585.  
  586.     while(1) {
  587.         WriteFormat(file,"    DC.B    %ld,%ld\n",t->FrontPen,t->BackPen);
  588.         WriteFormat(file,"    DC.B    ");
  589.  
  590.         if(RAWINC) WriteFormat(file,"$%02lx",t->DrawMode);
  591.         else       WriteDrMd(file,t->DrawMode,TRUE);
  592.  
  593.         WriteFormat(file,"\n    DC.W    %ld,%ld\n",t->LeftEdge,t->TopEdge);
  594.         WriteFormat(file,"    DC.L    0\n");
  595.         WriteFormat(file,"    DC.L    %sIText%ld\n",&TextLabel[0],i);
  596.  
  597.         if(t->NextText)
  598.             WriteFormat(file,"    DC.L    %s%ld\n\n",&TextLabel[0],i+1);
  599.         else
  600.             WriteFormat(file,"    DC.L    0\n\n");
  601.  
  602.         WriteFormat(file,"%sIText%ld:\n",&TextLabel[0],i++);
  603.         WriteFormat(file,"    DC.B    '%s',0\n",t->IText);
  604.         WriteFormat(file,"    CNOP    0,2\n\n");
  605.  
  606.         if(!(t = t->NextText)) break;
  607.  
  608.         WriteFormat(file,"%s%ld\n",&TextLabel[0],i);
  609.     }
  610. }
  611.  
  612. /*
  613.  * write assembler special render gadget
  614.  */
  615. static VOID WriteAsmCRG( BPTR file )
  616. {
  617.     if(TextGadget.GadgetText OR Borders.Head->Succ) {
  618.         if(NOT REQUESTER) {
  619.             WriteFormat(file,"%s:\n",&SpecialLabel[0]);
  620.  
  621.             if(RAWINC) WriteFormat(file,"    DC.L    0\n    DC.W    0,0,1,1,$0003,0,$0001\n");
  622.             else       WriteFormat(file,"    DC.L    0\n    DC.W    0,0,1,1,GADGHNONE,0,BOOLGADGET\n");
  623.  
  624.             if(Borders.Head->Succ AND gen_bo)
  625.                  WriteFormat(file,"    DC.L    %s0,",&BorderLabel[0]);
  626.             else
  627.                  WriteFormat(file,"    DC.L    0,");
  628.  
  629.             if(TextGadget.GadgetText AND gen_rt)
  630.                 WriteFormat(file,"0,%s0,",&TextLabel[0]);
  631.             else
  632.                 WriteFormat(file,"0,0,");
  633.  
  634.             WriteFormat(file,"0,0\n    DC.W    0\n    DC.L    0\n\n");
  635.        }
  636.     }
  637. }
  638.  
  639. /*
  640.  * write the assembler border structures
  641.  */
  642. static VOID WriteAsmB( BPTR file )
  643. {
  644.     register struct MyGadget *g;
  645.     register struct Border   *b;
  646.     register SHORT           *xy;
  647.     register UCOUNT           bc = 0,xyc;
  648.  
  649.     if(NOT Borders.Head->Succ) return;
  650.  
  651.     for( g = Borders.Head; g->Succ; g = g->Succ) {
  652.         b = (struct Border *)g->Gadget.GadgetRender;
  653.         while(1) {
  654.             xy = b->XY;
  655.             WriteFormat(file,"%sPairs%ld:\n    DC.W   ",&BorderLabel[0],bc);
  656.  
  657.             for(xyc = 0;xyc < (b->Count << 1); xyc++)
  658.                 WriteFormat(file,"%ld,",xy[xyc]);
  659.  
  660.             Seek(file,-1,OFFSET_CURRENT);
  661.             WriteFormat(file,"\n");
  662.             bc++;
  663.             if(!(b = b->NextBorder)) break;
  664.         }
  665.     }
  666.     WriteFormat(file,"\n");
  667.  
  668.     bc = 0;
  669.  
  670.     for(g = Borders.Head; g->Succ; g = g->Succ) {
  671.         b = (struct Border *)g->Gadget.GadgetRender;
  672.         while(1) {
  673.             WriteFormat(file,"%s%ld:\n",&BorderLabel[0],bc);
  674.             WriteFormat(file,"    DC.W    %ld,%ld\n",g->Gadget.LeftEdge,g->Gadget.TopEdge);
  675.  
  676.             if(RAWINC) WriteFormat(file,"    DC.B    %ld,0\n    DC.B    $00,%ld\n",b->FrontPen,b->Count);
  677.             else       WriteFormat(file,"    DC.B    %ld,0\n    DC.B    RP_JAM1,%ld\n",b->FrontPen,b->Count);
  678.  
  679.             WriteFormat(file,"    DC.L    %sPairs%ld,",&BorderLabel[0],bc);
  680.             bc++;
  681.             if(!(b = b->NextBorder)) {
  682.                 if(NOT g->Succ->Succ)
  683.                     WriteFormat(file,"0\n\n");
  684.                 else
  685.                     WriteFormat(file,"%s%ld\n\n",&BorderLabel[0],bc);
  686.                 break;
  687.             } else
  688.                 WriteFormat(file,"%s%ld\n\n",&BorderLabel[0],bc);
  689.         }
  690.     }
  691. }
  692.  
  693. /*
  694.  * Write the Image Bank in Assembler.
  695.  */
  696. static VOID WriteAsmBank( BPTR file )
  697. {
  698.     struct SharedImage  *sim;
  699.     struct Image        *image;
  700.  
  701.     if(NOT Images.Head->Succ) return;
  702.  
  703.     WriteFormat(file,"* IMAGE DATA MUST BE LOCATED IN CHIP MEMORY!!!\n\n");
  704.  
  705.     for(sim = Images.Head; sim->Succ; sim = sim->Succ) {
  706.         if(sim->UseCount)
  707.             WriteAsmImage(file,sim->Image,bank_account(sim->Image));
  708.     }
  709. }
  710.  
  711.  
  712. /*
  713.  * write the assembler shared border structures
  714.  */
  715. static VOID WriteAsmSB( BPTR file )
  716. {
  717.     register struct SharedBorder *s;
  718.     register struct Border       *b;
  719.     register SHORT               *xy;
  720.     register UCOUNT               bc = 0,pc = 0,xyc;
  721.     BOOL                          sr = FALSE;
  722.  
  723.     if(NOT SBorders.Head->Succ)  return;
  724.  
  725.     for(s = SBorders.Head; s->Succ; s = s->Succ) {
  726.         b = s->Border;
  727.         while(1) {
  728.             if(NOT TestBits((ULONG)s->SpecialFlags,SB_HIGHBORDER)) {
  729.                 xy = b->XY;
  730.                 WriteFormat(file,"%sPairs%ld:\n    DC.W    ",&SharedLabel[0],bc);
  731.  
  732.                 for(xyc = 0;xyc < (b->Count << 1); xyc++)
  733.                     WriteFormat(file,"%ld,",xy[xyc]);
  734.  
  735.                 Seek(file,-1,OFFSET_CURRENT);
  736.                 WriteFormat(file,"\n");
  737.                 bc++;
  738.                 if(!(b = b->NextBorder)) break;
  739.             } else
  740.                 break;
  741.         }
  742.     }
  743.     WriteFormat(file,"\n");
  744.  
  745.     bc = 0;
  746.  
  747.     for(s = SBorders.Head; s->Succ; s = s->Succ) {
  748.         b = s->Border;
  749.         while(1) {
  750.             WriteFormat(file,"%s%ld:\n",&SharedLabel[0],bc);
  751.             WriteFormat(file,"    DC.W    %ld,%ld\n",b->LeftEdge,b->TopEdge);
  752.  
  753.             if(RAWINC) WriteFormat(file,"    DC.B    %ld,0\n    DC.B    $00,%ld\n",b->FrontPen,b->Count);
  754.             else       WriteFormat(file,"    DC.B    %ld,0\n    DC.B    RP_JAM1,%ld\n",b->FrontPen,b->Count);
  755.  
  756.             if(TestBits((ULONG)s->SpecialFlags,SB_HIGHBORDER)) {
  757.                 if(NOT sr) pc -= 2;
  758.                 sr = TRUE;
  759.             }
  760.  
  761.             WriteFormat(file,"    DC.L    %sPairs%ld,",&SharedLabel[0],pc);
  762.             bc++;
  763.             pc++;
  764.             if(!(b = b->NextBorder)) {
  765.                 WriteFormat(file,"0\n\n");
  766.                 break;
  767.             } else
  768.                 WriteFormat(file,"%s%ld\n\n",&SharedLabel[0],bc);
  769.         }
  770.         sr = FALSE;
  771.     }
  772. }
  773.  
  774. /*
  775.  * write the assembler source code
  776.  */
  777. void WriteAsmGadgets( void )
  778. {
  779.     register struct MyGadget *gadget;
  780.     struct ColorMap          *cm;
  781.     USHORT                   *tab, cc, i, ii;
  782.     char                     *str;
  783.     ULONG                     rc, hg;
  784.     BPTR                      file;
  785.  
  786.     GenASM  = TRUE;
  787.     HaveGad = is_gadget();
  788.  
  789.     strcpy((char *)IODir->fr_HeadLine,"Save Asm Source");
  790.  
  791.     IODir->fr_Screen  = MainScreen;
  792.     IODir->fr_Caller  = MainWindow;
  793.  
  794.     IODir->fr_Flags  |= FR_NoInfo;
  795.  
  796.     rc = FileRequest(IODir);
  797.  
  798.     strcpy((char *)&name,(char *)IODir->fr_DirName);
  799.     strcat((char *)&name,(char *)IODir->fr_FileName);
  800.  
  801.     if(rc == FREQ_CANCELED) return;
  802.     else if(rc) {
  803.         Error("FileRequester won't open !");
  804.         return;
  805.     }
  806.  
  807.     cm  = MainScreen->ViewPort.ColorMap;
  808.     tab = (USHORT *)cm->ColorTable;
  809.  
  810.     if(NOT (file = Open((char *)&name,MODE_NEWFILE))) {
  811.         Error("Can't Open Write File !");
  812.         return;
  813.     }
  814.  
  815.     SetWindowTitles(MainWindow,(char *)-1L,(char *)"Saving Assembler Source.....");
  816.     buisy();
  817.     disable_window();
  818.     un_gzz();
  819.     cc = (1 << MainScreen->BitMap.Depth);
  820.  
  821.     WriteFormat(file,"*---------------------------------------------------\n");
  822.     WriteFormat(file,"* Gadgets created with PowerSource V3.0\n");
  823.     WriteFormat(file,"* which is (c) Copyright 1990-91 by Jaba Development\n");
  824.     WriteFormat(file,"* written by Jan van den Baard\n");
  825.     WriteFormat(file,"*---------------------------------------------------\n\n");
  826.  
  827.     if(NOT WBSCREEN AND gen_cl) {
  828.         WriteFormat(file,"%s:\n",&ColorLabel[0]);
  829.         for( ii = 0; ii < cc; ii += 8) {
  830.             WriteFormat(file,"    DC.W    ");
  831.             for( i = 0; i < 8; i++) {
  832.                 if((ii+i) < cc)
  833.                     WriteFormat(file,"$%04lx,",tab[ii+i]);
  834.             }
  835.             Seek(file,-1,OFFSET_CURRENT);
  836.             WriteFormat(file,"\n");
  837.         }
  838.         WriteFormat(file,"\n");
  839.     }
  840.  
  841.     split();
  842.  
  843.     if(gen_gd)                        WriteAsmBank(file);
  844.     if(gen_bo)                        WriteAsmB(file);
  845.     if(gen_gd)                        WriteAsmSB(file);
  846.     if(gen_rt)                        WriteAsmWDT(file);
  847.     if(gen_sg AND (gen_bo OR gen_rt)) WriteAsmCRG(file);
  848.  
  849.     if(HaveGad AND gen_gd) {
  850.         for(gadget = Gadgets.Head; gadget->Succ; gadget = gadget->Succ) {
  851.             if(TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET)) {
  852.                 WriteAsmPinfo(file,gadget);
  853.                 if(NOT TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE)) {
  854.                     WriteFormat(file,"%s_image:\n",&gadget->GadgetLabel);
  855.                     WriteFormat(file,"    DC.W    0,0,0,0,0\n    DC.L    0\n    DC.B    0,0\n    DC.L    0\n\n");
  856.                 }
  857.             }
  858.  
  859.             if(TestBits((ULONG)gadget->Gadget.GadgetType,STRGADGET))
  860.                 WriteAsmSinfo(file,gadget);
  861.  
  862.             if(gadget->Gadget.GadgetText)
  863.                 WriteAsmTexts(file,gadget);
  864.  
  865.             WriteAsmGadget(file,gadget);
  866.  
  867.             if(str = IoErrToStr()) {
  868.                 enable_window();
  869.                 ok();
  870.                 Close(file);
  871.                 Error(str);
  872.                 DeleteFile((char *)&name[0]);
  873.                 join();
  874.                 do_gzz();
  875.                 goto error;
  876.             }
  877.         }
  878.     }
  879.  
  880.     if(MenuStrip AND gen_mn) WriteAsmMenus(file);
  881.  
  882.     gadget = Gadgets.TailPred;
  883.  
  884.     if(NOT WBSCREEN AND gen_sc) WriteAsmScreen(file);
  885.     if(gen_wd)                  WriteAsmRW(file);
  886.  
  887.     if(gen_si) {
  888.         if(NOT WBSCREEN AND gen_cl) {
  889.             WriteFormat(file,"\nCOLORCOUNT   EQU    %ld",cc);
  890.             WriteFormat(file,"\nCOLORMAP:    DC.L   %s",&ColorLabel[0]);
  891.         }
  892.  
  893.         if(NOT REQUESTER AND gen_wd) {
  894.             WriteFormat(file,"\nNEWWINDOW:   DC.L   %s",&wlb);
  895.             WriteFormat(file,"\nWDBACKFILL   EQU    %ld",WDBackFill);
  896.         } else if(gen_wd)
  897.             WriteFormat(file,"\nREQUESTER:   DC.L   %s",&ReqLabel[0]);
  898.  
  899.         if(NOT WBSCREEN AND gen_sc)
  900.             WriteFormat(file,"\nNEWSCREEN:   DC.L   %s",&ScreenLabel[0]);
  901.         if(HaveGad AND gen_gd)
  902.             WriteFormat(file,"\nFIRSTGADGET: DC.L   %s",&Gadgets.TailPred->GadgetLabel);
  903.         if(TextGadget.GadgetText AND gen_rt)
  904.             WriteFormat(file,"\nFIRSTTEXT:   DC.L   %s0",&TextLabel[0]);
  905.         if(Borders.Head->Succ AND gen_bo)
  906.             WriteFormat(file,"\nFIRSTBORDER: DC.L   %s0",&BorderLabel[0]);
  907.         if(MenuStrip AND gen_mn)
  908.             WriteFormat(file,"\nFIRSTMENU:   DC.L   %s0",&MenuLabel[0]);
  909.     }
  910.     WriteFormat(file,"\n\n");
  911.  
  912.     if(str = IoErrToStr()) {
  913.         enable_window();
  914.         ok();
  915.         Error(str);
  916.         Close(file);
  917.         DeleteFile((char *)&name[0]);
  918.         join();
  919.         do_gzz();
  920.         goto error;
  921.     }
  922.  
  923.     join();
  924.     do_gzz();
  925.     Close(file);
  926.     enable_window();
  927.     ok();
  928. error:
  929.     refresh();
  930.     return;
  931. }
  932.  
  933. #define STAT    prefs.static_structures
  934.  
  935. /*
  936.  * write the C image structure
  937.  */
  938. static VOID WriteCImage( BPTR file, struct Image *image, ULONG account)
  939. {
  940.     register USHORT       *data, i, ii;
  941.     ULONG                  data_size;
  942.  
  943.     data  = image->ImageData;
  944.  
  945.     if(STAT) WriteFormat(file,"static ");
  946.  
  947.     WriteFormat(file,"USHORT %sData%ld[] = {\n",&ImageLabel[0],account);
  948.     data_size = (RASSIZE(image->Width,image->Height) * image->Depth);
  949.  
  950.     for( i = 0; i < (data_size >> 1); i += 8) {
  951.         for(ii = 0; ii < 8; ii++) {
  952.             if(i+ii < (data_size >> 1))
  953.                 WriteFormat(file,"  0x%04lx,",data[i+ii]);
  954.         }
  955.         WriteFormat(file,"\n");
  956.     }
  957.     Seek(file,-2,OFFSET_CURRENT);
  958.     WriteFormat(file," }; \n\n");
  959.  
  960.     if(STAT) WriteFormat(file,"static ");
  961.  
  962.     WriteFormat(file,"struct Image %s%ld = {\n",&ImageLabel[0],account);
  963.     WriteFormat(file,"  %ld,%ld,",image->LeftEdge,image->TopEdge);
  964.     WriteFormat(file,"%ld,%ld,",image->Width,image->Height);
  965.     WriteFormat(file,"%ld,",image->Depth);
  966.     WriteFormat(file,"(USHORT *)&%sData%ld[0],",&ImageLabel[0],account);
  967.     WriteFormat(file,"0x%02lx,",image->PlanePick);
  968.     WriteFormat(file,"0x%02lx,",image->PlaneOnOff);
  969.     WriteFormat(file,"NULL };\n\n");
  970. }
  971.  
  972. /*
  973.  * write the C PropInfo structure
  974.  */
  975. static VOID WriteCPinfo( BPTR file, struct MyGadget *gadget )
  976. {
  977.     struct PropInfo *info;
  978.  
  979.     info = (struct PropInfo *)gadget->Gadget.SpecialInfo;
  980.  
  981.     if(STAT) WriteFormat(file,"static ");
  982.  
  983.     WriteFormat(file,"struct PropInfo %s_info = {\n  ",&gadget->GadgetLabel);
  984.     WritePFlags(file,info);
  985.     WriteFormat(file,",0x%04lx,",info->HorizPot);
  986.     WriteFormat(file,"0x%04lx,",info->VertPot);
  987.     WriteFormat(file,"0x%04lx,",info->HorizBody);
  988.     WriteFormat(file,"0x%04lx,",info->VertBody);
  989.     WriteFormat(file,"0,0,0,0,0,0 };\n\n");
  990. }
  991.  
  992. /*
  993.  * write the C StringInfo structure
  994.  */
  995. static VOID WriteCSinfo( BPTR file, struct MyGadget *gadget )
  996. {
  997.     struct StringInfo *info;
  998.  
  999.     info = (struct StringInfo *)gadget->Gadget.SpecialInfo;
  1000.  
  1001.     if(STAT) WriteFormat(file,"static ");
  1002.  
  1003.     if(strlen(info->Buffer))
  1004.         WriteFormat(file,"UBYTE %s_buf[%ld] = %lc%s%lc;\n\n",&gadget->GadgetLabel,
  1005.                                                              info->MaxChars,'"',
  1006.                                                              info->Buffer,'"');
  1007.     else
  1008.         WriteFormat(file,"UBYTE %s_buf[%ld];\n\n",&gadget->GadgetLabel,info->MaxChars);
  1009.  
  1010.     if(info->UndoBuffer) {
  1011.         if(STAT) WriteFormat(file,"static ");
  1012.  
  1013.         WriteFormat(file,"UBYTE %s_ubuf[%ld];\n\n",&gadget->GadgetLabel,info->MaxChars);
  1014.     }
  1015.  
  1016.     if(STAT) WriteFormat(file,"static ");
  1017.  
  1018.     WriteFormat(file,"struct StringInfo %s_info = {\n",&gadget->GadgetLabel);
  1019.     WriteFormat(file,"  (UBYTE *)&%s_buf[0],",&gadget->GadgetLabel);
  1020.  
  1021.     if(info->UndoBuffer)
  1022.        WriteFormat(file,"(UBYTE *)&%s_ubuf[0],",&gadget->GadgetLabel);
  1023.     else
  1024.        WriteFormat(file,"NULL,");
  1025.  
  1026.     WriteFormat(file,"0,%ld,",info->MaxChars);
  1027.     WriteFormat(file,"0,0,0,0,0,0,");
  1028.     WriteFormat(file,"NULL,NULL,NULL };\n\n");
  1029. }
  1030.  
  1031.  
  1032. /*
  1033.  * write the C Gadget structure
  1034.  */
  1035. static VOID WriteCGadget( BPTR file, struct MyGadget *gadget )
  1036. {
  1037.     struct Gadget    *gad;
  1038.     struct MyGadget  *next;
  1039.     struct IntuiText *itext;
  1040.  
  1041.     gad = &gadget->Gadget;
  1042.  
  1043.     WriteFormat(file,"#define %s_ID    %ld\n\n",&gadget->GadgetLabel,gad->GadgetID);
  1044.  
  1045.     if(STAT) WriteFormat(file,"static ");
  1046.  
  1047.     WriteFormat(file,"struct Gadget %s = {\n  ",&gadget->GadgetLabel);
  1048.  
  1049.     if(gadget == Gadgets.Head) {
  1050.         if(NOT REQUESTER) {
  1051.             if(TextGadget.GadgetText OR Borders.Head->Succ) {
  1052.                 if(gen_sg AND (gen_bo OR gen_rt))
  1053.                     WriteFormat(file,"&%s,",&SpecialLabel[0]);
  1054.                 else
  1055.                     WriteFormat(file,"NULL,");
  1056.             } else
  1057.                 WriteFormat(file,"NULL,");
  1058.         } else
  1059.             WriteFormat(file,"NULL,");
  1060.     } else
  1061.         WriteFormat(file,"&%s,",&(gadget->Pred->GadgetLabel));
  1062.  
  1063.     WriteFormat(file,"%ld,%ld,",gad->LeftEdge,gad->TopEdge);
  1064.     WriteFormat(file,"%ld,%ld,\n  ",gad->Width,gad->Height);
  1065.     WriteFlags(file,gadget);
  1066.     WriteFormat(file,",\n  ");
  1067.     WriteActivation(file,gadget);
  1068.     WriteFormat(file,",\n  ");
  1069.     WriteType(file,gadget);
  1070.  
  1071.     if(TestBits((ULONG)gad->Flags,GADGIMAGE))
  1072.         WriteFormat(file,",\n  (APTR)&%s%ld,",&ImageLabel[0],bank_account(gad->GadgetRender));
  1073.     else if(TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET))
  1074.         WriteFormat(file,",\n  (APTR)&%s_image,",&gadget->GadgetLabel);
  1075.     else if(NOT TestBits((ULONG)gadget->SpecialFlags,NOBORDER))
  1076.         WriteFormat(file,",\n  (APTR)&%s[%ld],",&SharedLabel[0],SBordPos((struct Border *)gadget->Gadget.GadgetRender));
  1077.     else
  1078.         WriteFormat(file,",\n  NULL,");
  1079.  
  1080.     if((TestBits((ULONG)gad->Flags,GADGHIMAGE)) AND
  1081.        (NOT TestBits((ULONG)gad->Flags,GADGHBOX)) AND
  1082.        (NOT TestBits((ULONG)gadget->SpecialFlags,OS20HIGHBORDER)))
  1083.         WriteFormat(file,"(APTR)&%s%ld,\n  ",&ImageLabel[0],bank_account(gad->SelectRender));
  1084.     else if(TestBits((ULONG)gadget->SpecialFlags,OS20HIGHBORDER))
  1085.         WriteFormat(file,"(APTR)&%s[%ld],\n  ",&SharedLabel[0],SBordPos((struct Border *)gadget->Gadget.SelectRender));
  1086.     else
  1087.         WriteFormat(file,"NULL,\n  ");
  1088.  
  1089.     if((itext = gad->GadgetText)) {
  1090.         if(itext->NextText)
  1091.             WriteFormat(file,"&%s_text[0],NULL,",&gadget->GadgetLabel);
  1092.         else
  1093.             WriteFormat(file,"&%s_text,NULL,",&gadget->GadgetLabel);
  1094.     }
  1095.     else
  1096.         WriteFormat(file,"NULL,NULL,");
  1097.  
  1098.     if(gad->SpecialInfo)
  1099.         WriteFormat(file,"(APTR)&%s_info,",&gadget->GadgetLabel);
  1100.     else
  1101.         WriteFormat(file,"NULL,");
  1102.  
  1103.     WriteFormat(file,"%s_ID,NULL };\n\n",&gadget->GadgetLabel);
  1104. }
  1105.  
  1106. /*
  1107.  * write the C IntuiText structures
  1108.  */
  1109. static VOID WriteCTexts( BPTR file, struct MyGadget *gadget )
  1110. {
  1111.     register struct IntuiText *itext;
  1112.     register USHORT            i=1;
  1113.  
  1114.     if((itext = gadget->Gadget.GadgetText)) {
  1115.         if(STAT) WriteFormat(file,"static ");
  1116.  
  1117.         if(itext->NextText)
  1118.             WriteFormat(file,"struct IntuiText %s_text[] = {\n",&gadget->GadgetLabel);
  1119.         else
  1120.             WriteFormat(file,"struct IntuiText %s_text = {\n",&gadget->GadgetLabel);
  1121.  
  1122.         while(1) {
  1123.             WriteFormat(file,"  %ld,%ld,",itext->FrontPen,itext->BackPen);
  1124.             WriteDrMd(file,itext->DrawMode,FALSE);
  1125.             WriteFormat(file,",%ld,%ld,NULL,",itext->LeftEdge,itext->TopEdge);
  1126.             WriteFormat(file,"(UBYTE *)%lc%s%lc,",'"',itext->IText,'"');
  1127.             if(itext->NextText)
  1128.                 WriteFormat(file,"&%s_text[%ld],\n",&gadget->GadgetLabel,i++);
  1129.             else
  1130.                 WriteFormat(file,"NULL");
  1131.  
  1132.             if(!(itext = itext->NextText)) break;
  1133.        }
  1134.        WriteFormat(file," };\n\n");
  1135.     }
  1136. }
  1137.  
  1138. /*
  1139.  * write the C NewScreen structure
  1140.  */
  1141. static VOID WriteCScreen( BPTR file )
  1142. {
  1143.     if(STAT) WriteFormat(file,"static ");
  1144.  
  1145.     WriteFormat(file,"struct NewScreen %s = {\n",&ScreenLabel[0]);
  1146.     WriteFormat(file,"  0,0,%ld,%ld,",MainScreen->Width,MainScreen->Height);
  1147.     WriteFormat(file,"%ld,",MainScreen->BitMap.Depth);
  1148.     WriteFormat(file,"-1,-1,");
  1149.  
  1150.     if(MainScreen->BitMap.Depth == 5) WriteFormat(file,"NULL,");
  1151.     else                              WriteFormat(file,"HIRES,");
  1152.  
  1153.     WriteFormat(file,"CUSTOMSCREEN,NULL,NULL,NULL,NULL };\n\n");
  1154. }
  1155.  
  1156. /*
  1157.  * write the C window/requester structure
  1158.  */
  1159. static VOID WriteCRW( BPTR file )
  1160. {
  1161.     struct IntuiText *t;
  1162.  
  1163.     if(REQUESTER) {
  1164.         if(STAT) WriteFormat(file,"static ");
  1165.  
  1166.         WriteFormat(file,"struct Requester %s = {\n  NULL,",&ReqLabel[0]);
  1167.         WriteFormat(file,"%ld,%ld,",(MainWindow->LeftEdge + MainWindow->BorderLeft),
  1168.                                     (MainWindow->TopEdge + MainWindow->BorderTop));
  1169.         WriteFormat(file,"%ld,%ld,",MainWindow->GZZWidth,MainWindow->GZZHeight);
  1170.  
  1171.         if(HaveGad AND gen_gd)
  1172.             WriteFormat(file,"0,0,&%s,",&Gadgets.TailPred->GadgetLabel);
  1173.         else
  1174.             WriteFormat(file,"0,0,NULL,");
  1175.  
  1176.         if(Borders.Head->Succ AND gen_bo) {
  1177.             if(MultyB)
  1178.                 WriteFormat(file,"&%s[0],",&BorderLabel[0]);
  1179.             else
  1180.                 WriteFormat(file,"&%s,",&BorderLabel[0]);
  1181.         }
  1182.         else
  1183.             WriteFormat(file,"NULL,");
  1184.  
  1185.         if((t = TextGadget.GadgetText) AND gen_rt) {
  1186.             if(t->NextText) WriteFormat(file,"&%s[0],",&TextLabel[0]);
  1187.             else            WriteFormat(file,"&%s,",&TextLabel[0]);
  1188.         }
  1189.         else
  1190.             WriteFormat(file,"NULL,");
  1191.  
  1192.         WriteFormat(file,"NULL,%ld,",BackFill);
  1193.         WriteFormat(file,"NULL,NULL,NULL,NULL,NULL };\n\n");
  1194.     } else {
  1195.         if(STAT) WriteFormat(file,"static ");
  1196.  
  1197.         WriteFormat(file,"struct NewWindow %s = {\n  ",&wlb);
  1198.         WriteFormat(file,"%ld,%ld,%ld,%ld,",MainWindow->LeftEdge,MainWindow->TopEdge,
  1199.                                             MainWindow->Width,MainWindow->Height);
  1200.         WriteFormat(file,"%ld,%ld,\n  ",MainWindow->DetailPen,MainWindow->BlockPen);
  1201.         WriteIFlags(file);
  1202.         WriteFormat(file,",\n  ");
  1203.         WriteWFlags(file);
  1204.         WriteFormat(file,",\n");
  1205.  
  1206.         if(HaveGad AND gen_gd)
  1207.             WriteFormat(file,"  &%s,NULL,\n",Gadgets.TailPred->GadgetLabel);
  1208.         else if(Borders.Head->Succ OR TextGadget.GadgetText) {
  1209.             if(gen_sg AND (gen_bo OR gen_rt))
  1210.                 WriteFormat(file,"  &%s,NULL,\n",&SpecialLabel[0]);
  1211.             else
  1212.                 WriteFormat(file,"  NULL,NULL,\n");
  1213.         } else
  1214.             WriteFormat(file,"  NULL,NULL,\n");
  1215.  
  1216.         if(strlen((char *)&wdt))
  1217.             WriteFormat(file,"  (UBYTE *)%lc%s%lc,NULL,NULL,\n",'"',&wdt,'"');
  1218.         else
  1219.             WriteFormat(file,"  NULL,NULL,NULL,\n");
  1220.  
  1221.         WriteFormat(file,"  %ld,%ld,%ld,%ld,",MainWindow->MinWidth,
  1222.                                               MainWindow->MinHeight,
  1223.                                               MainWindow->MaxWidth,
  1224.                                               MainWindow->MaxHeight);
  1225.  
  1226.         if(WBSCREEN) WriteFormat(file,"WBENCHSCREEN };\n\n");
  1227.         else         WriteFormat(file,"CUSTOMSCREEN };\n\n");
  1228.     }
  1229. }
  1230.  
  1231. /*
  1232.  * write the C window/requester texts structures
  1233.  */
  1234. static VOID WriteCWDT( BPTR file )
  1235. {
  1236.     register struct IntuiText *t, *t1;
  1237.     register USHORT            i = 1;
  1238.  
  1239.     if(NOT TextGadget.GadgetText) return;
  1240.  
  1241.     t = TextGadget.GadgetText;
  1242.  
  1243.     if(STAT) WriteFormat(file,"static ");
  1244.  
  1245.     if(t->NextText)
  1246.         WriteFormat(file,"struct IntuiText %s[] = {\n  ",&TextLabel[0]);
  1247.     else
  1248.         WriteFormat(file,"struct IntuiText %s = {\n  ",&TextLabel[0]);
  1249.  
  1250.     while(1) {
  1251.         WriteFormat(file,"%ld,%ld,",t->FrontPen,t->BackPen);
  1252.         WriteDrMd(file,t->DrawMode,FALSE);
  1253.         WriteFormat(file,",%ld,%ld,NULL,",t->LeftEdge,t->TopEdge);
  1254.         WriteFormat(file,"(UBYTE *)%lc%s%lc,",'"',t->IText,'"');
  1255.  
  1256.         if(t->NextText)
  1257.             WriteFormat(file,"&%s[%ld],\n  ",&TextLabel[0],i++);
  1258.         else
  1259.             WriteFormat(file,"NULL");
  1260.  
  1261.         if(!(t = t->NextText)) break;
  1262.     }
  1263.     WriteFormat(file," };\n\n");
  1264. }
  1265.  
  1266. /*
  1267.  * write the C special render gadget
  1268.  */
  1269. static VOID WriteCRG( BPTR file )
  1270. {
  1271.     struct IntuiText *t;
  1272.  
  1273.     if(TextGadget.GadgetText OR Borders.Head->Succ) {
  1274.         if(NOT REQUESTER) {
  1275.             if(STAT) WriteFormat(file,"static ");
  1276.  
  1277.             WriteFormat(file,"struct Gadget %s = {\n  ",&SpecialLabel[0]);
  1278.             WriteFormat(file,"NULL,0,0,1,1,GADGHNONE,NULL,BOOLGADGET,\n");
  1279.  
  1280.             if(Borders.Head->Succ AND gen_bo) {
  1281.                 if(MultyB)
  1282.                     WriteFormat(file,"  (APTR)&%s[0],NULL,",&BorderLabel[0]);
  1283.                 else
  1284.                     WriteFormat(file,"  (APTR)&%s,NULL,",&BorderLabel[0]);
  1285.             }
  1286.             else
  1287.                 WriteFormat(file,"  NULL,NULL,");
  1288.  
  1289.             if((t = TextGadget.GadgetText) AND gen_rt) {
  1290.                 if(t->NextText) WriteFormat(file,"&%s[0],",&TextLabel[0]);
  1291.                 else            WriteFormat(file,"&%s,",&TextLabel[0]);
  1292.             }
  1293.             else
  1294.                 WriteFormat(file,"NULL,");
  1295.  
  1296.             WriteFormat(file,"NULL,NULL,NULL,NULL };\n\n");
  1297.         }
  1298.     }
  1299. }
  1300.  
  1301. /*
  1302.  * write the C border structures
  1303.  */
  1304. static VOID WriteCB( BPTR file )
  1305. {
  1306.     register struct MyGadget *g;
  1307.     register struct Border   *b;
  1308.     register SHORT           *xy;
  1309.     register UCOUNT           bc = 0,xyc;
  1310.  
  1311.     if(NOT Borders.Head->Succ) return;
  1312.  
  1313.     for(g = Borders.Head; g->Succ; g = g->Succ) {
  1314.         b = (struct Border *)g->Gadget.GadgetRender;
  1315.         while(1) {
  1316.             if(STAT) WriteFormat(file,"static ");
  1317.  
  1318.             xy = b->XY;
  1319.             WriteFormat(file,"SHORT %sPairs%ld[] = {\n  ",&BorderLabel[0],bc);
  1320.  
  1321.             for(xyc = 0;xyc < (b->Count << 1); xyc++)
  1322.                 WriteFormat(file,"%ld,",xy[xyc]);
  1323.  
  1324.             Seek(file,-1,OFFSET_CURRENT);
  1325.             WriteFormat(file," };\n");
  1326.             bc++;
  1327.  
  1328.             if(!(b = b->NextBorder)) break;
  1329.         }
  1330.     }
  1331.     WriteFormat(file,"\n");
  1332.  
  1333.     bc = 0;
  1334.  
  1335.     if(STAT) WriteFormat(file,"static ");
  1336.  
  1337.     if(b->NextBorder OR g->Succ) {
  1338.         WriteFormat(file,"struct Border %s[] = {\n",&BorderLabel[0]);
  1339.         MultyB = TRUE;
  1340.     } else {
  1341.         WriteFormat(file,"struct Border %s = {\n",&BorderLabel[0]);
  1342.         MultyB = FALSE;
  1343.     }
  1344.  
  1345.     for(g = Borders.Head; g->Succ; g = g->Succ) {
  1346.         b = (struct Border *)g->Gadget.GadgetRender;
  1347.         while(1) {
  1348.             WriteFormat(file,"  %ld,%ld,",g->Gadget.LeftEdge,g->Gadget.TopEdge);
  1349.             WriteFormat(file,"%ld,0,JAM1,%ld,",b->FrontPen,b->Count);
  1350.             WriteFormat(file,"(SHORT *)&%sPairs%ld[0],",&BorderLabel[0],bc);
  1351.             bc++;
  1352.  
  1353.             if(!(b = b->NextBorder)) {
  1354.                 if(g->Succ == (struct MyGadget *)&Borders.Tail)
  1355.                     WriteFormat(file,"NULL };\n\n");
  1356.                 else
  1357.                     WriteFormat(file,"&%s[%ld],\n",&BorderLabel[0],bc);
  1358.                 break;
  1359.             }
  1360.             else
  1361.                 WriteFormat(file,"&%s[%ld],\n",&BorderLabel[0],bc);
  1362.         }
  1363.     }
  1364. }
  1365.  
  1366. /*
  1367.  * write the C shared border structures
  1368.  */
  1369. static VOID WriteCSB( BPTR file )
  1370. {
  1371.     register struct SharedBorder *s;
  1372.     register struct Border       *b;
  1373.     register SHORT               *xy;
  1374.     register UCOUNT               bc = 0,pc = 0,xyc;
  1375.     BOOL                          sr = FALSE;
  1376.  
  1377.     if(NOT SBorders.Head->Succ)  return;
  1378.  
  1379.     for(s = SBorders.Head; s->Succ; s = s->Succ) {
  1380.         b = s->Border;
  1381.         while(1) {
  1382.             if(NOT TestBits((ULONG)s->SpecialFlags,SB_HIGHBORDER)) {
  1383.                 if(STAT) WriteFormat(file,"static ");
  1384.  
  1385.                 xy = b->XY;
  1386.                 WriteFormat(file,"SHORT %sPairs%ld[] = {\n  ",&SharedLabel[0],bc);
  1387.  
  1388.                 for(xyc = 0;xyc < (b->Count << 1); xyc++)
  1389.                     WriteFormat(file,"%ld,",xy[xyc]);
  1390.  
  1391.                 Seek(file,-1,OFFSET_CURRENT);
  1392.                 WriteFormat(file," };\n");
  1393.                 bc++;
  1394.  
  1395.                 if(!(b = b->NextBorder)) break;
  1396.             } else
  1397.                 break;
  1398.         }
  1399.     }
  1400.     WriteFormat(file,"\n");
  1401.  
  1402.     bc = 0;
  1403.  
  1404.     if(STAT) WriteFormat(file,"static ");
  1405.  
  1406.     WriteFormat(file,"struct Border %s[] = {\n",&SharedLabel[0]);
  1407.  
  1408.     for(s = SBorders.Head; s->Succ; s = s->Succ) {
  1409.         b = s->Border;
  1410.         while(1) {
  1411.             WriteFormat(file,"  %ld,%ld,",b->LeftEdge,b->TopEdge);
  1412.             WriteFormat(file,"%ld,0,JAM1,%ld,",b->FrontPen,b->Count);
  1413.  
  1414.             if(TestBits((ULONG)s->SpecialFlags,SB_HIGHBORDER)) {
  1415.                 if(NOT sr) pc -= 2;
  1416.                 sr = TRUE;
  1417.             }
  1418.  
  1419.             WriteFormat(file,"(SHORT *)&%sPairs%ld[0],",&SharedLabel[0],pc);
  1420.             bc++;
  1421.             pc++;
  1422.  
  1423.             if(!(b = b->NextBorder)) {
  1424.                 WriteFormat(file,"NULL,\n");
  1425.                 break;
  1426.             } else
  1427.                 WriteFormat(file,"&%s[%ld],\n",&SharedLabel[0],bc);
  1428.         }
  1429.         sr = FALSE;
  1430.     }
  1431.     Seek(file,-2,OFFSET_CURRENT);
  1432.     WriteFormat(file," };\n\n");
  1433. }
  1434.  
  1435. /*
  1436.  * Write the Image Bank in C.
  1437.  */
  1438. static VOID WriteCBank( BPTR file )
  1439. {
  1440.     struct SharedImage  *sim;
  1441.     struct Image        *image;
  1442.  
  1443.     if(NOT Images.Head->Succ) return;
  1444.  
  1445.     WriteFormat(file,"/* IMAGE DATA MUST BE LOCATED IN CHIP MEMORY!!! */\n\n");
  1446.  
  1447.     for(sim = Images.Head; sim->Succ; sim = sim->Succ) {
  1448.         if(sim->UseCount)
  1449.             WriteCImage(file,sim->Image,bank_account(sim->Image));
  1450.     }
  1451. }
  1452.  
  1453. /*
  1454.  * write the C source code
  1455.  */
  1456. void  WriteCGadgets( void )
  1457. {
  1458.     register struct MyGadget *gadget;
  1459.     struct ColorMap          *cm;
  1460.     USHORT                   *tab, cc, i, ii;
  1461.     char                     *str;
  1462.     BPTR                      file;
  1463.     ULONG                     rc;
  1464.  
  1465.     GenASM  = FALSE;
  1466.     HaveGad = is_gadget();
  1467.  
  1468.     strcpy((char *)IODir->fr_HeadLine,"Save C Source");
  1469.  
  1470.     IODir->fr_Screen  = MainScreen;
  1471.     IODir->fr_Caller  = MainWindow;
  1472.  
  1473.     IODir->fr_Flags  |= FR_NoInfo;
  1474.  
  1475.     rc = FileRequest(IODir);
  1476.  
  1477.     strcpy((char *)&name,(char *)IODir->fr_DirName);
  1478.     strcat((char *)&name,(char *)IODir->fr_FileName);
  1479.  
  1480.     if(rc == FREQ_CANCELED) return;
  1481.     else if(rc) {
  1482.         Error("FileRequester won't open !");
  1483.         return;
  1484.     }
  1485.  
  1486.     cm  = MainScreen->ViewPort.ColorMap;
  1487.     tab = (USHORT *)cm->ColorTable;
  1488.  
  1489.     if(NOT (file = Open((char *)&name,MODE_NEWFILE))) {
  1490.         Error("Can't open write file !");
  1491.         return;
  1492.     }
  1493.  
  1494.     SetWindowTitles(MainWindow,(char *)-1L,(char *)"Saving C Source.....");
  1495.     buisy();
  1496.     disable_window();
  1497.     un_gzz();
  1498.  
  1499.     cc = (1 << MainScreen->BitMap.Depth);
  1500.  
  1501.     WriteFormat(file,"/*---------------------------------------------------*\n");
  1502.     WriteFormat(file,"  Gadgets created with PowerSource V3.0\n");
  1503.     WriteFormat(file,"  which is (c) Copyright 1990-91 by Jaba Development\n");
  1504.     WriteFormat(file,"  written by Jan van den Baard\n");
  1505.     WriteFormat(file," *---------------------------------------------------*/\n\n");
  1506.  
  1507.     if(NOT WBSCREEN AND gen_cl) {
  1508.         if(STAT) WriteFormat(file,"static ");
  1509.  
  1510.         WriteFormat(file,"USHORT %s[] = {\n",&ColorLabel[0]);
  1511.         for(ii = 0; ii < cc; ii +=8) {
  1512.             for(i = 0; i < 8; i++) {
  1513.                 if((ii+i) < cc)
  1514.                     WriteFormat(file,"  0x%04lx,",tab[ii+i]);
  1515.             }
  1516.             WriteFormat(file,"\n");
  1517.         }
  1518.         Seek(file,-2,OFFSET_CURRENT);
  1519.         WriteFormat(file," };\n\n");
  1520.     }
  1521.  
  1522.     split();
  1523.  
  1524.     if(gen_gd)                        WriteCBank(file);
  1525.     if(gen_bo)                        WriteCB(file);
  1526.     if(gen_gd)                        WriteCSB(file);
  1527.     if(gen_rt)                        WriteCWDT(file);
  1528.     if(gen_sg AND (gen_bo OR gen_rt)) WriteCRG(file);
  1529.  
  1530.     if(HaveGad AND gen_gd) {
  1531.         for(gadget = Gadgets.Head; gadget->Succ; gadget = gadget->Succ) {
  1532.             if(TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET)) {
  1533.                 WriteCPinfo(file,gadget);
  1534.                 if(NOT TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE)) {
  1535.                     if(STAT) WriteFormat(file,"static ");
  1536.  
  1537.                     WriteFormat(file,"struct Image %s_image;\n\n",&gadget->GadgetLabel);
  1538.                 }
  1539.             }
  1540.  
  1541.             if(TestBits((ULONG)gadget->Gadget.GadgetType,STRGADGET))
  1542.                 WriteCSinfo(file,gadget);
  1543.  
  1544.             if(gadget->Gadget.GadgetText)
  1545.                 WriteCTexts(file,gadget);
  1546.  
  1547.             WriteCGadget(file,gadget);
  1548.  
  1549.             if(str = IoErrToStr()) {
  1550.                 Close(file);
  1551.                 enable_window();
  1552.                 ok();
  1553.                 Error(str);
  1554.                 DeleteFile((char *)&name[0]);
  1555.                 join();
  1556.                 do_gzz();
  1557.                 goto error;
  1558.             }
  1559.         }
  1560.     }
  1561.  
  1562.     if(MenuStrip AND gen_mn) WriteCMenus(file);
  1563.  
  1564.     gadget = Gadgets.TailPred;
  1565.  
  1566.     if(NOT WBSCREEN AND gen_sc) WriteCScreen(file);
  1567.     if(gen_wd)                  WriteCRW(file);
  1568.  
  1569.     if(gen_si) {
  1570.         if(NOT WBSCREEN AND gen_cl) {
  1571.             WriteFormat(file,"\n#define COLORCOUNT  %ld",cc);
  1572.             WriteFormat(file,"\n#define COLORMAP    &%s[0]",&ColorLabel[0]);
  1573.         }
  1574.  
  1575.         if(NOT REQUESTER AND gen_wd) {
  1576.             WriteFormat(file,"\n#define NEWWINDOW   &%s",&wlb);
  1577.             WriteFormat(file,"\n#define WDBACKFILL  %ld",WDBackFill);
  1578.         } else if(gen_wd)
  1579.             WriteFormat(file,"\n#define REQUESTER   &%s",&ReqLabel[0]);
  1580.  
  1581.         if(NOT WBSCREEN AND gen_sc)
  1582.             WriteFormat(file,"\n#define NEWSCREEN   &%s",&ScreenLabel[0]);
  1583.         if(HaveGad AND gen_gd)
  1584.             WriteFormat(file,"\n#define FIRSTGADGET &%s",&Gadgets.TailPred->GadgetLabel);
  1585.         if(TextGadget.GadgetText AND gen_rt) {
  1586.             WriteFormat(file,"\n#define FIRSTTEXT   &");
  1587.             if(TextGadget.GadgetText->NextText)
  1588.                 WriteFormat(file,"%s[0]",&TextLabel[0]);
  1589.             else
  1590.                 WriteFormat(file,"%s",&TextLabel[0]);
  1591.         }
  1592.         if(Borders.Head->Succ AND gen_bo) {
  1593.             WriteFormat(file,"\n#define FIRSTBORDER &");
  1594.             if(MultyB)
  1595.                 WriteFormat(file,"%s[0]",&BorderLabel[0]);
  1596.             else
  1597.                 WriteFormat(file,"%s",&BorderLabel[0]);
  1598.         }
  1599.         if(MenuStrip AND gen_mn)
  1600.             WriteFormat(file,"\n#define FIRSTMENU   &%s[0]",&MenuLabel[0]);
  1601.     }
  1602.     WriteFormat(file,"\n\n");
  1603.     if(str = IoErrToStr()) {
  1604.         enable_window();
  1605.         ok();
  1606.         Error(str);
  1607.         Close(file);
  1608.         DeleteFile((char *)&name[0]);
  1609.         join();
  1610.         do_gzz();
  1611.         goto error;
  1612.     }
  1613.  
  1614.     Close(file);
  1615.     join();
  1616.     do_gzz();
  1617.     enable_window();
  1618.     ok();
  1619. error:
  1620.     refresh();
  1621.     return;
  1622. }
  1623.