home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gui / IEdit231.lha / IEditor / Developer / Generators / C / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-18  |  32.1 KB  |  1,142 lines

  1. /*
  2. **
  3. **    C.generator - Copyright © 1996 Simone Tellini
  4. **                  All Rights Reserved
  5. **
  6. **    This is the standard C generator. You can easily modify this
  7. **    source to adapt it to your own needs.
  8. **
  9. **    You can spread modified copies of this code, provided that you
  10. **    respect these rules:
  11. **    - you MUST leave my name in it; if someone has modified the
  12. **      code before you, you MUST leave his name too
  13. **    - you MUST distribute the new generator in a small archive
  14. **      along with a little doc
  15. **    - the new generator should be FREEWARE, it can NOT be SHAREWARE
  16. **    - you should send me an e-mail telling me what kind of changes
  17. **      you've performed and the name of the archive
  18. **
  19. **
  20. */
  21.  
  22. /// Includes
  23. #define INTUI_V36_NAMES_ONLY
  24.  
  25. #include <exec/types.h>                 // exec
  26. #include <exec/lists.h>
  27. #include <exec/memory.h>
  28. #include <exec/nodes.h>
  29. #include <dos/dos.h>                    // dos
  30. #include <dos/dostags.h>
  31. #include <intuition/intuition.h>        // intuition
  32. #include <intuition/gadgetclass.h>
  33. #include <graphics/text.h>              // graphics
  34. #include <libraries/gadtools.h>         // libraries
  35. #include <libraries/reqtools.h>
  36. #include <clib/exec_protos.h>           // protos
  37. #include <clib/dos_protos.h>
  38. #include <clib/intuition_protos.h>
  39. #include <clib/reqtools_protos.h>
  40. #include <pragmas/exec_pragmas.h>       // pragmas
  41. #include <pragmas/dos_pragmas.h>
  42. #include <pragmas/intuition_pragmas.h>
  43. #include <pragmas/graphics_pragmas.h>
  44. #include <pragmas/gadtools_pragmas.h>
  45. #include <pragmas/reqtools_pragmas.h>
  46.  
  47. #include <string.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <ctype.h>
  51.  
  52. #include "DEV_IE:Generators/defs.h"
  53. #include "DEV_IE:Include/IEditor.h"
  54. #include "DEV_IE:Generators/C/Protos.h"
  55. ///
  56. /// Data
  57. struct CPrefs   Prefs = {
  58.         INTUIMSG | CLICKED | IDCMP_HANDLER | KEY_HANDLER | TO_LOWER,
  59.         0,
  60.         "UWORD __chip",
  61.         "",
  62.         "%s __saveds __asm",
  63.         "register __a%ld stuff"
  64. };
  65.  
  66. ULONG idcmps[] = {
  67.         1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200,
  68.         0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
  69.         0x10000, 0x20000, 0x40000, 0x80000, 0x100000,
  70.         0x200000, 0x400000, 0x800000, 0x1000000,
  71.         0x2000000, 0x4000000
  72.       };
  73.  
  74. ULONG wflgs[] = {
  75.         1, 2, 4, 8, 0x10, 0x20, 0, 0x40, 0x80, 0x100, 0x200,
  76.         0x400, 0x800, 0x1000, 0x10000, 0x20000, 0x40000,
  77.         0x200000
  78.       };
  79.  
  80. UBYTE Header[] =
  81.     "/*\n"
  82.     "    C source code created by Interface Editor\n"
  83.     "    Copyright © 1994-1996 by Simone Tellini\n\n"
  84.     "    Generator:  %s\n"
  85.     "    Copy registered to :  %s\n"
  86.     "    Serial Number      : #%ld\n"
  87.     "*/\n\n";
  88.  
  89. UBYTE   Null[] = "NULL";
  90.  
  91. static UBYTE   ARexxHandleArray[] = "\n"
  92.               "void HandleRexxMsg( void )\n"
  93.               "{\n"
  94.               "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
  95.               "\tWORD\t\tn;\n"
  96.               "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
  97.               "\tstruct RexxMsg\t*RxMsg;\n"
  98.               "\tUBYTE\t\tbuffer[1024], command[256];\n"
  99.               "\tUBYTE\t\t*arguments;\n"
  100.               "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
  101.               "\n"
  102.               "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
  103.               "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
  104.               "\t\t\tif( RxMsg->rm_Args[15] )\n"
  105.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
  106.               "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
  107.               "\t\t\tDeleteRexxMsg( RxMsg );\n"
  108.               "\t\t\tRX_Unconfirmed -= 1;\n"
  109.               "\t\t}\n"
  110.               "\t\telse {\n\n"
  111.               "\t\t\tRxMsg->rm_Result1 = NULL;\n"
  112.               "\t\t\tRxMsg->rm_Result2 = NULL;\n"
  113.               "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
  114.               "\n"
  115.               "\t\t\tn = 0;\n"
  116.               "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
  117.               "\t\t\t\tcommand[n] = buffer[n];\n"
  118.               "\t\t\t\tn++;\n"
  119.               "\t\t\t};\n"
  120.               "\t\t\tcommand[n] = '\\0';\n\n"
  121.               "\t\t\tn = 0;\n"
  122.               "\t\t\twhile( CmdTable[n].command ) {\n"
  123.               "\t\t\t\tif( stricmp( CmdTable[n].command, command ) == 0 ) {\n"
  124.               "\t\t\t\t\tfound = TRUE;\n"
  125.               "\t\t\t\t\tbreak;\n"
  126.               "\t\t\t\t} else\n"
  127.               "\t\t\t\t\tn++;\n"
  128.               "\t\t\t};\n\n"
  129.               "\t\t\tif( found ) {\n"
  130.               "\t\t\t\tif( CmdTable[n].template ) {\n"
  131.               "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
  132.               "\t\t\t\t\t\targuments = buffer + strlen( CmdTable[n].command );\n\n"
  133.               "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
  134.               "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
  135.               "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
  136.               "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
  137.               "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
  138.               "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
  139.               "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
  140.               "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
  141.               "\n"
  142.               "\t\t\t\t\t\tif( rdargs = ReadArgs( CmdTable[n].template, ArgArray, args )) {\n\n"
  143.               "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n"
  144.               "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
  145.               "\t\t\t\t\t\t} else\n"
  146.               "\t\t\t\t\t\t\tfail = TRUE;\n\n"
  147.               "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
  148.               "\t\t\t\t\t} else\n"
  149.               "\t\t\t\t\t\tfail = TRUE;\n\n"
  150.               "\t\t\t\t} else\n"
  151.               "\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n\n"
  152.               "\t\t\t} else {\n\n"
  153.               "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
  154.               "\t\t\t\t\tfail = TRUE;\n\n"
  155.               "\t\t\t};\n\n"
  156.               "\t\t\tif( fail )\n"
  157.               "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
  158.               "\t\t\tif( found )\n"
  159.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
  160.               "\t\t}\n"
  161.               "\t}\n"
  162.               "}\n";
  163.  
  164. static UBYTE   ARexxHandleList[] = "\n"
  165.               "void HandleRexxMsg( void )\n"
  166.               "{\n"
  167.               "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
  168.               "\tWORD\t\tn;\n"
  169.               "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
  170.               "\tstruct RexxMsg\t*RxMsg;\n"
  171.               "\tUBYTE\t\tbuffer[1024], command[256];\n"
  172.               "\tUBYTE\t\t*arguments;\n"
  173.               "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
  174.               "\n"
  175.               "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
  176.               "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
  177.               "\t\t\tif( RxMsg->rm_Args[15] )\n"
  178.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
  179.               "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
  180.               "\t\t\tDeleteRexxMsg( RxMsg );\n"
  181.               "\t\t\tRX_Unconfirmed -= 1;\n"
  182.               "\t\t}\n"
  183.               "\t\telse {\n\n"
  184.               "\t\t\tRxMsg->rm_Result1 = NULL;\n"
  185.               "\t\t\tRxMsg->rm_Result2 = NULL;\n"
  186.               "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
  187.               "\n"
  188.               "\t\t\tn = 0;\n"
  189.               "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
  190.               "\t\t\t\tcommand[n] = buffer[n];\n"
  191.               "\t\t\t\tn++;\n"
  192.               "\t\t\t};\n"
  193.               "\t\t\tcommand[n] = '\\0';\n\n"
  194.               "\t\t\tn = 0;\n"
  195.               "\t\t\tstruct CmdNode *Cmd;\n"
  196.               "\t\t\tfor( Cmd = RexxCommands.mlh_Head; Cmd->Node.ln_Succ; Cmd = Cmd->Node.ln_Succ ) {\n"
  197.               "\t\t\t\tif( stricmp( Cmd->Node.ln_Name, command ) == 0 ) {\n"
  198.               "\t\t\t\t\tfound = TRUE;\n"
  199.               "\t\t\t\t\tbreak;\n"
  200.               "\t\t\t\t}"
  201.               "\t\t\t};\n\n"
  202.               "\t\t\tif( found ) {\n"
  203.               "\t\t\t\tif( Cmd->Template ) {\n"
  204.               "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
  205.               "\t\t\t\t\t\targuments = buffer + strlen( Cmd->Node.ln_Name );\n\n"
  206.               "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
  207.               "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
  208.               "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
  209.               "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
  210.               "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
  211.               "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
  212.               "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
  213.               "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
  214.               "\n"
  215.               "\t\t\t\t\t\tif( rdargs = ReadArgs( Cmd->Template, ArgArray, args )) {\n\n"
  216.               "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n"
  217.               "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
  218.               "\t\t\t\t\t\t} else\n"
  219.               "\t\t\t\t\t\t\tfail = TRUE;\n\n"
  220.               "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
  221.               "\t\t\t\t\t} else\n"
  222.               "\t\t\t\t\t\tfail = TRUE;\n\n"
  223.               "\t\t\t\t} else\n"
  224.               "\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n\n"
  225.               "\t\t\t} else {\n\n"
  226.               "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
  227.               "\t\t\t\t\tfail = TRUE;\n\n"
  228.               "\t\t\t};\n\n"
  229.               "\t\t\tif( fail )\n"
  230.               "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
  231.               "\t\t\tif( found )\n"
  232.               "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
  233.               "\t\t}\n"
  234.               "\t}\n"
  235.               "}\n";
  236.  
  237.  
  238. static UBYTE   ARexxCode[] = "\nBOOL SetupRexxPort( void )\n"
  239.               "{\n"
  240.               "\tUWORD\t\tcnt = 0;\n"
  241.               "\n"
  242.               "\tForbid();\n"
  243.               "\n"
  244.               "\tdo {\n"
  245.               "\t\tcnt += 1;\n"
  246.               "\t\tsprintf( RexxPortName, RexxPort_fmt, cnt );\n"
  247.               "\t} while( FindPort( RexxPortName ));\n"
  248.               "\n"
  249.               "\tRexxPort = CreateMsgPort();\n"
  250.               "\tif (!RexxPort) {\n"
  251.               "\t\tPermit();\n"
  252.               "\t\treturn( FALSE );\n"
  253.               "\t};\n"
  254.               "\n"
  255.               "\tRexxPort->mp_Node.ln_Name = RexxPortName;\n"
  256.               "\tRexxPort->mp_Node.ln_Pri  = 0;\n"
  257.               "\n"
  258.               "\tAddPort( RexxPort );\n\n"
  259.               "\tPermit();\n\n"
  260.               "\treturn( TRUE );\n"
  261.               "}\n"
  262.               "\n"
  263.               "void DeleteRexxPort( void )\n"
  264.               "{\n"
  265.               "\tAPTR\tm;\n\n"
  266.               "\tif (!RexxPort)\n"
  267.               "\t\treturn;\n"
  268.               "\n"
  269.               "\twhile( RX_Unconfirmed ) {\n"
  270.               "\t\tWaitPort( RexxPort );\n"
  271.               "\t\tHandleRexxMsg();\n"
  272.               "\t};\n"
  273.               "\n"
  274.               "\tForbid();\n"
  275.               "\tRemPort( RexxPort );\n\n"
  276.               "\twhile( m = GetMsg( RexxPort ))\n"
  277.               "\t\tReplyMsg( m );\n\n"
  278.               "\tDeleteMsgPort( RexxPort );\n"
  279.               "\tRexxPort = NULL;\n"
  280.               "\tPermit();\n"
  281.               "}\n"
  282.               "\n"
  283.               "BOOL SendRexxMsg( char *Host, char *Ext, char *Command, APTR Msg, LONG Flags )\n"
  284.               "{\n"
  285.               "\tAPTR\t\tstring;\n"
  286.               "\tstruct MsgPort\t*Port;\n"
  287.               "\tstruct RexxMsg\t*RxMsg;\n\n"
  288.               "\tif(!( RexxPort ))\n"
  289.               "\t\treturn( FALSE );\n"
  290.               "\n"
  291.               "\tif(!( RxMsg = CreateRexxMsg( RexxPort, Ext, RexxPortName )))\n"
  292.               "\t\treturn( FALSE );\n"
  293.               "\n"
  294.               "\tif(!( string = CreateArgstring( Command, strlen( Command )))) {\n"
  295.               "\t\tDeleteRexxMsg( RxMsg );\n"
  296.               "\t\treturn( FALSE );\n"
  297.               "\t};\n\n"
  298.               "\tRxMsg->rm_Args[0]  = string;\n"
  299.               "\tRxMsg->rm_Args[15] = Msg;\n"
  300.               "\tRxMsg->rm_Action   = Flags | RXCOMM;\n"
  301.               "\n"
  302.               "\tForbid();\n"
  303.               "\tif( Port = FindPort( Host ))\n"
  304.               "\t\tPutMsg( Port, ( struct Message * )RxMsg );\n"
  305.               "\tPermit();\n\n"
  306.               "\tif( Port ) {\n"
  307.               "\t\tRX_Unconfirmed += 1;\n"
  308.               "\t\treturn( TRUE );\n"
  309.               "\t} else {\n"
  310.               "\t\tDeleteArgstring( string );\n"
  311.               "\t\tDeleteRexxMsg( RxMsg );\n"
  312.               "\t\treturn( FALSE );\n"
  313.               "\t};\n"
  314.               "}\n";
  315.  
  316. ///
  317.  
  318.  
  319. //  ***  Main Routines  ***
  320. /// GrabOldPrefs
  321. void GrabOldPrefs( struct IE_Data *IE )
  322. {
  323.     if(!( PrefsOK )) {
  324.  
  325.     Prefs.Flags = IE->C_Prefs;
  326.  
  327.     strcpy( Prefs.ChipString, IE->ChipString );
  328.  
  329.     PrefsOK = TRUE;
  330.     }
  331. }
  332. ///
  333.  
  334. /// OpenFiles
  335. struct GenFiles *OpenFiles( __A0 struct IE_Data *IE, __A1 UBYTE *BaseName )
  336. {
  337.     UBYTE               buffer[1024], buffer2[1024];
  338.     UBYTE              *ptr, *ptr2, *ptr3;
  339.     struct GenFiles    *Files;
  340.  
  341.     GrabOldPrefs( IE );
  342.  
  343.     if(!( Files = AllocMem( sizeof( struct GenFiles ), MEMF_CLEAR )))
  344.     return( NULL );
  345.  
  346.     ptr2 = FilePart( BaseName );
  347.  
  348.     ptr  = BaseName;
  349.     ptr3 = buffer;
  350.     while( ptr != ptr2 )
  351.     *ptr3++ = *ptr++;
  352.  
  353.     *ptr3 = '\0';
  354.  
  355.     ptr = buffer2;
  356.     while(( *ptr2 != '.' ) && ( *ptr2 ))
  357.     *ptr++ = *ptr2++;
  358.     *ptr = '\0';
  359.  
  360.     AddPart( buffer, buffer2, 1024 );
  361.  
  362.     strcpy( buffer2, buffer );
  363.     strcat( buffer2, ".c" );
  364.  
  365.     if(!( Files->Std = Open( buffer2, MODE_NEWFILE )))
  366.     return( NULL );
  367.  
  368.     strcpy( buffer2, buffer );
  369.     strcat( buffer2, ".h" );
  370.     strcpy( Files->XDefName, buffer2 );
  371.  
  372.     if(!( Files->XDef = Open( buffer2, MODE_NEWFILE )))
  373.     goto error;
  374.  
  375.  
  376.     if( Prefs.Flags & GEN_TEMPLATE ) {
  377.  
  378.     strcpy( buffer2, buffer );
  379.     strcat( buffer2, "_temp.c" );
  380.  
  381.     if(!( Files->Temp = Open( buffer2, MODE_NEWFILE )))
  382.         goto error;
  383.  
  384.     }
  385.  
  386.     if( IE->SrcFlags & MAINPROC ) {
  387.  
  388.     strcpy( buffer2, buffer );
  389.     strcat( buffer2, "Main.c" );
  390.  
  391.     if( AskFile( buffer2, IE ))
  392.         if(!( Files->Main = Open( buffer2, MODE_NEWFILE )))
  393.         goto error;
  394.     }
  395.  
  396.     if( IE->SrcFlags & LOCALIZE ) {
  397.     Files->User1 = IE;
  398.     Prefs.Flags |= SMART_STR;
  399.     }
  400.  
  401.     return( Files );
  402.  
  403.  
  404. error:
  405.  
  406.     CloseFiles( Files );
  407.  
  408.     return( NULL );
  409. }
  410. ///
  411. /// CloseFiles
  412. void CloseFiles( __A0 struct GenFiles *Files )
  413. {
  414.     if( Files ) {
  415.     if( Files->Std   )  Close( Files->Std   );
  416.     if( Files->Temp  )  Close( Files->Temp  );
  417.     if( Files->XDef  )  Close( Files->XDef  );
  418.     if( Files->Main  )  Close( Files->Main  );
  419.  
  420.     if( Files->User1 ) {
  421.         UBYTE  *from, *to, *ptr;
  422.         UBYTE   path[256], locale[256];
  423.  
  424.         /* get the path where the files must be created */
  425.  
  426.         from = Files->XDefName;
  427.         to   = FilePart( Files->XDefName );
  428.         ptr  = path;
  429.  
  430.         while( from < to )
  431.         *ptr++ = *from++;
  432.  
  433.         *ptr = '\0';
  434.  
  435.         /* build the name of the locale file */
  436.  
  437.         ptr = locale;
  438.  
  439.         while( *to != '.' )
  440.         *ptr++ = *to++;
  441.  
  442.         *ptr = '\0';
  443.  
  444.         strcat( locale, "_Locale.h" );
  445.  
  446.  
  447.         if( Prefs.MoreFlags & USE_CATCOMP ) {
  448.         UBYTE   command[ 1024 ];
  449.  
  450.         /* built the command line */
  451.  
  452.         strcpy( command, "CatComp \"" );
  453.         strcat( command, path );
  454.         strcat( command, ((struct IE_Data *)Files->User3 )->Locale->Catalog );
  455.         strcat( command, ".cd\" CFILE \"" );
  456.         strcat( command, path );
  457.         strcat( command, locale );
  458.         strcat( command, "\"" );
  459.  
  460.         /* and execute it */
  461.  
  462.         SystemTagList( command, NULL );
  463.  
  464.         } else {
  465.         AddPart( path, locale, 256 );
  466.         WriteLocaleH( Files, (struct IE_Data *)Files->User1, path );
  467.         }
  468.     }
  469.  
  470.     FreeMem( Files, sizeof( struct GenFiles ));
  471.     }
  472. }
  473. ///
  474.  
  475. /// WriteHeaders
  476. BOOL WriteHeaders( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  477. {
  478.     APTR                UserHeaders = NULL;
  479.     struct WindowInfo  *wnd;
  480.     struct GadgetInfo  *gad;
  481.     ULONG               cnt;
  482.  
  483.  
  484.     if( Prefs.HeadersFile[0] ) {
  485.     ULONG   size;
  486.     BPTR    file;
  487.  
  488.     if( file = Open( Prefs.HeadersFile, MODE_OLDFILE )) {
  489.  
  490.         Seek( file, 0, OFFSET_END );
  491.         size = Seek( file, 0, OFFSET_BEGINNING );
  492.  
  493.         if( UserHeaders = AllocVec( size, MEMF_ANY )) {
  494.  
  495.         Read( file, UserHeaders, size );
  496.  
  497.         ( *IE->IEXFun->SplitLines )( UserHeaders ); // VERY important!
  498.         }
  499.  
  500.         Close( file );
  501.     }
  502.     }
  503.  
  504.  
  505.     FPrintf( Files->Std,  Header, LibId, IE->User->Name, IE->User->Number );
  506.     FPrintf( Files->XDef, Header, LibId, IE->User->Name, IE->User->Number );
  507.  
  508.     if( Files->Temp ) {
  509.     FPrintf( Files->Temp, Header, LibId, IE->User->Name, IE->User->Number );
  510.  
  511.     FPuts( Files->Temp,
  512.         "/*\n"
  513.         "   In this file you'll find empty  template  routines\n"
  514.         "   referenced in the GUI source.  You  can fill these\n"
  515.         "   routines with your code or use them as a reference\n"
  516.         "   to create your main program.\n"
  517.         "*/\n\n"
  518.         "#include <stdio.h>\n"
  519.         "#include <exec/types.h>\n\n" );
  520.     }
  521.  
  522.     if( Files->Main ) {
  523.     FPrintf( Files->Main, Header, LibId, IE->User->Name, IE->User->Number );
  524.     WriteMain( Files, IE );
  525.     }
  526.  
  527.     if( UserHeaders == NULL ) {
  528.  
  529.     FPuts( Files->Std, "#include <exec/types.h>\n"
  530.                "#include <exec/nodes.h>\n"
  531.                "#include <intuition/intuition.h>\n"
  532.                "#include <intuition/gadgetclass.h>\n"
  533.                "#include <libraries/gadtools.h>\n"
  534.                "#include <clib/exec_protos.h>\n"
  535.                "#include <clib/intuition_protos.h>\n"
  536.                "#include <clib/gadtools_protos.h>\n"
  537.                "#include <clib/graphics_protos.h>\n"
  538.                "#ifdef PRAGMAS\n"
  539.                "#include <pragmas/exec_pragmas.h>\n"
  540.                "#include <pragmas/intuition_pragmas.h>\n"
  541.                "#include <pragmas/graphics_pragmas.h>\n"
  542.                "#include <pragmas/gadtools_pragmas.h>\n"
  543.                "#endif\n"
  544.                "#include <ctype.h>\n"
  545.                "#include <string.h>\n\n" );
  546.  
  547.     FPuts( Files->XDef, "#ifndef EXEC_TYPES_H\n"
  548.                 "#include <exec/types.h>\n"
  549.                 "#endif\n"
  550.                 "#ifndef EXEC_NODES_H\n"
  551.                 "#include <exec/nodes.h>\n"
  552.                 "#endif\n"
  553.                 "#ifndef INTUITION_INTUITION_H\n"
  554.                 "#include <intuition/intuition.h>\n"
  555.                 "#endif\n"
  556.                 "#ifndef INTUITION_GADGETCLASS_H\n"
  557.                 "#include <intuition/gadgetclass.h>\n"
  558.                 "#endif\n"
  559.                 "#ifndef LIBRARIES_GADTOOLS_H\n"
  560.                 "#include <libraries/gadtools.h>\n"
  561.                 "#endif\n"
  562.                 "#ifndef CLIB_EXEC_PROTOS_H\n"
  563.                 "#include <clib/exec_protos.h>\n"
  564.                 "#endif\n"
  565.                 "#ifndef CLIB_INTUITION_PROTOS_H\n"
  566.                 "#include <clib/intuition_protos.h>\n"
  567.                 "#endif\n"
  568.                 "#ifndef CLIB_GADTOOLS_PROTOS_H\n"
  569.                 "#include <clib/gadtools_protos.h>\n"
  570.                 "#endif\n"
  571.                 "#ifndef CLIB_GRAPHICS_PROTOS_H\n"
  572.                 "#include <clib/graphics_protos.h>\n"
  573.                 "#endif\n"
  574.                 "#ifndef CTYPE_H\n"
  575.                 "#include <ctype.h>\n"
  576.                 "#endif\n"
  577.                 "#ifndef STRING_H\n"
  578.                 "#include <string.h>\n"
  579.                 "#endif\n\n" );
  580.     } else {
  581.     STRPTR  inc;
  582.  
  583.     if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "STANDARD" )) {
  584.  
  585.         FPuts( Files->Std,  inc );
  586.         FPuts( Files->XDef, inc );
  587.     }
  588.     }
  589.  
  590.  
  591.     if( CheckMultiSelect( IE ))
  592.     FPuts( Files->XDef, "#include <utility/hooks.h>\n" );
  593.  
  594.  
  595.     if( IE->SrcFlags & OPENDISKFONT ) {
  596.     if( UserHeaders ) {
  597.         STRPTR  inc;
  598.  
  599.         if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "DISKFONT" ))
  600.         FPuts( Files->Std,  inc );
  601.  
  602.     } else
  603.         FPuts( Files->Std, "#include <clib/diskfont_protos.h>\n\n" );
  604.     }
  605.  
  606.     if( IE->NumRexxs ) {
  607.     if( UserHeaders ) {
  608.         STRPTR  inc;
  609.  
  610.         if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "AREXX" ))
  611.         FPuts( Files->Std,  inc );
  612.  
  613.     } else
  614.         FPuts( Files->Std, "#include <rexx/rxslib.h>\n"
  615.                    "#include <rexx/rexxio.h>\n"
  616.                    "#include <rexx/errors.h>\n"
  617.                    "#include <rexx/storage.h>\n"
  618.                    "#include <dos/dos.h>\n"
  619.                    "#include <dos/rdargs.h>\n"
  620.                    "#include <clib/dos_protos.h>\n"
  621.                    "#include <clib/rexxsyslib_protos.h>\n"
  622.                    "#include <clib/alib_stdio_protos.h>\n"
  623.                    "#ifdef PRAGMAS\n"
  624.                    "#include <pragmas/dos_pragmas.h>\n"
  625.                    "#include <pragmas/rexxsyslib_pragmas.h>\n"
  626.                    "#endif\n\n" );
  627.     }
  628.  
  629.     if( IE->SrcFlags & LOCALIZE ) {
  630.     if( UserHeaders ) {
  631.         STRPTR  inc;
  632.  
  633.         if( inc = ( *IE->IEXFun->GetFirstLine )( UserHeaders, "LOCALE" ))
  634.         FPuts( Files->Std,  inc );
  635.  
  636.     } else
  637.        FPuts( Files->Std, "#include <libraries/locale.h>\n"
  638.                    "#include <clib/locale_protos.h>\n"
  639.                    "#ifdef PRAGMAS\n"
  640.                    "#include <pragmas/locale_pragmas.h>\n"
  641.                    "#endif\n\n" );
  642.     }
  643.  
  644.     FPrintf( Files->Std, "#include \"%s\"\n\n", FilePart( Files->XDefName ));
  645.  
  646.     if( IE->SrcFlags & LOCALIZE ) {
  647.  
  648.     UBYTE   *to, buffer[60];
  649.  
  650.     strcpy( buffer, FilePart( Files->XDefName ));
  651.  
  652.     to = strrchr( buffer, '.' );
  653.     *to = '\0';
  654.  
  655.     strcat( buffer, "_Locale.h" );
  656.  
  657.     FPrintf( Files->Std, "#define CATCOMP_ARRAY\n"
  658.                  "#include \"%s\"\n\n",
  659.          buffer );
  660.     }
  661.  
  662.  
  663.     FPuts( Files->XDef, "#define GetString( g )\t((( struct StringInfo * )g->SpecialInfo )->Buffer  )\n"
  664.             "#define GetNumber( g )\t((( struct StringInfo * )g->SpecialInfo )->LongInt )\n\n"
  665.             "#define WT_LEFT\t\t\t\t0\n"
  666.             "#define WT_TOP\t\t\t\t1\n"
  667.             "#define WT_WIDTH\t\t\t2\n"
  668.             "#define WT_HEIGHT\t\t\t3\n\n" );
  669.  
  670.     for( cnt = 0; cnt < 3; cnt++ ) {
  671.     TEXT    buf[32];
  672.  
  673.     sprintf( buf, Prefs.RegisterDef, cnt );
  674.  
  675.     FPrintf( Files->XDef, "#define A%ld(stuff) %s\n", cnt, buf );
  676.     }
  677.  
  678.  
  679.     if( IE->SrcFlags & LOCALIZE )
  680.     FPuts( Files->XDef, "extern struct CatCompArrayType CatCompArray[];\n"
  681.                 "extern struct Library *LocaleBase;\n\n" );
  682.  
  683.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  684.     struct GadgetBank  *bank;
  685.  
  686.     cnt = 0;
  687.     for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  688.         if( gad->g_Kind < MIN_IEX_ID ) {
  689.         FPrintf( Files->XDef, "#define GD_%s\t\t\t\t\t%ld\n", gad->g_Label, cnt );
  690.         cnt += 1;
  691.         }
  692.  
  693.  
  694.     for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ )
  695.         for( cnt = 0, gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  696.         if( gad->g_Kind < MIN_IEX_ID ) {
  697.             FPrintf( Files->XDef, "#define GD_%s\t\t\t\t\t%ld\n", gad->g_Label, cnt );
  698.             cnt += 1;
  699.         }
  700.  
  701.  
  702.     if( cnt )
  703.         FPutC( Files->XDef, 10 );
  704.     }
  705.  
  706.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  707.     struct GadgetBank  *bank;
  708.  
  709.     cnt = wnd->wi_NumGads - wnd->wi_NumBools;
  710.     if( cnt )
  711.         FPrintf( Files->XDef, "#define %s_CNT %ld\n", wnd->wi_Label, cnt );
  712.  
  713.     for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ ) {
  714.         struct GadgetInfo  *gad;
  715.  
  716.         for( cnt = 0, gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  717.         if( gad->g_Kind < BOOLEAN )
  718.             cnt += 1;
  719.  
  720.         if( cnt )
  721.         FPrintf( Files->XDef, "#define %s_CNT %ld\n", bank->Label, cnt );
  722.     }
  723.     }
  724.  
  725.     FPutC( Files->XDef, '\n' );
  726.  
  727.     ( *IE->IEXSrcFun->Headers )( Files );
  728.  
  729.     return( TRUE );
  730. }
  731. ///
  732. /// WriteVars
  733. BOOL WriteVars( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  734. {
  735.     int                 cnt;
  736.     struct WindowInfo  *wnd;
  737.  
  738.     FPuts( Files->Std, "APTR\t\t\tVisualInfo;\n"
  739.                "int\t\t\tYOffset;\n"
  740.                "UWORD\t\t\tXOffset;\n"
  741.                "struct Screen\t\t*Scr = NULL;\n" );
  742.  
  743.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  744.     if( wnd->wi_NumGBanks ) {
  745.  
  746.         FPuts( Files->XDef, "struct WindowBanks {\n"
  747.                 "\tstruct Gadget **Banks;\n"
  748.                 "\tUWORD           Count;\n"
  749.                 "};\n\n" );
  750.         break;
  751.     }
  752.  
  753.  
  754.     FPuts( Files->XDef, "extern struct IntuitionBase\t*IntuitionBase;\n"
  755.             "extern struct Library\t\t*GadToolsBase;\n"
  756.             "extern struct Library\t\t*GfxBase;\n"
  757.             "extern struct Screen\t\t*Scr;\n"
  758.             "extern int\t\t\tYOffset;\n"
  759.             "extern UWORD\t\t\tXOffset;\n"
  760.             "extern APTR\t\t\tVisualInfo;\n" );
  761.  
  762.     if( IE->SrcFlags & FONTSENSITIVE )
  763.     FPuts( Files->Std, "struct TextAttr\t\t*Font, Attr;\n"
  764.                "UWORD\t\t\tFontX, FontY;\n" );
  765.  
  766.     if(!( IE->flags_2 & GENERASCR )) {
  767.     FPuts( Files->Std,  "UBYTE\t\t\t*PubScreenName = NULL;\n" );
  768.     FPuts( Files->XDef, "extern UBYTE\t\t\t*PubScreenName;\n" );
  769.     } else {
  770.     if( IE->ScreenData->ScrAttrs & SC_ERRORCODE ) {
  771.         FPuts( Files->Std,  "ULONG\t\t\tScreenError = NULL;\n" );
  772.         FPuts( Files->XDef, "extern ULONG\t\t\tScreenError;\n" );
  773.     }
  774.     }
  775.  
  776.     if( IE->SrcFlags & LOCALIZE ) {
  777.     FPrintf( Files->Std, "UBYTE\t\t\tLocalized[ %ld ];\n"
  778.                  "struct Catalog\t\t*Catalog = NULL;\n",
  779.          IE->num_win );
  780.     FPuts( Files->XDef, "extern struct Catalog\t\t*Catalog;\n" );
  781.     }
  782.  
  783.     if( IE->NumRexxs ) {
  784.     FPrintf( Files->Std, "UWORD\t\t\tRX_Unconfirmed;\n"
  785.                  "struct MsgPort\t\t*RexxPort;\n"
  786.                  "UBYTE\t\t\tRexxPortName[%ld];\n"
  787.                  "const char\t\t*RexxPort_fmt = \"%s.%%d\";\n"
  788.                  "const char\t\t*REXX_ext = \"%s\";\n",
  789.          strlen( IE->RexxPortName ) + 4,
  790.          IE->RexxPortName, IE->RexxExt );
  791.     }
  792.  
  793.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  794.     FPrintf( Files->Std,  "struct Window\t\t*%sWnd = NULL;\n", wnd->wi_Label );
  795.     FPrintf( Files->XDef, "extern struct Window\t\t*%sWnd;\n", wnd->wi_Label );
  796.     }
  797.  
  798.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  799.     if( wnd->wi_NumMenus ) {
  800.         FPrintf( Files->Std,  "struct Menu\t\t*%sMenus = NULL;\n", wnd->wi_Label );
  801.         FPrintf( Files->XDef, "extern struct Menu\t\t*%sMenus;\n", wnd->wi_Label );
  802.     }
  803.     }
  804.  
  805.  
  806.     //      Gadget Lists
  807.  
  808.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  809.     if( wnd->wi_NumGads - wnd->wi_NumBools ) {
  810.         FPrintf( Files->Std,  "struct Gadget\t\t*%sGList = NULL;\n", wnd->wi_Label );
  811.         FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGList;\n", wnd->wi_Label );
  812.     }
  813.     }
  814.  
  815.  
  816.     //      Gadget Banks
  817.  
  818.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  819.     if( wnd->wi_NumGBanks ) {
  820.         struct GadgetBank  *bank;
  821.  
  822.         FPrintf( Files->Std,  "static struct Gadget\t*%sGBanks[%ld];\n"
  823.                   "struct WindowBanks\t%sWBanks = { &%sGBanks[ 0 ], 0 };\n",
  824.                   wnd->wi_Label, wnd->wi_NumGBanks,
  825.                   wnd->wi_Label, wnd->wi_Label );
  826.         FPrintf( Files->XDef, "extern struct WindowBanks\t\t%sWBanks;\n", wnd->wi_Label );
  827.  
  828.         for( bank = wnd->wi_GBanks.mlh_Head; bank->Node.ln_Succ; bank = bank->Node.ln_Succ ) {
  829.         struct GadgetInfo  *gad;
  830.         ULONG               count = 0;
  831.  
  832.         for( gad = bank->Storage.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
  833.             if( gad->g_Kind < BOOLEAN )
  834.             count += 1;
  835.  
  836.         if( count ) {
  837.             FPrintf( Files->Std,  "struct Gadget\t\t*%sGList = NULL;\n"
  838.                       "struct Gadget\t\t*%sGadgets[%ld];\n",
  839.                       bank->Label, bank->Label, count );
  840.  
  841.             FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGList;\n"
  842.                       "extern struct Gadget\t\t*%sGadgets[%ld];\n",
  843.                      bank->Label, bank->Label, count );
  844.         }
  845.         }
  846.     }
  847.     }
  848.  
  849.  
  850.     //      IntuiMessages
  851.  
  852.     if( Prefs.Flags & INTUIMSG ) {
  853.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  854.         if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT ))) {
  855.         FPrintf( Files->Std,  "struct IntuiMessage\t%sMsg;\n", wnd->wi_Label );
  856.         FPrintf( Files->XDef, "extern struct IntuiMessage\t%sMsg;\n", wnd->wi_Label );
  857.         }
  858.     }
  859.     }
  860.  
  861.  
  862.  
  863.     //      Gadget Pointers Arrays
  864.  
  865.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  866.     cnt = wnd->wi_NumGads - wnd->wi_NumBools;
  867.     if( cnt ) {
  868.         FPrintf( Files->Std,  "struct Gadget\t\t*%sGadgets[%ld];\n", wnd->wi_Label, cnt );
  869.         FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGadgets[%ld];\n", wnd->wi_Label, cnt );
  870.     }
  871.     }
  872.  
  873.  
  874.     if( IE->SrcFlags & SHARED_PORT ) {
  875.     Files->User2 = IE->SharedPort[0] ? (APTR)&IE->SharedPort[0] : (APTR)"IDCMPPort";
  876.  
  877.     FPrintf( Files->XDef, "extern struct MsgPort\t\t*%s;\n"
  878.                   "extern struct IntuiMessage\tIDCMPMsg;\n"
  879.                   "extern LONG OpenWndShd( struct Gadget *, struct TagItem *, struct Window **, ULONG );\n"
  880.                   "extern void CloseWndShd( struct Window **, struct Gadget **, struct Menu ** );\n"
  881.                   "extern void HandleIDCMPPort( void );\n",
  882.          Files->User2 );
  883.  
  884.     if(!( IE->SharedPort[0] ))
  885.         FPuts( Files->Std, "\nstruct MsgPort\t\t*IDCMPPort;\n" );
  886.  
  887.     FPuts( Files->Std, "struct IntuiMessage\tIDCMPMsg;\n" );
  888.     }
  889.  
  890.  
  891.     // Expanders
  892.     ( *IE->IEXSrcFun->Globals )( Files );
  893.  
  894.     if( IE->SrcFlags & OPENDISKFONT )
  895.     WriteFontPtrs( Files, IE );
  896.  
  897.     return( TRUE );
  898. }
  899. ///
  900. /// WriteData
  901. BOOL WriteData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  902. {
  903.     struct WindowInfo  *wnd;
  904.  
  905.     // Gadget Labels
  906.  
  907.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  908.     WriteGLabels( Files, IE, &wnd->wi_Gadgets, wnd );
  909.  
  910.  
  911.     // Gadget Types
  912.  
  913.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  914.     if( wnd->wi_NumGads - wnd->wi_NumBools ) {
  915.  
  916.         FPrintf( Files->XDef, "extern UWORD\t\t\t%sGTypes[];\n", wnd->wi_Label );
  917.         FPrintf( Files->Std, "\nUWORD %sGTypes[] = {\n\t", wnd->wi_Label );
  918.  
  919.         WriteGTypes( Files, IE, &wnd->wi_Gadgets );
  920.     }
  921.     }
  922.  
  923.     // Fonts
  924.  
  925.     struct TxtAttrNode *fnt;
  926.     for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
  927.     FPrintf( Files->XDef, "extern struct TextAttr\t\t%s;\n", fnt->txa_Label );
  928.     FPrintf( Files->Std, "\nstruct TextAttr %s = {\n"
  929.                  "\t(STRPTR)\"%s\", %ld, 0x%lx, 0x%lx };\n",
  930.          fnt->txa_Label, fnt->txa_FontName, fnt->txa_Size,
  931.          fnt->txa_Style, fnt->txa_Flags );
  932.     }
  933.  
  934.     // Gadget Data that should preceed gadget tags
  935.     WriteGadgetExtData( Files, IE );
  936.  
  937.     // NewGadget structures
  938.     WriteNewGadgets( Files, IE );
  939.  
  940.     // Gadget Tags
  941.     WriteGadgetTags( Files, IE );
  942.  
  943.     // Boolean Structures
  944.     WriteBoolStruct( Files, IE );
  945.  
  946.     // Gadget Banks Data
  947.     WriteGadgetBanks( Files, IE );
  948.  
  949.     // Expanders
  950.     ( *IE->IEXSrcFun->Data )( Files );
  951.  
  952.     // Menus
  953.     WriteMenuStruct( Files, IE );
  954.  
  955.     // IntuiTexts
  956.     WriteITexts( Files, IE );
  957.  
  958.     // Images (used by the GUI)
  959.     WriteImgStruct( Files, IE );
  960.  
  961.     // Images (in windows)
  962.     WriteImageStruct( Files, IE );
  963.  
  964.     // Rexx Commands
  965.     WriteRexxCmds( Files, IE );
  966.  
  967.     // Windows' Zoom
  968.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  969.     if( wnd->wi_Tags & W_ZOOM ) {
  970.         FPrintf( Files->XDef, "extern UWORD\t\t\t%sZoom[];\n", wnd->wi_Label );
  971.         FPrintf( Files->Std, "\nUWORD %sZoom[] = { ", wnd->wi_Label );
  972.         VFPrintf( Files->Std, "%d, %d, %d, %d };\n", &wnd->wi_ZLeft );
  973.     }
  974.     }
  975.  
  976.     // Windows Tags
  977.     WriteWindowTags( Files, IE );
  978.  
  979.     // Screen Tags
  980.     if( IE->flags_2 & GENERASCR )
  981.     WriteScreenTags( Files, IE );
  982.  
  983.     return( TRUE );
  984. }
  985. ///
  986. /// WriteChipData
  987. BOOL WriteChipData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  988. {
  989.     struct ImageNode   *img;
  990.     UWORD               words, num, *ptr;
  991.  
  992.     for( img = IE->Img_List.mlh_Head; img->in_Node.ln_Succ; img = img->in_Node.ln_Succ ) {
  993.     if( img->in_Size ) {
  994.  
  995.         words = img->in_Size >> 1;
  996.  
  997.         FPrintf( Files->Std, "\n%s %sImgData[%ld] = {\n\t",
  998.              Prefs.ChipString, img->in_Label, words );
  999.  
  1000.         FPrintf( Files->XDef, "extern %s %sImgData[%ld];\n",
  1001.              Prefs.ChipString, img->in_Label, words );
  1002.  
  1003.         ptr = img->in_Data;
  1004.  
  1005.         num = 8;
  1006.  
  1007.         do {
  1008.  
  1009.         FPrintf( Files->Std, "0x%04lx", *ptr++ );
  1010.  
  1011.         num   -= 1;
  1012.         words -= 1;
  1013.  
  1014.         if( words ) {
  1015.  
  1016.             FPutC( Files->Std, ',' );
  1017.  
  1018.             if(!( num )) {
  1019.             FPuts( Files->Std, "\n\t" );
  1020.             num = 8;
  1021.             }
  1022.         }
  1023.  
  1024.         } while( words );
  1025.  
  1026.         FPuts( Files->Std, "\n};\n" );
  1027.  
  1028.     }
  1029.     }
  1030.  
  1031.     // Expanders
  1032.     ( *IE->IEXSrcFun->ChipData )( Files );
  1033.  
  1034.     return( TRUE );
  1035. }
  1036. ///
  1037. /// WriteCode
  1038. BOOL WriteCode( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  1039. {
  1040.  
  1041.     // Expanders
  1042.     ( *IE->IEXSrcFun->Support )( Files );
  1043.  
  1044.     if( IE->SrcFlags & SHARED_PORT )
  1045.     WriteOpenWndShd( Files, IE );
  1046.  
  1047.     if( IE->SrcFlags & LOCALIZE )
  1048.     WriteLocale( Files, IE );
  1049.  
  1050.     WriteSetupScr( Files, IE );
  1051.  
  1052.     WriteListHook( Files, IE );
  1053.  
  1054.     WriteGBanksHandling( Files, IE );
  1055.  
  1056.     WriteOpenFonts( Files, IE );
  1057.  
  1058.     WriteOpenWnd( Files, IE );
  1059.  
  1060.     WriteRender( Files, IE );
  1061.  
  1062.     if( IE->NumRexxs ) {
  1063.     FPuts( Files->Std, ARexxCode );
  1064.  
  1065.     if( IE->SrcFlags & AREXX_CMD_LIST )
  1066.         FPuts( Files->Std, ARexxHandleList );
  1067.     else
  1068.         FPuts( Files->Std, ARexxHandleArray );
  1069.     }
  1070.  
  1071.     if( Prefs.Flags & IDCMP_HANDLER )
  1072.     WriteIDCMPHandler( Files, IE );
  1073.  
  1074.     if( Prefs.Flags & KEY_HANDLER )
  1075.     WriteKeyHandler( Files, IE );
  1076.  
  1077.     FPuts( Files->XDef, "\nextern int SetupScreen( void );\n"
  1078.             "extern void CloseDownScreen( void );\n"
  1079.             "extern struct Gadget *MakeGadgets( struct Gadget **GList, struct Gadget *Gads[],\n"
  1080.             "\tstruct NewGadget NGad[], UWORD GTypes[], ULONG GTags[], UWORD CNT );\n"
  1081.             "extern LONG OpenWnd( struct Gadget *GList, struct TagItem WTags[], struct Window **Wnd );\n"
  1082.             "extern void CloseWnd( struct Window **Wnd, struct Gadget **GList, struct Menu **Mn );\n"
  1083.      );
  1084.  
  1085.     if( Prefs.Flags & CLICKED )
  1086.     WriteClickedPtrs( Files, IE );
  1087.  
  1088.     return( TRUE );
  1089. }
  1090. ///
  1091. /// WriteStrings
  1092. BOOL WriteStrings( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  1093. {
  1094.  
  1095.     if(!( IE->SrcFlags & LOCALIZE )) {
  1096.  
  1097.     if( Prefs.Flags & SMART_STR ) {
  1098.         struct LocaleStr   *str;
  1099.  
  1100.         FPutC( Files->Std, 10 );
  1101.  
  1102.         for( str = IE->Locale->ExtraStrings.mlh_Head; str->Node.ln_Succ; str = str->Node.ln_Succ )
  1103.         if( str->Node.ln_Pri & LOC_GUI )
  1104.             break;
  1105.  
  1106.         for( ; str->Node.ln_Succ; str = str->Node.ln_Succ ) {
  1107.  
  1108.         FPrintf( Files->XDef, "extern UBYTE\t\t\t%s[];\n", str->ID );
  1109.  
  1110.         FPrintf( Files->Std, "UBYTE %s[] = \"%s\";\n",
  1111.              str->ID, str->Node.ln_Name );
  1112.         }
  1113.     }
  1114.     }
  1115.  
  1116.     if( Prefs.Flags & SMART_STR ) {
  1117.     struct ArrayNode   *ar;
  1118.     UBYTE             **array;
  1119.  
  1120.     for( ar = IE->Locale->Arrays.mlh_Head; ar->Next; ar = ar->Next ) {
  1121.  
  1122.         FPrintf( Files->XDef, "extern UBYTE\t\t\t*%s[];\n", ar->Label );
  1123.  
  1124.         FPrintf( Files->Std, "\nUBYTE *%s[] = {", ar->Label );
  1125.  
  1126.         array = ar->Array;
  1127.  
  1128.         while( *array ) {
  1129.         FPrintf( Files->Std, "\n\t(UBYTE *)%s,",
  1130.              (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, *array ))->ID );
  1131.         array++;
  1132.         }
  1133.  
  1134.         FPuts( Files->Std, "\n\tNULL\n};\n" );
  1135.     }
  1136.     }
  1137.  
  1138.     return( TRUE );
  1139. }
  1140. ///
  1141.  
  1142.