
#ifndef DEMO

#include "Toolmaker.h"
#include "Externs.h"

#include <string.h>

#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>

/****************************************************************************/

BOOL GenerateHeader(void)
  {
  int    wcount;
  int    gcount;
  int    errcount;
  int    idcount;
  int    idcount2;
  int    menucount;
  int    itemcount;
  int    subcount;
  struct WindowNode    *windownode;
  struct NewGadgetNode *newgadgetnode;
  struct MenuNode      *menunode;
  struct ItemNode      *itemnode;
  struct SubNode       *subnode;
  struct TagNode       *tagnode;
  struct StringNode    *stringnode;
  struct TextAttrNode  *textattrnode;
  FILE                 *fp;
  BOOL   st=TRUE;

  DEBUGENTER("GenerateHeader", NULL);

  sprintf(fullname, "%s_tm.h", filename);

  if(fp = fopen(fullname, "wb"))
    {
    /***************** Title ******************/

    st = GenerateString("", fp, st, NULL);
    sprintf(string, "/* Include file generated by %s V%s */", title, version);
    st = GenerateString(string, fp, st, NULL);
    st = GenerateString("", fp, st, NULL);

    sprintf(string,     "#include \"%s_tm_text.h\"", savefilename);
    st = GenerateString(string, fp, st, "Toolmaker text header file");
    st = GenerateString("", fp, st, NULL);

    /****************************************/
    /******** TMScreenInfo Structure ********/
    /****************************************/

    st = GenerateString(NULL, fp, st, "TMScreenInfo structure");
    st = GenerateString(NULL, fp, st, "");

    st = GenerateString("struct TMScreenInfo", fp, st, NULL);
    st = GenerateString("  {", fp, st, NULL);
    st = GenerateString("  struct Screen *Screen;", fp, st, "pointer to Screen structure");
    st = GenerateString("  struct TagItem *MoreTags;", fp, st, "pointer to additional tag array");
    st = GenerateString("  struct VisualInfo *VisualInfo;", fp, st, "pointer to VisualInfo structure");
    st = GenerateString("  APTR UserData;", fp, st, NULL);
    st = GenerateString("  };", fp, st, NULL);
    st = GenerateString("", fp, st, NULL);

    /****************************************/
    /******** TMWindowInfo Structure ********/
    /****************************************/

    st = GenerateString(NULL, fp, st, "TMWindowInfo structure");
    st = GenerateString(NULL, fp, st, "");

    st = GenerateString("struct TMWindowInfo", fp, st, NULL);
    st = GenerateString("  {", fp, st, NULL);
    st = GenerateString("  struct Window *Window;", fp, st, "pointer to Window structure");
    st = GenerateString("  struct TagItem *MoreTags;", fp, st, "pointer to additional tag array");
    st = GenerateString("  struct IntuiMessage *GT_IMsg;", fp, st, "pointer to last gadtools IntuiMessage");
    st = GenerateString("  struct Menu *Menu;", fp, st, "pointer to Menu structure");
    st = GenerateString("  struct Requester Requester;", fp, st, "Requester structure for DISABLE/ENABLE");
    st = GenerateString("  UBYTE DisableCount;", fp, st, "Count for nested DISABLE/ENABLEs");
    st = GenerateString("  ULONG Flags;", fp, st, "TMWF_ flags");
    st = GenerateString("  struct Gadget *FirstGadget;", fp, st, "pointer to first gadget");
    st = GenerateString("  struct Gadget *ContextGadget;", fp, st, "pointer to context gadget");
    st = GenerateString("  APTR UserData;", fp, st, NULL);
    st = GenerateString("  };", fp, st, NULL);
    st = GenerateString("", fp, st, NULL);

    /****************************************/
    /******** TMGadgetInfo Structure ********/
    /****************************************/

    st = GenerateString(NULL, fp, st, "TMGadgetInfo structure");
    st = GenerateString(NULL, fp, st, "");

    st = GenerateString("struct TMGadgetInfo", fp, st, NULL);
    st = GenerateString("  {", fp, st, NULL);
    st = GenerateString("  struct Gadget *Gadget;", fp, st, NULL);
    st = GenerateString("  struct TagItem *MoreTags;", fp, st, NULL);
    st = GenerateString("  APTR UserData;", fp, st, NULL);
    st = GenerateString("  };", fp, st, NULL);
    st = GenerateString("", fp, st, NULL);

    /**********************************/
    /******** TMData structure ********/
    /**********************************/

    st = GenerateString(NULL, fp, st, "TMData structure");
    st = GenerateString(NULL, fp, st, "");

    st = GenerateString("struct TMData", fp, st, NULL);
    st = GenerateString("  {", fp, st, NULL);
    st = GenerateString("  ULONG Size;", fp, st, "Size of TMData structure");
    st = GenerateString("  struct MsgPort *WindowMsgPort;", fp, st, "pointer to window message port");

    if(arexxflag)
      {
      st = GenerateString("  AREXXCONTEXT ARexxContext;", fp, st, "ARexx context structure");
      st = GenerateString("  ULONG ARexxSignal;", fp, st, "ARexx signal flag for Wait");
      st = GenerateString("  LONG  ARexxErrorLevel;", fp, st, "ARexx error level");
      st = GenerateString("  char *ARexxError;", fp, st, "ARexx error string");
      st = GenerateString("  char *ARexxResult;", fp, st, "ARexx result string");
      }

    if(usersignalflag)
      {
      st = GenerateString("  ULONG UserSignal;", fp, st, "User signal flag for Wait");
      }

    if(diskfontcount)
      {
      sprintf(string, "  struct TextFont *TextFont[%d];", diskfontcount);
      st = GenerateString(string, fp, st, "TextFont structure pointer array");
      }

    st = GenerateString("  LONG ReturnCode;", fp, st, "Return code for exit()");
    st = GenerateString("  struct FileRequester *FileRequester;", fp, st, "ASL file requester pointer");
    st = GenerateString("  struct FontRequester *FontRequester;", fp, st, "ASL font requester pointer");
    st = GenerateString("  struct TMScreenInfo TMScreenInfo[1];", fp, st, "TMScreenInfo structure array");

    wcount = 0;
    for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
        windownode = (struct WindowNode *) windownode->Node.ln_Succ)
      {
      gcount = 0;
      for(newgadgetnode = (struct NewGadgetNode *) windownode->NewGadgetList.lh_Head; newgadgetnode->Node.ln_Succ;
          newgadgetnode = (struct NewGadgetNode *) newgadgetnode->Node.ln_Succ)
        {
        gcount++;
        }

      if(gcount)
        {
        sprintf(string, "  struct TMGadgetInfo TMGadgetInfo_%s[%d];", windownode->SourceLabel, gcount);
        st = GenerateString(string, fp, st, "TMGadgetInfo structure array");
        }

      wcount++;
      }

    sprintf(string, "  struct TMWindowInfo TMWindowInfo[%d];", wcount);
    st = GenerateString(string, fp, st, "TMWindowInfo structure array");

    if(!chipflag)
      {
      st = GenerateString("  UWORD *WaitPointer;", fp, st, NULL);
      }

    st = GenerateString("  APTR UserData;", fp, st, NULL);
    st = GenerateString("  };", fp, st, NULL);
    st = GenerateString("", fp, st, NULL);

    /******************************************/
    /*************** Prototypes ***************/
    /******************************************/

    st = GenerateString(NULL, fp, st, "Function Prototypes");
    st = GenerateString(NULL, fp, st, "");

    st = GenerateString("struct TMData *TM_Open(ULONG *);", fp, st, NULL);
    st = GenerateString("VOID TM_Close(struct TMData *);", fp, st, NULL);
    st = GenerateString("LONG TM_Request(struct Window *, UBYTE *, UBYTE *, UBYTE *, ULONG *, APTR, ...);", fp, st, NULL);
    st = GenerateString("VOID TM_EventLoop(struct TMData *);", fp, st, NULL);

    if(arexxflag)
      {
      st = GenerateString("BOOL ARexxMessage(struct TMData *, struct RexxMsg *);", fp, st, NULL);
      }

    if(usersignalflag)
      {
      st = GenerateString("BOOL UserSignal(struct TMData *, ULONG);", fp, st, NULL);
      }

    if(screennode.Workbench)
      {
      st = GenerateString("BOOL OpenScreen_Workbench(struct TMData *);", fp, st, NULL);
      st = GenerateString("VOID CloseScreen_Workbench(struct TMData *);", fp, st, NULL);
      }
    else
      {
      sprintf(string, "BOOL OpenScreen_%s(struct TMData *);", screennode.SourceLabel);
      st = GenerateString(string, fp, st, NULL);
      sprintf(string, "VOID CloseScreen_%s(struct TMData *);", screennode.SourceLabel);
      st = GenerateString(string, fp, st, NULL);
      }

    for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
        windownode = (struct WindowNode *) windownode->Node.ln_Succ)
      {
      sprintf(string, "BOOL OpenWindow_%s(struct TMData *);", windownode->SourceLabel);
      st = GenerateString(string, fp, st, NULL);
      sprintf(string, "VOID CloseWindow_%s(struct TMData *);", windownode->SourceLabel);
      st = GenerateString(string, fp, st, NULL);
      sprintf(string, "VOID DisableWindow_%s(struct TMData *);", windownode->SourceLabel);
      st = GenerateString(string, fp, st, NULL);
      sprintf(string, "VOID EnableWindow_%s(struct TMData *);", windownode->SourceLabel);
      st = GenerateString(string, fp, st, NULL);

      if(windownode->IDCMP & IDCMP_MENUPICK)
        {
        sprintf(string, "BOOL Window_%s_MENUPICK(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_REFRESHWINDOW)
        {
        sprintf(string, "VOID Window_%s_REFRESHWINDOW(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_GADGETDOWN)
        {
        sprintf(string, "BOOL Window_%s_GADGETDOWN(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_GADGETUP)
        {
        sprintf(string, "BOOL Window_%s_GADGETUP(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_CLOSEWINDOW)
        {
        sprintf(string, "BOOL Window_%s_CLOSEWINDOW(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_MOUSEBUTTONS)
        {
        sprintf(string, "BOOL Window_%s_MOUSEBUTTONS(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_MOUSEMOVE)
        {
        sprintf(string, "BOOL Window_%s_MOUSEMOVE(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_CHANGEWINDOW)
        {
        sprintf(string, "BOOL Window_%s_CHANGEWINDOW(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_SIZEVERIFY)
        {
        sprintf(string, "BOOL Window_%s_SIZEVERIFY(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_NEWSIZE)
        {
        sprintf(string, "BOOL Window_%s_NEWSIZE(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_REQSET)
        {
        sprintf(string, "BOOL Window_%s_REQSET(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_RAWKEY)
        {
        sprintf(string, "BOOL Window_%s_RAWKEY(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_REQVERIFY)
        {
        sprintf(string, "BOOL Window_%s_REQVERIFY(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_REQCLEAR)
        {
        sprintf(string, "BOOL Window_%s_REQCLEAR(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_MENUVERIFY)
        {
        sprintf(string, "BOOL Window_%s_MENUVERIFY(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_NEWPREFS)
        {
        sprintf(string, "BOOL Window_%s_NEWPREFS(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_DISKINSERTED)
        {
        sprintf(string, "BOOL Window_%s_DISKINSERTED(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_DISKREMOVED)
        {
        sprintf(string, "BOOL Window_%s_DISKREMOVED(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_ACTIVEWINDOW)
        {
        sprintf(string, "BOOL Window_%s_ACTIVEWINDOW(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_INACTIVEWINDOW)
        {
        sprintf(string, "BOOL Window_%s_INACTIVEWINDOW(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_DELTAMOVE)
        {
        sprintf(string, "BOOL Window_%s_DELTAMOVE(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_VANILLAKEY)
        {
        sprintf(string, "BOOL Window_%s_VANILLAKEY(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_INTUITICKS)
        {
        sprintf(string, "BOOL Window_%s_INTUITICKS(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_IDCMPUPDATE)
        {
        sprintf(string, "BOOL Window_%s_IDCMPUPDATE(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      if(windownode->IDCMP & IDCMP_MENUHELP)
        {
        sprintf(string, "BOOL Window_%s_MENUHELP(struct TMData *, struct IntuiMessage *);", windownode->SourceLabel);
        st = GenerateString(string, fp, st, NULL);
        }
      }

    st = GenerateString("", fp, st, NULL);

    /******************************************/
    /**************** externs *****************/
    /******************************************/

    st = GenerateString(NULL, fp, st, "Library pointers");
    st = GenerateString(NULL, fp, st, "");

    st = GenerateString("extern struct Library *SysBase;", fp, st, NULL);
    st = GenerateString("extern struct Library *DOSBase;", fp, st, NULL);
    st = GenerateString("extern struct Library *IntuitionBase;", fp, st, NULL);
    st = GenerateString("extern struct Library *GadToolsBase;", fp, st, NULL);
    st = GenerateString("extern struct Library *UtilityBase;", fp, st, NULL);

    if(diskfontcount)
      {
      st = GenerateString("extern struct Library *GfxBase;", fp, st, NULL);
      st = GenerateString("extern struct Library *DiskfontBase;", fp, st, NULL);
      }

    if(aslflag)
      {
      st = GenerateString("extern struct Library *AslBase;", fp, st, NULL);
      }

    st = GenerateString("", fp, st, NULL);

    /******************************************/
    /*************** #define's ****************/
    /******************************************/

    /* Constants */

    st = GenerateString(NULL, fp, st, "Constants");
    st = GenerateString(NULL, fp, st, "");

    st = GenerateString("#define OPENFILE\t0", fp, st, "For open file requester");
    st = GenerateString("#define SAVEFILE\t1", fp, st, "For save file requester");
    st = GenerateString("", fp, st, NULL);
    st = GenerateString("#define TMWF_OPENED\t0x00000001", fp, st, "Window opened flag");
    st = GenerateString("#define TMWF_DISABLED\t0x00000002", fp, st, "Window disabled flag");
    st = GenerateString("", fp, st, NULL);
    st = GenerateString("#define TMERR_OK\t0", fp, st, NULL);
    st = GenerateString("#define TMERR_MEMORY\t1", fp, st, NULL);
    st = GenerateString("#define TMERR_MSGPORT\t2", fp, st, NULL);

    errcount = 3;
    for(textattrnode = (struct TextAttrNode *) TextAttrList.lh_Head; textattrnode->Node.ln_Succ;
        textattrnode = (struct TextAttrNode *) textattrnode->Node.ln_Succ)
      {
      if(!((strcmp(textattrnode->FontName, "topaz.font") == 0) &&
          ((textattrnode->TextAttr.ta_YSize == 8) ||
           (textattrnode->TextAttr.ta_YSize == 9))))
        {
        sprintf(string, "#define TMERR_%s\t%d", textattrnode->Name, errcount++);
        st = GenerateString(string, fp, st, NULL);
        }
      }
    st = GenerateString("", fp, st, NULL);

    /* Screen pointer */

    st = GenerateString(NULL, fp, st, "Screen pointer");
    st = GenerateString(NULL, fp, st, "");

    if(screennode.Workbench)
      {
      st = GenerateString("#define screen_Workbench\tTMData->TMScreenInfo[0].Screen", fp, st, "Default public screen pointer");
      }
    else
      {
      sprintf(string, "#define screen_%s\tTMData->TMScreenInfo[0].Screen", screennode.SourceLabel);
      st = GenerateString(string, fp, st, "Custom screen pointer");
      }
    st = GenerateString("", fp, st, NULL);

    /* Window, menu, and gadget pointers */

    st = GenerateString(NULL, fp, st, "Window, Menu, and Gadget pointers");
    st = GenerateString(NULL, fp, st, "");

    wcount = 0;
    for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
        windownode = (struct WindowNode *) windownode->Node.ln_Succ)
      {
      sprintf(string, "#define window_%s\tTMData->TMWindowInfo[%d].Window", windownode->SourceLabel, wcount);
      st = GenerateString(string, fp, st, "Window pointer");

      if(windownode->Menu)
        {
        sprintf(string, "#define menu_%s\tTMData->TMWindowInfo[%d].Menu", windownode->SourceLabel, wcount);
        st = GenerateString(string, fp, st, "Menu pointer");
        }
      gcount = 0;
      for(newgadgetnode = (struct NewGadgetNode *) windownode->NewGadgetList.lh_Head; newgadgetnode->Node.ln_Succ;
          newgadgetnode = (struct NewGadgetNode *) newgadgetnode->Node.ln_Succ)
        {
        if(!(InvalidLabel(newgadgetnode->SourceLabel)))
          {
          sprintf(string, "#define gadget_%s\tTMData->TMGadgetInfo_%s[%d].Gadget", newgadgetnode->SourceLabel, windownode->SourceLabel, gcount);
          st = GenerateString(string, fp, st, "Gadget pointer");
          }
        gcount++;
        }
      wcount++;
      }
    st = GenerateString("", fp, st, NULL);

    /* Gadget IDs */

    st = GenerateString(NULL, fp, st, "Gadget IDs");
    st = GenerateString(NULL, fp, st, "");

    idcount = 1;
    for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
        windownode = (struct WindowNode *) windownode->Node.ln_Succ)
      {
      for(newgadgetnode = (struct NewGadgetNode *) windownode->NewGadgetList.lh_Head; newgadgetnode->Node.ln_Succ;
          newgadgetnode = (struct NewGadgetNode *) newgadgetnode->Node.ln_Succ)
        {
        if(/* newgadgetnode->Kind != TEXT_KIND &&
           newgadgetnode->Kind != NUMBER_KIND && */
           !InvalidLabel(newgadgetnode->SourceLabel))
          {
          sprintf(string, "#define ID_%s\t%d", newgadgetnode->SourceLabel, idcount);
          st = GenerateString(string, fp, st, "Gadget ID");
          }
        idcount++;

        idcount2 = 0;
        for(tagnode = (struct TagNode *) newgadgetnode->TagList.lh_Head; tagnode->Node.ln_Succ;
            tagnode = (struct TagNode *) tagnode->Node.ln_Succ)
          {
          for(stringnode = (struct StringNode *) tagnode->SourceLabelList.lh_Head; stringnode->Node.ln_Succ;
              stringnode = (struct StringNode *) stringnode->Node.ln_Succ)
            {
            if(!(InvalidLabel(stringnode->String)))
              {
              sprintf(string, "#define ID_%s_%s\t%d", newgadgetnode->SourceLabel, stringnode->String, idcount2);
              st = GenerateString(string, fp, st, "Gadget label ID");
              }
            idcount2++;
            }
          }
        }
      }
    st = GenerateString("", fp, st, NULL);

    /* Menus, items, and subitems */

    st = GenerateString(NULL, fp, st, "Menu, item, and subitem IDs");
    st = GenerateString(NULL, fp, st, "");

    for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
        windownode = (struct WindowNode *) windownode->Node.ln_Succ)
      {
      menucount = 0;
      for(menunode = (struct MenuNode *) windownode->MenuList.lh_Head; menunode->Node.ln_Succ;
          menunode = (struct MenuNode *) menunode->Node.ln_Succ)
        {
        sprintf(string, "#define MENU_%s\t%d", menunode->SourceLabel, menucount);
        st = GenerateString(string, fp, st, "Menu number");

        itemcount = 0;
        for(itemnode = (struct ItemNode *) menunode->ItemList.lh_Head; itemnode->Node.ln_Succ;
            itemnode = (struct ItemNode *) itemnode->Node.ln_Succ)
          {
          if(itemnode->ItemText[0] != '-')
            {
            sprintf(string, "#define ITEM_%s\t%d", itemnode->SourceLabel, itemcount);
            st = GenerateString(string, fp, st, "Item number");
            }

          subcount = 0;
          for(subnode = (struct SubNode *) itemnode->SubList.lh_Head; subnode->Node.ln_Succ;
              subnode = (struct SubNode *) subnode->Node.ln_Succ)
            {
            if(subnode->SubText[0] != '-')
              {
              sprintf(string, "#define SUBITEM_%s\t%d", subnode->SourceLabel, subcount);
              st = GenerateString(string, fp, st, "Subitem number");
              }

            subcount++;
            }
          itemcount++;
          }
        menucount++;
        }
      }
    st = GenerateString("", fp, st, NULL);

    /* ScreenInfo pointers */

    st = GenerateString(NULL, fp, st, "ScreenInfo pointers");
    st = GenerateString(NULL, fp, st, "");
    if(screennode.Workbench)
      strcpy(string,  "#define ScreenInfo_Workbench\tTMData->TMScreenInfo[0]");
    else
      sprintf(string, "#define ScreenInfo_%s\tTMData->TMScreenInfo[0]", screennode.SourceLabel);
    st = GenerateString(string, fp, st, "TMScreenInfo structure pointer");
    st = GenerateString("", fp, st, NULL);

    /* WindowInfo pointers */

    st = GenerateString(NULL, fp, st, "WindowInfo pointers");
    st = GenerateString(NULL, fp, st, "");

    wcount = 0;
    for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
        windownode = (struct WindowNode *) windownode->Node.ln_Succ)
      {
      sprintf(string, "#define WindowInfo_%s\tTMData->TMWindowInfo[%d]", windownode->SourceLabel, wcount);
      st = GenerateString(string, fp, st, "TMWindowInfo structure pointer");

      wcount++;
      }
    st = GenerateString("", fp, st, NULL);

    /* GadgetInfo pointers */

    st = GenerateString(NULL, fp, st, "GadgetInfo pointers");
    st = GenerateString(NULL, fp, st, "");

    for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
        windownode = (struct WindowNode *) windownode->Node.ln_Succ)
      {
      gcount = 0;
      for(newgadgetnode = (struct NewGadgetNode *) windownode->NewGadgetList.lh_Head; newgadgetnode->Node.ln_Succ;
          newgadgetnode = (struct NewGadgetNode *) newgadgetnode->Node.ln_Succ)
        {
        sprintf(string, "#define GadgetInfo_%s\tTMData->TMGadgetInfo_%s[%d]", newgadgetnode->SourceLabel, windownode->SourceLabel, gcount);
        st = GenerateString(string, fp, st, "TMGadgetInfo structure pointer");
        gcount++;
        }
      }
    st = GenerateString("", fp, st, NULL);

    if(userdataflag)
      {
      st = GenerateString(NULL, fp, st, "NewMenu UserData structures");
      st = GenerateString(NULL, fp, st, "");

      for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
          windownode = (struct WindowNode *) windownode->Node.ln_Succ)
        {
        for(menunode = (struct MenuNode *) windownode->MenuList.lh_Head; menunode->Node.ln_Succ;
            menunode = (struct MenuNode *) menunode->Node.ln_Succ)
          {
          for(itemnode = (struct ItemNode *) menunode->ItemList.lh_Head; itemnode->Node.ln_Succ;
              itemnode = (struct ItemNode *) itemnode->Node.ln_Succ)
            {
            if(itemnode->ItemText[0] != '-')
              {
              sprintf(string, "extern TMOBJECTDATA tmobjectdata_%s;", itemnode->SourceLabel);
              st = GenerateString(string, fp, st, itemnode->SourceLabel);
              }

            for(subnode = (struct SubNode *) itemnode->SubList.lh_Head; subnode->Node.ln_Succ;
                subnode = (struct SubNode *) subnode->Node.ln_Succ)
              {
              if(subnode->SubText[0] != '-')
                {
                sprintf(string, "extern TMOBJECTDATA tmobjectdata_%s;", subnode->SourceLabel);
                st = GenerateString(string, fp, st, subnode->SourceLabel);
                }

              }
            }
          }
        }
      st = GenerateString("", fp, st, NULL);

      st = GenerateString(NULL, fp, st, "NewGadget UserData structures");
      st = GenerateString(NULL, fp, st, "");

      for(windownode = (struct WindowNode *) WindowList.lh_Head; windownode->Node.ln_Succ;
          windownode = (struct WindowNode *) windownode->Node.ln_Succ)
        {
        for(newgadgetnode = (struct NewGadgetNode *) windownode->NewGadgetList.lh_Head; newgadgetnode->Node.ln_Succ;
            newgadgetnode = (struct NewGadgetNode *) newgadgetnode->Node.ln_Succ)
          {
          sprintf(string, "extern TMOBJECTDATA tmobjectdata_%s;", newgadgetnode->SourceLabel);
          st = GenerateString(string, fp, st, newgadgetnode->SourceLabel);
          }
        }
      st = GenerateString("", fp, st, NULL);
      }

    fclose(fp);

    st = UpdateIcon(fullname, "h", st);

    if(!st)
      {
      DeleteFile(fullname);
      DeleteIcon(fullname);
      }
    }
  else
    {
    st = FALSE;
    }

  DEBUGEXIT(TRUE, st);
  return(st);
  }

#endif
