/*
**
**    C.generator - Copyright © 1996 Simone Tellini
**                  All Rights Reserved
**
**    $VER: C.generator 37.5 (9.5.96)
**
**    This is the standard C generator. You can easily modify this
**    source to adapt it to your own needs.
**
**    You can spread modified copies of this code, provided that you
**    respect these rules:
**    - you MUST leave my name in it; if someone has modified the
**      code before you, you MUST leave his name too
**    - you MUST distribute the new generator in a small archive
**      along with a little doc
**    - the new generator should be FREEWARE, it can NOT be SHAREWARE
**    - you should send me an e-mail telling me what kind of changes
**      you've performed and the name of the archive
**
**
**    DICE:    dcc funcs.c -// -mD -c -mi -mRR -O o/
**             dlink o/tag.o o/lib.o o/funcs.o o/Config.o dlib:amiga.lib
**                   dlib:csr.lib -o DEV_IE:Generators/C.generator
**
*/

/// Includes
#define INTUI_V36_NAMES_ONLY

#include <exec/nodes.h>                 // exec
#include <exec/lists.h>
#include <exec/memory.h>
#include <exec/types.h>
#include <dos/dos.h>                    // dos
#include <dos/dostags.h>
#include <intuition/intuition.h>        // intuition
#include <intuition/gadgetclass.h>
#include <graphics/text.h>              // graphics
#include <libraries/gadtools.h>         // libraries
#include <libraries/reqtools.h>
#include <clib/exec_protos.h>           // protos
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <clib/reqtools_protos.h>
#include <pragmas/exec_pragmas.h>       // pragmas
#include <pragmas/dos_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/gadtools_pragmas.h>
#include <pragmas/reqtools_pragmas.h>

#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#include "DEV_IE:Generators/defs.h"
#include "DEV_IE:Include/IEditor.h"
#include "DEV_IE:Generators/C/Config.h"
///
/// Prototypes
static void WriteMain( struct GenFiles *, struct IE_Data * );
static void WriteSetupScr( struct GenFiles *, struct IE_Data * );
static void WriteOpenWnd( struct GenFiles *, struct IE_Data * );
static void WriteOpenWndShd( struct GenFiles *, struct IE_Data * );
static void WriteRender( struct GenFiles *, struct IE_Data * );
static void WriteIDCMPHandler( struct GenFiles *, struct IE_Data * );
static void WriteKeyHandler( struct GenFiles *, struct IE_Data * );
static void WriteClickedPtrs( struct GenFiles *, struct IE_Data * );
static void WriteLocale( struct GenFiles *, struct IE_Data * );

static void WriteFontPtrs( struct GenFiles *, struct IE_Data * );
static void WriteOpenFonts( struct GenFiles *, struct IE_Data * );

static BOOL AskFile( UBYTE *, struct IE_Data * );
static void WriteList( struct GenFiles *, struct MinList *, UBYTE *, UWORD, struct IE_Data *IE );
static void WriteCD( struct GenFiles * );

static UWORD CountArray( UBYTE ** );
static BOOL CmpArrays( UBYTE **, struct MinList * );
static struct StringNode *FindString( struct MinList *, UBYTE * );
static struct ArrayNode *FindArray( struct MinList *, struct MinList * );
static BOOL AddString( struct MinList *, UBYTE * );
static BOOL AddArray( struct GenFiles *, struct MinList * );
static void PutLabels( struct IE_Data *, struct GenFiles * );
static BOOL ProcessStrings( struct IE_Data *, struct GenFiles * );
static void FreeStrings( struct GenFiles * );

static void WriteNewGadgets( struct GenFiles *, struct IE_Data * );
static void WriteGadgetTags( struct GenFiles *, struct IE_Data * );
static void WriteBoolStruct( struct GenFiles *, struct IE_Data * );
static void WriteMenuStruct( struct GenFiles *, struct IE_Data * );
static void WriteITexts( struct GenFiles *, struct IE_Data * );
static void WriteImgStruct( struct GenFiles *, struct IE_Data * );
static void WriteImageStruct( struct GenFiles *, struct IE_Data * );
static void WriteRexxCmds( struct GenFiles *, struct IE_Data * );
static void WriteWindowTags( struct GenFiles *, struct IE_Data * );
static void WriteScreenTags( struct GenFiles *, struct IE_Data * );
///
/// Data
static ULONG CheckedTag[] = { GTCB_Checked, 0, TAG_END };

static UWORD stringjusts[] = {
    GACT_STRINGLEFT, GACT_STRINGRIGHT, GACT_STRINGCENTER
};

static ULONG gadget_flags[] = { 1, 2, 4, 8, 16, 0 };

static ULONG idcmps[] = {
	    1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200,
	    0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
	    0x10000, 0x20000, 0x40000, 0x80000, 0x100000,
	    0x200000, 0x400000, 0x800000, 0x1000000,
	    0x2000000, 0x4000000
      };

#define IDCMPS_NUM 27

static ULONG wflgs[] = {
	    1, 2, 4, 8, 0x10, 0x20, 0, 0x40, 0x80, 0x100, 0x200,
	    0x400, 0x800, 0x1000, 0x10000, 0x20000, 0x40000,
	    0x200000
      };

#define WFLAGS_NUM 18

static UBYTE Header[] =
    "/*\n"
    "    C source code created by Interface Editor\n"
    "    Copyright © 1994-1996 by Simone Tellini\n\n"
    "    Generator:  %s\n"
    "    Copy registered to :  %s\n"
    "    Serial Number      : #%ld\n"
    "*/\n\n";

static UBYTE *GadKinds[] = {
    "BUTTON_KIND",
    "CHECKBOX_KIND",
    "INTEGER_KIND",
    "LISTVIEW_KIND",
    "MX_KIND",
    "NUMBER_KIND",
    "CYCLE_KIND",
    "PALETTE_KIND",
    "SCROLLER_KIND",
    NULL,
    "SLIDER_KIND",
    "STRING_KIND",
    "TEXT_KIND"
};

static UBYTE  *GadFlags[] = {
    "PLACETEXT_LEFT",
    "PLACETEXT_RIGHT",
    "PLACETEXT_ABOVE",
    "PLACETEXT_BELOW",
    "PLACETEXT_IN"
};

static UBYTE  *STRINGA_txts[] = {
    NULL,
    "GACT_STRINGRIGHT",
    "GACT_STRINGCENTER"
};

static UBYTE  *GTJ_txts[] = {
    NULL,
    "GTJ_RIGHT",
    "GTJ_CENTER"
};

static UBYTE  *WndFlags[] = {
    "WFLG_SIZEGADGET",
    "WFLG_DRAGBAR",
    "WFLG_DEPTHGADGET",
    "WFLG_CLOSEGADGET",
    "WFLG_SIZEBRIGHT",
    "WFLG_SIZEBBOTTOM",
    "WFLG_SMART_REFRESH",
    "WFLG_SIMPLE_REFRESH",
    "WFLG_SUPER_BITMAP",
    "WFLG_BACKDROP",
    "WFLG_REPORTMOUSE",
    "WFLG_GIMMEZEROZERO",
    "WFLG_BORDERLESS",
    "WFLG_ACTIVATE",
    "WFLG_RMBTRAP",
    "WFLG_NOCAREREFRESH",
    "WFLG_NW_EXTENDED",
    "WFLG_NEWLOOKMENUS"
};

static UBYTE  *WndIDCMP[] = {
    "IDCMP_SIZEVERIFY",
    "IDCMP_NEWSIZE",
    "IDCMP_REFRESHWINDOW",
    "IDCMP_MOUSEBUTTONS",
    "IDCMP_MOUSEMOVE",
    "IDCMP_GADGETDOWN",
    "IDCMP_GADGETUP",
    "IDCMP_REQSET",
    "IDCMP_MENUPICK",
    "IDCMP_CLOSEWINDOW",
    "IDCMP_RAWKEY",
    "IDCMP_REQVERIFY",
    "IDCMP_REQCLEAR",
    "IDCMP_MENUVERIFY",
    "IDCMP_NEWPREFS",
    "IDCMP_DISKINSERTED",
    "IDCMP_DISKREMOVED",
    "IDCMP_WBENCHMESSAGE",
    "IDCMP_ACTIVEWINDOW",
    "IDCMP_INACTIVEWINDOW",
    "IDCMP_DELTAMOVE",
    "IDCMP_VANILLAKEY",
    "IDCMP_INTUITICKS",
    "IDCMP_IDCMPUPDATE",
    "IDCMP_MENUHELP",
    "IDCMP_CHANGEWINDOW",
    "IDCMP_GADGETHELP"
};

static UBYTE  *GadIDCMP[] = {
    "BUTTONIDCMP",
    "CHECKBOXIDCMP",
    "INTEGERIDCMP",
    "LISTVIEWIDCMP",
    "MXIDCMP",
    "NUMBERIDCMP",
    "CYCLEIDCMP",
    "PALETTEIDCMP",
    "SCROLLERIDCMP",
    NULL,
    "SLIDERIDCMP",
    "STRINGIDCMP",
    "TEXTIDCMP",
    "IDCMP_GADGETUP|IDCMP_GADGETDOWN"
};

static UBYTE   Null[] = "NULL";

static UBYTE   GADisabled[]         = "(GA_Disabled), TRUE, ";
static UBYTE   GAImmediate[]        = "(GA_Immediate), TRUE, ";
static UBYTE   GATabCycle[]         = "(GA_TabCycle), FALSE, ";
static UBYTE   GARelVerify[]        = "(GA_RelVerify), TRUE, ";
static UBYTE   STRINGAExitHelp[]    = "(STRINGA_ExitHelp), TRUE, ";
static UBYTE   STRINGAReplaceMode[] = "(STRINGA_ReplaceMode), TRUE, ";
static UBYTE   PGAFreedom[]         = "(PGA_Freedom), LORIENT_VERT, ";
static UBYTE   LAYOUTASpacing[]     = "(LAYOUTA_Spacing), %ld, ";

static UBYTE   MenuTmp[] = "\nBOOL %sMenued( void )\n"
		    "{\n"
		    "\t/*  Routine for menu \"%s\"  */\n"
		    "\treturn( TRUE );\n"
		    "}\n";

static UBYTE   ARexxHandleArray[] = "\n"
		      "void HandleRexxMsg( void )\n"
		      "{\n"
		      "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
		      "\tWORD\t\tn;\n"
		      "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
		      "\tstruct RexxMsg\t*RxMsg;\n"
		      "\tUBYTE\t\tbuffer[1024], command[256];\n"
		      "\tUBYTE\t\t*arguments;\n"
		      "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
		      "\n"
		      "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
		      "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
		      "\t\t\tif( RxMsg->rm_Args[15] )\n"
		      "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
		      "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
		      "\t\t\tDeleteRexxMsg( RxMsg );\n"
		      "\t\t\tRX_Unconfirmed -= 1;\n"
		      "\t\t}\n"
		      "\t\telse {\n\n"
		      "\t\t\tRxMsg->rm_Result1 = NULL;\n"
		      "\t\t\tRxMsg->rm_Result2 = NULL;\n"
		      "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
		      "\n"
		      "\t\t\tn = 0;\n"
		      "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
		      "\t\t\t\tcommand[n] = buffer[n];\n"
		      "\t\t\t\tn++;\n"
		      "\t\t\t};\n"
		      "\t\t\tcommand[n] = '\\0';\n\n"
		      "\t\t\tn = 0;\n"
		      "\t\t\twhile( CmdTable[n].command ) {\n"
		      "\t\t\t\tif( stricmp( CmdTable[n].command, command ) == 0 ) {\n"
		      "\t\t\t\t\tfound = TRUE;\n"
		      "\t\t\t\t\tbreak;\n"
		      "\t\t\t\t} else\n"
		      "\t\t\t\t\tn++;\n"
		      "\t\t\t};\n\n"
		      "\t\t\tif( found ) {\n"
		      "\t\t\t\tif( CmdTable[n].template ) {\n"
		      "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
		      "\t\t\t\t\t\targuments = buffer + strlen( CmdTable[n].command );\n\n"
		      "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
		      "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
		      "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
		      "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
		      "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
		      "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
		      "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
		      "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
		      "\n"
		      "\t\t\t\t\t\tif( rdargs = ReadArgs( CmdTable[n].template, ArgArray, args )) {\n\n"
		      "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n"
		      "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
		      "\t\t\t\t\t\t} else\n"
		      "\t\t\t\t\t\t\tfail = TRUE;\n\n"
		      "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
		      "\t\t\t\t\t} else\n"
		      "\t\t\t\t\t\tfail = TRUE;\n\n"
		      "\t\t\t\t} else\n"
		      "\t\t\t\t\tRxMsg->rm_Result1 = (*CmdTable[n].routine)(ArgArray, RxMsg);\n\n"
		      "\t\t\t} else {\n\n"
		      "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
		      "\t\t\t\t\tfail = TRUE;\n\n"
		      "\t\t\t};\n\n"
		      "\t\t\tif( fail )\n"
		      "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
		      "\t\t\tif( found )\n"
		      "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
		      "\t\t}\n"
		      "\t}\n"
		      "}\n";

static UBYTE   ARexxHandleList[] = "\n"
		      "void HandleRexxMsg( void )\n"
		      "{\n"
		      "\tULONG\t\tArgArray[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n"
		      "\tWORD\t\tn;\n"
		      "\tstruct RDArgs\t*args = NULL, *rdargs;\n"
		      "\tstruct RexxMsg\t*RxMsg;\n"
		      "\tUBYTE\t\tbuffer[1024], command[256];\n"
		      "\tUBYTE\t\t*arguments;\n"
		      "\tBOOL\t\tfound = FALSE, fail = FALSE;\n"
		      "\n"
		      "\twhile( RxMsg = (struct RexxMsg *)GetMsg( RexxPort )) {\n\n"
		      "\t\tif( RxMsg->rm_Node.mn_Node.ln_Type == NT_REPLYMSG ) {\n\n"
		      "\t\t\tif( RxMsg->rm_Args[15] )\n"
		      "\t\t\t\tReplyMsg(( struct Message * )RxMsg->rm_Args[15] );\n\n"
		      "\t\t\tDeleteArgstring( RxMsg->rm_Args[0] );\n"
		      "\t\t\tDeleteRexxMsg( RxMsg );\n"
		      "\t\t\tRX_Unconfirmed -= 1;\n"
		      "\t\t}\n"
		      "\t\telse {\n\n"
		      "\t\t\tRxMsg->rm_Result1 = NULL;\n"
		      "\t\t\tRxMsg->rm_Result2 = NULL;\n"
		      "\t\t\tstrcpy( buffer, RxMsg->rm_Args[0] );\n"
		      "\n"
		      "\t\t\tn = 0;\n"
		      "\t\t\twhile(( buffer[n] != '\\0' ) && ( buffer[n] != ' ' )) {\n"
		      "\t\t\t\tcommand[n] = buffer[n];\n"
		      "\t\t\t\tn++;\n"
		      "\t\t\t};\n"
		      "\t\t\tcommand[n] = '\\0';\n\n"
		      "\t\t\tn = 0;\n"
		      "\t\t\tstruct CmdNode *Cmd;\n"
		      "\t\t\tfor( Cmd = RexxCommands.mlh_Head; Cmd->Node.ln_Succ; Cmd = Cmd->Node.ln_Succ ) {\n"
		      "\t\t\t\tif( stricmp( Cmd->Node.ln_Name, command ) == 0 ) {\n"
		      "\t\t\t\t\tfound = TRUE;\n"
		      "\t\t\t\t\tbreak;\n"
		      "\t\t\t\t}"
		      "\t\t\t};\n\n"
		      "\t\t\tif( found ) {\n"
		      "\t\t\t\tif( Cmd->Template ) {\n"
		      "\t\t\t\t\tif( args = AllocDosObject( DOS_RDARGS, NULL )) {\n\n"
		      "\t\t\t\t\t\targuments = buffer + strlen( Cmd->Node.ln_Name );\n\n"
		      "\t\t\t\t\t\tstrcat( arguments, \"\\12\" );\n"
		      "\t\t\t\t\t\targs->RDA_Source.CS_Buffer = arguments;\n"
		      "\t\t\t\t\t\targs->RDA_Source.CS_Length = strlen( arguments );\n"
		      "\t\t\t\t\t\targs->RDA_Source.CS_CurChr = 0;\n"
		      "\t\t\t\t\t\targs->RDA_DAList           = NULL;\n"
		      "\t\t\t\t\t\targs->RDA_Buffer           = NULL;\n"
		      "\t\t\t\t\t\targs->RDA_BufSiz           = 0L;\n"
		      "\t\t\t\t\t\targs->RDA_Flags           |= RDAF_NOPROMPT;\n"
		      "\n"
		      "\t\t\t\t\t\tif( rdargs = ReadArgs( Cmd->Template, ArgArray, args )) {\n\n"
		      "\t\t\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n"
		      "\t\t\t\t\t\t\tFreeArgs( rdargs );\n\n"
		      "\t\t\t\t\t\t} else\n"
		      "\t\t\t\t\t\t\tfail = TRUE;\n\n"
		      "\t\t\t\t\t\tFreeDosObject( DOS_RDARGS, args );\n\n"
		      "\t\t\t\t\t} else\n"
		      "\t\t\t\t\t\tfail = TRUE;\n\n"
		      "\t\t\t\t} else\n"
		      "\t\t\t\t\tRxMsg->rm_Result1 = (*Cmd->Routine)(ArgArray, RxMsg);\n\n"
		      "\t\t\t} else {\n\n"
		      "\t\t\t\tif(!( SendRexxMsg( \"REXX\", REXX_ext, RxMsg->rm_Args[0], RxMsg, 0 )))\n"
		      "\t\t\t\t\tfail = TRUE;\n\n"
		      "\t\t\t};\n\n"
		      "\t\t\tif( fail )\n"
		      "\t\t\t\tRxMsg->rm_Result1 = RC_FATAL;\n\n"
		      "\t\t\tif( found )\n"
		      "\t\t\t\tReplyMsg(( struct Message * )RxMsg );\n\n"
		      "\t\t}\n"
		      "\t}\n"
		      "}\n";


static UBYTE   ARexxCode[] = "\nBOOL SetupRexxPort( void )\n"
		      "{\n"
		      "\tUWORD\t\tcnt = 0;\n"
		      "\n"
		      "\tForbid();\n"
		      "\n"
		      "\tdo {\n"
		      "\t\tcnt += 1;\n"
		      "\t\tsprintf( RexxPortName, RexxPort_fmt, cnt );\n"
		      "\t} while( FindPort( RexxPortName ));\n"
		      "\n"
		      "\tRexxPort = CreateMsgPort();\n"
		      "\tif (!RexxPort) {\n"
		      "\t\tPermit();\n"
		      "\t\treturn( FALSE );\n"
		      "\t};\n"
		      "\n"
		      "\tRexxPort->mp_Node.ln_Name = RexxPortName;\n"
		      "\tRexxPort->mp_Node.ln_Pri  = 0;\n"
		      "\n"
		      "\tAddPort( RexxPort );\n\n"
		      "\tPermit();\n\n"
		      "\treturn( TRUE );\n"
		      "}\n"
		      "\n"
		      "void DeleteRexxPort( void )\n"
		      "{\n"
		      "\tAPTR\tm;\n\n"
		      "\tif (!RexxPort)\n"
		      "\t\treturn;\n"
		      "\n"
		      "\twhile( RX_Unconfirmed ) {\n"
		      "\t\tWaitPort( RexxPort );\n"
		      "\t\tHandleRexxMsg();\n"
		      "\t};\n"
		      "\n"
		      "\tForbid();\n"
		      "\tRemPort( RexxPort );\n\n"
		      "\twhile( m = GetMsg( RexxPort ))\n"
		      "\t\tReplyMsg( m );\n\n"
		      "\tDeleteMsgPort( RexxPort );\n"
		      "\tRexxPort = NULL;\n"
		      "\tPermit();\n"
		      "}\n"
		      "\n"
		      "BOOL SendRexxMsg( char *Host, char *Ext, char *Command, APTR Msg, LONG Flags )\n"
		      "{\n"
		      "\tAPTR\t\tstring;\n"
		      "\tstruct MsgPort\t*Port;\n"
		      "\tstruct RexxMsg\t*RxMsg;\n\n"
		      "\tif(!( RexxPort ))\n"
		      "\t\treturn( FALSE );\n"
		      "\n"
		      "\tif(!( RxMsg = CreateRexxMsg( RexxPort, Ext, RexxPortName )))\n"
		      "\t\treturn( FALSE );\n"
		      "\n"
		      "\tif(!( string = CreateArgstring( Command, strlen( Command )))) {\n"
		      "\t\tDeleteRexxMsg( RxMsg );\n"
		      "\t\treturn( FALSE );\n"
		      "\t};\n\n"
		      "\tRxMsg->rm_Args[0]  = string;\n"
		      "\tRxMsg->rm_Args[15] = Msg;\n"
		      "\tRxMsg->rm_Action   = Flags | RXCOMM;\n"
		      "\n"
		      "\tForbid();\n"
		      "\tif( Port = FindPort( Host ))\n"
		      "\t\tPutMsg( Port, ( struct Message * )RxMsg );\n"
		      "\tPermit();\n\n"
		      "\tif( Port ) {\n"
		      "\t\tRX_Unconfirmed += 1;\n"
		      "\t\treturn( TRUE );\n"
		      "\t} else {\n"
		      "\t\tDeleteArgstring( string );\n"
		      "\t\tDeleteRexxMsg( RxMsg );\n"
		      "\t\treturn( FALSE );\n"
		      "\t};\n"
		      "}\n";

static ULONG IDCMPVer[] = { IDCMP_MENUVERIFY, IDCMP_REQVERIFY, IDCMP_SIZEVERIFY };
static UBYTE *IDCMPVerStr[] = {
    "\n\t\tif( class == IDCMP_MENUVERIFY )\n\t\t\trunning = %sMenuVerify();\n",
    "\n\t\tif( class == IDCMP_REQVERIFY )\n\t\t\trunning = %sReqVerify();\n",
    "\n\t\tif( class == IDCMP_SIZEVERIFY )\n\t\t\trunning = %sSizeVerify();\n"
};
static UBYTE *IDCMPVerProto[] = {
    "extern BOOL %sMenuVerify( void );\n",
    "extern BOOL %sReqVerify( void );\n",
    "extern BOOL %sSizeVerify( void );\n"
};
static UBYTE *IDCMPVerTmp[] = {
    "\nBOOL %sMenuVerify( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_MENUVERIFY  */\n"
    "\treturn( TRUE );\n"
    "}\n", // ---
    "\nBOOL %sReqVerify( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_REQVERIFY  */\n"
    "\treturn( TRUE );\n"
    "}\n", // ---
    "\nBOOL %sSizeVerify( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_SIZEVERIFY  */\n"
    "\treturn( TRUE );\n"
    "}\n",
};

static UBYTE VanillaTmp[] = "\nBOOL %sVanillaKey( void )\n"
			    "{\n"
			    "\t/*  Routine for IDCMP_VANILLAKEY  */\n"
			    "\treturn( TRUE );\n"
			    "}\n";

static UBYTE CaseRefresh[] = "\n\t\t\tcase\tIDCMP_REFRESHWINDOW:\n"
			     "\t\t\t\tGT_BeginRefresh( %sWnd );\n"
			     "\t\t\t\tGT_EndRefresh( %sWnd, TRUE );\n"
			     "\t\t\t\tbreak;\n";

static UBYTE CaseRefresh2[] = "\n\t\t\tcase\tIDCMP_REFRESHWINDOW:\n"
			      "\t\t\t\tGT_BeginRefresh( %sWnd );\n"
			      "\t\t\t\t%sRender();\n"
			      "\t\t\t\tGT_EndRefresh( %sWnd, TRUE );\n"
			      "\t\t\t\tbreak;\n";

static UBYTE *IDCMPStr[] = {
    NULL,
    "\n\t\t\tcase\tIDCMP_NEWSIZE:\n"
    "\t\t\t\trunning = %sNewSize();\n"
    "\t\t\t\tbreak;\n",

    CaseRefresh,

    "\n\t\t\tcase\tIDCMP_MOUSEBUTTONS:\n"
    "\t\t\t\trunning = %sMouseButtons();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_MOUSEMOVE:\n"
    "\t\t\t\trunning = %sMouseMove();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_GADGETDOWN:\n"
    "\t\t\t\tfunc = (( struct Gadget * )%sMsg.IAddress )->UserData;\n"
    "\t\t\t\trunning = (*func)();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_GADGETUP:\n"
    "\t\t\t\tfunc = (( struct Gadget * )%sMsg.IAddress )->UserData;\n"
    "\t\t\t\trunning = (*func)();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_REQSET:\n"
    "\t\t\t\trunning = %sReqSet();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_MENUPICK:\n"
    "\t\t\t\twhile( %sMsg.Code != MENUNULL ) {\n"
    "\t\t\t\t\tn = ItemAddress( %sMenus, %sMsg.Code );\n"
    "\t\t\t\t\tfunc = (GTMENUITEM_USERDATA( n ));\n"
    "\t\t\t\t\trunning = (*func)();\n"
    "\t\t\t\t\t%sMsg.Code = n->NextSelect;\n"
    "\t\t\t\t}\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_CLOSEWINDOW:\n"
    "\t\t\t\trunning = %sCloseWindow();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_RAWKEY:\n"
    "\t\t\t\trunning = %sRawKey();\n"
    "\t\t\t\tbreak;\n",

    NULL,

    "\n\t\t\tcase\tIDCMP_REQCLEAR:\n"
    "\t\t\t\trunning = %sReqClear();\n"
    "\t\t\t\tbreak;\n",

    NULL,

    "\n\t\t\tcase\tIDCMP_NEWPREFS:\n"
    "\t\t\t\trunning = %sNewPrefs();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_DISKINSERTED:\n"
    "\t\t\t\trunning = %sDiskInserted();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_DISKREMOVED:\n"
    "\t\t\t\trunning = %sDiskRemoved();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_WBENCHMESSAGE:\n"
    "\t\t\t\trunning = %sWBenchMessage();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_ACTIVEWINDOW:\n"
    "\t\t\t\trunning = %sActiveWindow();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_INACTIVEWINDOW:\n"
    "\t\t\t\trunning = %sInactiveWindow();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_DELTAMOVE:\n"
    "\t\t\t\trunning = %sDeltaMove();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_VANILLAKEY:\n"
    "\t\t\t\trunning = %sVanillaKey();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_INTUITICKS:\n"
    "\t\t\t\trunning = %sIntuiTicks();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_IDCMPUPDATE:\n"
    "\t\t\t\trunning = %sIDCMPUpdate();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_MENUHELP:\n"
    "\t\t\t\trunning = %sMenuHelp();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_CHANGEWINDOW:\n"
    "\t\t\t\trunning = %sChangeWindow();\n"
    "\t\t\t\tbreak;\n",

    "\n\t\t\tcase\tIDCMP_GADGETHELP:\n"
    "\t\t\t\trunning = %sGadgetHelp();\n"
    "\t\t\t\tbreak;\n"
};

static UBYTE *IDCMPProto[] = {
    NULL,
    "extern BOOL %sNewSize( void );\n",
    NULL,
    "extern BOOL %sMouseButtons( void );\n",
    "extern BOOL %sMouseMove( void );\n",
    NULL,
    NULL,
    "extern BOOL %sReqSet( void );\n",
    NULL,
    "extern BOOL %sCloseWindow( void );\n",
    "extern BOOL %sRawKey( void );\n",
    NULL,
    "extern BOOL %sReqClear( void );\n",
    NULL,
    "extern BOOL %sNewPrefs( void );\n",
    "extern BOOL %sDiskInserted( void );\n",
    "extern BOOL %sDiskRemoved( void );\n",
    "extern BOOL %sWBenchMessage( void );\n",
    "extern BOOL %sActiveWindow( void );\n",
    "extern BOOL %sInactiveWindow( void );\n",
    "extern BOOL %sDeltaMove( void );\n",
    "extern BOOL %sVanillaKey( void );\n",
    "extern BOOL %sIntuiTicks( void );\n",
    "extern BOOL %sIDCMPUpdate( void );\n",
    "extern BOOL %sMenuHelp( void );\n",
    "extern BOOL %sChangeWindow( void );\n",
    "extern BOOL %sGadgetHelp( void );\n"
};

static UBYTE *IDCMPTmp[] = {
    NULL,
    "\nBOOL %sNewSize( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_NEWSIZE  */\n"
    "\treturn( TRUE );\n"
    "}\n",
    NULL,
    "\nBOOL %sMouseButtons( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_MOUSEBUTTONS  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sMouseMove( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_MOUSEMOVE  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    NULL,
    NULL,
    "\nBOOL %sReqSet( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_REQSET  */\n"
    "\treturn( TRUE );\n"
    "}\n",
    NULL,
    "\nBOOL %sCloseWindow( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_CLOSEWINDOW  */\n"
    "\t/*  Return FALSE to quit, I suppose... ;)  */\n"
    "\treturn( FALSE );\n"
    "}\n",

    "\nBOOL %sRawKey( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_RAWKEY  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    NULL,
    "\nBOOL %sReqClear( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_REQCLEAR  */\n"
    "\treturn( TRUE );\n"
    "}\n",
    NULL,
    "\nBOOL %sNewPrefs( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_NEWPREFS  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sDiskInserted( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_DISKINSERTED  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sDiskRemoved( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_DISKREMOVED  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sWBenchMessage( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_WBENCHMESSAGE  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sActiveWindow( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_ACTIVEWINDOW  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sInactiveWindow( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_INACTIVEWINDOW  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sDeltaMove( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_DELTAMOVE  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sVanillaKey( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_VANILLAKEY  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sIntuiTicks( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_INTUITICKS  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sIDCMPUpdate( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_IDCMPUPDATE  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sMenuHelp( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_MENUHELP  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sChangeWindow( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_CHANGEWINDOW  */\n"
    "\treturn( TRUE );\n"
    "}\n",

    "\nBOOL %sGadgetHelp( void )\n"
    "{\n"
    "\t/*  Routine for IDCMP_GADGETHELP  */\n"
    "\treturn( TRUE );\n"
    "}\n"
};
///


// Misc
/// AskFile
BOOL AskFile( UBYTE *File, struct IE_Data *IE )
{
    BOOL    ret = TRUE;
    BPTR    lock;

    if( lock = Lock( File, ACCESS_READ )) {

	UnLock( lock );

	ULONG   tags[] = { RT_ReqPos, REQPOS_CENTERSCR, RT_Underscore, '_',
			   RT_Screen, IE->ScreenData->Screen, TAG_DONE };

	ret = rtEZRequest( "%s alreay exists.\n"
			   "Overwrite?",
			   "_Yes|_No",
			   NULL, (struct TagItem *)tags,
			   FilePart( File )
			 );
    }

    return( ret );
}
///
/// WriteList
void WriteList( struct GenFiles *Files, struct MinList *List, UBYTE *Label, UWORD Num, struct IE_Data *IE )
{
    struct GadgetScelta *gs;
    UWORD                cnt;

    if( Num ) {

	FPrintf( Files->XDef, "extern struct MinList %sList;\n", Label );

	FPrintf( Files->Std, "\nstruct Node %sNodes[] = {\n\t", Label );

	gs = List->mlh_Head;

	if( Num == 1 ) {
	    FPrintf( Files->Std, "(struct Node *)&%sList.mlh_Tail, (struct Node *)&%sList.mlh_Head, 0, 0, ",
		     Label, Label );

	    if( IE->C_Prefs & SMART_STR )
		FPrintf( Files->Std, "%s", (FindString( &Files->Strings, gs->gs_Testo ))->Label );
	    else
		FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );

	    FPuts( Files->Std, " };\n" );
	} else {

	    FPrintf( Files->Std, "&%sNodes[1], (struct Node *)&%sList.mlh_Head, 0, 0, ",
		     Label, Label );

	    if( IE->C_Prefs & SMART_STR )
		FPrintf( Files->Std, "%s", (FindString( &Files->Strings, gs->gs_Testo ))->Label );
	    else
		FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );

	    FPuts( Files->Std, ",\n" );

	    for( cnt = 1; cnt < Num - 1; cnt++ ) {

		gs = gs->gs_Node.ln_Succ;

		FPrintf( Files->Std, "\t&%sNodes[%ld], &%sNodes[%ld], 0, 0, ",
			 Label, cnt + 1, Label, cnt - 1 );

		if( IE->C_Prefs & SMART_STR )
		    FPrintf( Files->Std, "%s", (FindString( &Files->Strings, gs->gs_Testo ))->Label );
		else
		    FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );

		FPuts( Files->Std, ",\n" );
	    }

	    gs = gs->gs_Node.ln_Succ;
	    FPrintf( Files->Std, "\t(struct Node *)&%sList.mlh_Tail, &%sNodes[%ld], 0, 0, ",
		     Label, Label, Num - 2 );

	    if( IE->C_Prefs & SMART_STR )
		FPrintf( Files->Std, "%s", (FindString( &Files->Strings, gs->gs_Testo ))->Label );
	    else
		FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );

	    FPuts( Files->Std, " };\n" );
	}

	FPrintf( Files->Std, "\nstruct MinList %sList = {\n"
			     "\t(struct MinNode *)&%sNodes[0], (struct MinNode *)NULL, (struct MinNode *)&%sNodes[%ld] };\n",
		 Label, Label, Label, Num - 1 );
    }
}
///
/// WriteCD
void WriteCD( struct GenFiles *Files )
{
    struct StringNode  *str;
    UWORD               cnt = 0;

    for( str = Files->Strings.mlh_Head; str->Next; str = str->Next ) {

	FPrintf( (BPTR)Files->User1, "MSG_STRING_%ld (//)\n%s\n;\n",
		 cnt, str->String );

	cnt += 1;
    }
}
///

// Smart String System
/// CountArray
UWORD CountArray( UBYTE **Array )
{
    UWORD   cnt = 0;

    while( *Array++ )
	cnt += 1;

    return( cnt );
}
///
/// CmpArrays
BOOL CmpArrays( UBYTE **First, struct MinList *Second )
{
    UWORD                   num, cnt;
    struct GadgetScelta    *gs;

    num = CountArray( First );

    gs = Second->mlh_Head;
    cnt = 0;
    while( gs->gs_Node.ln_Succ ) {
	cnt += 1;
	gs = gs->gs_Node.ln_Succ;
    }

    if( num != cnt )
	return( FALSE );

    gs = Second->mlh_Head;

    for( cnt = 0; cnt < num; cnt++ ) {
	if( strcmp( *First++, gs->gs_Testo ))
	    return( FALSE );
	gs = gs->gs_Node.ln_Succ;
    }

    return( TRUE );
}
///
/// FindString
struct StringNode *FindString( struct MinList *List, UBYTE *String )
{
    struct StringNode  *str;

    for( str = List->mlh_Head; str->Next; str = str->Next )
	if(!( strcmp( str->String, String )))
	    return( str );

    return( NULL );
}
///
/// FindArray
struct ArrayNode *FindArray( struct MinList *List, struct MinList *Array )
{
    struct ArrayNode   *ar;

    for( ar = List->mlh_Head; ar->Next; ar = ar->Next )
	if( CmpArrays( ar->Array, Array ))
	    return( ar );

    return( NULL );
}
///
/// AddString
BOOL AddString( struct MinList *List, UBYTE *String )
{
    struct StringNode  *str;

    if(!( FindString( List, String ))) {
	if(!( str = AllocMem( sizeof( struct StringNode ), 0L )))
	    return( FALSE );

	AddTail(( struct List * )List, ( struct Node * )str );

	str->String = String;
    }

    return( TRUE );
}
///
/// AddArray
BOOL AddArray( struct GenFiles *Files, struct MinList *Items )
{
    struct ArrayNode       *ar;
    struct GadgetScelta    *gs;
    UBYTE                 **Array;
    UBYTE                   size = 4;

    if(!( FindArray( &Files->Arrays, Items ))) {
	if(!( ar = AllocMem( sizeof( struct ArrayNode ), 0L )))
	    return( FALSE );

	AddTail(( struct List * )&Files->Arrays, ( struct Node * )ar );

	gs = Items->mlh_Head;
	while( gs = gs->gs_Node.ln_Succ )
	    size += 4;

	if(!( Array = AllocVec( size, 0L )))
	    return( FALSE );

	ar->Array = Array;

	for( gs = Items->mlh_Head; gs->gs_Node.ln_Succ; gs = gs->gs_Node.ln_Succ ) {

	    *Array++ = gs->gs_Testo;

	    if(!( AddString( &Files->Strings, gs->gs_Testo ))) {
		FreeVec( ar->Array );
		return( FALSE );
	    }
	}

	*Array = NULL;

    }

    return( TRUE );
}
///
/// PutLabels
void PutLabels( struct IE_Data *IE, struct GenFiles *Files )
{
    UWORD               cnt;
    struct StringNode  *str;
    STRPTR              label;

    label = ( IE->SrcFlags & LOCALIZE ) ? "MSG_STRING_%ld" : "String%ld";

    for( str = Files->Strings.mlh_Head, cnt = 0; str->Next; str = str->Next ) {
	sprintf( str->Label, label, cnt );
	cnt += 1;
    }

    struct ArrayNode   *ar;

    for( ar = Files->Arrays.mlh_Head, cnt = 0; ar->Next; ar = ar->Next ) {
	sprintf( ar->Label, "Array%ld", cnt );
	cnt += 1;
    }
}
///
/// ProcessStrings
BOOL ProcessStrings( struct IE_Data *IE, struct GenFiles *Files )
{
    struct WindowInfo  *wnd;
    BOOL                loc;

    if(( IE->ScreenData->Title[0] ) && ( IE->flags_2 & GENERASCR ))
	if(!( AddString( &Files->Strings, IE->ScreenData->Title )))
	    return( FALSE );

    loc = ( IE->SrcFlags & LOCALIZE ) ? TRUE : FALSE;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {

	LONG   add;

	add = loc ? ( wnd->wi_Tags & W_LOC_TITLE ) : TRUE;

	if(( wnd->wi_Titolo[0] ) && ( add ))
	    if(!( AddString( &Files->Strings, wnd->wi_Titolo )))
		return( FALSE );

	if( loc )
	    add = wnd->wi_Tags & W_LOC_SCRTITLE;
	else
	    add = TRUE;

	if(( wnd->wi_TitoloSchermo[0] ) && ( add ))
	    if(!( AddString( &Files->Strings, wnd->wi_TitoloSchermo )))
		return( FALSE );

	struct GadgetInfo  *gad;

	if( loc )
	    add = wnd->wi_Tags & W_LOC_GADGETS;
	else
	    add = TRUE;

	if( add ) {
	    for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {

		if(( gad->g_Titolo[0] ) && ( gad->g_Kind < MIN_IEX_ID ))
		    if(!( AddString( &Files->Strings, gad->g_Titolo )))
			return( FALSE );

		switch( gad->g_Kind ) {

		    case MX_KIND:
		    case CYCLE_KIND:
			if(!( AddArray( Files, &gad->g_Scelte )))
			    return( FALSE );
			break;

		    case LISTVIEW_KIND:
			struct GadgetScelta *gs;
			for( gs = gad->g_Scelte.mlh_Head; gs->gs_Node.ln_Succ; gs = gs->gs_Node.ln_Succ )
			    if(!( AddString( &Files->Strings, gs->gs_Testo )))
				return( FALSE );
			break;

		    case TEXT_KIND:
		    case STRING_KIND:
			if( *((UBYTE *)(gad->g_ExtraMem)) )
			    if(!( AddString( &Files->Strings, gad->g_ExtraMem )))
				return( FALSE );
			break;

		    case NUMBER_KIND:
			if(( ((struct NK)(gad->g_Data)).Format[0] ) && ( strcmp( ((struct NK)(gad->g_Data)).Format, "%ld" )))
			    if(!( AddString( &Files->Strings, ((struct NK)(gad->g_Data)).Format )))
				return( FALSE );
			break;

		    case SLIDER_KIND:
			if( ((struct SlK)(gad->g_Data)).Format[0] )
			    if(!( AddString( &Files->Strings, ((struct SlK)(gad->g_Data)).Format )))
				return( FALSE );
			break;
		}

	    }
	}

	struct ITextNode   *txt;

	if( loc )
	    add = wnd->wi_Tags & W_LOC_TEXTS;
	else
	    add = TRUE;

	if( add )
	    for( txt = wnd->wi_ITexts.mlh_Head; txt->itn_Node.ln_Succ; txt = txt->itn_Node.ln_Succ )
		if( txt->itn_Text[0] )
		    if(!( AddString( &Files->Strings, txt->itn_Text )))
			return( FALSE );

	if( loc )
	    add = wnd->wi_Tags & W_LOC_MENUS;
	else
	    add = TRUE;

	if( add ) {
	    struct MenuTitle   *menu;
	    for( menu = wnd->wi_Menus.mlh_Head; menu->mt_Node.ln_Succ; menu = menu->mt_Node.ln_Succ ) {

		if( menu->mt_Text[0] )
		    if(!( AddString( &Files->Strings, menu->mt_Text )))
			return( FALSE );

		struct _MenuItem *item;
		for( item = menu->mt_Items.mlh_Head; item->min_Node.ln_Succ; item = item->min_Node.ln_Succ ) {

		    if(( item->min_Text[0] ) && (!( item->min_Flags & M_BARLABEL )))
			if(!( AddString( &Files->Strings, item->min_Text )))
			    return( FALSE );

		    if( item->min_CommKey[0] )
			if(!( AddString( &Files->Strings, item->min_CommKey )))
			    return( FALSE );

		    struct MenuSub *sub;
		    for( sub = item->min_Subs.mlh_Head; sub->msn_Node.ln_Succ; sub = sub->msn_Node.ln_Succ ) {

			if(( sub->msn_Text[0] ) && (!( sub->msn_Flags & M_BARLABEL )))
			    if(!( AddString( &Files->Strings, sub->msn_Text )))
				return( FALSE );

			if( sub->msn_CommKey[0] )
			    if(!( AddString( &Files->Strings, sub->msn_CommKey )))
				return( FALSE );
		    }
		}
	    }
	}

    }

    PutLabels( IE, Files );

    return( TRUE );
}
///
/// FreeStrings
void FreeStrings( struct GenFiles *Files )
{
    struct StringNode  *Str;
    struct ArrayNode   *Array;

    while( Str = RemHead(( struct List * )&Files->Strings ))
	FreeMem( Str, sizeof( struct StringNode ));

    while( Array = RemHead(( struct List * )&Files->Arrays )) {
	FreeVec( Array->Array );
	FreeMem( Array, sizeof( struct ArrayNode ));
    }
}
///

// Code
/// WriteMain
void WriteMain( struct GenFiles *Files, struct IE_Data *IE )
{
    struct LibNode     *lib;
    struct WndToOpen   *wto;
    BOOL               bool;

    FPrintf( Files->Main,
	"#define INTUI_V36_NAMES_ONLY\n\n"
	"#include <dos/dos.h>\n"
	"#include <exec/libraries.h>\n"
	"#include <clib/exec_protos.h>\n"
	"#include <clib/dos_protos.h>\n\n"
	"#include <stdio.h>\n"
	"#include <stdlib.h>\n"
	"#include <string.h>\n"
	"#include <errno.h>\n\n"
	"#include \"%s\"\n"
	"int    main( void );\n"
	"void   OpenLibs( void );\n"
	"void   Setup( void );\n"
	"void   CloseLibs( void );\n"
	"void   CloseAll( void );\n"
	"void   PlayTheGame( void );\n"
	"void   Error( STRPTR, STRPTR );\n"
	"void   End( ULONG );\n",
	FilePart( Files->XDefName ));

    if( IE->MainProcFlags & MAIN_WB )
	FPuts( Files->Main, "int    wbmain( struct WBStartup * );\n" );

    if( IE->ExtraProc[0] ) {
	FPrintf( Files->Main, "extern void %s( void );\n", IE->ExtraProc );

	if( IE->C_Prefs & GEN_TEMPLATE ) {
	    FPrintf( Files->Temp,
		"void %s( void );\n"
		"{\n"
		"\t/*  ...Initialization Stuff...  */\n"
		"}\n",
		IE->ExtraProc );
	}
    }

    if( IE->MainProcFlags & MAIN_OTHERBITS ) {
	FPuts( Files->Main, "extern BOOL HandleOtherSignals( void );\n" );

	if( IE->C_Prefs & GEN_TEMPLATE ) {
	    FPuts( Files->Temp,
		"BOOL HandleOtherSignals( void )\n"
		"{\n"
		"\t/*  Routine to handle other signals  */\n"
		"\treturn( TRUE );\n"
		"}\n" );
	}
    }

    FPuts( Files->Main,
	"\nBOOL\t\t\tOk_to_Run = TRUE;\n"
	"ULONG\t\t\tmask = NULL;\n\n"
	"extern struct Library\t*SysBase;\n"
	"extern struct Library\t*DOSBase;\n" );

    if( IE->MainProcFlags & MAIN_WB )
	FPuts( Files->Main, "struct WBStartup\t\t*WBMsg = NULL;\n" );

    for( lib = IE->Libs_List.mlh_Head; lib->lbn_Node.ln_Succ; lib = lib->lbn_Node.ln_Succ )
	FPrintf( Files->Main, "struct Library\t\t*%s = NULL;\n", lib->lbn_Base );


    FPuts( Files->Main,
	"\n#include \"IE_Errors.h\"\n"
	"\nint main( void )\n"
	"{\n"
	"\tOpenLibs();\n"
	"\tSetup();\n" );

    if( IE->ExtraProc[0] )
	FPrintf( Files->Main, "\t%s();\n", IE->ExtraProc );

    FPuts( Files->Main,
	"\tPlayTheGame();\n"
	"\tEnd( RETURN_OK );\n"
	"}\n\n"
	"void End( ULONG RetCode )\n"
	"{\n"
	"\tCloseAll();\n"
	"\tCloseLibs();\n"
	"\texit( RetCode );\n"
	"}\n\n"
	"void OpenLibs( void )\n"
	"{\n" );

    for( lib = IE->Libs_List.mlh_Head; lib->lbn_Node.ln_Succ; lib = lib->lbn_Node.ln_Succ ) {
	if ( lib->lbn_Node.ln_Pri & L_FAIL )
	    FPrintf( Files->Main,
		     "\tif (!( %s = OpenLibrary( \"%s\", %ld )))\n"
		     "\t\tError( ErrStrings[ OPEN_LIB ], \"%s\" );\n",
		     lib->lbn_Base, lib->lbn_Name, lib->lbn_Version, lib->lbn_Name );
	else
	    FPrintf( Files->Main,
		     "\t%s = OpenLibrary( \"%s\", %ld );\n",
		     lib->lbn_Base, lib->lbn_Name, lib->lbn_Version );
    }

    FPuts( Files->Main,
	   "}\n\n"
	   "void Setup( void )\n"
	   "{\n"
	   "\tULONG\t\tret;\n" );

    if( IE->SrcFlags & OPENDISKFONT ) {
	struct TxtAttrNode *fnt;

	bool = FALSE;
	for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next )
	    if( fnt->txa_Flags & FPB_DISKFONT )
		bool = TRUE;

	if( bool )
	    FPuts( Files->Main,
		   "\tif (!( OpenDiskFonts()))\n"
		   "\t\tError( ErrStrings[ OPEN_FONTS ], NULL );\n" );
    }

    FPuts( Files->Main,
	   "\tif ( ret = SetupScreen())\n"
	   "\t\tError( ErrStrings[ SETUP_SCR ], ErrStrings[ SETUP_SCR+ret ]);\n" );

    for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
	FPrintf( Files->Main,
		 "\tif ( ret = Open%sWindow())\n"
		 "\t\tError( ErrStrings[ OPEN_WND ], ErrStrings[ OPEN_WND+ret ]);\n",
		 wto->wto_Label );

    if( IE->NumRexxs )
	FPuts( Files->Main, "\tSetupRexxPort();\n" );

    FPuts( Files->Main,
	   "}\n\n"
	   "void CloseAll( void )\n"
	   "{\n" );

    for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
	FPrintf( Files->Main, "\tClose%sWindow();\n", wto->wto_Label );

    FPuts( Files->Main, "\tCloseDownScreen();\n" );

    if(( IE->SrcFlags & OPENDISKFONT ) && ( bool ))
	FPuts( Files->Main, "\tCloseDiskFonts();\n" );

    if( IE->NumRexxs )
	FPuts( Files->Main, "\tDeleteRexxPort();\n" );

    FPuts( Files->Main, "}\n\nvoid CloseLibs( void )\n{\n" );

    for( lib = IE->Libs_List.mlh_Head; lib->lbn_Node.ln_Succ; lib = lib->lbn_Node.ln_Succ )
	FPrintf( Files->Main, "\tif ( %s )\n"
			      "\t\tCloseLibrary( %s );\n",
		 lib->lbn_Base, lib->lbn_Base );

    FPuts( Files->Main,
	   "}\n\n"
	   "void PlayTheGame( void )\n"
	   "{\n"
	   "\tULONG\tsignals, other = mask;\n" );

    for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
	FPrintf( Files->Main, "\tULONG\t%s_signal = 1 << %sWnd->UserPort->mp_SigBit;\n",
		 wto->wto_Label, wto->wto_Label );

    if( IE->NumRexxs )
	FPuts( Files->Main, "\tULONG\trexx_signal = NULL;\n\n"
			    "\tif ( RexxPort )\n"
			    "\t\trexx_signal = 1 << RexxPort->mp_SigBit;\n\n" );

    FPuts( Files->Main, "\tmask = mask" );

    if( IE->MainProcFlags & MAIN_CTRL_C )
	FPuts( Files->Main, " | SIGBREAKF_CTRL_C" );

    for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
	FPrintf( Files->Main, " | %s_signal", wto->wto_Label );

    if( IE->NumRexxs )
	FPuts( Files->Main, " | rexx_signal" );

    FPuts( Files->Main, ";\n\n\twhile( Ok_to_Run ) {\n\t\tsignals = Wait( mask );\n" );

    for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
	FPrintf( Files->Main, "\t\tif (signals & %s_signal)\n"
			      "\t\t\tOk_to_Run = Handle%sIDCMP();\n",
		 wto->wto_Label, wto->wto_Label );

    if( IE->NumRexxs )
	FPuts( Files->Main, "\t\tif (signals & rexx_signal)\n"
			    "\t\t\tHandleRexxMsg();\n" );

    if( IE->MainProcFlags & MAIN_OTHERBITS )
	FPuts( Files->Main, "\t\tif (signals & other)\n"
			    "\t\t\tOk_to_Run = HandleOtherSignals();\n" );

    if( IE->MainProcFlags & MAIN_CTRL_C )
	FPuts( Files->Main, "\t\tif (signals & SIGBREAKF_CTRL_C)\n"
			    "\t\t\tOk_to_Run = FALSE;\n" );

    FPuts( Files->Main, "\t};\n\n}\n" );

    if( IE->MainProcFlags & MAIN_WB )
	FPuts( Files->Main, "\nint wbmain( struct WBStartup *msg )\n{\n"
			    "\tWBMsg = msg;\n"
			    "\treturn( main() );\n}\n" );
}
///
/// WriteSetupScr
void WriteSetupScr( struct GenFiles *Files, struct IE_Data *IE )
{
    if( IE->SrcFlags & FONTSENSITIVE ) {

	FPuts( Files->XDef, "extern UWORD ScaleX( UWORD );\n"
			    "extern UWORD ScaleY( UWORD );\n" );

	FPrintf( Files->Std, "\nUWORD ScaleX( UWORD value )\n"
			     "{\n"
			     "\treturn(( UWORD )((( FontX * value ) + %ld ) / %ld ));\n"
			     "}\n"
			     "\n"
			     "UWORD ScaleY( UWORD value )\n"
			     "{\n"
			     "\treturn(( UWORD )((( FontY * value ) + %ld ) / %ld ));\n"
			     "}\n"
			     "\n"
			     "static void ComputeFont( UWORD width, UWORD height )\n"
			     "{\n"
			     "\tFont = &Attr;\n"
			     "\tFont->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;\n"
			     "\tFont->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;\n"
			     "\tFontX = Scr->RastPort.Font->tf_XSize;\n"
			     "\n"
			     "\tXOffset = Scr->WBorLeft;\n"
			     "\tYOffset = Scr->RastPort.TxHeight + Scr->WBorTop;\n"
			     "\n"
			     "\tif( width && height )\n"
			     "\t\tif((( ScaleX( width ) + Scr->WBorRight ) > Scr->Width ) ||\n"
			     "\t\t\t(( ScaleY( height ) + Scr->WBorBottom + YOffset ) > Scr->Height ))\n"
			     "\t\t\t\t{\n"
			     "\t\t\t\t\tFont->ta_Name = (STRPTR)\"topaz.font\";\n"
			     "\t\t\t\t\tFontX = FontY = Font->ta_YSize = 8;\n"
			     "\t\t\t\t}\n"
			     "}\n",
		 IE->ScreenData->Screen->RastPort.Font->tf_XSize >> 1,
		 IE->ScreenData->Screen->RastPort.Font->tf_XSize,
		 IE->ScreenData->Screen->RastPort.Font->tf_YSize >> 1,
		 IE->ScreenData->Screen->RastPort.Font->tf_YSize );
    }

    FPuts( Files->Std, "\nint SetupScreen( void )\n"
		       "{\n"
		       "\tif(!( Scr = " );

    if( IE->flags_2 & GENERASCR )
	FPuts( Files->Std, "OpenScreenTagList( NULL, (struct TagItem *)ScreenTags" );
    else
	FPuts( Files->Std, "LockPubScreen( PubScreenName" );

    FPuts( Files->Std, " )))\n\t\treturn( 1L );\n\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\tComputeFont( 0, 0 );\n" );
    else
	FPuts( Files->Std, "\tYOffset = Scr->WBorTop + Scr->Font->ta_YSize;\n"
			   "\tXOffset = Scr->WBorLeft;\n" );

    FPuts( Files->Std, "\n\tif(!( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))\n"
		       "\t\treturn( 2L );\n" );

    if(( IE->SrcFlags & SHARED_PORT ) && (!( IE->SharedPort[0] )))
	FPuts( Files->Std, "\n\tif(!( IDCMPPort = CreateMsgPort() ))\n"
			   "\t\treturn( 3L );\n" );

    // Expanders
    ( *IE->IEXSrcFun->Setup )( Files );

    FPuts( Files->Std, "\n"
		       "\treturn( 0L );\n"
		       "}\n\n"
		       "void CloseDownScreen( void )\n"
		       "{\n"
		       "\tif( VisualInfo ) {\n"
		       "\t\tFreeVisualInfo( VisualInfo );\n"
		       "\t\tVisualInfo = NULL;\n"
		       "\t}\n" );

    // Expanders
    ( *IE->IEXSrcFun->CloseDown )( Files );

    FPuts( Files->Std, "\n\tif( Scr ) {\n\t\t" );

    if( IE->flags_2 & GENERASCR )
	FPuts( Files->Std, "CloseScreen(" );
    else
	FPuts( Files->Std, "UnlockPubScreen( NULL," );

    FPuts( Files->Std, " Scr );\n"
		       "\t\tScr = NULL;\n"
		       "\t}\n" );

    if(( IE->SrcFlags & SHARED_PORT ) && (!( IE->SharedPort[0] )))
	FPuts( Files->Std, "\tif( IDCMPPort ) {\n"
			   "\t\tDeleteMsgPort( IDCMPPort );\n"
			   "\t\tIDCMPPort = NULL;\n"
			   "\t}" );

    FPuts( Files->Std, "\n}\n"
		       "\n"
		       "LONG OpenWnd( struct Gadget *GList, struct TagItem WTags[], struct Window **Wnd )\n"
		       "{\n"
		       "\tUWORD\t\ttc;\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\tUWORD\t\tww, wh, oldww, oldwh;\n" );

    FPuts( Files->Std, "\n\tif( GList ) {\n"
		       "\t\ttc = 0;\n"
		       "\t\twhile( WTags[ tc ].ti_Tag != WA_Gadgets ) tc++;\n"
		       "\t\tWTags[ tc ].ti_Data = (ULONG)GList;\n"
		       "\t}\n\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\tww = ScaleX( WTags[ WT_WIDTH  ].ti_Data ) + XOffset + Scr->WBorRight;\n"
			   "\twh = ScaleY( WTags[ WT_HEIGHT ].ti_Data ) + YOffset + Scr->WBorBottom;\n"
			   "\n"
			   "\tif(( WTags[ WT_LEFT ].ti_Data + ww ) > Scr->Width  )\n"
			   "\t\tWTags[ WT_LEFT ].ti_Data = Scr->Width  - ww;\n"
			   "\tif(( WTags[ WT_TOP  ].ti_Data + wh ) > Scr->Height )\n"
			   "\t\tWTags[ WT_TOP  ].ti_Data = Scr->Height - wh;\n"
			   "\n"
			   "\toldww = WTags[ WT_WIDTH  ].ti_Data;\n"
			   "\toldwh = WTags[ WT_HEIGHT ].ti_Data;\n"
			   "\tWTags[ WT_WIDTH  ].ti_Data = ww;\n"
			   "\tWTags[ WT_HEIGHT ].ti_Data = wh;\n\n" );

    FPuts( Files->Std, "\tWTags[8].ti_Data = (ULONG)Scr;\n"
		       "\n\t*Wnd = OpenWindowTagList( NULL, &WTags[0] );\n\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\tWTags[ WT_WIDTH  ].ti_Data = oldww;\n"
			   "\tWTags[ WT_HEIGHT ].ti_Data = oldwh;\n\n" );

    FPuts( Files->Std, "\tif(!( *Wnd ))\n"
		       "\t\treturn( 4L );\n\n"
		       "\tGT_RefreshWindow( *Wnd, NULL );\n"
		       "\treturn( 0L );\n}\n"
		       "\n"
		       "void CloseWnd( struct Window **Wnd, struct Gadget **GList, struct Menu **Mn )\n"
		       "{\n"
		       "\tif( Mn ) {\n"
		       "\t\tif( *Wnd )\n"
		       "\t\t\tClearMenuStrip( *Wnd );\n\n"
		       "\t\tFreeMenus( *Mn );\n"
		       "\t\t*Mn = NULL;\n"
		       "\t}\n"
		       "\tif( *Wnd ) {\n"
		       "\t\tCloseWindow( *Wnd );\n"
		       "\t\t*Wnd = NULL;\n"
		       "\t}\n"
		       "\tif( GList ) {\n"
		       "\t\tFreeGadgets( *GList );\n"
		       "\t\t*GList = NULL;\n"
		       "\t}\n"
		       "}\n"
		       "\n"
		       "LONG MakeGadgets( struct Gadget **GList, struct Gadget *Gads[],\n"
		       "\tstruct NewGadget NGad[], UWORD GTypes[], ULONG GTags[], UWORD CNT )\n"
		       "{\n"
		       "\tstruct Gadget\t\t*g;\n"
		       "\tUWORD\t\t\tlc, tc;\n"
		       "\tstruct NewGadget\tng;\n\n"
		       "\tif(!( g = CreateContext( GList )))\n"
		       "\t\treturn( 1L );\n\n"
		       "\tfor( lc = 0, tc = 0; lc < CNT; lc++ ) {\n\n"
		       "\t\tCopyMem(( char * )&NGad[ lc ], ( char * )&ng, ( long )sizeof( struct NewGadget ));\n"
		       "\t\tng.ng_VisualInfo = VisualInfo;\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\t\tng.ng_TextAttr = Font;\n"
			   "\t\tng.ng_LeftEdge = XOffset + ScaleX( ng.ng_LeftEdge );\n"
			   "\t\tng.ng_TopEdge  = YOffset + ScaleY( ng.ng_TopEdge  );\n"
			   "\t\tng.ng_Width    = ScaleX( ng.ng_Width  );\n"
			   "\t\tng.ng_Height   = ScaleY( ng.ng_Height );\n" );
    else
	FPuts( Files->Std, "\t\tng.ng_TopEdge  += YOffset;\n"
			   "\t\tng.ng_LeftEdge += XOffset;\n" );

    FPuts( Files->Std, "\t\tGads[ lc ] = g = CreateGadgetA((ULONG)GTypes[ lc ], g, &ng, (struct TagItem *)&GTags[ tc ] );\n\n"
		       "\t\twhile( GTags[ tc ] )\n"
		       "\t\t\ttc += 2;\n"
		       "\t\ttc++;\n\n"
		       "\t\tif( !g )\n"
		       "\t\t\treturn( 2L );\n"
		       "\t}\n\n"
		       "\treturn( 0L );\n"
		       "}\n" );
}
///
/// WriteOpenWnd
void WriteOpenWnd( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct GadgetInfo  *gad;
    UWORD               cnt = 0;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {

	FPrintf( Files->XDef, "extern LONG Open%sWindow( void );\n"
			      "extern void Close%sWindow( void );\n",
		 wnd->wi_Label, wnd->wi_Label );

	if(!( wnd->wi_NoOpenWnd )) { // supplied by an expander?

	    FPrintf( Files->Std, "\nLONG Open%sWindow( void )\n"
				 "{\n"
				 "\tLONG\t\tret_code = NULL;\n",
		     wnd->wi_Label );

	    if( wnd->wi_NumGads ) {
		if( wnd->wi_NumBools )
		    if( wnd->wi_IDCMP & IDCMP_GADGETHELP )
			FPuts( Files->Std, "\tstruct ExtGadget\t*g;\n"
					   "\tint\t\tc;\n" );
		    else
			FPuts( Files->Std, "\tstruct Gadget\t*g;\n"
					   "\tint\t\tc;\n" );
	    }

	    if( IE->SrcFlags & FONTSENSITIVE )
		FPrintf( Files->Std, "\n\tComputeFont( %ld, %ld );\n",
			 wnd->wi_Width - ( IE->ScreenData->XOffset + IE->ScreenData->Screen->WBorRight  ),
			 wnd->wi_Height - ( IE->ScreenData->YOffset + IE->ScreenData->Screen->WBorBottom ));

	    if(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & ( W_LOC_TITLE | W_LOC_SCRTITLE | W_LOC_GADGETS | W_LOC_MENUS | W_LOC_TEXTS ))) {

		FPrintf( Files->Std, "\n\tif(!( Localized[ %ld ] )) {\n", cnt );

		if(( wnd->wi_Titolo[0] ) && ( wnd->wi_Tags & W_LOC_TITLE ))
		    FPrintf( Files->Std, "\n\t\t%sWTags[ 9 ].ti_Data = (ULONG)CatCompArray[ %sWTags[ 9 ].ti_Data ].cca_Str;\n",
			     wnd->wi_Label, wnd->wi_Label );

		if(( wnd->wi_TitoloSchermo[0] ) && ( wnd->wi_Tags & W_LOC_SCRTITLE ))
		    FPrintf( Files->Std, "\n\t\tULONG *tg;\n"
					 "\t\ttg = (ULONG *)&%sWTags[0];\n"
					 "\t\twhile( *tg++ != WA_ScreenTitle );\n"
					 "\t\t*tg = (ULONG)CatCompArray[ *tg ].cca_Str;\n",
			     wnd->wi_Label );

		if(( wnd->wi_NumGads - wnd->wi_NumBools ) && ( wnd->wi_Tags & W_LOC_GADGETS )) {

		    FPrintf( Files->Std, "\n\t\tLocalizeGadgets( &%sNGad[0], &%sGTags[0], &%sGTypes[0], %s_CNT );\n",
			     wnd->wi_Label, wnd->wi_Label,
			     wnd->wi_Label, wnd->wi_Label );

		    for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ )
			if(( gad->g_Kind == LISTVIEW_KIND ) && ( gad->g_NumScelte ))
			    FPrintf( Files->Std, "\t\tLocalizeList( &%sList );\n",
				     gad->g_Label );
		}

		if(( wnd->wi_NumTexts ) && ( wnd->wi_Tags & W_LOC_TEXTS ))
		    FPrintf( Files->Std, "\n\t\tLocalizeITexts( &%sIText[0], %ld );\n",
			     wnd->wi_Label, wnd->wi_NumTexts );

		if(( wnd->wi_NumMenus ) && ( wnd->wi_Tags & W_LOC_MENUS ))
		    FPrintf( Files->Std, "\n\t\tLocalizeMenus( &%sNewMenu[0] );\n",
			     wnd->wi_Label );

		FPuts( Files->Std, "\t}\n" );
	    }

	    if( wnd->wi_NumGads ) {

		FPrintf( Files->Std, "\n\tret_code = MakeGadgets( &%sGList, %sGadgets, %sNGad,\n"
				     "\t\t%sGTypes, %sGTags, %s_CNT );\n"
				     "\tif( ret_code )\n"
				     "\t\treturn( ret_code );\n",
			 wnd->wi_Label, wnd->wi_Label, wnd->wi_Label,
			 wnd->wi_Label, wnd->wi_Label, wnd->wi_Label );

		if( wnd->wi_NumBools ) {

		    gad = wnd->wi_Gadgets.mlh_Head;
		    while( gad->g_Kind != BOOLEAN )
			gad = gad->g_Node.ln_Succ;

		    if( wnd->wi_IDCMP & IDCMP_GADGETHELP ) {
			if( IE->SrcFlags & FONTSENSITIVE )
			    FPrintf( Files->Std, "\tg = &%sGadget;\n"
					       "\tfor( c = 0; c < %ld; c++ ) {\n"
					       "\t\tg->BoundsLeftEdge = g->LeftEdge = XOffset + ScaleX( g->LeftEdge );\n"
					       "\t\tg->BoundsTopEdge  = g->TopEdge  = YOffset + ScaleY( g->TopEdge );\n",
				   gad->g_Label, wnd->wi_NumBools );
			else
			    FPrintf( Files->Std, "\tg = &%sGadget;\n"
					       "\tfor( c = 0; c < %ld; c++ ) {\n"
					       "\t\tg->LeftEdge       += XOffset;\n"
					       "\t\tg->TopEdge        += YOffset;\n"
					       "\t\tg->BoundsLeftEdge += XOffset;\n"
					       "\t\tg->BoundsTopEdge  += YOffset;\n",
				   gad->g_Label, wnd->wi_NumBools );
		    } else {
			if( IE->SrcFlags & FONTSENSITIVE )
			    FPrintf( Files->Std, "\tg = &%sGadget;\n"
					       "\tfor( c = 0; c < %ld; c++ ) {\n"
					       "\t\tg->LeftEdge = XOffset + ScaleX( g->LeftEdge );\n"
					       "\t\tg->TopEdge  = YOffset + ScaleY( g->TopEdge );\n",
				   gad->g_Label, wnd->wi_NumBools );
			else
			    FPrintf( Files->Std, "\tg = &%sGadget;\n"
					       "\tfor( c = 0; c < %ld; c++ ) {\n"
					       "\t\tg->LeftEdge += XOffset;\n"
					       "\t\tg->TopEdge  += YOffset;\n",
				   gad->g_Label, wnd->wi_NumBools );
		    }

		    if(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & W_LOC_GADGETS ))
			FPrintf( Files->Std, "\t\tif( g->GadgetText )\n"
					     "\t\t\tif(!( Localized[ %ld ] ) && ( g->GadgetText->IText ))\n"
					     "\t\t\t\tg->GadgetText->IText = (UBYTE *)CatCompArray[ (ULONG)g->GadgetText->IText ].cca_Str;\n",
				 cnt );

		    FPuts( Files->Std, "\t\tg = g->NextGadget;\n"
				       "\t}\n" );

		    gad = wnd->wi_Gadgets.mlh_TailPred;
		    while( gad->g_Kind != BOOLEAN )
			gad = gad->g_Node.ln_Pred;

		    FPrintf( Files->Std, "\t%sGadget.NextGadget = %sGList;\n",
			     gad->g_Label, wnd->wi_Label );
		}
	    }

	    if( wnd->wi_NumMenus )
		FPrintf( Files->Std, "\tif(!( %sMenus = CreateMenus( %sNewMenu, TAG_END )))\n"
				     "\t\treturn( 3L );\n\n"
				     "\tLayoutMenus( %sMenus, VisualInfo, GTMN_NewLookMenus, TRUE, TAG_END );\n\n",
			 wnd->wi_Label, wnd->wi_Label, wnd->wi_Label );
	}

	// Expanders
	IE->win_info = wnd;
	( *IE->IEXSrcFun->OpenWnd )( Files );

	if(!( wnd->wi_NoOpenWnd )) {

	    FPuts( Files->Std, (( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT )) ?
			       "\tret_code = OpenWndShd( " : "\tret_code = OpenWnd( " );

	    if( wnd->wi_NumGads )
		if( wnd->wi_NumBools ) {
		    gad = wnd->wi_Gadgets.mlh_Head;
		    while( gad->g_Kind != BOOLEAN )
			gad = gad->g_Node.ln_Succ;
		    FPrintf( Files->Std, "&%sGadget", gad->g_Label );
		} else {
		    FPrintf( Files->Std, "%sGList", wnd->wi_Label );
		}
	    else
		FPuts( Files->Std, Null );

	    FPrintf( Files->Std, ", %sWTags, &%sWnd",
		     wnd->wi_Label, wnd->wi_Label );

	    if(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT ))
		FPrintf( Files->Std, ", %s_IDCMP", wnd->wi_Label );

	    FPuts( Files->Std, " );\n"
			       "\tif( ret_code )\n"
			       "\t\treturn( ret_code );\n" );

	    if( wnd->wi_NumMenus )
		FPrintf( Files->Std, "\tSetMenuStrip( %sWnd, %sMenus );\n",
			 wnd->wi_Label, wnd->wi_Label );

	    if( wnd->wi_NeedRender )
		FPrintf( Files->Std, "\n\t%sRender();\n", wnd->wi_Label );

	    if(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & ( W_LOC_TITLE | W_LOC_SCRTITLE | W_LOC_GADGETS | W_LOC_MENUS | W_LOC_TEXTS )))
		FPrintf( Files->Std, "\n\tLocalized[ %ld ] = TRUE;\n", cnt );

	    FPuts( Files->Std, "\treturn( 0L );\n}\n\n" );
	}

	FPrintf( Files->Std, "void Close%sWindow( void )\n"
			     "{\n",
		 wnd->wi_Label );

	if( wnd->wi_NumBools )
	    if( wnd->wi_IDCMP & IDCMP_GADGETHELP )
		FPuts( Files->Std, "\tstruct ExtGadget\t*g;\n"
				   "\tint\t\tc;\n" );
	    else
		FPuts( Files->Std, "\tstruct Gadget\t*g;\n"
				   "\tint\t\tc;\n" );

	FPrintf( Files->Std, (( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT )) ?
		 "\n\tCloseWndShd( &%sWnd, " : "\n\tCloseWnd( &%sWnd, ", wnd->wi_Label );

	if( wnd->wi_NumGads - wnd->wi_NumBools )
	    FPrintf( Files->Std, "&%sGList, ", wnd->wi_Label );
	else
	    FPuts( Files->Std, "NULL, " );

	if( wnd->wi_NumMenus )
	    FPrintf( Files->Std, "&%sMenus", wnd->wi_Label );
	else
	    FPuts( Files->Std, Null );

	FPuts( Files->Std, " );\n" );

	if( wnd->wi_NumBools ) {

	    gad = wnd->wi_Gadgets.mlh_Head;
	    while( gad->g_Kind != BOOLEAN )
		gad = gad->g_Node.ln_Succ;

	    if( wnd->wi_IDCMP & IDCMP_GADGETHELP ) {
		if( IE->SrcFlags & FONTSENSITIVE )
		    FPrintf( Files->Std, "\tg = &%sGadget;\n"
				       "\tfor( c = 0; c < %ld; c++ ) {\n"
				       "\t\tg->BoundsLeftEdge = g->LeftEdge = (((( g->LeftEdge - XOffset ) * %ld ) - %ld ) / FontX);\n"
				       "\t\tg->BoundsTopEdge  = g->TopEdge  = (((( g->TopEdge  - YOffset ) * %ld ) - %ld ) / FontY);\n"
				       "\t\tg = g->NextGadget;\n"
				       "\t}\n",
			   gad->g_Label, wnd->wi_NumBools,
			   IE->ScreenData->Screen->RastPort.Font->tf_XSize,
			   IE->ScreenData->Screen->RastPort.Font->tf_XSize >> 1,
			   IE->ScreenData->Screen->RastPort.Font->tf_YSize,
			   IE->ScreenData->Screen->RastPort.Font->tf_XSize >> 1 );
		else
		    FPrintf( Files->Std, "\tg = &%sGadget;\n"
				       "\tfor( c = 0; c < %ld; c++ ) {\n"
				       "\t\tg->LeftEdge       -= XOffset;\n"
				       "\t\tg->TopEdge        -= YOffset;\n"
				       "\t\tg->BoundsLeftEdge -= XOffset;\n"
				       "\t\tg->BoundsTopEdge  -= YOffset;\n"
				       "\t\tg = g->NextGadget;\n"
				       "\t}\n",
			   gad->g_Label, wnd->wi_NumBools );
	    } else {
		if( IE->SrcFlags & FONTSENSITIVE )
		    FPrintf( Files->Std, "\tg = &%sGadget;\n"
				       "\tfor( c = 0; c < %ld; c++ ) {\n"
				       "\t\tg->LeftEdge = (((( g->LeftEdge - XOffset ) * %ld ) - %ld ) / FontX);\n"
				       "\t\tg->TopEdge  = (((( g->TopEdge  - YOffset ) * %ld ) - %ld ) / FontY);\n"
				       "\t\tg = g->NextGadget;\n"
				       "\t}\n",
			   gad->g_Label, wnd->wi_NumBools,
			   IE->ScreenData->Screen->RastPort.Font->tf_XSize,
			   IE->ScreenData->Screen->RastPort.Font->tf_XSize >> 1,
			   IE->ScreenData->Screen->RastPort.Font->tf_YSize,
			   IE->ScreenData->Screen->RastPort.Font->tf_XSize >> 1 );
		else
		    FPrintf( Files->Std, "\tg = &%sGadget;\n"
				       "\tfor( c = 0; c < %ld; c++ ) {\n"
				       "\t\tg->LeftEdge -= XOffset;\n"
				       "\t\tg->TopEdge  -= YOffset;\n"
				       "\t\tg = g->NextGadget;\n"
				       "\t}\n",
			   gad->g_Label, wnd->wi_NumBools );
	    }
	}

	// Expanders
	( *IE->IEXSrcFun->CloseWnd )( Files );

	FPuts( Files->Std, "\n}\n" );

	cnt += 1;
    }
}
///
/// WriteOpenWndShd
void WriteOpenWndShd( struct GenFiles *Files, struct IE_Data *IE )
{
    FPuts( Files->Std, "LONG OpenWndShd( struct Gadget *GList, struct TagItem *WTags, struct Window **Wnd, ULONG IDCMP )\n"
		       "{\n"
		       "\tUWORD\t\ttc;\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\tUWORD\t\tww, wh, oldww, oldwh;\n" );

    FPuts( Files->Std, "\n\tif( GList ) {\n"
		       "\t\ttc = 0;\n"
		       "\t\twhile( WTags[ tc ].ti_Tag != WA_Gadgets ) tc++;\n"
		       "\t\tWTags[ tc ].ti_Data = (ULONG)GList;\n"
		       "\t}\n\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\tww = ScaleX( WTags[ WT_WIDTH  ].ti_Data ) + XOffset + Scr->WBorRight;\n"
			   "\twh = ScaleY( WTags[ WT_HEIGHT ].ti_Data ) + YOffset + Scr->WBorBottom;\n"
			   "\n"
			   "\tif(( WTags[ WT_LEFT ].ti_Data + ww ) > Scr->Width  )\n"
			   "\t\tWTags[ WT_LEFT ].ti_Data = Scr->Width  - ww;\n"
			   "\tif(( WTags[ WT_TOP  ].ti_Data + wh ) > Scr->Height )\n"
			   "\t\tWTags[ WT_TOP  ].ti_Data = Scr->Height - wh;\n"
			   "\n"
			   "\toldww = WTags[ WT_WIDTH  ].ti_Data;\n"
			   "\toldwh = WTags[ WT_HEIGHT ].ti_Data;\n"
			   "\tWTags[ WT_WIDTH  ].ti_Data = ww;\n"
			   "\tWTags[ WT_HEIGHT ].ti_Data = wh;\n\n" );

    FPrintf( Files->Std, "\tWTags[8].ti_Data = (ULONG)Scr;\n"
			 "\n\tif( *Wnd = OpenWindowTagList( NULL, &WTags[0] )) {\n"
			 "\t\t( *Wnd )->UserPort = %s;\n"
			 "\t\tModifyIDCMP( *Wnd, IDCMP );\n"
			 "\t}\n\n",
	   Files->User2 );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "\tWTags[ WT_WIDTH  ].ti_Data = oldww;\n"
			   "\tWTags[ WT_HEIGHT ].ti_Data = oldwh;\n\n" );

    FPrintf( Files->Std, "\tif(!( *Wnd ))\n"
			 "\t\treturn( 4L );\n\n"
			 "\tGT_RefreshWindow( *Wnd, NULL );\n"
			 "\treturn( 0L );\n"
			 "}\n"
			 "\nvoid CloseWndShd( struct Window **Wnd, struct Gadget **GList, struct Menu **Mn )\n"
			 "{\n"
			 "\tstruct IntuiMessage\t*Msg;\n"
			 "\tstruct Node\t\t\t*succ;\n"
			 "\n\tif( Mn ) {\n"
			 "\t\tif( *Wnd )\n"
			 "\t\t\tClearMenuStrip( *Wnd );\n"
			 "\t\tFreeMenus( *Mn );\n"
			 "\t\t*Mn = NULL;\n"
			 "\t}\n"
			 "\n\tif( *Wnd ) {\n"
			 "\n\t\tForbid();\n"
			 "\n\t\tMsg = (struct IntuiMessage *)( *Wnd )->UserPort->mp_MsgList.lh_Head;\n"
			 "\t\twhile( succ = Msg->ExecMessage.mn_Node.ln_Succ ) {\n"
			 "\t\t\tif( Msg->IDCMPWindow == *Wnd ) {\n"
			 "\t\t\t\tRemove(( struct Node *)Msg );\n"
			 "\t\t\t\tReplyMsg(( struct Message *)Msg );\n"
			 "\t\t\t}\n"
			 "\t\t\tMsg = (struct IntuiMessage *)succ;\n"
			 "\t\t}\n"
			 "\n\t\t( *Wnd )->UserPort = NULL;\n"
			 "\t\tModifyIDCMP( *Wnd, 0L );\n"
			 "\n\t\tPermit();\n"
			 "\n\t\tCloseWindow( *Wnd );\n"
			 "\t\t*Wnd = NULL;\n"
			 "\t}\n"
			 "\n\tif( GList ) {\n"
			 "\t\tFreeGadgets( *GList );\n"
			 "\t\t*GList = NULL;\n"
			 "\t}\n"
			 "\n}\n"
			 "\n"
			 "void HandleIDCMPPort( void )\n"
			 "{\n"
			 "\tstruct IntuiMsg\t*m;\n"
			 "\tvoid\t\t(*func)(void);\n"
			 "\n"
			 "\twhile( m = GT_GetIMsg( %s )) {\n"
			 "\t\tCopyMem((char *)m, (char *)&IDCMPMsg, (long)sizeof( struct IntuiMessage ));\n"
			 "\t\tGT_ReplyIMsg( m );\n"
			 "\t\tfunc = IDCMPMsg.IDCMPWindow->ExtData;\n"
			 "\t\t(*func)();\n"
			 "\t}\n"
			 "}\n",
		    Files->User2 );
}
///
/// WriteRender
void WriteRender( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo      *wnd;
    struct BevelBoxNode    *box;
    WORD                    x, y;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NeedRender ) {

	    FPrintf( Files->XDef, "extern void %sRender( void );\n", wnd->wi_Label );

	    FPrintf( Files->Std, "\nvoid %sRender( void )\n{\n", wnd->wi_Label );

	    if( IE->SrcFlags & FONTSENSITIVE ) {

		if( wnd->wi_NumImages )
		    FPuts( Files->Std, "\tstruct Image\t\tim;\n"
				       "\tstruct Image\t\t*imp;\n" );

		if( wnd->wi_NumTexts )
		    FPuts( Files->Std, "\tstruct IntuiText\tit;\n" );

		if(( wnd->wi_NumImages ) || ( wnd->wi_NumTexts ))
		    FPuts( Files->Std, "\tUWORD\t\t\tc;\n" );
	    }

	    IE->win_info = wnd;
	    ( *IE->IEXSrcFun->RenderMinusZero )( Files );

	    for( box = wnd->wi_Boxes.mlh_Head; box->bb_Next; box = box->bb_Next ) {
		x = box->bb_Left - IE->ScreenData->XOffset;
		y = box->bb_Top  - IE->ScreenData->YOffset;

		if( IE->SrcFlags & FONTSENSITIVE )
		    FPrintf( Files->Std, "\n\tDrawBevelBox( %sWnd->RPort, ScaleX( %ld ) + XOffset, ScaleY( %ld ) + YOffset, ScaleX( %ld ), ScaleY( %ld ),\n"
					 "\t\tGT_VisualInfo, VisualInfo,",
			     wnd->wi_Label, x, y, box->bb_Width, box->bb_Height );
		else
		    FPrintf( Files->Std, "\n\tDrawBevelBox( %sWnd->RPort, %ld + XOffset, %ld + YOffset, %ld, %ld,\n"
					 "\t\tGT_VisualInfo, VisualInfo,",
			     wnd->wi_Label, x, y, box->bb_Width, box->bb_Height );

		if( box->bb_Recessed )
		    FPuts( Files->Std, " GTBB_Recessed, TRUE," );

		if( box->bb_FrameType != 1 )
		    VFPrintf( Files->Std, " GTBB_FrameType, %ld,", &box->bb_FrameType );

		FPuts( Files->Std, " TAG_DONE );\n" );
	    }

	    if( wnd->wi_NumImages ) {
		if( IE->SrcFlags & FONTSENSITIVE ) {
		    FPrintf( Files->Std, "\n\timp = &%s_0Image;\n"
					 "\tfor( c = 0; c < %ld; c++ ) {\n"
					 "\t\tCopyMem(( char * )imp, ( char * )&im, ( long )sizeof( struct Image ));\n"
					 "\t\timp = imp->NextImage;\n"
					 "\t\tim.NextImage = NULL;\n"
					 "\t\tim.LeftEdge  = XOffset + ScaleX( im.LeftEdge );\n"
					 "\t\tim.TopEdge   = YOffset + ScaleY( im.TopEdge  );\n"
					 "\t\tDrawImage( %sWnd->RPort, &im, 0, 0 );\n"
					 "\t}\n",
			     wnd->wi_Label, wnd->wi_NumImages, wnd->wi_Label );
		} else {
		    FPrintf( Files->Std, "\n\tDrawImage( %sWnd->RPort, &%s_0Image, XOffset, YOffset );\n",
			     wnd->wi_Label, wnd->wi_Label );
		}
	    }

	    if( wnd->wi_NumTexts ) {
		if( IE->SrcFlags & FONTSENSITIVE ) {
		    FPrintf( Files->Std, "\n\tfor( c = 0; c < %ld; c++ ) {\n"
					 "\t\tCopyMem(( char * )&%sIText[ c ], ( char * )&it, ( long )sizeof( struct IntuiText ));\n"
					 "\t\tit.ITextFont = Font;\n"
					 "\t\tit.LeftEdge  = XOffset + ScaleX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );\n"
					 "\t\tit.TopEdge   = YOffset + ScaleY( it.TopEdge  ) - ( Font->ta_YSize >> 1 );\n"
					 "\t\tPrintIText( %sWnd->RPort, &it, 0, 0 );\n"
					 "\t}\n",
			     wnd->wi_NumTexts, wnd->wi_Label, wnd->wi_Label );
		} else {
		    FPrintf( Files->Std, "\n\tPrintIText( %sWnd->RPort, %sIText, XOffset, YOffset );\n",
			     wnd->wi_Label, wnd->wi_Label );
		}
	    }

	    ( *IE->IEXSrcFun->RenderPlusZero )( Files );

	    FPuts( Files->Std, "}\n" );

	}
    }
}
///
/// WriteIDCMPHandler
void WriteIDCMPHandler( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    UWORD               c;
    ULONG               idcmp;


    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_IDCMP ) {

	    FPrintf( Files->XDef, "extern LONG Handle%sIDCMP( void );\n", wnd->wi_Label );

	    FPrintf( Files->Std, "\nLONG Handle%sIDCMP( void )\n"
				 "{\n",
		     wnd->wi_Label );

	    if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT )))
		FPuts( Files->Std, "\tstruct IntuiMessage\t*m;\n" );

	    if( wnd->wi_IDCMP & IDCMP_MENUPICK )
		FPuts( Files->Std, "\tstruct MenuItem\t\t*n;\n" );

	    FPuts( Files->Std, "\tBOOL\t\t\t(*func)(void);\n"
			       "\tBOOL\t\t\trunning = TRUE;\n"
			       "\tint\t\t\tclass;\n"
			       "\n" );

	    if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT )))
		FPrintf( Files->Std, "\twhile( m = GT_GetIMsg( %sWnd->UserPort )) {\n\n"
				     "\t\tCopyMem((char *)m, (char *)&%sMsg, (long)sizeof( struct IntuiMessage ));\n\n",
			 wnd->wi_Label, wnd->wi_Label );
	    else
		FPrintf( Files->Std, "#define\t%sMsg IDCMPMsg\n\n", wnd->wi_Label );

	    FPrintf( Files->Std, "\t\tclass = %sMsg.Class;\n", wnd->wi_Label );

	    IE->win_info = wnd;
	    idcmp = ( *IE->IEXSrcFun->IDCMP )( wnd->wi_IDCMP );

	    for( c = 0; c < 3; c++ ) {
		if( idcmp & IDCMPVer[ c ]) {
		    FPrintf( Files->XDef, IDCMPVerProto[ c ], wnd->wi_Label );
		    FPrintf( Files->Std, IDCMPVerStr[ c ], wnd->wi_Label );
		    if( IE->C_Prefs & GEN_TEMPLATE )
			FPrintf( Files->Temp, IDCMPVerTmp[ c ], wnd->wi_Label );
		}
	    }

	    if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT )))
		FPuts( Files->Std, "\n\t\tGT_ReplyIMsg( m );\n\n" );

	    FPuts( Files->Std, "\t\tswitch( class ) {\n" );

	    if(( idcmp & IDCMP_GADGETUP ) && ( idcmp & IDCMP_GADGETDOWN )) {
		idcmp &= ~( IDCMP_GADGETUP | IDCMP_GADGETDOWN );
		FPrintf( Files->Std, "\n\t\t\tcase\tIDCMP_GADGETUP:\n"
				     "\t\t\tcase\tIDCMP_GADGETDOWN:\n"
				     "\t\t\t\tfunc = (( struct Gadget * )%sMsg.IAddress )->UserData;\n"
				     "\t\t\t\trunning = (*func)();\n"
				     "\t\t\t\tbreak;\n",
			 wnd->wi_Label );
	    }

	    if(( IE->C_Prefs & KEY_HANDLER ) && ( wnd->wi_NumKeys )) {

		FPrintf( Files->Std, "\n\t\t\tcase\tIDCMP_VANILLAKEY:\n"
				     "\t\t\t\trunning = Handle%sKeys();\n"
				     "\t\t\t\tbreak;\n",
			 wnd->wi_Label );

		if( idcmp & IDCMP_VANILLAKEY ) {
		    idcmp &= ~IDCMP_VANILLAKEY;
		    FPrintf( Files->XDef, "extern BOOL %sVanillaKey( void );\n", wnd->wi_Label );
		    if( IE->C_Prefs & GEN_TEMPLATE )
			FPrintf( Files->Temp, VanillaTmp, wnd->wi_Label );
		}
	    }

	    IDCMPStr[2] = wnd->wi_NeedRender ? CaseRefresh2 : CaseRefresh;

	    for( c = 0; c < IDCMPS_NUM; c++ ) {
		if( idcmp & idcmps[ c ]) {
		    if( IDCMPStr[ c ]) {

			FPrintf( Files->Std, IDCMPStr[ c ],
				 wnd->wi_Label, wnd->wi_Label,
				 wnd->wi_Label, wnd->wi_Label );

			if( IDCMPProto[ c ])
			    FPrintf( Files->XDef, IDCMPProto[ c ], wnd->wi_Label );

			if(( IE->C_Prefs & GEN_TEMPLATE ) && ( IDCMPTmp[ c ]))
			    FPrintf( Files->Temp, IDCMPTmp[ c ], wnd->wi_Label );
		    }
		}
	    }

	    if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT )))
		FPuts( Files->Std, "\n\t\t}" );

	    FPuts( Files->Std, "\n\t}\n\treturn( running );\n}\n" );
	}
    }
}
///
/// WriteKeyHandler
void WriteKeyHandler( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct GadgetInfo  *gad;
    UBYTE               ch;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumKeys ) {

	    FPrintf( Files->XDef, "extern BOOL Handle%sKeys( void );\n", wnd->wi_Label );

	    FPrintf( Files->Std, "\nBOOL Handle%sKeys( void )\n"
				 "{\n"
				 "\tBOOL running = TRUE;\n\n",
		     wnd->wi_Label );

	    if(!(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & W_LOC_GADGETS ))) {
		if( IE->C_Prefs & TO_LOWER )
		    FPrintf( Files->Std, "\tswitch( tolower( %sMsg.Code )) {\n", wnd->wi_Label );
		else
		    FPrintf( Files->Std, "\tswitch( %sMsg.Code ) {\n", wnd->wi_Label );
	    } else {
		FPuts( Files->Std, "\tUBYTE ch = " );
		if( IE->C_Prefs & TO_LOWER )
		    FPrintf( Files->Std, "tolower( %sMsg.Code );\n", wnd->wi_Label );
		else
		    FPrintf( Files->Std, "%sMsg.Code;\n", wnd->wi_Label );
	    }

	    for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {
		if( gad->g_flags2 & G_KEYPRESSED ) {


		    if(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & W_LOC_GADGETS )) {
			if( IE->C_Prefs & TO_LOWER )
			    FPrintf( Files->Std, "\n\tif( ch == tolower( GetActivationKey( %sNGad[ GD_%s ].ng_GadgetText ))) {\n",
				     wnd->wi_Label, gad->g_Label );
			else
			    FPrintf( Files->Std, "\n\tif( ch == GetActivationKey( %sNGad[ GD_%s ].ng_GadgetText )) {\n",
				     wnd->wi_Label, gad->g_Label );
		    } else {
			ch = ( IE->C_Prefs & TO_LOWER ) ? tolower( gad->g_Key ) : gad->g_Key;
			FPrintf( Files->Std, "\n\t\tcase\t'%lc':\n", ch );
		    }


		    if(( gad->g_Kind == STRING_KIND ) || ( gad->g_Kind == INTEGER_KIND )) {
			FPrintf( Files->Std, "\t\t\tif(!( %sGadgets[ GD_%s ]->Flags & GFLG_DISABLED ))\n"
					     "\t\t\t\tActivateGadget( %sGadgets[ GD_%s ], %sWnd, NULL );\n",
				 wnd->wi_Label, gad->g_Label, wnd->wi_Label, gad->g_Label, wnd->wi_Label );
		    } else {

			if(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & W_LOC_GADGETS ))
			    FPrintf( Files->Std, "\t\treturn( %sKeyPressed() );\n",
				     gad->g_Label );
			else
			    FPrintf( Files->Std, "\t\t\trunning = %sKeyPressed();\n",
				     gad->g_Label );

			FPrintf( Files->XDef, "extern BOOL %sKeyPressed( void );\n", gad->g_Label );

			if( IE->C_Prefs & GEN_TEMPLATE )
			    FPrintf( Files->Temp, "\nBOOL %sKeyPressed( void )\n"
						  "{\n"
						  "\t/*  Routine when \"%s\"'s activation key is pressed  */\n"
						  "\n"
						  "\t/*  ...or return TRUE not to call the gadget function  */\n"
						  "\treturn %sClicked();\n"
						  "}\n",
				     gad->g_Label, gad->g_Titolo, gad->g_Label );
		    }

		    if(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & W_LOC_GADGETS ))
			FPuts( Files->Std, "\t}\n" );
		    else
			FPuts( Files->Std, "\t\tbreak;\n" );
		}
	    }

	    if( wnd->wi_IDCMP & IDCMP_VANILLAKEY )
		if(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & W_LOC_GADGETS ))
		    FPrintf( Files->Std, "\n\trunning = %sVanillaKey();\n",
			     wnd->wi_Label );
		else
		    FPrintf( Files->Std, "\n\t\tdefault:\n"
					 "\t\t\trunning = %sVanillaKey();\n"
					 "\t\t\tbreak;\n",
			     wnd->wi_Label );

	    if(!(( IE->SrcFlags & LOCALIZE ) && ( wnd->wi_Tags & W_LOC_GADGETS )))
		FPuts( Files->Std, "\n\t}" ); /* end Select */

	    FPuts( Files->Std, "\n\treturn( running );\n}\n" );
	}
    }
}
///
/// WriteClickedPtrs
void WriteClickedPtrs( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct GadgetInfo  *gad;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {
	    if( gad->g_flags2 & G_CLICKED ) {

		FPrintf( Files->XDef, "extern BOOL %sClicked( void );\n", gad->g_Label );

		if( IE->C_Prefs & GEN_TEMPLATE )
		    FPrintf( Files->Temp, "\nBOOL %sClicked( void )\n"
					  "{\n"
					  "\t/*  Routine when \"%s\" is clicked  */\n"
					  "\treturn( TRUE );\n"
					  "}\n",
			     gad->g_Label, gad->g_Titolo );
	    }

	}

    }
}
///
/// WriteLocale
void WriteLocale( struct GenFiles *Files, struct IE_Data *IE )
{
    UWORD   cnt;

    FPuts( Files->XDef, "extern void SetupLocale( void );\n"
			"extern void LocalizeArray( UBYTE ** );\n"
			"extern void LocalizeTags( ULONG *, UWORD );\n"
			"extern void LocalizeList( struct MinList * );\n"
			"extern void LocalizeGadgets( struct NewGadget *, ULONG *, UWORD *, UWORD );\n"
			"extern void LocalizeMenus( struct NewMenu * );\n"
			"extern void LocalizeITexts( struct IntuiText *, UWORD );\n"
			"extern UBYTE GetActivationKey( STRPTR );\n" );

    FPrintf( Files->Std, "\nvoid SetupLocale( void )\n"
			 "{\n"
			 "\tUWORD\tcnt;\n\n"
			 "\tif( LocaleBase ) {\n"
			 "\t\tif( Catalog = OpenCatalog( NULL, \"%s.catalog\", OC_BuiltInLanguage, \"%s\", OC_Version, %ld, TAG_DONE )) {\n"
			 "\t\t\tfor( cnt = 0; cnt < ( sizeof( CatCompArray ) / sizeof( struct CatCompArrayType )); cnt++ )\n"
			 "\t\t\t\tCatCompArray[ cnt ].cca_Str = GetCatalogStr( Catalog, cnt, CatCompArray[ cnt ].cca_Str );\n"
			 "\t\t}\n"
			 "\t}\n",
	     IE->Locale->Catalog, IE->Locale->BuiltIn, IE->Locale->Version );

    struct ArrayNode *ar;
    for( cnt = 0, ar = Files->Arrays.mlh_Head; ar->Next; ar = ar->Next, cnt++ )
	FPrintf( Files->Std, "\n\tLocalizeArray( &%s[0] );", ar->Label );

    FPuts( Files->Std, "\n}\n"
		       "\n"
		       "void LocalizeArray( UBYTE **Array )\n"
		       "{\n"
		       "\twhile( *Array ) {\n"
		       "\t\t*Array = (UBYTE *)CatCompArray[ (ULONG)*Array ].cca_Str;\n"
		       "\t\t*Array++;\n"
		       "\t}\n"
		       "}\n"
		       "\n"
		       "void LocalizeTags( ULONG *Tags, UWORD Kind )\n"
		       "{\n"
		       "\tULONG\ttag;\n\t"
		       "\tswitch( Kind ) {\n"
		       "\t\tcase\tSTRING_KIND:\n"
		       "\t\t\t\ttag = GTST_String;\n"
		       "\t\t\t\tbreak;\n"
		       "\t\tcase\tTEXT_KIND:\n"
		       "\t\t\t\ttag = GTTX_Text;\n"
		       "\t\t\t\tbreak;\n"
		       "\t\tcase\tNUMBER_KIND:\n"
		       "\t\t\t\ttag = GTNM_Format;\n"
		       "\t\t\t\tbreak;\n"
		       "\t\tcase\tSLIDER_KIND:\n"
		       "\t\t\t\ttag = GTSL_LevelFormat;\n"
		       "\t\t\t\tbreak;\n"
		       "\t\tdefault:\n"
		       "\t\t\t\treturn;\n"
		       "\t\t\t\tbreak;\n"
		       "\t}\n"
		       "\twhile(( *Tags != tag ) && ( *Tags ))\n"
		       "\t\tTags++;\n"
		       "\tif( *Tags++ )\n"
		       "\t\t*Tags = (ULONG)CatCompArray[ *Tags ].cca_Str;\n\n"
		       "}\n"
		       "\n"
		       "void LocalizeList( struct MinList *List )\n"
		       "{\n"
		       "\tstruct Node\t*node;\n\n"
		       "\tfor( node = (struct Node *)List->mlh_Head; node->ln_Succ; node = node->ln_Succ )\n"
		       "\t\tnode->ln_Name = (char *)CatCompArray[ (ULONG)node->ln_Name ].cca_Str;\n"
		       "}\n"
		       "\n"
		       "void LocalizeGadgets( struct NewGadget *ng, ULONG *tags, UWORD *kinds, UWORD num )\n"
		       "{\n"
		       "\tUWORD\tcnt;\n\n"
		       "\tfor( cnt = 0; cnt < num; cnt++ ) {\n"
		       "\t\tif( ng->ng_GadgetText )\n"
		       "\t\t\tng->ng_GadgetText = CatCompArray[ (ULONG)ng->ng_GadgetText ].cca_Str;\n"
		       "\t\tLocalizeTags( tags, *kinds++ );\n"
		       "\t\twhile( *tags++ );\n"
		       "\t\tng++;\n"
		       "\t}\n"
		       "}\n"
		       "\n"
		       "void LocalizeMenus( struct NewMenu *menu )\n"
		       "{\n"
		       "\twhile( menu->nm_Type != NM_END ) {\n"
		       "\t\tif( menu->nm_Label != NM_BARLABEL )\n"
		       "\t\t\tmenu->nm_Label = (STRPTR)CatCompArray[ (ULONG)menu->nm_Label ].cca_Str;\n"
		       "\t\tif( menu->nm_CommKey )\n"
		       "\t\t\tmenu->nm_CommKey = (STRPTR)CatCompArray[ (ULONG)menu->nm_CommKey ].cca_Str;\n"
		       "\t\tmenu++;\n"
		       "\t}\n"
		       "}\n"
		       "\n"
		       "void LocalizeITexts( struct IntuiText *txt, UWORD cnt )\n"
		       "{\n"
		       "\twhile( cnt-- ) {\n"
		       "\t\ttxt->IText = (UBYTE *)CatCompArray[ (ULONG)txt->IText ].cca_Str;\n"
		       "\t\ttxt++;\n"
		       "\t}\n"
		       "}\n"
		       "\n"
		       "UBYTE GetActivationKey( STRPTR Text )\n"
		       "{\n"
		       "\twhile( *Text++ != '_' )\n"
		       "\t\tif( *Text == '\\0' )\n"
		       "\t\t\treturn( 0 );\n"
		       "\n\treturn( *Text );\n"
		       "}\n" );
}
///

// Diskfonts
/// WriteFontPtrs
void WriteFontPtrs( struct GenFiles *Files, struct IE_Data *IE )
{
    struct TxtAttrNode *fnt;

    if( IE->SrcFlags & OPENDISKFONT ) {
	for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
	    if( fnt->txa_Flags & FPB_DISKFONT ) {
		FPrintf( Files->Std,  "struct TextFont\t\t*%sFont = NULL;\n", fnt->txa_Label );
		FPrintf( Files->XDef, "extern struct TextFont\t\t*%sFont;\n", fnt->txa_Label );
	    }
	}
    }
}
///
/// WriteOpenFonts
void WriteOpenFonts( struct GenFiles *Files, struct IE_Data *IE )
{
    struct TxtAttrNode *fnt;
    BOOL                ok = FALSE;

    if( IE->SrcFlags & OPENDISKFONT ) {

	for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
	    if( fnt->txa_Flags & FPB_DISKFONT )
		ok = TRUE;
	}

	if( ok ) {

	    FPuts( Files->XDef, "extern struct Library\t*DiskfontBase;\n"
				"extern struct Library\t*GfxBase;\n"
				"extern BOOL OpenDiskFonts( void );\n"
				"extern void CloseDiskFonts( void );\n" );

	    FPuts( Files->Std,  "\nBOOL OpenDiskFonts( void )\n"
				"{\n" );

	    for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
		if( fnt->txa_Flags & FPB_DISKFONT )
		    FPrintf( Files->Std, "\tif (!( %sFont = OpenDiskFont( &%s )))\n"
					 "\t\treturn( FALSE );\n",
			     fnt->txa_Label, fnt->txa_Label );
	    }

	    FPuts( Files->Std, "\treturn( TRUE );\n"
			       "}\n\n"
			       "void CloseDiskFonts( void )\n"
			       "{\n" );

	    for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
		if( fnt->txa_Flags & FPB_DISKFONT ) {
		    FPrintf( Files->Std, "\tif ( %sFont ) {\n"
					 "\t\tCloseFont( %sFont );\n"
					 "\t\t%sFont = NULL;\n"
					 "\t}\n",
			     fnt->txa_Label, fnt->txa_Label, fnt->txa_Label );
		}
	    }

	    FPuts( Files->Std, "}\n" );
	}

    }
}
///

// Data & Structures
/// WriteNewGadgets
void WriteNewGadgets( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct GadgetInfo  *gad;
    UBYTE               buffer[256], *or;
    UWORD               c, c2;
    LONG                loc;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumGads - wnd->wi_NumBools ) {

	    FPrintf( Files->XDef, "extern struct NewGadget\t\t%sNGad[];\n", wnd->wi_Label );
	    FPrintf( Files->Std, "\nstruct NewGadget %sNGad[] = {\n\t", wnd->wi_Label );

	    loc = IE->C_Prefs & SMART_STR;

	    if( IE->SrcFlags & LOCALIZE )
		loc = wnd->wi_Tags & W_LOC_GADGETS;

	    for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {
		if( gad->g_Kind < BOOLEAN ) {

		    FPrintf( Files->Std, "%ld, %ld, %ld, %ld, ",
			     gad->g_Left - IE->ScreenData->XOffset,
			     gad->g_Top  - IE->ScreenData->YOffset,
			     gad->g_Width, gad->g_Height );

		    if( gad->g_Titolo[0] ) {
			if( loc )
			    FPrintf( Files->Std, "(UBYTE *)%s", (FindString( &Files->Strings, gad->g_Titolo ))->Label );
			else
			    FPrintf( Files->Std, "\"%s\"", gad->g_Titolo );
		    } else
			FPuts( Files->Std, Null );

		    FPuts( Files->Std, ", " );

		    if( gad->g_Font )
			FPrintf( Files->Std, "&%s", gad->g_Font->txa_Label );
		    else
			FPuts( Files->Std, Null );

		    FPrintf( Files->Std, ", GD_%s, ", gad->g_Label );

		    if( gad->g_Flags ) {

			buffer[0] = '\0';

			if( gad->g_Flags & 32 ) {
			    strcpy( buffer, "NG_HIGHLABEL" );
			    or = "|";
			} else {
			    or = "";
			}

			c = gad->g_Flags & 0xFFDF;
			if( c ) {
			    strcat( buffer, or );

			    c2 = 0;
			    while(!( c & gadget_flags[ c2 ]))
				c2 += 1;

			    strcat( buffer, GadFlags[ c2 ]);
			}

			FPuts( Files->Std, buffer );
		    } else {
			FPuts( Files->Std, Null );
		    }

		    FPuts( Files->Std, ", NULL, " );

		    if(( IE->C_Prefs & CLICKED ) && ( gad->g_Kind != TEXT_KIND ) && ( gad->g_Kind != NUMBER_KIND ))
			FPrintf( Files->Std, "(APTR)%sClicked", gad->g_Label );
		    else
			FPuts( Files->Std, Null );

		    FPuts( Files->Std, ",\n\t" );
		}
	    }

	    Flush( Files->Std );
	    Seek( Files->Std, -3, OFFSET_CURRENT );
	    FPuts( Files->Std, "\n};\n" );

	}
    }

}
///
/// WriteGadgetTags
void WriteGadgetTags( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct GadgetInfo  *gad;
    ULONG               loc;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumGads - wnd->wi_NumBools ) {

	    loc = IE->C_Prefs & SMART_STR;

	    if( IE->SrcFlags & LOCALIZE )
		loc = wnd->wi_Tags & W_LOC_GADGETS;

	    FPrintf( Files->XDef, "extern ULONG\t\t\t%sGTags[];\n", wnd->wi_Label );
	    FPrintf( Files->Std, "\nULONG %sGTags[] = {\n\t", wnd->wi_Label );

	    for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {
		if( gad->g_Kind < BOOLEAN ) {

		    if( gad->g_Tags & 1 )
			FPuts( Files->Std, "(GT_Underscore), '_', " );

		    switch( gad->g_Kind ) {

			case BUTTON_KIND:
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, GAImmediate );
			    break;

			case CHECKBOX_KIND:
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, "(GTCB_Checked), TRUE, " );
			    if( gad->g_Tags & 8 )
				FPuts( Files->Std, "(GTCB_Scaled), TRUE, " );
			    break;

			case INTEGER_KIND:
			    if( ((struct IK)(gad->g_Data)).Num )
				FPrintf( Files->Std, "(GTIN_Number), %ld, ", ((struct IK)(gad->g_Data)).Num );
			    if( ((struct IK)(gad->g_Data)).MaxC != 10 )
				FPrintf( Files->Std, "(GTIN_MaxChars), %ld, ", ((struct IK)(gad->g_Data)).MaxC );
			    if( ((struct IK)(gad->g_Data)).Just )
				FPrintf( Files->Std, "(STRINGA_Justification), %s, ", STRINGA_txts[ ((struct IK)(gad->g_Data)).Just ]);
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, GAImmediate );
			    if(!( gad->g_Tags & 8 ))
				FPuts( Files->Std, GATabCycle );
			    if( gad->g_Tags & 0x10 )
				FPuts( Files->Std, STRINGAExitHelp );
			    if( gad->g_Tags & 0x20 )
				FPuts( Files->Std, STRINGAReplaceMode );
			    break;

			case LISTVIEW_KIND:
			    if( gad->g_NumScelte )
				FPrintf( Files->Std, "(GTLV_Labels), (ULONG)&%sList, ", gad->g_Label );
			    if( ((struct LK)(gad->g_Data)).Top )
				FPrintf( Files->Std, "(GTLV_Top), %ld, ", ((struct LK)(gad->g_Data)).Top );
			    if( ((struct LK)(gad->g_Data)).Vis )
				FPrintf( Files->Std, "(GTLV_MakeVisible), %ld, ", ((struct LK)(gad->g_Data)).Vis );
			    if( ((struct LK)(gad->g_Data)).ScW != 16 )
				FPrintf( Files->Std, "(GTLV_ScrollWidth), %ld, ", ((struct LK)(gad->g_Data)).ScW );
			    if( ((struct LK)(gad->g_Data)).Sel )
				FPrintf( Files->Std, "(GTLV_Selected), %ld, ", ((struct LK)(gad->g_Data)).Sel );
			    if( ((struct LK)(gad->g_Data)).Spc )
				FPrintf( Files->Std, LAYOUTASpacing, ((struct LK)(gad->g_Data)).Spc );
			    if( ((struct LK)(gad->g_Data)).IH )
				FPrintf( Files->Std, "(GTLV_ItemHeight), %ld, ", ((struct LK)(gad->g_Data)).IH );
			    if( ((struct LK)(gad->g_Data)).MaxP )
				FPrintf( Files->Std, "(GTLV_MaxPen), %ld, ", ((struct LK)(gad->g_Data)).MaxP );
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, "(GTLV_ReadOnly), TRUE, " );
			    if( gad->g_Tags & 8 )
				FPuts( Files->Std, "(GTLV_ShowSelected), NULL, " );
			    break;

			case MX_KIND:
			    FPuts( Files->Std, "(GTMX_Labels), (ULONG)&" );
			    if( loc )
				FPrintf( Files->Std, "%s", (FindArray( &Files->Arrays, &gad->g_Scelte ))->Label );
			    else
				FPrintf( Files->Std, "%sLabels", gad->g_Label );
			    FPuts( Files->Std, "[0], " );
			    if( ((struct MK)(gad->g_Data)).Act )
				FPrintf( Files->Std, "(GTMX_Active), %ld, ", ((struct MK)(gad->g_Data)).Act );
			    if( ((struct MK)(gad->g_Data)).Spc != 1 )
				FPrintf( Files->Std, "(GTMX_Spacing), %ld, ", ((struct MK)(gad->g_Data)).Spc );
			    if( gad->g_Titolo[0] )
				FPrintf( Files->Std, "(GTMX_TitlePlace), %s, ", GadFlags[ ((struct MK)(gad->g_Data)).TitPlc ]);
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, "(GTMX_Scaled), TRUE, " );
			    break;

			case NUMBER_KIND:
			    if( ((struct NK)(gad->g_Data)).Num )
				FPrintf( Files->Std, "(GTNM_Number), %ld, ", ((struct NK)(gad->g_Data)).Num );
			    if( ((struct NK)(gad->g_Data)).FPen != -1 )
				FPrintf( Files->Std, "(GTNM_FrontPen), %ld, ", ((struct NK)(gad->g_Data)).FPen );
			    if( ((struct NK)(gad->g_Data)).BPen != -1 )
				FPrintf( Files->Std, "(GTNM_BackPen), %ld, ", ((struct NK)(gad->g_Data)).BPen );
			    if( ((struct NK)(gad->g_Data)).Just )
				FPrintf( Files->Std, "(GTNM_Justification), %s, ", GTJ_txts[ ((struct NK)(gad->g_Data)).Just ]);
			    if( ((struct NK)(gad->g_Data)).MNL != 10 )
				FPrintf( Files->Std, "(GTNM_MaxNumberLen), %ld, ", ((struct NK)(gad->g_Data)).MNL );
			    if( strcmp( ((struct NK)(gad->g_Data)).Format, "%ld" )) {
				FPuts( Files->Std, "(GTNM_Format), (ULONG)" );
				if( loc )
				    FPrintf( Files->Std, "%s, ", (FindString( &Files->Strings, ((struct NK)(gad->g_Data)).Format ))->Label );
				else
				    FPrintf( Files->Std, "\"%s\", ", ((struct NK)(gad->g_Data)).Format );
			    }
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, "(GTNM_Border), TRUE, " );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, "(GTNM_Clipped), TRUE, " );
			    break;

			case CYCLE_KIND:
			    FPuts( Files->Std, "(GTCY_Labels), (ULONG)&" );
			    if( loc )
				FPrintf( Files->Std, "%s", (FindArray( &Files->Arrays, &gad->g_Scelte ))->Label );
			    else
				FPrintf( Files->Std, "%sLabels", gad->g_Label );
			    FPuts( Files->Std, "[0], " );
			    if( ((struct CK)(gad->g_Data)).Act )
				FPrintf( Files->Std, "(GTCY_Active), %ld, ", ((struct CK)(gad->g_Data)).Act );
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    break;

			case PALETTE_KIND:
			    if( ((struct PK)(gad->g_Data)).Depth != 1 )
				FPrintf( Files->Std, "(GTPA_Depth), %ld, ", ((struct PK)(gad->g_Data)).Depth );
			    if( ((struct PK)(gad->g_Data)).Color != 1 )
				FPrintf( Files->Std, "(GTPA_Color), %ld, ", ((struct PK)(gad->g_Data)).Color );
			    if( ((struct PK)(gad->g_Data)).ColOff )
				FPrintf( Files->Std, "(GTPA_ColorOffset), %ld, ", ((struct PK)(gad->g_Data)).ColOff );
			    if( ((struct PK)(gad->g_Data)).IW )
				FPrintf( Files->Std, "(GTPA_IndicatorWidth), %ld, ", ((struct PK)(gad->g_Data)).IW );
			    if( ((struct PK)(gad->g_Data)).IH )
				FPrintf( Files->Std, "(GTPA_IndicatorHeight), %ld, ", ((struct PK)(gad->g_Data)).IH );
			    if(( ((struct PK)(gad->g_Data)).NumCol ) && ( ((struct PK)(gad->g_Data)).NumCol != 2 ))
				FPrintf( Files->Std, "(GTPA_NumColors), %ld, ", ((struct PK)(gad->g_Data)).NumCol );
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    break;

			case SCROLLER_KIND:
			    if( ((struct SK)(gad->g_Data)).Top )
				FPrintf( Files->Std, "(GTSC_Top), %ld, ", ((struct SK)(gad->g_Data)).Top );
			    if( ((struct SK)(gad->g_Data)).Tot )
				FPrintf( Files->Std, "(GTSC_Total), %ld, ", ((struct SK)(gad->g_Data)).Tot );
			    if( ((struct SK)(gad->g_Data)).Vis != 2 )
				FPrintf( Files->Std, "(GTSC_Visible), %ld, ", ((struct SK)(gad->g_Data)).Vis );
			    if( ((struct SK)(gad->g_Data)).Arr )
				FPrintf( Files->Std, "(GTSC_Arrows), %ld, ", ((struct SK)(gad->g_Data)).Arr );
			    if( ((struct SK)(gad->g_Data)).Free )
				FPuts( Files->Std, PGAFreedom );
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GARelVerify );
			    if( gad->g_Tags & 8 )
				FPuts( Files->Std, GAImmediate );
			    break;

			case SLIDER_KIND:
			    if( ((struct SlK)(gad->g_Data)).Min )
				FPrintf( Files->Std, "(GTSL_Min), %ld, ", ((struct SlK)(gad->g_Data)).Min );
			    if( ((struct SlK)(gad->g_Data)).Max != 15 )
				FPrintf( Files->Std, "(GTSL_Max), %ld, ", ((struct SlK)(gad->g_Data)).Max );
			    if( ((struct SlK)(gad->g_Data)).Level )
				FPrintf( Files->Std, "(GTSL_Level), %ld, ", ((struct SlK)(gad->g_Data)).Level );
			    if( ((struct SlK)(gad->g_Data)).MLL != 2 )
				FPrintf( Files->Std, "(GTSL_MaxLevelLen), %ld, ", ((struct SlK)(gad->g_Data)).MLL );
			    FPrintf( Files->Std, "(GTSL_LevelPlace), %s, ", GadFlags[ ((struct SlK)(gad->g_Data)).LevPlc ]);
			    if( ((struct SlK)(gad->g_Data)).Just )
				FPrintf( Files->Std, "(GTSL_Justification), %ld, ", GTJ_txts[ ((struct SlK)(gad->g_Data)).Just ]);
			    if( ((struct SlK)(gad->g_Data)).Free )
				FPuts( Files->Std, PGAFreedom );
			    if( ((struct SlK)(gad->g_Data)).MPL )
				FPrintf( Files->Std, "(GTSL_MaxPixelLen), %ld, ", ((struct SlK)(gad->g_Data)).MPL );
			    FPuts( Files->Std, "(GTSL_LevelFormat), (ULONG)" );
			    if( loc )
				FPrintf( Files->Std, "%s, ", (FindString( &Files->Strings, ((struct SlK)(gad->g_Data)).Format ))->Label );
			    else
				FPrintf( Files->Std, "\"%s\", ", ((struct SlK)(gad->g_Data)).Format );
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GARelVerify );
			    if( gad->g_Tags & 8 )
				FPuts( Files->Std, GAImmediate );
			    break;

			case STRING_KIND:
			    if( ((struct StK)(gad->g_Data)).MaxC )
				FPrintf( Files->Std, "(GTST_MaxChars), %ld, ", ((struct StK)(gad->g_Data)).MaxC );
			    if( ((struct StK)(gad->g_Data)).Just )
				FPrintf( Files->Std, "(STRINGA_Justification), %s, ", STRINGA_txts[ ((struct StK)(gad->g_Data)).Just ]);
			    if ( *((UBYTE *)(gad->g_ExtraMem)) ) {
				FPuts( Files->Std, "(GTST_String), (ULONG)" );
				if( loc )
				    FPrintf( Files->Std, "%s, ", (FindString( &Files->Strings, gad->g_ExtraMem ))->Label );
				else
				    FPrintf( Files->Std, "\"%s\", ", gad->g_ExtraMem );
			    }
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, GADisabled );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, GAImmediate );
			    if(!( gad->g_Tags & 8 ))
				FPuts( Files->Std, GATabCycle );
			    if( gad->g_Tags & 0x10 )
				FPuts( Files->Std, STRINGAExitHelp );
			    if( gad->g_Tags & 0x20 )
				FPuts( Files->Std, STRINGAReplaceMode );
			    break;

			case TEXT_KIND:
			    if( ((struct TK)(gad->g_Data)).FPen != -1 )
				FPrintf( Files->Std, "(GTTX_FrontPen), %ld, ", ((struct TK)(gad->g_Data)).FPen );
			    if( ((struct TK)(gad->g_Data)).BPen != -1 )
				FPrintf( Files->Std, "(GTTX_BackPen), %ld, ", ((struct TK)(gad->g_Data)).BPen );
			    if( ((struct TK)(gad->g_Data)).Just )
				FPrintf( Files->Std, "(GTTX_Justification), %s, ", GTJ_txts[ ((struct TK)(gad->g_Data)).Just ]);
			    if ( *((UBYTE *)(gad->g_ExtraMem)) ) {
				FPuts( Files->Std, "(GTTX_Text), (ULONG)" );
				if( loc )
				    FPrintf( Files->Std, "%s, ", (FindString( &Files->Strings, gad->g_ExtraMem ))->Label );
				else
				    FPrintf( Files->Std, "\"%s\", ", gad->g_ExtraMem );
			    }
			    if( gad->g_Tags & 2 )
				FPuts( Files->Std, "(GTTX_CopyText), TRUE, " );
			    if( gad->g_Tags & 4 )
				FPuts( Files->Std, "(GTTX_Border), TRUE, " );
			    if( gad->g_Tags & 8 )
				FPuts( Files->Std, "(GTTX_Clipped), TRUE, " );
			    break;
		    }

		    FPuts( Files->Std, "(TAG_DONE),\n\t" );
		}
	    }

	    Flush( Files->Std );
	    Seek( Files->Std, -3, OFFSET_CURRENT );
	    FPuts( Files->Std, "\n};\n" );

	}
    }
}
///
/// WriteBoolStruct
void WriteBoolStruct( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct BooleanInfo *gad, *next;
    UBYTE              *str;
    struct ImageNode   *img;
    LONG                loc;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {

	loc = IE->C_Prefs & SMART_STR;

	if( IE->SrcFlags & LOCALIZE )
	    loc = wnd->wi_Tags & W_LOC_GADGETS;

	if( wnd->wi_NumBools ) {
	    for( gad = wnd->wi_Gadgets.mlh_TailPred; gad->b_Node.ln_Pred; gad = gad->b_Node.ln_Pred ) {
		if( gad->b_Kind == BOOLEAN ) {

		    if(( gad->b_flags2 & B_TEXT ) && ( gad->b_Titolo[0] )) {

			FPrintf( Files->Std, "\nstruct IntuiText %sIText = {\n", gad->b_Label );

			FPrintf( Files->Std, "\t%ld, %ld, %ld,\n"
					      "\t%ld, %ld,\n\t",
				  gad->b_FrontPen, gad->b_BackPen,
				  gad->b_DrawMode, gad->b_TxtLeft,
				  gad->b_TxtTop );

			if( gad->b_Font )
			    FPrintf( Files->Std, "&%s", gad->b_Font->txa_Label );
			else
			    FPuts( Files->Std, Null );

			FPuts( Files->Std, ",\n\t(UBYTE *)" );

			if( loc )
			    FPrintf( Files->Std, "%s", (FindString( &Files->Strings, gad->b_Titolo ))->Label );
			else
			    FPrintf( Files->Std, "\"%s\"", gad->b_Titolo );
			FPuts( Files->Std, ",\n\tNULL\n};\n" );
		    }

		    str = ( wnd->wi_IDCMP & IDCMP_GADGETHELP ) ? "extern struct ExtGadget\t\t%sGadget;\n" : "extern struct Gadget\t\t%sGadget;\n";
		    FPrintf( Files->XDef, str, gad->b_Label );

		    str = ( wnd->wi_IDCMP & IDCMP_GADGETHELP ) ? "\nstruct ExtGadget %sGadget = {\n\t" : "\nstruct Gadget %sGadget = {\n\t";
		    FPrintf( Files->Std, str, gad->b_Label );

		    next = gad->b_Node.ln_Succ;
		    if( next->b_Node.ln_Succ ) {
			FPrintf( Files->Std, "&%sGadget", next->b_Label );
		    } else {
			FPuts( Files->Std, Null );
		    }

		    FPrintf( Files->Std, ",\n\t%ld, %ld, %ld, %ld,\n",
			     gad->b_Left - IE->ScreenData->XOffset,
			     gad->b_Top  - IE->ScreenData->YOffset,
			     gad->b_Width, gad->b_Height );

		    VFPrintf( Files->Std, "\t0x%04x, 0x%04x, 1,\n", &gad->b_Flags );

		    if( img = gad->b_GadgetRender ) {
			(ULONG)img -= sizeof( struct Node );
			FPrintf( Files->Std, "\t&%sImg, ", img->in_Label );
		    } else {
			FPuts( Files->Std, "\tNULL, " );
		    }

		    if( img = gad->b_SelectRender ) {
			(ULONG)img -= sizeof( struct Node );
			FPrintf( Files->Std, "&%sImg,\n", img->in_Label );
		    } else {
			FPuts( Files->Std, "NULL,\n" );
		    }

		    if(( gad->b_flags2 & B_TEXT ) && ( gad->b_Titolo[0] ))
			FPrintf( Files->Std, "\t&%sIText", gad->b_Label );
		    else
			FPuts( Files->Std, "\tNULL" );

		    FPrintf( Files->Std, ",\n\t0, 0,\n\tGD_%s,\n\t", gad->b_Label );

		    if( IE->C_Prefs & CLICKED )
			FPrintf( Files->Std, "(APTR)%sClicked", gad->b_Label );
		    else
			FPuts( Files->Std, Null );

		    if( wnd->wi_IDCMP & IDCMP_GADGETHELP )
			FPrintf( Files->Std, ",\n\t3,\n\t%ld, %ld, %ld, %ld",
				 gad->b_Left - IE->ScreenData->XOffset,
				 gad->b_Top  - IE->ScreenData->YOffset,
				 gad->b_Width, gad->b_Height );

		    FPuts( Files->Std, "\n};\n" );
		}
	    }
	}
    }
}
///
/// WriteMenuStruct
void WriteMenuStruct( struct GenFiles *Files, struct IE_Data *IE )
{
    struct MenuTitle   *title;
    struct _MenuItem   *item;
    struct MenuSub     *sub;
    struct WindowInfo  *wnd;
    struct ImageNode   *img;
    UBYTE               buffer[300], lent, leni, lens, *str, flags[100];
    ULONG               smart;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumMenus ) {

	    smart = IE->C_Prefs & SMART_STR;

	    if( IE->SrcFlags & LOCALIZE )
		smart = wnd->wi_Tags & W_LOC_MENUS;

	    FPrintf( Files->Std, "\nstruct NewMenu %sNewMenu[] = {\n", wnd->wi_Label );

	    for( title = wnd->wi_Menus.mlh_Head; title->mt_Node.ln_Succ; title = title->mt_Node.ln_Succ ) {

		FPuts( Files->Std, "\tNM_TITLE, (STRPTR)" );

		if( title->mt_Text[0] ) {
		    lent = strlen( title->mt_Text );
		    strcpy( buffer, title->mt_Text );
		    strcat( buffer, "/" );

		    if( smart )
			FPrintf( Files->Std, "%s", (FindString( &Files->Strings, title->mt_Text ))->Label );
		    else
			FPrintf( Files->Std, "\"%s\"", title->mt_Text );
		} else {
		    FPuts( Files->Std, Null );
		}

		FPuts( Files->Std, ", NULL, " );

		if( title->mt_Flags & M_DISABLED )
		    FPuts( Files->Std, "NM_MENUDISABLED" );
		else
		    FPuts( Files->Std, Null );

		FPuts( Files->Std, ", 0, NULL,\n" );

		for( item = title->mt_Items.mlh_Head; item->min_Node.ln_Succ; item = item->min_Node.ln_Succ ) {

		    str = item->min_Image ? "\t  IM_ITEM" : "\t  NM_ITEM";
		    FPuts( Files->Std, str );

		    leni = strlen( item->min_Text );
		    strcat( buffer, item->min_Text );

		    FPuts( Files->Std, ", (STRPTR)" );

		    if( item->min_Flags & M_BARLABEL ) {
			FPuts( Files->Std, "NM_BARLABEL" );
		    } else {
			if( img = item->min_Image ) {
			    (ULONG)img -= sizeof( struct Node );
			    FPrintf( Files->Std, "&%sImg", img->in_Label );
			} else {
			    if( item->min_Text[0] )
				if( smart )
				    FPrintf( Files->Std, "%s", (FindString( &Files->Strings, item->min_Text ))->Label );
				else
				    FPrintf( Files->Std, "\"%s\"", item->min_Text );
			    else
				FPuts( Files->Std, Null );
			}
		    }

		    FPuts( Files->Std, ", " );

		    if(!( item->min_NumSubs )) {
			if( item->min_CommKey[0] ) {
			    FPuts( Files->Std, "(STRPTR)" );
			    if( smart )
				FPrintf( Files->Std, "%s", (FindString( &Files->Strings, item->min_CommKey ))->Label );
			    else
				FPrintf( Files->Std, "\"%s\"", item->min_CommKey );
			} else
			    FPuts( Files->Std, Null );
		    } else {
			FPuts( Files->Std, Null );
		    }

		    flags[0] = '\0';

		    if( item->min_Flags & M_DISABLED )
			strcpy( flags, "NM_ITEMDISABLED|" );

		    if( item->min_Flags & M_CHECKIT )
			strcat( flags, "CHECKIT|" );

		    if( item->min_Flags & M_CHECKED )
			strcat( flags, "CHECKED|" );

		    if( item->min_Flags & M_MENUTOGGLE )
			strcat( flags, "MENUTOGGLE|" );

		    if(!( item->min_NumSubs ))
			if( item->min_CommKey[0] )
			    if( item->min_CommKey[1] )
				strcat( flags, "NM_COMMANDSTRING|" );

		    if(!( flags[0] ))
			strcpy( flags, Null );
		    else
			flags[ strlen( flags ) - 1 ] = '\0';

		    FPrintf( Files->Std, ", %s, %ld, ", flags, item->min_MutualExclude );

		    if(( IE->C_Prefs & CLICKED ) && (!( item->min_NumSubs )) && (!( item->min_Flags & M_BARLABEL ))) {

			FPrintf( Files->XDef, "extern BOOL %sMenued( void );\n", item->min_Label );
			FPrintf( Files->Std, "(APTR)%sMenued", item->min_Label );

			if( IE->C_Prefs & GEN_TEMPLATE )
			    FPrintf( Files->Temp, MenuTmp, item->min_Label, buffer );

		    } else {
			FPuts( Files->Std, Null );
		    }

		    FPuts( Files->Std, ",\n" );

		    strcat( buffer, "/" );

		    for( sub = item->min_Subs.mlh_Head; sub->msn_Node.ln_Succ; sub = sub->msn_Node.ln_Succ ) {

			lens = strlen( sub->msn_Text );
			strcat( buffer, sub->msn_Text );

			str = sub->msn_Image ? "\t    IM_SUB" : "\t    NM_SUB";
			FPuts( Files->Std, str );

			FPuts( Files->Std, ", (STRPTR)" );

			if( sub->msn_Flags & M_BARLABEL ) {
			    FPuts( Files->Std, "NM_BARLABEL" );
			} else {
			    if( img = sub->msn_Image ) {
				(ULONG)img -= sizeof( struct Node );
				FPrintf( Files->Std, "&%sImg", img->in_Label );
			    } else {
				if( sub->msn_Text[0] )
				    if( smart )
					FPrintf( Files->Std, "%s", (FindString( &Files->Strings, sub->msn_Text ))->Label );
				    else
					FPrintf( Files->Std, "\"%s\"", sub->msn_Text );
				else
				    FPuts( Files->Std, Null );
			    }
			}

			FPuts( Files->Std, ", " );

			if( sub->msn_CommKey[0] ) {
			    FPuts( Files->Std, "(STRPTR)" );
			    if( smart )
				FPrintf( Files->Std, "%s", (FindString( &Files->Strings, sub->msn_CommKey ))->Label );
			    else
				FPrintf( Files->Std, "\"%s\"", sub->msn_CommKey );
			} else
			    FPuts( Files->Std, Null );

			flags[0] = '\0';

			if( sub->msn_Flags & M_DISABLED )
			    strcpy( flags, "NM_ITEMDISABLED|" );

			if( sub->msn_Flags & M_CHECKIT )
			    strcat( flags, "CHECKIT|" );

			if( sub->msn_Flags & M_CHECKED )
			    strcat( flags, "CHECKED|" );

			if( sub->msn_Flags & M_MENUTOGGLE )
			    strcat( flags, "MENUTOGGLE|" );

			if( sub->msn_CommKey[0] )
			    if( sub->msn_CommKey[1] )
				strcat( flags, "NM_COMMANDSTRING|" );

			if(!( flags[0] ))
			    strcpy( flags, Null );
			else
			    flags[ strlen( flags ) - 1 ] = '\0';

			FPrintf( Files->Std, ", %s, %ld, ", flags, sub->msn_MutualExclude );

			if(( IE->C_Prefs & CLICKED ) && (!( sub->msn_Flags & M_BARLABEL ))) {

			    FPrintf( Files->XDef, "extern BOOL %sMenued( void );\n", sub->msn_Label );
			    FPrintf( Files->Std, "(APTR)%sMenued", sub->msn_Label );

			    if( IE->C_Prefs & GEN_TEMPLATE )
				FPrintf( Files->Temp, MenuTmp, sub->msn_Label, buffer );

			} else {
			    FPuts( Files->Std, Null );
			}

			FPuts( Files->Std, ",\n" );

			buffer[ lent+leni+2 ] = '\0';
		    }

		    buffer[ lent+1 ] = '\0';
		}
	    }

	    FPuts( Files->Std, "\tNM_END, NULL, NULL, 0, 0L, NULL };\n" );
	}
    }
}
///
/// WriteITexts
void WriteITexts( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct ITextNode   *txt;
    struct TxtAttrNode *fnt;
    UWORD               x, y, next;
    ULONG               loc;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumTexts ) {

	    loc = IE->C_Prefs & SMART_STR;

	    if( IE->SrcFlags & LOCALIZE )
		loc = wnd->wi_Tags & W_LOC_TEXTS;

	    FPrintf( Files->XDef, "extern struct IntuiText\t\t%sIText[];\n", wnd->wi_Label );
	    FPrintf( Files->Std, "\nstruct IntuiText %sIText[] = {\n", wnd->wi_Label );

	    next = 1;

	    for( txt = wnd->wi_ITexts.mlh_Head; txt->itn_Node.ln_Succ; txt = txt->itn_Node.ln_Succ ) {

		FPrintf( Files->Std, "\t%ld, %ld, %ld, ",
			 txt->itn_FrontPen, txt->itn_BackPen, txt->itn_DrawMode );

		x = txt->itn_LeftEdge - IE->ScreenData->XOffset;
		y = txt->itn_TopEdge - IE->ScreenData->YOffset;

		if( IE->SrcFlags & FONTSENSITIVE ) {
		    x += ( IntuiTextLength(( struct IntuiText * )&txt->itn_FrontPen ) >> 1 );
		    y += ( IE->ScreenData->Screen->RastPort.TxHeight >> 1 );
		}

		FPrintf( Files->Std, "%ld, %ld, ", x, y );

		if( fnt = txt->itn_ITextFont ) {
		    (ULONG)fnt -= sizeof( struct Node );
		    FPrintf( Files->Std, "&%s", fnt->txa_Label );
		} else {
		    FPuts( Files->Std, Null );
		}

		FPuts( Files->Std, ", (UBYTE *)" );

		if( loc )
		    FPrintf( Files->Std, "%s", (FindString( &Files->Strings, txt->itn_Text ))->Label );
		else
		    FPrintf( Files->Std, "\"%s\"", txt->itn_Text );

		if((!( IE->SrcFlags & FONTSENSITIVE )) && ( next != wnd->wi_NumTexts )) {
		    FPrintf( Files->Std, ", &%sIText[%ld],\n", wnd->wi_Label, next );
		    next += 1;
		} else {
		    FPuts( Files->Std, ", NULL,\n" );
		}
	    }

	    Flush( Files->Std );
	    Seek( Files->Std, -2, OFFSET_CURRENT );
	    FPuts( Files->Std, "\n};\n" );

	}
    }
}
///
/// WriteImgStruct
void WriteImgStruct( struct GenFiles *Files, struct IE_Data *IE )
{
    struct ImageNode   *img;

    for( img = IE->Img_List.mlh_Head; img->in_Node.ln_Succ; img = img->in_Node.ln_Succ ) {

	FPrintf( Files->XDef, "extern struct Image\t\t%sImg;\n", img->in_Label );
	FPrintf( Files->Std, "\nstruct Image %sImg = {\n", img->in_Label );

	VFPrintf( Files->Std, "\t%d, %d,\n\t%d, %d, %d,\n\t", &img->in_Left );

	if( img->in_Size )
	    FPrintf( Files->Std, "%sImgData", img->in_Label );
	else
	    FPuts( Files->Std, Null );

	FPrintf( Files->Std, ",\n\t%ld, %ld,\n\t0\n};\n",
		 img->in_PlanePick, img->in_PlaneOnOff );
    }
}
///
/// WriteImageStruct
void WriteImageStruct( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct WndImages   *img;
    UWORD               cnt;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {

	cnt = 0;

	for( img = wnd->wi_Images.mlh_Head; img->wim_Next; img = img->wim_Next ) {

	    FPrintf( Files->XDef, "extern struct Image\t\t%s_%ldImage;\n", wnd->wi_Label, cnt );
	    FPrintf( Files->Std, "\nstruct Image %s_%ldImage = {\n", wnd->wi_Label, cnt );

	    cnt += 1;

	    FPrintf( Files->Std, "\t%ld, %ld,\n\t%ld, %ld, %ld,\n\t",
		     img->wim_Left - IE->ScreenData->XOffset,
		     img->wim_Top  - IE->ScreenData->YOffset,
		     img->wim_Width, img->wim_Height, img->wim_Depth );

	    if( img->wim_ImageNode->in_Size )
		FPrintf( Files->Std, "%sImgData", img->wim_ImageNode->in_Label );
	    else
		FPuts( Files->Std, Null );

	    FPrintf( Files->Std, ",\n\t%ld, %ld,\n\t",
		     img->wim_PlanePick, img->wim_PlaneOnOff );

	    if( cnt < wnd->wi_NumImages )
		FPrintf( Files->Std, "&%s_%ldImage", wnd->wi_Label, cnt );
	    else
		FPuts( Files->Std, Null );

	    FPuts( Files->Std, "\n};\n" );
	}
    }
}
///
/// WriteRexxCmds
void WriteRexxCmds( struct GenFiles *Files, struct IE_Data *IE )
{
    struct RexxNode *rx;

    if( IE->NumRexxs ) {

	FPuts( Files->XDef, "extern UWORD\t\t\tRX_Unconfirmed;\n"
			    "extern struct MsgPort\t\t*RexxPort;\n"
			    "extern UBYTE\t\t\tRexxPortName[];\n"
			    "extern BOOL SetupRexxPort( void );\n"
			    "extern void DeleteRexxPort( void );\n"
			    "extern void HandleRexxMsg( void );\n"
			    "extern BOOL SendRexxMsg( char *Host, char *Ext, char *Command, APTR Msg, LONG Flags );\n" );

	if( IE->SrcFlags & AREXX_CMD_LIST ) {
	    FPuts( Files->XDef, "extern struct MinList\t\tRexxCommands;\n"
				"\n"
				"struct CmdNode {\n"
				"\tstruct Node\tNode;\n"
				"\tSTRPTR\tTemplate;\n"
				"\tLONG\t( *Routine )( ULONG *, struct RexxMsg * );\n"
				"};\n" );
	} else
	    FPuts( Files->Std, "\nstatic struct parser { char *command; char *template; LONG (*routine)(ULONG *, struct RexxMsg *); } CmdTable[] = {\n" );

	for( rx = IE->Rexx_List.mlh_Head; rx->rxn_Node.ln_Succ; rx = rx->rxn_Node.ln_Succ ) {

	    FPrintf( Files->XDef, "extern LONG %sRexxed( ULONG *ArgArray, struct RexxMsg *Msg );\n",
		     rx->rxn_Label );

	    if( IE->C_Prefs & GEN_TEMPLATE )
		FPrintf( Files->Temp, "\nLONG %sRexxed( ULONG *ArgArray, struct RexxMsg *Msg )\n"
				      "{\n"
				      "\t/*  Routine for the \"%s\" ARexx command  */\n"
				      "\treturn( 0L );\n"
				      "}\n",
			 rx->rxn_Label, rx->rxn_Name );
	}


	if( IE->SrcFlags & AREXX_CMD_LIST ) {

	    FPuts( Files->Std, "\nstatic struct CmdNode RexxCmds[] = {\n\t" );

	    rx = IE->Rexx_List.mlh_Head;

	    if( IE->NumRexxs == 1 ) {
		FPuts( Files->Std, "(struct CmdNode *)&RexxCommands.mlh_Tail, (struct CmdNode *)&RexxCommands.mlh_Head, 0, 0, " );

		FPrintf( Files->Std, "\"%s\", ", rx->rxn_Name );

		if( rx->rxn_Template[0] )
		    FPrintf( Files->Std, "\"%s\"", rx->rxn_Template );
		else
		    FPuts( Files->Std, Null );

		FPrintf( Files->Std, ", (APTR)%sRexxed\n", rx->rxn_Label );

		FPuts( Files->Std, " };\n" );
	    } else {

		FPuts( Files->Std, "&RexxCmds[1], (struct Node *)&RexxCommands.mlh_Head, 0, 0, " );

		FPrintf( Files->Std, "\"%s\", ", rx->rxn_Name );

		if( rx->rxn_Template[0] )
		    FPrintf( Files->Std, "\"%s\"", rx->rxn_Template );
		else
		    FPuts( Files->Std, Null );

		FPrintf( Files->Std, ", (APTR)%sRexxed,\n", rx->rxn_Label );

		ULONG   cnt;
		for( cnt = 1; cnt < IE->NumRexxs - 1; cnt++ ) {

		    rx = rx->rxn_Node.ln_Succ;

		    FPrintf( Files->Std, "\t&RexxCmds[%ld], &RexxCmds[%ld], 0, 0, ",
			     cnt + 1, cnt - 1 );

		    FPrintf( Files->Std, "\"%s\", ", rx->rxn_Name );

		    if( rx->rxn_Template[0] )
			FPrintf( Files->Std, "\"%s\"", rx->rxn_Template );
		    else
			FPuts( Files->Std, Null );

		    FPrintf( Files->Std, ", (APTR)%sRexxed,\n", rx->rxn_Label );
		}

		rx = rx->rxn_Node.ln_Succ;
		FPrintf( Files->Std, "\t(struct CmdNode *)&RexxCommands.mlh_Tail, &RexxCmds[%ld], 0, 0, ",
			 IE->NumRexxs - 2 );

		FPrintf( Files->Std, "\"%s\", ", rx->rxn_Name );

		if( rx->rxn_Template[0] )
		    FPrintf( Files->Std, "\"%s\"", rx->rxn_Template );
		else
		    FPuts( Files->Std, Null );

		FPrintf( Files->Std, ", (APTR)%sRexxed\n};\n", rx->rxn_Label );
	    }

	    FPrintf( Files->Std, "\nstruct MinList RexxCommands = {\n"
				 "\t(struct MinNode *)&RexxCmds[0], (struct MinNode *)NULL, (struct MinNode *)&RexxCmds[%ld] };\n",
		     IE->NumRexxs - 1 );

	} else {

	    for( rx = IE->Rexx_List.mlh_Head; rx->rxn_Node.ln_Succ; rx = rx->rxn_Node.ln_Succ ) {

		FPrintf( Files->Std, "\t\"%s\", ", rx->rxn_Name );

		if( rx->rxn_Template[0] )
		    FPrintf( Files->Std, "\"%s\"", rx->rxn_Template );
		else
		    FPuts( Files->Std, Null );

		FPrintf( Files->Std, ", (APTR)%sRexxed,\n", rx->rxn_Label );
	    }

	    FPuts( Files->Std, "\tNULL\n};\n" );
	}
    }
}
///
/// WriteWindowTags
void WriteWindowTags( struct GenFiles *Files, struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    UWORD               w, h;
    ULONG               idcmp;
    static UBYTE WAIdcmp[] = "\n\t{ WA_IDCMP, ";
    ULONG               loc;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {

	FPrintf( Files->XDef, "extern struct TagItem\t\t%sWTags[];\n", wnd->wi_Label );

	FPrintf( Files->Std, "\nstruct TagItem %sWTags[] = {\n"
			     "\t{ WA_Left, %ld },\n"
			     "\t{ WA_Top, %ld },\n",
		 wnd->wi_Label, wnd->wi_Left, wnd->wi_Top );

	w = wnd->wi_Width;
	h = wnd->wi_Height;

	if( IE->SrcFlags & FONTSENSITIVE ) {
	    w -= ( IE->ScreenData->XOffset + IE->ScreenData->Screen->WBorRight  );
	    h -= ( IE->ScreenData->YOffset + IE->ScreenData->Screen->WBorBottom );
	}

	FPrintf( Files->Std, "\t{ WA_Width, %ld },\n"
			     "\t{ WA_Height, %ld },\n", w, h );

	VFPrintf( Files->Std, "\t{ WA_MinWidth, %d },\n"
			      "\t{ WA_MaxWidth, %d },\n"
			      "\t{ WA_MinHeight, %d },\n"
			      "\t{ WA_MaxHeight, %d },",
		  &wnd->wi_MinWidth );

	if( IE->flags_2 & GENERASCR )
	    FPuts( Files->Std, "\n\t{ WA_CustomScreen, NULL }," );
	else
	    FPuts( Files->Std, "\n\t{ WA_PubScreen, NULL }," );

	if( wnd->wi_Titolo[0] ) {
	    FPuts( Files->Std, "\n\t{ WA_Title, (ULONG)" );

	    loc = IE->C_Prefs & SMART_STR;

	    if( IE->SrcFlags & LOCALIZE )
		loc = wnd->wi_Tags & W_LOC_TITLE;

	    if( loc )
		FPrintf( Files->Std, "%s", (FindString( &Files->Strings, wnd->wi_Titolo ))->Label );
	    else
		FPrintf( Files->Std, "\"%s\"", wnd->wi_Titolo );

	    FPuts( Files->Std, " }," );
	}

	if( wnd->wi_Flags ) {
	    FPuts( Files->Std, "\n\t{ WA_Flags, " );

	    for( w = 0; w < WFLAGS_NUM; w++ )
		if( wnd->wi_Flags & wflgs[ w ]) {
		    FPuts( Files->Std, WndFlags[ w ]);
		    FPutC( Files->Std, '|' );
		}

	    Flush( Files->Std );
	    Seek( Files->Std, -1, OFFSET_CURRENT );
	    FPuts( Files->Std, " }," );
	}

	h = FALSE;
	for( w = 0; w < 13; w++ )
	    if( wnd->wi_GadTypes[ w ])
		h = TRUE;

	if( h ) {
	    if(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT ))
		FPrintf( Files->Std, "\n#define\t\t%s_IDCMP ", wnd->wi_Label );
	    else
		FPuts( Files->Std, WAIdcmp );

	    for( w = 0; w < 13; w++ ) {
		if( wnd->wi_GadTypes[ w ]) {
		    FPuts( Files->Std, GadIDCMP[ w ]);
		    FPutC( Files->Std, '|' );
		}
	    }

	    Flush( Files->Std );
	    Seek( Files->Std, -1, OFFSET_CURRENT );
	    FPutC( Files->Std, ' ' );
	}

	IE->win_info = wnd;
	if( idcmp = ( *IE->IEXSrcFun->IDCMP )( wnd->wi_IDCMP )) {

	    if(( IE->C_Prefs & KEY_HANDLER ) && ( wnd->wi_NumKeys ))
		idcmp |= IDCMP_VANILLAKEY;

	    if( h ) {
		Flush( Files->Std );
		Seek( Files->Std, -1, OFFSET_CURRENT );
		FPutC( Files->Std, '|' );
	    } else {
		FPuts( Files->Std, WAIdcmp );
	    }

	    for( w = 0; w < IDCMPS_NUM; w++ ) {
		if( idcmp & idcmps[ w ]) {
		    FPuts( Files->Std, WndIDCMP[ w ]);
		    FPutC( Files->Std, '|' );
		}
	    }

	    Flush( Files->Std );
	    Seek( Files->Std, -1, OFFSET_CURRENT );
	    FPutC( Files->Std, ' ' );
	}

	if(( h ) || ( wnd->wi_IDCMP ))
	    if(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT ))
		FPutC( Files->Std, '\n' );
	    else
		FPuts( Files->Std, "}," );

	if( wnd->wi_TitoloSchermo[0] ) {
	    FPuts( Files->Std, "\n\t{ WA_ScreenTitle, (ULONG)" );

	    loc = IE->C_Prefs & SMART_STR;

	    if( IE->SrcFlags & LOCALIZE )
		loc = wnd->wi_Tags & W_LOC_SCRTITLE;

	    if( loc )
		FPrintf( Files->Std, "%s", (FindString( &Files->Strings, wnd->wi_TitoloSchermo ))->Label );
	    else
		FPrintf( Files->Std, "\"%s\"", wnd->wi_TitoloSchermo );

	    FPuts( Files->Std, " }," );
	}

	if( wnd->wi_Tags & W_MOUSEQUEUE )
	    VFPrintf( Files->Std, "\n\t{ WA_MouseQueue, %d },", &wnd->wi_MouseQueue );

	if( wnd->wi_Tags & W_RPTQUEUE )
	    VFPrintf( Files->Std, "\n\t{ WA_RptQueue, %d },", &wnd->wi_RptQueue );

	if(!( wnd->wi_Tags & W_AUTOADJUST ))
	    FPuts( Files->Std, "\n\t{ WA_AutoAdjust, FALSE }," );

	if( wnd->wi_Tags & W_FALLBACK )
	    FPuts( Files->Std, "\n\t{ WA_PubScreenFallBack, TRUE }," );

	if( wnd->wi_Tags & W_ZOOM )
	    FPrintf( Files->Std, "\n\t{ WA_Zoom, %sZoom },", wnd->wi_Label );

	if( wnd->wi_flags1 & W_USA_INNER_W )
	    VFPrintf( Files->Std, "\n\t{ WA_InnerWidth, %d },", &wnd->wi_InnerWidth );

	if( wnd->wi_flags1 & W_USA_INNER_H )
	    VFPrintf( Files->Std, "\n\t{ WA_InnerHeight, %d },", &wnd->wi_InnerHeight );

	if( wnd->wi_NumGads )
	    FPuts( Files->Std, "\n\t{ WA_Gadgets, NULL }," );

	if( wnd->wi_Tags & W_TABLETMESSAGE )
	    FPuts( Files->Std, "\n\t{ WA_TabletMessages, TRUE }," );

	if( wnd->wi_Tags & W_MENUHELP )
	    FPuts( Files->Std, "\n\t{ WA_MenuHelp, TRUE }," );

	if( wnd->wi_Tags & W_NOTIFYDEPTH )
	    FPuts( Files->Std, "\n\t{ WA_NotifyDepth, TRUE }," );

	FPuts( Files->Std, "\n\t{ TAG_DONE, NULL }\n};\n" );
    }
}
///
/// WriteScreenTags
void WriteScreenTags( struct GenFiles *Files, struct IE_Data *IE )
{
    UWORD   cnt, col, r, g, b;

    FPuts( Files->XDef, "extern struct TextAttr\t\tScreenFont;\n"
			"extern struct ColorSpec\t\tScreenColors[];\n"
			"extern UWORD\t\t\tDriPens[];\n"
			"extern ULONG\t\t\tScreenTags[];\n" );

    FPrintf( Files->Std, "\nstruct TextAttr ScreenFont = {\n"
			 "\t( STRPTR )\"%s\", %ld, 0x%lx, 0x%lx };\n"
			 "\nstruct ColorSpec ScreenColors[] = {\n",
	     IE->ScreenData->FontScr, IE->ScreenData->NewFont.ta_YSize,
	     IE->ScreenData->NewFont.ta_Style,
	     IE->ScreenData->NewFont.ta_Flags );

    for( cnt = 0; cnt < 1 << IE->ScreenData->Tags[ SCRDEPTH ]; cnt++ ) {

	col = GetRGB4( IE->ScreenData->Screen->ViewPort.ColorMap, cnt );

	r = (col >> 8) & 0x0F;
	g = (col >> 4) & 0x0F;
	b = col & 0x0F;

	FPrintf( Files->Std, "\t%ld, 0x0%lx, 0x0%lx, 0x0%lx,\n", cnt, r, g, b );
    }

    VFPrintf( Files->Std, "\t~0, 0x00, 0x00, 0x00 };\n\n"
			  "UWORD DriPens[] = {\n"
			  "\t%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, ~0 };\n",
	      IE->ScreenData->DriPens );

    FPuts( Files->Std, "\nULONG ScreenTags[] = {\n"
			 "\tSA_Type, " );

    if(!( IE->ScreenData->ScrAttrs & SC_LIKEWORKBENCH ))
	FPrintf( Files->Std, "\tSA_Depth, %ld, SA_DisplayID, 0x%lx,\n"
			     "\tSA_Pens, (ULONG)DriPens,\n"
			     "\tSA_Colors, (ULONG)ScreenColors,\n",
		 IE->ScreenData->Tags[ SCRDEPTH ],
		 IE->ScreenData->Tags[ SCRID ] );

    if( IE->ScreenData->Type )
	FPuts( Files->Std, "CUSTOMSCREEN,\n" );
    else
	FPuts( Files->Std, "PUBLICSCREEN,\n" );

    FPuts( Files->Std, "\tSA_Font, (ULONG)&ScreenFont,\n" );

    if(!( IE->ScreenData->ScrAttrs & ( SC_OVERSCAN | SC_LIKEWORKBENCH )))
	FPrintf( Files->Std, "\tSA_Width, %ld, SA_Height, %ld,\n",
		 IE->ScreenData->Screen->Width,
		 IE->ScreenData->Screen->Height );

    if( IE->ScreenData->Title[0] )
	FPrintf( Files->Std, "\tSA_Title, (ULONG)\"%s\",\n", IE->ScreenData->Title );

    if( IE->ScreenData->PubName[0] )
	FPrintf( Files->Std, "\tSA_PubName, (ULONG)\"%s\",\n", IE->ScreenData->PubName );

    if(!( IE->ScreenData->ScrAttrs & SC_LIKEWORKBENCH )) {
	if( IE->ScreenData->ScrAttrs & SC_LEFT )
	    FPrintf( Files->Std, "\tSA_Left, %ld,\n", IE->ScreenData->St_Left );
	if( IE->ScreenData->ScrAttrs & SC_TOP )
	    FPrintf( Files->Std, "\tSA_Top, %ld,\n", IE->ScreenData->St_Top );
    }

    if(!( IE->ScreenData->ScrAttrs & SC_SHOWTITLE ))
	FPuts( Files->Std, "\tSA_ShowTitle, FALSE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_BEHIND )
	FPuts( Files->Std, "\tSA_Behind, TRUE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_QUIET )
	FPuts( Files->Std, "\tSA_Quiet, TRUE,\n" );

    if(( IE->ScreenData->ScrAttrs & SC_OVERSCAN ) && (!( IE->ScreenData->ScrAttrs & SC_LIKEWORKBENCH )))
	FPrintf( Files->Std, "\tSA_Overscan, 0x%lx,\n", IE->ScreenData->Tags[ SCROVERSCAN ]);

    if( IE->ScreenData->ScrAttrs & SC_FULLPALETTE )
	FPuts( Files->Std, "\tSA_FullPalette, TRUE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_ERRORCODE )
	FPuts( Files->Std, "\tSA_ErrorCode, &ScreenError,\n" );

    if(!( IE->ScreenData->ScrAttrs & SC_DRAGGABLE ))
	FPuts( Files->Std, "\tSA_Draggable, FALSE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_EXCLUSIVE )
	FPuts( Files->Std, "\tSA_Exclusive, TRUE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_SHAREPENS )
	FPuts( Files->Std, "\tSA_SharePens, TRUE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_INTERLEAVED )
	FPuts( Files->Std, "\tSA_Interleaved, TRUE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_LIKEWORKBENCH )
	FPuts( Files->Std, "\tSA_LikeWorkbench, TRUE,\n" );

    if( IE->ScreenData->ScrAttrs & SC_MINIMIZEISG )
	FPuts( Files->Std, "\tSA_MinimizeISG, TRUE,\n" );

    FPuts( Files->Std, "\tTAG_DONE\n};\n" );
}
///


//  ***  Main Routines  ***
/// OpenFiles
struct GenFiles *OpenFiles( __A0 struct IE_Data *IE, __A1 UBYTE *BaseName )
{
    UBYTE               buffer[1024], buffer2[1024];
    UBYTE              *ptr, *ptr2, *ptr3;
    struct GenFiles    *Files;

    if(!( Files = AllocMem( sizeof( struct GenFiles ), MEMF_CLEAR )))
	return( NULL );

    ptr2 = FilePart( BaseName );

    ptr  = BaseName;
    ptr3 = buffer;
    while( ptr != ptr2 )
	*ptr3++ = *ptr++;

    *ptr3 = '\0';

    ptr = buffer2;
    while(( *ptr2 != '.' ) && ( *ptr2 ))
	*ptr++ = *ptr2++;
    *ptr = '\0';

    AddPart( buffer, buffer2, 1024 );

    strcpy( buffer2, buffer );
    strcat( buffer2, ".c" );

    if(!( Files->Std = Open( buffer2, MODE_NEWFILE )))
	return( NULL );

    strcpy( buffer2, buffer );
    strcat( buffer2, ".h" );
    strcpy( Files->XDefName, buffer2 );

    if(!( Files->XDef = Open( buffer2, MODE_NEWFILE )))
	goto error;


    if( IE->C_Prefs & GEN_TEMPLATE ) {

	strcpy( buffer2, buffer );
	strcat( buffer2, "_temp.c" );

	if(!( Files->Temp = Open( buffer2, MODE_NEWFILE )))
	    goto error;

    }

    if( IE->SrcFlags & MAINPROC ) {

	strcpy( buffer2, buffer );
	strcat( buffer2, "Main.c" );

	if( AskFile( buffer2, IE ))
	    if(!( Files->Main = Open( buffer2, MODE_NEWFILE )))
		goto error;
    }

    if( IE->SrcFlags & LOCALIZE ) {

	IE->C_Prefs |= SMART_STR;

	strcpy( buffer2, buffer );  // get the right dir
	*( FilePart( buffer2 )) = '\0';

	strcat( buffer2, IE->Locale->Catalog );
	strcat( buffer2, ".cd" );

	if( AskFile( buffer2, IE ))
	    if(!( (BPTR)Files->User1 = Open( buffer2, MODE_NEWFILE )))
		goto error;

	FPrintf(( BPTR )Files->User1, ";\n"
				      ";    C source code created by Interface Editor\n"
				      ";    Copyright © 1994-1996 by Simone Tellini\n;\n"
				      ";    Generator:  %s;\n"
				      ";    Copy registered to :  %s\n"
				      ";    Serial Number      : #%ld\n"
				      ";\n",
		 LibId, IE->User->Name, IE->User->Number );

	if( IE->Locale->JoinFile[0] ) {

	    BPTR lock;

	    if(!( lock = Lock( IE->Locale->JoinFile, ACCESS_READ ))) {

		ULONG tags[] = { RT_ReqPos, REQPOS_CENTERSCR, RT_Underscore, '_',
				 RT_Screen, IE->ScreenData->Screen, TAG_DONE };

		UBYTE fault[80];

		Fault( ERROR_OBJECT_NOT_FOUND, NULL, fault, 80 );

		rtEZRequest( "%s:\n%s.", "_Oops...",
			     NULL, (struct TagItem *)tags,
			     IE->Locale->JoinFile, fault );
	    } else {
		APTR                    copy;
		BPTR                    join;
		struct FileInfoBlock    fib;

		Examine( lock, &fib );

		UnLock( lock );

		if(!( join = Open( IE->Locale->JoinFile, MODE_OLDFILE )))
		    goto error;

		if(!( copy = AllocMem( fib.fib_Size, 0L )))
		    goto error;

		Read( join, copy, fib.fib_Size );
		Close( join );

		Flush(( BPTR )Files->User1 );
		Write(( BPTR )Files->User1, copy, fib.fib_Size );

		FreeMem( copy, fib.fib_Size );
	    }
	}

	Files->User3 = IE;
    }

    NewList(( struct List *)&Files->Strings );
    NewList(( struct List *)&Files->Arrays  );

    if( IE->C_Prefs & SMART_STR )
	if(!( ProcessStrings( IE, Files )))
	    goto error;

    return( Files );


error:

    CloseFiles( Files );

    return( NULL );
}
///
/// CloseFiles
void CloseFiles( __A0 struct GenFiles *Files )
{
    UBYTE   buffer[256];

    if( Files ) {
	if( Files->Std   )  Close( Files->Std   );
	if( Files->Temp  )  Close( Files->Temp  );
	if( Files->XDef  )  Close( Files->XDef  );
	if( Files->Main  )  Close( Files->Main  );

	if( Files->User1 ) {
	    UBYTE  *from, *to, *ptr;
	    UBYTE   command[ 1024 ];

	    strcpy( command, "CatComp \"" );

	    from = Files->XDefName;
	    to = FilePart( Files->XDefName );
	    ptr = buffer;
	    while( from < to )
		*ptr++ = *from++;
	    *ptr = '\0';

	    strcat( command, buffer );
	    strcat( command, ((struct IE_Data *)Files->User3 )->Locale->Catalog );
	    strcat( command, ".cd\" CTFILE \"" );
	    strcat( command, buffer );
	    strcat( command, ((struct IE_Data *)Files->User3 )->Locale->Catalog );
	    strcat( command, ".ct\" CFILE \"" );
	    strcat( command, buffer );

	    ptr = command;
	    while( *ptr++ );
	    ptr -= 1;

	    while( *to != '.' )
		*ptr++ = *to++;
	    *ptr = '\0';

	    strcat( command, "_Locale.h\"" );

	    Close( (BPTR)Files->User1 );

	    SystemTagList( command, NULL );
	}

	FreeStrings( Files );

	FreeMem( Files, sizeof( struct GenFiles ));
    }
}
///

/// WriteHeaders
BOOL WriteHeaders( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
{

    FPrintf( Files->Std,  Header, LibId, IE->User->Name, IE->User->Number );
    FPrintf( Files->XDef, Header, LibId, IE->User->Name, IE->User->Number );

    if( Files->Temp ) {
	FPrintf( Files->Temp, Header, LibId, IE->User->Name, IE->User->Number );

	FPuts( Files->Temp,
	    "/*\n"
	    "   In this file you'll find empty  template  routines\n"
	    "   referenced in the GUI source.  You  can fill these\n"
	    "   routines with your code or use them as a reference\n"
	    "   to create your main program.\n"
	    "*/\n\n"
	    "#include <stdio.h>\n"
	    "#include <exec/types.h>\n\n" );
    }

    if( Files->Main ) {
	FPrintf( Files->Main, Header, LibId, IE->User->Name, IE->User->Number );
	WriteMain( Files, IE );
    }

    FPuts( Files->Std, "#include <exec/types.h>\n"
		       "#include <exec/nodes.h>\n"
		       "#include <intuition/intuition.h>\n"
		       "#include <intuition/gadgetclass.h>\n"
		       "#include <libraries/gadtools.h>\n"
		       "#include <clib/exec_protos.h>\n"
		       "#include <clib/intuition_protos.h>\n"
		       "#include <clib/gadtools_protos.h>\n"
		       "#include <clib/graphics_protos.h>\n"
		       "#ifdef PRAGMAS\n"
		       "#include <pragmas/exec_pragmas.h>\n"
		       "#include <pragmas/intuition_pragmas.h>\n"
		       "#include <pragmas/graphics_pragmas.h>\n"
		       "#include <pragmas/gadtools_pragmas.h>\n"
		       "#endif\n"
		       "#include <ctype.h>\n"
		       "#include <string.h>\n\n" );

    FPuts( Files->XDef, "#ifndef EXEC_TYPES_H\n"
			"#include <exec/types.h>\n"
			"#endif\n"
			"#ifndef EXEC_NODES_H\n"
			"#include <exec/nodes.h>\n"
			"#endif\n"
			"#ifndef INTUITION_INTUITION_H\n"
			"#include <intuition/intuition.h>\n"
			"#endif\n"
			"#ifndef INTUITION_GADGETCLASS_H\n"
			"#include <intuition/gadgetclass.h>\n"
			"#endif\n"
			"#ifndef LIBRARIES_GADTOOLS_H\n"
			"#include <libraries/gadtools.h>\n"
			"#endif\n"
			"#ifndef CLIB_EXEC_PROTOS_H\n"
			"#include <clib/exec_protos.h>\n"
			"#endif\n"
			"#ifndef CLIB_INTUITION_PROTOS_H\n"
			"#include <clib/intuition_protos.h>\n"
			"#endif\n"
			"#ifndef CLIB_GADTOOLS_PROTOS_H\n"
			"#include <clib/gadtools_protos.h>\n"
			"#endif\n"
			"#ifndef CLIB_GRAPHICS_PROTOS_H\n"
			"#include <clib/graphics_protos.h>\n"
			"#endif\n"
			"#ifndef CTYPE_H\n"
			"#include <ctype.h>\n"
			"#endif\n"
			"#ifndef STRING_H\n"
			"#include <string.h>\n"
			"#endif\n\n" );


    if( IE->SrcFlags & OPENDISKFONT )
	FPuts( Files->Std, "#include <clib/diskfont_protos.h>\n\n" );

    if( IE->NumRexxs )
	FPuts( Files->Std, "#include <rexx/rxslib.h>\n"
			   "#include <rexx/rexxio.h>\n"
			   "#include <rexx/errors.h>\n"
			   "#include <rexx/storage.h>\n"
			   "#include <dos/dos.h>\n"
			   "#include <dos/rdargs.h>\n"
			   "#include <clib/dos_protos.h>\n"
			   "#include <clib/rexxsyslib_protos.h>\n"
			   "#include <clib/alib_stdio_protos.h>\n"
			   "#ifdef PRAGMAS\n"
			   "#include <pragmas/dos_pragmas.h>\n"
			   "#include <pragmas/rexxsyslib_pragmas.h>\n"
			   "#endif\n\n" );

    if( IE->SrcFlags & LOCALIZE )
	FPuts( Files->Std, "#include <libraries/locale.h>\n"
			   "#include <clib/locale_protos.h>\n"
			   "#ifdef PRAGMAS\n"
			   "#include <pragmas/locale_pragmas.h>\n"
			   "#endif\n\n" );

    FPrintf( Files->Std, "#include \"%s\"\n\n", FilePart( Files->XDefName ));

    if( IE->SrcFlags & LOCALIZE ) {

	UBYTE   *to, buffer[60];

	strcpy( buffer, Files->XDefName );

	to = strrchr( buffer, '.' );
	*to = '\0';

	strcat( buffer, "_Locale.h" );

	FPrintf( Files->Std, "#define CATCOMP_ARRAY\n"
			     "#include \"%s\"\n\n",
		 buffer );
    }

    FPuts( Files->XDef, "#define GetString( g )\t((( struct StringInfo * )g->SpecialInfo )->Buffer  )\n"
			"#define GetNumber( g )\t((( struct StringInfo * )g->SpecialInfo )->LongInt )\n\n"
			"#define WT_LEFT\t\t\t\t0\n"
			"#define WT_TOP\t\t\t\t1\n"
			"#define WT_WIDTH\t\t\t2\n"
			"#define WT_HEIGHT\t\t\t3\n\n" );

    if( IE->SrcFlags & LOCALIZE )
	FPuts( Files->XDef, "extern struct CatCompArrayType CatCompArray[];\n"
			    "extern struct Library *LocaleBase;\n\n" );

    struct WindowInfo  *wnd;
    struct GadgetInfo  *gad;
    int                 cnt;
    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumGads - wnd->wi_NumBools ) {
	    cnt = 0;
	    for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {
		if( gad->g_Kind < MIN_IEX_ID ) {
		    FPrintf( Files->XDef, "#define GD_%s\t\t\t\t\t%ld\n", gad->g_Label, cnt );
		    cnt += 1;
		}
	    }
	    FPutC( Files->XDef, 10 );
	}
    }

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	cnt = wnd->wi_NumGads - wnd->wi_NumBools;
	if( cnt )
	    FPrintf( Files->XDef, "#define %s_CNT %ld\n", wnd->wi_Label, cnt );
    }

    FPutC( Files->XDef, 10 );

    ( *IE->IEXSrcFun->Headers )( Files );

    return( TRUE );
}
///
/// WriteVars
BOOL WriteVars( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
{
    int                 cnt;
    struct WindowInfo  *wnd;

    FPuts( Files->Std, "APTR\t\t\tVisualInfo;\n"
		       "int\t\t\tYOffset;\n"
		       "UWORD\t\t\tXOffset;\n"
		       "struct Screen\t\t*Scr = NULL;\n" );

    FPuts( Files->XDef, "extern struct IntuitionBase\t*IntuitionBase;\n"
			"extern struct Library\t\t*GadToolsBase;\n"
			"extern struct Screen\t\t*Scr;\n"
			"extern int\t\t\tYOffset;\n"
			"extern UWORD\t\t\tXOffset;\n"
			"extern APTR\t\t\tVisualInfo;\n" );

    if( IE->SrcFlags & FONTSENSITIVE )
	FPuts( Files->Std, "struct TextAttr\t\t*Font, Attr;\n"
			   "UWORD\t\t\tFontX, FontY;\n" );

    if(!( IE->flags_2 & GENERASCR )) {
	FPuts( Files->Std,  "UBYTE\t\t\t*PubScreenName = NULL;\n" );
	FPuts( Files->XDef, "extern UBYTE\t\t\t*PubScreenName;\n" );
    } else {
	if( IE->ScreenData->ScrAttrs & SC_ERRORCODE ) {
	    FPuts( Files->Std,  "ULONG\t\t\tScreenError = NULL;\n" );
	    FPuts( Files->XDef, "extern ULONG\t\t\tScreenError;\n" );
	}
    }

    if( IE->SrcFlags & LOCALIZE ) {
	FPrintf( Files->Std, "UBYTE\t\t\tLocalized[ %ld ];\n"
			     "struct Catalog\t\t*Catalog = NULL;\n",
		 IE->num_win );
	FPuts( Files->XDef, "extern struct Catalog\t\t*Catalog;\n" );
    }

    if( IE->NumRexxs ) {
	FPrintf( Files->Std, "UWORD\t\t\tRX_Unconfirmed;\n"
			     "struct MsgPort\t\t*RexxPort;\n"
			     "UBYTE\t\t\tRexxPortName[%ld];\n"
			     "const char\t\t*RexxPort_fmt = \"%s.%%d\";\n"
			     "const char\t\t*REXX_ext = \"%s\";\n",
		 strlen( IE->RexxPortName ) + 4,
		 IE->RexxPortName, IE->RexxExt );
    }

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	FPrintf( Files->Std,  "struct Window\t\t*%sWnd = NULL;\n", wnd->wi_Label );
	FPrintf( Files->XDef, "extern struct Window\t\t*%sWnd;\n", wnd->wi_Label );
    }

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumMenus ) {
	    FPrintf( Files->Std,  "struct Menu\t\t*%sMenus = NULL;\n", wnd->wi_Label );
	    FPrintf( Files->XDef, "extern struct Menu\t\t*%sMenus;\n", wnd->wi_Label );
	}
    }

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumGads - wnd->wi_NumBools ) {
	    FPrintf( Files->Std,  "struct Gadget\t\t*%sGList = NULL;\n", wnd->wi_Label );
	    FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGList;\n", wnd->wi_Label );
	}
    }

    if( IE->C_Prefs & INTUIMSG ) {
	for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	    if(!(( IE->SrcFlags & SHARED_PORT ) && ( wnd->wi_Tags & W_SHARED_PORT ))) {
		FPrintf( Files->Std,  "struct IntuiMessage\t%sMsg = NULL;\n", wnd->wi_Label );
		FPrintf( Files->XDef, "extern struct IntuiMessage\t%sMsg;\n", wnd->wi_Label );
	    }
	}
    }

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	cnt = wnd->wi_NumGads - wnd->wi_NumBools;
	if( cnt ) {
	    FPrintf( Files->Std,  "struct Gadget\t\t*%sGadgets[%ld];\n", wnd->wi_Label, cnt );
	    FPrintf( Files->XDef, "extern struct Gadget\t\t*%sGadgets[%ld];\n", wnd->wi_Label, cnt );
	}
    }


    if( IE->SrcFlags & SHARED_PORT ) {
	Files->User2 = IE->SharedPort[0] ? (APTR)&IE->SharedPort[0] : (APTR)"IDCMPPort";

	FPrintf( Files->XDef, "extern struct MsgPort\t\t*%s;\n"
			      "extern struct IntuiMessage\tIDCMPMsg;\n"
			      "extern LONG OpenWndShd( struct Gadget *, struct TagItem *, struct Window **, ULONG );\n"
			      "extern void CloseWndShd( struct Window **, struct Gadget **, struct Menu ** );\n"
			      "extern void HandleIDCMPPort( void );\n",
		 Files->User2 );

	if(!( IE->SharedPort[0] ))
	    FPuts( Files->Std, "\nstruct MsgPort\t\t*IDCMPPort;\n" );

	FPuts( Files->Std, "struct IntuiMessage\tIDCMPMsg;\n" );
    }


    // Expanders
    ( *IE->IEXSrcFun->Globals )( Files );

    if( IE->SrcFlags & OPENDISKFONT )
	WriteFontPtrs( Files, IE );

    return( TRUE );
}
///
/// WriteData
BOOL WriteData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
{
    struct WindowInfo  *wnd;
    struct GadgetInfo  *gad;
    ULONG               loc;

    // Gadget Labels

    loc = IE->C_Prefs & SMART_STR;

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {

	if( IE->SrcFlags & LOCALIZE )
	    loc = wnd->wi_Tags & W_LOC_GADGETS;

	for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {

	    switch( gad->g_Kind ) {

		case LISTVIEW_KIND:
		    WriteList( Files, &gad->g_Scelte, gad->g_Label, gad->g_NumScelte, IE );
		    break;

		case MX_KIND:
		case CYCLE_KIND:

		    if(!( loc )) {

			struct GadgetScelta *gs;

			FPrintf( Files->XDef, "extern UBYTE\t\t\t*%sLabels[];\n", gad->g_Label );
			FPrintf( Files->Std,  "\nUBYTE *%sLabels[] = {\n\t", gad->g_Label );

			for( gs = gad->g_Scelte.mlh_Head; gs->gs_Node.ln_Succ; gs = gs->gs_Node.ln_Succ )
			    FPrintf( Files->Std, "(UBYTE *)\"%s\",\n\t", gs->gs_Testo );

			FPuts( Files->Std, "NULL\n};\n" );
		    }
		    break;
	    }

	}
    }

    // Gadget Types

    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_NumGads - wnd->wi_NumBools ) {

	    FPrintf( Files->XDef, "extern UWORD\t\t\t%sGTypes[];\n", wnd->wi_Label );
	    FPrintf( Files->Std, "\nUWORD %sGTypes[] = {\n\t", wnd->wi_Label );

	    for( gad = wnd->wi_Gadgets.mlh_Head; gad->g_Node.ln_Succ; gad = gad->g_Node.ln_Succ ) {
		if( gad->g_Kind < BOOLEAN ) {
		    FPuts( Files->Std, GadKinds[ gad->g_Kind - 1 ]);
		    FPuts( Files->Std, ",\n\t" );
		}
	    }

	    FPuts( Files->Std, "NULL };\n" );

	}
    }

    // Fonts

    struct TxtAttrNode *fnt;
    for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next ) {
	FPrintf( Files->XDef, "extern struct TextAttr\t\t%s;\n", fnt->txa_Label );
	FPrintf( Files->Std, "\nstruct TextAttr %s = {\n"
			     "\t(STRPTR)\"%s\", %ld, 0x%lx, 0x%lx };\n",
		 fnt->txa_Label, fnt->txa_FontName, fnt->txa_Size,
		 fnt->txa_Style, fnt->txa_Flags );
    }


    // NewGadget structures
    WriteNewGadgets( Files, IE );

    // Gadget Tags
    WriteGadgetTags( Files, IE );

    // Boolean Structures
    WriteBoolStruct( Files, IE );

    // Expanders
    ( *IE->IEXSrcFun->Data )( Files );

    // Menus
    WriteMenuStruct( Files, IE );

    // IntuiTexts
    WriteITexts( Files, IE );

    // Images (used by the GUI)
    WriteImgStruct( Files, IE );

    // Images (in windows)
    WriteImageStruct( Files, IE );

    // Rexx Commands
    WriteRexxCmds( Files, IE );

    // Windows' Zoom
    for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
	if( wnd->wi_Tags & W_ZOOM ) {
	    FPrintf( Files->XDef, "extern UWORD\t\t\t%sZoom[];\n", wnd->wi_Label );
	    FPrintf( Files->Std, "\nUWORD %sZoom[] = { ", wnd->wi_Label );
	    VFPrintf( Files->Std, "%d, %d, %d, %d };\n", &wnd->wi_ZLeft );
	}
    }

    // Windows Tags
    WriteWindowTags( Files, IE );

    // Screen Tags
    if( IE->flags_2 & GENERASCR )
	WriteScreenTags( Files, IE );

    return( TRUE );
}
///
/// WriteChipData
BOOL WriteChipData( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
{
    struct ImageNode   *img;
    UWORD               words, num, *ptr;

    for( img = IE->Img_List.mlh_Head; img->in_Node.ln_Succ; img = img->in_Node.ln_Succ ) {
	if( img->in_Size ) {

	    words = img->in_Size >> 1;

	    FPrintf( Files->Std, "\n%s %sImgData[%ld] = {\n\t",
		     IE->ChipString, img->in_Label, words );

	    FPrintf( Files->XDef, "extern %s %sImgData[%ld];\n",
		     IE->ChipString, img->in_Label, words );

	    ptr = img->in_Data;

	    num = 8;
	    do {

		FPrintf( Files->Std, "0x%04lx", *ptr++ );

		num   -= 1;
		words -= 1;

		if( words ) {

		    FPutC( Files->Std, ',' );

		    if(!( num )) {
			FPuts( Files->Std, "\n\t" );
			num = 8;
		    }
		}

	    } while( words );

	    FPuts( Files->Std, "\n};\n" );

	}
    }

    // Expanders
    ( *IE->IEXSrcFun->ChipData )( Files );

    return( TRUE );
}
///
/// WriteCode
BOOL WriteCode( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
{

    // Expanders
    ( *IE->IEXSrcFun->Support )( Files );

    if( IE->SrcFlags & SHARED_PORT )
	WriteOpenWndShd( Files, IE );

    if( IE->SrcFlags & LOCALIZE )
	WriteLocale( Files, IE );

    WriteSetupScr( Files, IE );

    WriteOpenFonts( Files, IE );

    WriteOpenWnd( Files, IE );

    WriteRender( Files, IE );

    if( IE->NumRexxs ) {
	FPuts( Files->Std, ARexxCode );

	if( IE->SrcFlags & AREXX_CMD_LIST )
	    FPuts( Files->Std, ARexxHandleList );
	else
	    FPuts( Files->Std, ARexxHandleArray );
    }

    if( IE->C_Prefs & IDCMP_HANDLER )
	WriteIDCMPHandler( Files, IE );

    if( IE->C_Prefs & KEY_HANDLER )
	WriteKeyHandler( Files, IE );

    FPuts( Files->XDef, "\nextern int SetupScreen( void );\n"
			"extern void CloseDownScreen( void );\n"
			"extern LONG MakeGadgets( struct Gadget **GList, struct Gadget *Gads[],\n"
			"\tstruct NewGadget NGad[], UWORD GTypes[], ULONG GTags[], UWORD CNT );\n"
			"extern LONG OpenWnd( struct Gadget *GList, struct TagItem WTags[], struct Window **Wnd );\n"
			"extern void CloseWnd( struct Window **Wnd, struct Gadget **GList, struct Menu **Mn );\n"
	 );

    if( IE->C_Prefs & CLICKED )
	WriteClickedPtrs( Files, IE );

    return( TRUE );
}
///
/// WriteStrings
BOOL WriteStrings( __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
{

    if( Files->User1 ) {
	WriteCD( Files );
    } else {
	if(( IE->C_Prefs & SMART_STR ) && (!( IE->SrcFlags & LOCALIZE ))) {

	    struct StringNode  *str;

	    FPutC( Files->Std, 10 );

	    for( str = Files->Strings.mlh_Head; str->Next; str = str->Next ) {

		FPrintf( Files->XDef, "extern UBYTE\t\t\t%s[];\n", str->Label );

		FPrintf( Files->Std, "UBYTE %s[] = \"%s\";\n",
			 str->Label, str->String );
	    }
	}
    }

    if( IE->C_Prefs & SMART_STR ) {

	struct ArrayNode   *ar;
	UBYTE             **array;

	for( ar = Files->Arrays.mlh_Head; ar->Next; ar = ar->Next ) {

	    FPrintf( Files->XDef, "extern UBYTE\t\t\t*%s[];\n", ar->Label );

	    FPrintf( Files->Std, "\nUBYTE *%s[] = {", ar->Label );

	    array = ar->Array;

	    while( *array ) {
		FPrintf( Files->Std, "\n\t(UBYTE *)%s,",
			 ( FindString( &Files->Strings, *array ))->Label );
		array++;
	    }

	    FPuts( Files->Std, "\n\tNULL\n};\n" );
	}
    }

    return( TRUE );
}
///

/// Config
void Config( __A0 struct IE_Data *IE )
{
    struct Window  *Wnd = NULL;
    struct Gadget  *GList = NULL, *Gadgets[ Conf_CNT ];
    UBYTE           Back;
    BOOL            ret;

    if( OpenConfWindow( &Wnd, &GList, &Gadgets[0], IE )) {

	(*IE->Functions->Status)( "Cannot open my window!", TRUE, 0 );

    } else {

	Back = IE->C_Prefs;

	IE->C_Prefs = ~IE->C_Prefs;
	TemplateKeyPressed( IE, Wnd, Gadgets );
	ClickKeyPressed( IE, Wnd, Gadgets );
	MsgKeyPressed( IE, Wnd, Gadgets );
	HandlerKeyPressed( IE, Wnd, Gadgets );
	KeyHandlerKeyPressed( IE, Wnd, Gadgets );
	ToLowerKeyPressed( IE, Wnd, Gadgets );
	SmartStrKeyPressed( IE, Wnd, Gadgets );
	IE->C_Prefs = Back;

	GT_SetGadgetAttrs( Gadgets[ GD_Chip ], Wnd, NULL,
			   GTST_String, IE->ChipString, TAG_END );

	do {
	    WaitPort( Wnd->UserPort );
	    ret = HandleConfIDCMP( Wnd, IE, &Gadgets[0] );
	} while ( ret == 0 );

	if( ret > 0 ) {
	    IE->C_Prefs = Back;
	} else {
	    strcpy( IE->ChipString, GetString( Gadgets[ GD_Chip ] ));
	}

    }

    CloseWnd( &Wnd, &GList );
}

/*
    C source code created by Interface Editor
    Copyright © 1994-1996 by Simone Tellini

    Generator:  C.generator 37.0 (16.1.96)

    Copy registered to :  Simone Tellini
    Serial Number      : #0
*/

/*
   In this file you'll find empty  template  routines
   referenced in the GUI source.  You  can fill these
   routines with your code or use them as a reference
   to create your main program.
*/

BOOL MsgKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "Intui_Message "'s activation key is pressed  */

    CheckedTag[1] = ( IE->C_Prefs & INTUIMSG ) ? FALSE : TRUE;
    GT_SetGadgetAttrsA( Gadgets[ GD_Msg ], Wnd, NULL, (struct TagItem *)CheckedTag );

	/*  ...or return TRUE not to call the gadget function  */
	return MsgClicked( IE, Wnd, Gadgets );
}

BOOL ClickKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "Clicked _Ptr  "'s activation key is pressed  */

    CheckedTag[1] = ( IE->C_Prefs & CLICKED ) ? FALSE : TRUE;
    GT_SetGadgetAttrsA( Gadgets[ GD_Click ], Wnd,
			NULL, (struct TagItem *)CheckedTag );

	/*  ...or return TRUE not to call the gadget function  */
	return ClickClicked( IE, Wnd, Gadgets );
}

BOOL OkKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Ok"'s activation key is pressed  */

	/*  ...or return TRUE not to call the gadget function  */
	return OkClicked( IE, Wnd, Gadgets );
}

BOOL CancKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Cancel"'s activation key is pressed  */

	/*  ...or return TRUE not to call the gadget function  */
	return CancClicked( IE, Wnd, Gadgets );
}

BOOL HandlerKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "IDCMP _Handler"'s activation key is pressed  */

    CheckedTag[1] = ( IE->C_Prefs & IDCMP_HANDLER ) ? FALSE : TRUE;
    GT_SetGadgetAttrsA( Gadgets[ GD_Handler ], Wnd,
			NULL, (struct TagItem *)CheckedTag );

	/*  ...or return TRUE not to call the gadget function  */
	return HandlerClicked( IE, Wnd, Gadgets );
}

BOOL KeyHandlerKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Key Handler  "'s activation key is pressed  */

    CheckedTag[1] = ( IE->C_Prefs & KEY_HANDLER ) ? FALSE : TRUE;
    GT_SetGadgetAttrsA( Gadgets[ GD_KeyHandler ], Wnd,
			NULL, (struct TagItem *)CheckedTag );

	/*  ...or return TRUE not to call the gadget function  */
	return KeyHandlerClicked( IE, Wnd, Gadgets );
}

BOOL TemplateKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Template     "'s activation key is pressed  */
    CheckedTag[1] = ( IE->C_Prefs & GEN_TEMPLATE ) ? FALSE : TRUE;
    GT_SetGadgetAttrsA( Gadgets[ GD_Template ], Wnd,
			NULL, (struct TagItem *)CheckedTag );

	/*  ...or return TRUE not to call the gadget function  */
	return TemplateClicked( IE, Wnd, Gadgets );
}

BOOL ToLowerKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "To Lo_wer     "'s activation key is pressed  */
    CheckedTag[1] = ( IE->C_Prefs & TO_LOWER ) ? FALSE : TRUE;
    GT_SetGadgetAttrsA( Gadgets[ GD_ToLower ], Wnd,
			NULL, (struct TagItem *)CheckedTag );

	/*  ...or return TRUE not to call the gadget function  */
	return ToLowerClicked( IE, Wnd, Gadgets );
}

BOOL SmartStrKeyPressed( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Smart String"'s activation key is pressed  */
    CheckedTag[1] = ( IE->C_Prefs & SMART_STR ) ? FALSE : TRUE;
    GT_SetGadgetAttrsA( Gadgets[ GD_SmartStr ], Wnd,
			NULL, (struct TagItem *)CheckedTag );

	/*  ...or return TRUE not to call the gadget function  */
	return SmartStrClicked( IE, Wnd, Gadgets );
}

BOOL MsgClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "Intui_Message " is clicked  */

	IE->C_Prefs ^= INTUIMSG;

	return( 0 );
}

BOOL ClickClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "Clicked _Ptr  " is clicked  */

	IE->C_Prefs ^= CLICKED;

	return( 0 );
}

BOOL OkClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Ok" is clicked  */
	return( -1 );
}

BOOL CancClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Cancel" is clicked  */
	return( 1 );
}

BOOL HandlerClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "IDCMP _Handler" is clicked  */

	IE->C_Prefs ^= IDCMP_HANDLER;

	if( IE->C_Prefs & IDCMP_HANDLER ) {

	    IE->C_Prefs &= ~( CLICKED | INTUIMSG );

	    MsgKeyPressed( IE, Wnd, Gadgets );
	    ClickKeyPressed( IE, Wnd, Gadgets );
	}

	return( 0 );
}

BOOL KeyHandlerClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Key Handler  " is clicked  */

	IE->C_Prefs ^= KEY_HANDLER;

	if( IE->C_Prefs & KEY_HANDLER ) {

	    IE->C_Prefs &= ~( CLICKED | INTUIMSG );

	    MsgKeyPressed( IE, Wnd, Gadgets );
	    ClickKeyPressed( IE, Wnd, Gadgets );
	}

	return( 0 );
}

BOOL TemplateClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Template     " is clicked  */

	IE->C_Prefs ^= GEN_TEMPLATE;

	return( 0 );
}

BOOL ToLowerClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "To Lo_wer     " is clicked  */

	IE->C_Prefs ^= TO_LOWER;

	return( 0 );
}

BOOL ChipClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_UWORD chip:" is clicked  */
	return( 0 );
}                

BOOL SmartStrClicked( struct IE_Data *IE, struct Window *Wnd, struct Gadget *Gadgets[] )
{
	/*  Routine when "_Smart String" is clicked  */

	IE->C_Prefs ^= SMART_STR;

	return( 0 );
}
///
