/*******************************************************************************
* YORKTOWN ADVANCED SGML PARSER (YASP)                                         *
*         An SGML Parser conforming to International Standard ISO 8879 --      *
*         Standard Generalized Markup Language                                 *
*------------------------------------------------------------------------------*
* Written 1987 - 1993 by                                                       *
*         Pierre G. Richard                                                    *
*         IBM T.J. Watson Research Center                                      *
*         Yorktown Heights, New York                                           *
*         petrus@watson.ibm.com                                                *
*------------------------------------------------------------------------------*
* FUNCTION NAME    = SGML Parser / Ref OCS table creation                      *
* STATUS           = Version 0, Release 1, Level 34 and up                     *
* COMPONENT NAME   = gnname.c                                                  *
* DESCRIPTIVE NAME = Build miscellaneous chunks based on the ref naming.       *
* DATE_WR          = 05/19/1987                                                *
* AUTHOR           = Pierre G. Richard - PETRUS at YKTVMX                      *
*                                                                              *
* FUNCTIONAL DESCRIPTION =                                                     *
* Creates PSE.H, GEN.H and OCSMIN.H                                            *
* Just a tool for me, because I'm making too much mistakes when I'm changing   *
* the reference names.                                                         *
*                                                                              *
* IMPLEMENTATION NOTE =                                                        *
*                                                                              *
* DEPENDENCIES =  (see Include list)                                           *
*                                                                              *
* IMPORT=                                                                      *
*                                                                              *
* EXPORT=                                                                      *
*                                                                              *
* CHANGE HISTORY =                                                             *
* Number Date     Inits    Change & Reason (brief)                             *
*      1 12/31/88 PETRUS   Added DSC to be recognized in TAG mode ([149.2])    *
*      2 02/14/88 PETRUS   Added QUANTITY                                      *
*      3 10/11/89 PETRUS   ISO8879 - Amendment 1                               *
*      4 11/28/90 PETRUS   NAMELEN_MAX to 32, LITLEN to 2400 (28001A Reqrts)   *
*      5 12/13/90 PETRUS   ALWDTAB lists all keywords and replaces SGWD        *
*      6 06/27/92 PETRUS   Created ASL mode -- removed change 1                *
*******************************************************************************/

/*-------------+
|Include Files |
+-------------*/
#include "machine.h"
#include "portable.h"
#include <stdio.h>
#include <string.h>
#include <time.h>

static char beg_of_prod[] =
"/*@ Produced by gnname.exe %.24s -- do not change directly */\n";
static char end_of_prod[] =
"/*@ End of production (gnname.exe) -----------\
------------------------------- */\n";

static char def_16_bits_systems[] =  /* how to recognize 16-bits systems? */
   "(defined(DOS_SYS) || defined(OS2V1_SYS))";

static char s_AND []      =  "AND";
static char s_ANY []      =  "ANY";
static char s_APPINFO []  =  "APPINFO";
static char s_ASN1 []     =  "ASN1";
static char s_ATTCAP []   =  "ATTCAP";
static char s_ATTCHCAP [] =  "ATTCHCAP";
static char s_ATTCNT []   =  "ATTCNT";
static char s_ATTLIST []  =  "ATTLIST";
static char s_ATTSPLEN [] =  "ATTSPLEN";
static char s_AVGRPCAP [] =  "AVGRPCAP";
static char s_BASESET []  =  "BASESET";
static char s_BSEQLEN []  =  "BSEQLEN";
static char s_CAPACITY [] =  "CAPACITY";
static char s_CDATA []    =  "CDATA";
static char s_CHANGES []  =  "CHANGES";
static char s_CHARSET []  =  "CHARSET";
static char s_COM []      =  "COM";
static char s_CONCUR []   =  "CONCUR";
static char s_CONREF []   =  "CONREF";
static char s_CONTROLS [] =  "CONTROLS";
static char s_CRO []      =  "CRO";
static char s_CURRENT []  =  "CURRENT";
static char s_DATATAG []  =  "DATATAG";
static char s_DEFAULT []  =  "DEFAULT";
static char s_DELIM []    =  "DELIM";
static char s_DELIMLEN [] =  "DELIMLEN";
static char s_DESCSET []  =  "DESCSET";
static char s_DOCTYPE []  =  "DOCTYPE";
static char s_DOCUMENT [] =  "DOCUMENT";
static char s_DSC []      =  "DSC";
static char s_DSO []      =  "DSO";
static char s_DTACAP []   =  "DTACAP";
static char s_DTACHCAP [] =  "DTACHCAP";
static char s_DTAGLEN []  =  "DTAGLEN";
static char s_DTD []      =  "DTD";
static char s_DTEMPLEN [] =  "DTEMPLEN";
static char s_DTGC []     =  "DTGC";
static char s_DTGO []     =  "DTGO";
static char s_ELEMCAP []  =  "ELEMCAP";
static char s_ELEMENT []  =  "ELEMENT";
static char s_ELEMENTS [] =  "ELEMENTS";
static char s_EMPTY []    =  "EMPTY";
static char s_ENDTAG []   =  "ENDTAG";
static char s_ENTCAP []   =  "ENTCAP";
static char s_ENTCHCAP [] =  "ENTCHCAP";
static char s_ENTITIES [] =  "ENTITIES";
static char s_ENTITY []   =  "ENTITY";
static char s_ENTLVL []   =  "ENTLVL";
static char s_ERO []      =  "ERO";
static char s_ETAGO []    =  "ETAGO";
static char s_EXCLUDE []  =  "EXCLUDE";
static char s_EXGRPCAP [] =  "EXGRPCAP";
static char s_EXNMCAP []  =  "EXNMCAP";
static char s_EXPLICIT [] =  "EXPLICIT";
static char s_FEATURES [] =  "FEATURES";
static char s_FIXED []    =  "FIXED";
static char s_FORMAL []   =  "FORMAL";
static char s_FUNCHAR []  =  "FUNCHAR";
static char s_FUNCTION [] =  "FUNCTION";
static char s_GENERAL []  =  "GENERAL";
static char s_GRPC []     =  "GRPC";
static char s_GRPCAP []   =  "GRPCAP";
static char s_GRPCNT []   =  "GRPCNT";
static char s_GRPGTCNT [] =  "GRPGTCNT";
static char s_GRPLVL []   =  "GRPLVL";
static char s_GRPO []     =  "GRPO";
static char s_ID []       =  "ID";
static char s_IDCAP []    =  "IDCAP";
static char s_IDLINK []   =  "IDLINK";
static char s_IDREF []    =  "IDREF";
static char s_IDREFCAP [] =  "IDREFCAP";
static char s_IDREFS []   =  "IDREFS";
static char s_IGNORE []   =  "IGNORE";
static char s_IMPLICIT [] =  "IMPLICIT";
static char s_IMPLIED []  =  "IMPLIED";
static char s_INCLUDE []  =  "INCLUDE";
static char s_INITIAL []  =  "INITIAL";
static char s_INSTANCE [] =  "INSTANCE";
static char s_LCNMCHAR [] =  "LCNMCHAR";
static char s_LCNMSTRT [] =  "LCNMSTRT";
static char s_LINK []     =  "LINK";
static char s_LINKTYPE [] =  "LINKTYPE";
static char s_LIT []      =  "LIT";
static char s_LITA []     =  "LITA";
static char s_LITLEN []   =  "LITLEN";
static char s_LKNMCAP []  =  "LKNMCAP";
static char s_LKSETCAP [] =  "LKSETCAP";
static char s_LPD []      =  "LPD";
static char s_MAPCAP []   =  "MAPCAP";
static char s_MD []       =  "MD";
static char s_MDC []      =  "MDC";
static char s_MDO []      =  "MDO";
static char s_MINIMIZE [] =  "MINIMIZE";
static char s_MINUS []    =  "MINUS";
static char s_MODEL []    =  "MODEL";
static char s_MS []       =  "MS";
static char s_MSC []      =  "MSC";
static char s_MSICHAR []  =  "MSICHAR";
static char s_MSOCHAR []  =  "MSOCHAR";
static char s_MSSCHAR []  =  "MSSCHAR";
static char s_NAME []     =  "NAME";
static char s_NAMECASE [] =  "NAMECASE";
static char s_NAMELEN []  =  "NAMELEN";
static char s_NAMES []    =  "NAMES";
static char s_NAMING []   =  "NAMING";
static char s_NDATA []    =  "NDATA";
static char s_NET []      =  "NET";
static char s_NMTOKEN []  =  "NMTOKEN";
static char s_NMTOKENS [] =  "NMTOKENS";
static char s_NO []       =  "NO";
static char s_NONE []     =  "NONE";
static char s_NONSGML []  =  "NONSGML";
static char s_NORMSEP []  =  "NORMSEP";
static char s_NOTATION [] =  "NOTATION";
static char s_NOTCAP []   =  "NOTCAP";
static char s_NOTCHCAP [] =  "NOTCHCAP";
static char s_NUMBER []   =  "NUMBER";
static char s_NUMBERS []  =  "NUMBERS";
static char s_NUTOKEN []  =  "NUTOKEN";
static char s_NUTOKENS [] =  "NUTOKENS";
static char s_O []        =  "O";
static char s_OMITTAG []  =  "OMITTAG";
static char s_OPT []      =  "OPT";
static char s_OR []       =  "OR";
static char s_OTHER []    =  "OTHER";
static char s_PACK []     =  "PACK";
static char s_PCDATA []   =  "PCDATA";
static char s_PERO []     =  "PERO";
static char s_PI []       =  "PI";
static char s_PIC []      =  "PIC";
static char s_PILEN []    =  "PILEN";
static char s_PIO []      =  "PIO";
static char s_PLUS []     =  "PLUS";
static char s_POSTLINK [] =  "POSTLINK";
static char s_PUBLIC []   =  "PUBLIC";
static char s_QUANTITY [] =  "QUANTITY";
static char s_RANK []     =  "RANK";
static char s_RCDATA []   =  "RCDATA";
static char s_RE []       =  "RE";
static char s_REFC []     =  "REFC";
static char s_REP []      =  "REP";
static char s_REQUIRED [] =  "REQUIRED";
static char s_RESTORE []  =  "RESTORE";
static char s_RNI []      =  "RNI";
static char s_RS []       =  "RS";
static char s_SCOPE []    =  "SCOPE";
static char s_SDATA []    =  "SDATA";
static char s_SDIF []     =  "SDIF";
static char s_SEPCHAR []  =  "SEPCHAR";
static char s_SEQ []      =  "SEQ";
static char s_SEQUENCE [] =  "SEQUENCE";
static char s_SGML []     =  "SGML";
static char s_SGMLREF []  =  "SGMLREF";
static char s_SHORTREF [] =  "SHORTREF";
static char s_SHORTTAG [] =  "SHORTTAG";
static char s_SHUNCHAR [] =  "SHUNCHAR";
static char s_SIMPLE []   =  "SIMPLE";
static char s_SPACE []    =  "SPACE";
static char s_SRCNT []    =  "SRCNT";
static char s_SRLEN []    =  "SRLEN";
static char s_STAGO []    =  "STAGO";
static char s_STARTTAG [] =  "STARTTAG";
static char s_SUBDOC []   =  "SUBDOC";
static char s_SWITCHES [] =  "SWITCHES";
static char s_SYNTAX []   =  "SYNTAX";
static char s_SYSTEM []   =  "SYSTEM";
static char s_TAB []      =  "TAB";
static char s_TAGC []     =  "TAGC";
static char s_TAGLEN []   =  "TAGLEN";
static char s_TAGLVL []   =  "TAGLVL";
static char s_TEMP []     =  "TEMP";
static char s_TEXT []     =  "TEXT";
static char s_TOTALCAP [] =  "TOTALCAP";
static char s_UCNMCHAR [] =  "UCNMCHAR";
static char s_UCNMSTRT [] =  "UCNMSTRT";
static char s_UNPACK []   =  "UNPACK";
static char s_UNUSED []   =  "UNUSED";
static char s_USELINK []  =  "USELINK";
static char s_USEMAP []   =  "USEMAP";
static char s_VALIDATE [] =  "VALIDATE";
static char s_VI []       =  "VI";
static char s_YES []      =  "YES";

static char ISO_banner[] = "ISO 8879:1986";

/*----------------------------------------------------------------------------+
| List of the 180 ISO 8879 keywords + 2 YASP specific words                   |
|                                                                             |
| This list must be in alphabetic order                                       |
+----------------------------------------------------------------------------*/
#define SGML  0x01        /* Name found in the SGML Declaration  */
#define GEN   0x02        /* and/or in others Declarations ( ->GNWD table) */
#define FCLS  0x04        /* for function classes */
#define DLIM  0x08        /* Delimiteur role */
#define QNTY  0x10        /* Quantity name */
#define CAPA  0x20        /* Capacity name */
#define SYST  0x40        /* System Declaration */
#define NON_ISO_CAP  0x80 /* YASP specific: Not in ISO */

#define DLVL_CHARID     'a'
#define CAPA_CHARID     'c'
#define DLIM_CHARID     'd'
#define FCLS_CHARID     'f'
#define GEN_CHARID      'g'
#define QNTY_CHARID     'q'
#define SGML_CHARID     's'
#define SYST_CHARID     'y'

typedef struct {
   char *name;
   uint wh;
}LISTE;

static LISTE liste[] = {
   {s_AND      ,  DLIM         },
   {s_ANY      ,  GEN          },
   {s_APPINFO  ,  SGML         },
   {s_ASN1     ,  SYST         },
   {s_ATTCAP   ,  CAPA         },
   {s_ATTCHCAP ,  CAPA         },
   {s_ATTCNT   ,  QNTY         },
   {s_ATTLIST  ,  GEN          },
   {s_ATTSPLEN ,  QNTY         },
   {s_AVGRPCAP ,  CAPA         },
   {s_BASESET  ,  SGML         },
   {s_BSEQLEN  ,  QNTY         },
   {s_CAPACITY ,  GEN + SGML   },    /* PT and OSCCAP:105 */
   {s_CDATA    ,  GEN          },
   {s_CHANGES  ,  SYST         },
   {s_CHARSET  ,  GEN + SGML   },    /* PT and OCSCOMP:224 */
   {s_COM      ,  DLIM         },
   {s_CONCUR   ,  SGML         },
   {s_CONREF   ,  GEN          },
   {s_CONTROLS ,  SGML         },    /* SGML only */
   {s_CRO      ,  DLIM         },
   {s_CURRENT  ,  GEN          },
   {s_DATATAG  ,  SGML         },
   {s_DEFAULT  ,  GEN          },
   {s_DELIM    ,  SGML         },
   {s_DELIMLEN ,  SYST         },
   {s_DESCSET  ,  SGML         },
   {s_DOCTYPE  ,  GEN          },
   {s_DOCUMENT ,  GEN + SGML   },    /* PT and OCSCOMP:151 (tough) */
   {s_DSC      ,  DLIM         },
   {s_DSO      ,  DLIM         },
   {s_DTACAP   ,  NON_ISO_CAP  },    /* Not in ISO */
   {s_DTACHCAP ,  NON_ISO_CAP  },    /* Not in ISO */
   {s_DTAGLEN  ,  QNTY         },
   {s_DTD      ,  GEN          },
   {s_DTEMPLEN ,  QNTY         },
   {s_DTGC     ,  DLIM         },
   {s_DTGO     ,  DLIM         },
   {s_ELEMCAP  ,  CAPA         },
   {s_ELEMENT  ,  GEN          },
   {s_ELEMENTS ,  GEN          },
   {s_EMPTY    ,  GEN          },
   {s_ENDTAG   ,  GEN          },
   {s_ENTCAP   ,  CAPA         },
   {s_ENTCHCAP ,  CAPA         },
   {s_ENTITIES ,  GEN          },
   {s_ENTITY   ,  GEN + SGML   },    /* AT and OCSCOMP:380 */
   {s_ENTLVL   ,  QNTY         },
   {s_ERO      ,  DLIM         },
   {s_ETAGO    ,  DLIM         },
   {s_EXCLUDE  ,  SYST         },
   {s_EXGRPCAP ,  CAPA         },
   {s_EXNMCAP  ,  CAPA         },
   {s_EXPLICIT ,  SGML         },    /* SGML only */
   {s_FEATURES ,  SGML         },
   {s_FIXED    ,  GEN          },
   {s_FORMAL   ,  SGML         },
   {s_FUNCHAR  ,  FCLS         },    /* Function Class */
   {s_FUNCTION ,  SGML         },
   {s_GENERAL  ,  SGML         },    /* SGML only */
   {s_GRPC     ,  DLIM         },
   {s_GRPCAP   ,  CAPA         },
   {s_GRPCNT   ,  QNTY         },
   {s_GRPGTCNT ,  QNTY         },
   {s_GRPLVL   ,  QNTY         },
   {s_GRPO     ,  DLIM         },
   {s_ID       ,  GEN          },
   {s_IDCAP    ,  CAPA         },
   {s_IDLINK   ,  GEN          },    /* Amendment 1 */
   {s_IDREF    ,  GEN          },
   {s_IDREFCAP ,  CAPA         },
   {s_IDREFS   ,  GEN          },
   {s_IGNORE   ,  GEN          },
   {s_IMPLICIT ,  SGML         },
   {s_IMPLIED  ,  GEN          },
   {s_INCLUDE  ,  GEN          },
   {s_INITIAL  ,  GEN          },    /* Amendment 1 */
   {s_INSTANCE ,  SGML         },
   {s_LCNMCHAR ,  SGML         },
   {s_LCNMSTRT ,  SGML         },
   {s_LINK     ,  GEN + SGML   },    /* LT and OCSCOMP.C */
   {s_LINKTYPE ,  GEN          },
   {s_LIT      ,  DLIM         },
   {s_LITA     ,  DLIM         },
   {s_LITLEN   ,  QNTY         },
   {s_LKNMCAP  ,  CAPA         },
   {s_LKSETCAP ,  CAPA         },
   {s_LPD      ,  GEN          },
   {s_MAPCAP   ,  CAPA         },
   {s_MD       ,  GEN          },
   {s_MDC      ,  DLIM         },
   {s_MDO      ,  DLIM         },
   {s_MINIMIZE ,  SGML         },
   {s_MINUS    ,  DLIM         },
   {s_MODEL    ,  SYST         },
   {s_MS       ,  GEN          },
   {s_MSC      ,  DLIM         },
   {s_MSICHAR  ,  FCLS         },    /* Function Class */
   {s_MSOCHAR  ,  FCLS         },    /* Function Class */
   {s_MSSCHAR  ,  FCLS         },    /* Function Class */
   {s_NAME     ,  GEN          },
   {s_NAMECASE ,  SGML         },
   {s_NAMELEN  ,  QNTY         },
   {s_NAMES    ,  GEN + SGML   },    /* AT and OCSNAME:146 */
   {s_NAMING   ,  SGML         },
   {s_NDATA    ,  GEN          },
   {s_NET      ,  DLIM         },
   {s_NMTOKEN  ,  GEN          },
   {s_NMTOKENS ,  GEN          },
   {s_NO       ,  SGML         },    /* SGML only */
   {s_NONE     ,  SGML         },    /* SGML only */
   {s_NONSGML  ,  GEN          },
   {s_NORMSEP  ,  QNTY         },
   {s_NOTATION ,  GEN          },
   {s_NOTCAP   ,  CAPA         },
   {s_NOTCHCAP ,  CAPA         },
   {s_NUMBER   ,  GEN          },
   {s_NUMBERS  ,  GEN          },
   {s_NUTOKEN  ,  GEN          },
   {s_NUTOKENS ,  GEN          },
   {s_O        ,  GEN          },
   {s_OMITTAG  ,  SGML         },
   {s_OPT      ,  DLIM         },
   {s_OR       ,  DLIM         },
   {s_OTHER    ,  SGML         },
   {s_PACK     ,  SYST         },
   {s_PCDATA   ,  GEN          },
   {s_PERO     ,  DLIM         },
   {s_PI       ,  GEN          },
   {s_PIC      ,  DLIM         },
   {s_PILEN    ,  QNTY         },
   {s_PIO      ,  DLIM         },
   {s_PLUS     ,  DLIM         },
   {s_POSTLINK ,  GEN          },    /* Amendment 1 */
   {s_PUBLIC   ,  GEN + SGML   },    /* XID and OCSCAP */
   {s_QUANTITY ,  SGML         },
   {s_RANK     ,  SGML         },
   {s_RCDATA   ,  GEN          },
   {s_RE       ,  GEN          },    /* GEN only */
   {s_REFC     ,  DLIM         },
   {s_REP      ,  DLIM         },
   {s_REQUIRED ,  GEN          },
   {s_RESTORE  ,  GEN          },    /* Amendment 1 */
   {s_RNI      ,  DLIM         },
   {s_RS       ,  GEN          },    /* GEN only */
   {s_SCOPE    ,  SGML         },
   {s_SDATA    ,  GEN          },
   {s_SDIF     ,  SYST         },
   {s_SEPCHAR  ,  FCLS         },    /* Function Class */
   {s_SEQ      ,  DLIM         },
   {s_SEQUENCE ,  SYST         },
   {s_SGML     ,  SGML         },
   {s_SGMLREF  ,  SGML         },    /* SGML only */
   {s_SHORTREF ,  GEN          },
   {s_SHORTTAG ,  SGML         },    /* SGML only */
   {s_SHUNCHAR ,  SGML         },
   {s_SIMPLE   ,  GEN + SGML   },    /* SGML and GEN */
   {s_SPACE    ,  GEN          },    /* GEN only */
   {s_SRCNT    ,  SYST         },
   {s_SRLEN    ,  SYST         },
   {s_STAGO    ,  DLIM         },
   {s_STARTTAG ,  GEN          },
   {s_SUBDOC   ,  GEN + SGML   },    /* PT and OCSCOMP:464 */
   {s_SWITCHES ,  SGML         },
   {s_SYNTAX   ,  GEN + SGML   },    /* PT and OCSCOMP:254 */
   {s_SYSTEM   ,  GEN          },
   {s_TAB      ,  SGML         },
   {s_TAGC     ,  DLIM         },
   {s_TAGLEN   ,  QNTY         },
   {s_TAGLVL   ,  QNTY         },
   {s_TEMP     ,  GEN          },
   {s_TEXT     ,  GEN          },
   {s_TOTALCAP ,  CAPA         },
   {s_UCNMCHAR ,  SGML         },
   {s_UCNMSTRT ,  SGML         },
   {s_UNPACK   ,  SYST         },
   {s_UNUSED   ,  SGML         },    /* SGML only */
   {s_USELINK  ,  GEN          },
   {s_USEMAP   ,  GEN          },
   {s_VALIDATE ,  SYST         },
   {s_VI       ,  DLIM         },
   {s_YES      ,  SGML         }     /* SGML only */
};

/*----------------------------------------------------------------------------+
| Recognition Modes: each MODE must be used at least one time:                |
|                    do not define 11 modes, while                            |
|                    using 10 modes only !                                    |
+----------------------------------------------------------------------------*/
#define CON_MO   (1<< 0)
#define DS_MO    (1<< 1)
#define GRP_MO   (1<< 2)
#define LITC_MO  (1<< 3) /* for literal with replaceable char data */
#define MD_MO    (1<< 4)
#define TAG_MO   (1<< 5)
#define ASL_MO   (1<< 6) /* for attribute specification list DSO initiated */
#define LITP_MO  (1<< 7) /* for literal with replaceable param data */
#define RCD_MO   (1<< 8) /* for replaceable char data in context (RCDATA) */
#define FCD_MO   (1<< 9) /* for fixed char data in context (CDATA) */
#define RCDMS_MO (1<<10) /* for replaceable char data in MS (RCDATA) */
#define FCDMS_MO (1<<11) /* for fixed char data in MS (CDATA) */
#define IGNMS_MO (1<<12) /* for an IGNOREd MS (marked section) */
#define INI_MO   (1<<13) /* When the parse starts (not said in ISO) */
#define NBR_OF_MODES 14  /* must be next digit..*/

typedef struct {
   char *name;
   int  val;
}MODES;
static MODES modes[NBR_OF_MODES] = {
   { "CON"   , CON_MO   },
   { "DS"    , DS_MO    },
   { "GRP"   , GRP_MO   },
   { "LITC"  , LITC_MO  },
   { "MD"    , MD_MO    },
   { "TAG"   , TAG_MO   },
   { "ASL"   , ASL_MO   },
   { "LITP"  , LITP_MO  },
   { "RCD"   , RCD_MO   },
   { "FCD"   , FCD_MO   },
   { "RCDMS" , RCDMS_MO },
   { "FCDMS" , FCDMS_MO },
   { "IGNMS" , IGNMS_MO },
   { "INI"   , INI_MO   }
};

#define DSTAB 0x01    /* must exist in a DSTAB */
typedef struct {      /* Single Delimiters */
   char *name;
   uint wh;
   char *assign;
   uint   mode;
}DLISTE;
static DLISTE dliste[] = {
   {s_AND     , 0    , "&"   , GRP_MO                                         },
   {s_COM     , DSTAB, "--"  , MD_MO                                          },
   {s_CRO     , DSTAB, "&#"  , CON_MO | LITC_MO | LITP_MO | RCD_MO | RCDMS_MO },
   {s_DSC     , 0    , "]"   , DS_MO  | MD_MO | ASL_MO                        },
   {s_DSO     , 0    , "["   , MD_MO                                          },
   {s_DTGC    , 0    , "]"   , GRP_MO                                         },
   {s_DTGO    , 0    , "["   , GRP_MO                                         },
   {s_ERO     , DSTAB, "&"   , CON_MO | LITC_MO | RCD_MO | RCDMS_MO           },
   {s_ETAGO   , DSTAB, "</"  , CON_MO | TAG_MO | RCD_MO | FCD_MO              },
   {s_GRPC    , 0    , ")"   , GRP_MO                                         },
   {s_GRPO    , 0    , "("   , GRP_MO | MD_MO                                 },
   {s_LIT     , DSTAB, "\\\"", GRP_MO |LITC_MO |LITP_MO |MD_MO |TAG_MO |ASL_MO},
   {s_LITA    , DSTAB, "'"   , GRP_MO |LITC_MO |LITP_MO |MD_MO |TAG_MO |ASL_MO},
   {s_MDC     , DSTAB, ">"   , MD_MO                                          },
   {s_MDO     , DSTAB, "<!"  , CON_MO | DS_MO | INI_MO                        },
   {s_MINUS   , DSTAB, "-"   , 0                                              },
   {s_MSC     , 0    , "]]"  , 0                                              },
   {s_NET     , 0    , "/"   , CON_MO | TAG_MO | RCD_MO | FCD_MO              },
   {s_OPT     , 0    , "?"   , GRP_MO                                         },
   {s_OR      , 0    , "|"   , GRP_MO                                         },
   {s_PERO    , DSTAB, "%"   , DS_MO  | GRP_MO | MD_MO | LITP_MO              },
   {s_PIC     , DSTAB, ">"   , 0                                              },
   {s_PIO     , DSTAB, "<?"  , CON_MO | DS_MO | INI_MO                        },
   {s_PLUS    , 0    , "+"   , GRP_MO                                         },
   {s_REFC    , DSTAB, ";"   , 0                                              },
   {s_REP     , 0    , "*"   , GRP_MO                                         },
   {s_RNI     , DSTAB, "#"   , GRP_MO | MD_MO                                 },
   {s_SEQ     , 0    , ","   , GRP_MO                                         },
   {s_SHORTREF, 0    , ""    , CON_MO                                         },
   {s_STAGO   , DSTAB, "<"   , CON_MO | TAG_MO | INI_MO                       },
   {s_TAGC    , DSTAB, ">"   , TAG_MO                                         },
   {s_VI      , DSTAB, "="   , TAG_MO | ASL_MO                                }
};

typedef struct {      /* Double (combined) Delimiters */
   char *name_1;
   char *name_2;
   uint wh;
   uint  mode;
}DDLISTE;
static DDLISTE ddliste[] = {
   { s_ERO  ,s_GRPO,0    , CON_MO | LITC_MO | RCD_MO | RCDMS_MO             },
   { s_ETAGO,s_TAGC,0    , CON_MO | TAG_MO | RCD_MO | FCD_MO                },
   { s_ETAGO,s_GRPO,0    , CON_MO | TAG_MO | RCD_MO | FCD_MO                },
   { s_MDO  ,s_COM ,0    , CON_MO | DS_MO  | INI_MO                         },
   { s_MDO  ,s_DSO ,DSTAB, CON_MO | DS_MO  | IGNMS_MO                       },
   { s_MDO  ,s_MDC ,0    , CON_MO | DS_MO  | INI_MO                         },
   { s_MSC  ,s_MDC ,DSTAB, CON_MO | DS_MO  | RCDMS_MO | FCDMS_MO | IGNMS_MO },
   { s_PERO ,s_GRPO,0    , DS_MO  | GRP_MO | MD_MO | LITP_MO                },
   { s_STAGO,s_TAGC,0    , CON_MO | TAG_MO | INI_MO                         },
   { s_STAGO,s_GRPO,0    , CON_MO | TAG_MO | INI_MO                         },
   { s_MINUS,s_GRPO,0    , MD_MO                                            },
   { s_PLUS ,s_GRPO,0    , MD_MO                                            }
};

typedef struct {
   char *name;
   int   value;
   int   min;
   int   max_16;                /* Max for 16 bits machines */
   int   max_32;                /* Max for 32 bits machines */
   boolean is_RCS_used;
}QNTYLISTE;

#define NAMELEN_RCS 8

static QNTYLISTE qntyliste[] = {
   /* Name            RCS       min   max_16   max_32  RCS used    Comments */
   {s_ATTCNT   ,           40 ,  1  ,   180  ,   180            },
   {s_ATTSPLEN ,          960 ,  1  , 16000  , 16000            },
   {s_BSEQLEN  ,          960 ,  0                              }, /* (1)   */
   {s_DTAGLEN  ,           16 ,  0                              }, /* (2)   */
   {s_DTEMPLEN ,           16 ,  0                              }, /* (3)   */
   {s_ENTLVL   ,           16 ,  1  ,    40  ,    40            },
   {s_GRPCNT   ,           32 ,  1  ,   100  ,   500            }, /* (5)   */
   {s_GRPGTCNT ,           96 ,  3  ,   300  ,  1000            }, /* (6)   */
   {s_GRPLVL   ,           16 ,  0                              },
   {s_LITLEN   ,          240 ,  1  ,  2400  ,  2400   , TRUE   }, /* (1)   */
   {s_NAMELEN  ,  NAMELEN_RCS ,  1  ,    32  ,    32   , TRUE   }, /* (5,6) */
   {s_NORMSEP  ,            2 ,  1  , 16000  , 16000            },
   {s_PILEN    ,          240 ,  1  ,  2400  ,  2400            }, /* (4)   */
   {s_TAGLEN   ,          960 ,  1  , 16000  , 16000            },
   {s_TAGLVL   ,           24 ,  1  ,    40  ,    40            }
};
/* (1) see BUFSIZE in GLOBAL.H */
/* (2) see ODBF in global.h    */
/* (3) DTEMPLEN < LITLEN       */
/* (4) PILEN == LITLEN (in case of an internal PI entity: see em.c */
/* (5) ((GRPCNT+1)*(NAMELEN+1)) less than 64K on 16-bits: see odtelem.c */
/* (6) (16 * GRPCNT+1) less than 64K on 16-bits: see odtambg.c */

typedef struct {
   char *name;
   uchar *points;
}CAPLISTE;

static CAPLISTE capliste[] = {
   { s_ATTCAP   ,     "NAMELEN_RCS" },
   { s_ATTCHCAP ,               "1" },
   { s_AVGRPCAP ,     "NAMELEN_RCS" },
   { s_DTACAP   ,               "0" },      /* 0: doesn't exist in ISO !!! */
   { s_DTACHCAP ,               "0" },      /* 0: doesn't exist in ISO !!! */
   { s_ELEMCAP  ,     "NAMELEN_RCS" },
   { s_ENTCAP   ,     "NAMELEN_RCS" },
   { s_ENTCHCAP ,               "1" },
   { s_EXGRPCAP ,     "NAMELEN_RCS" },
   { s_EXNMCAP  ,     "NAMELEN_RCS" },
   { s_GRPCAP   ,     "NAMELEN_RCS" },
   { s_IDCAP    ,     "NAMELEN_RCS" },
   { s_IDREFCAP ,     "NAMELEN_RCS" },
   { s_LKNMCAP  ,     "NAMELEN_RCS" },
   { s_LKSETCAP ,     "NAMELEN_RCS" },
   { s_MAPCAP   ,     "NAMELEN_RCS" },
   { s_NOTCAP   ,     "NAMELEN_RCS" },
   { s_NOTCHCAP ,               "1" },
   { s_TOTALCAP ,     "NAMELEN_RCS" }
};

static char *pse_banner[] = {
   "/*******************************************************************************",
   "* YORKTOWN ADVANCED SGML PARSER (YASP)                                         *",
   "*         An SGML Parser conforming to International Standard ISO 8879 --      *",
   "*         Standard Generalized Markup Language                                 *",
   "*------------------------------------------------------------------------------*",
   "* Written 1987 - 1993 by                                                       *",
   "*         Pierre G. Richard                                                    *",
   "*         IBM T.J. Watson Research Center                                      *",
   "*         Yorktown Heights, New York                                           *",
   "*         petrus@watson.ibm.com                                                *",
   "*------------------------------------------------------------------------------*",
   "* FUNCTION NAME    = YASP + Application / Header file                          *",
   "* STATUS           = Version 0, Release 1, Level 34 and up                     *",
   "* COMPONENT NAME   = pse.h                                                     *",
   "* DESCRIPTIVE NAME = Indeces to tables returned by Parser Services.            *",
   "* DATE_WR          = 01/07/1991                                                *",
   "* AUTHOR           = Pierre G. Richard - PETRUS at YKTVMX                      *",
   "*                                                                              *",
   "* FUNCTIONAL DESCRIPTION =                                                     *",
   "* This H file defines the values of the indeces to the delimiter, capacity     *",
   "* and quantity tables returned by the QDLM, QCAPA and QQTY Parser Services.    *",
   "*                                                                              *",
   "* CHANGE HISTORY =                                                             *",
   "* Number Date     Inits    Change & reason (brief)                             *",
   "*******************************************************************************/",
   ""
   "#ifndef YASP_PSE_INCLUDED  /* multiple include protection */",
   "#define YASP_PSE_INCLUDED",
   ""
};

static char *dlstr_ix_en_tete[] = {
   " Indeces to the Delimiter Strings Table (QDLM_PSF)",
   "",
   " The \"Query the Concrete Delimiter Strings\" Parser Service Function",
   " returns an array of delimiter strings.  The index to each specific",
   " delimiter string has the value listed below."
};

static char *capa_ix_en_tete[] = {
   " Indeces to the Capacity Tables (QCAPA_PSF)",
   "",
   " The \"Query Information About Capacities\" Parser Service Function",
   " returns 3 tables:",
   "  1)- an array of unsigned longs containing the count of each object,",
   "  2)- an array of unsigned integers defining the value in capacity",
   "      points for each object,",
   "  3)- an array of unsigned longs containing the maximum capacity",
   "      points defined for each object",
   " The list below describes the index to a specific value of all 3 arrays,",
   " except TOTALCAP_ix that is valid only for the maximum capacity array."
};

static char *qnty_ix_en_tete[] = {
   " Indeces to the Capacity Tables (QQTY_PSF)",
   "",
   " The \"Query the Quantities\" Parser Service Function",
   " returns an array of unsigned integers.  The index to each specific",
   " quantity value is listed below."
};

static char *gnwd_en_tete[] = {
   " General Keyword",
   "",
   " ALWDTAB is a list of all keywords (found in OCSMIN.H)",
   " GNWDTAB is a list of keywords found in the prolog and instance",
   "",
   " Each keyword is preceded by a character that identify the",
   " type of the keyword, according to the CHARID values."
};
static char *gnwd_intro[] = {
   "typedef struct {",
   "   union {",
   "      unsigned char *p;",
   "      OFS ofs;",
   "   }s;",
#ifdef TOKEN_NEEDED_IN_GNWD   /* I am not sure at today (7/30/1987) */
   "   TK  token;",           /* I'm sure we don't need it (10/01/1988) */
#endif
   "}GNWD;",
   "",
   "typedef struct {",
   "   union {",
   "      unsigned char *p;",
   "      OFS ofs;",
   "   }s;",
   "   TK   token;",
   "}EQTK;",
   "",
   "typedef struct {",
   "   int  gnwd_ofs;",
   "   int  value;",
   "}CHOICES;",
   ""
};

static char *dlstr_en_tete[] = {
   " Delimiter String Table",
   "",
   " This has not to be an exhaustive list: to speed up the",
   " scanning, for some delimiters it is faster to work with",
   " the string, rather than using the Delimiter Vector Structure."
};

static char *dlstr_intro[] = {
   "typedef union {",
   "   unsigned char *p;",
   "   OFS ofs;",
   "}DSTAB_ITM;",
   ""
};

static char *mode_en_tete[] = {
   " Recognition Modes",
   "",
   " Some modes have been added vs. ISO 8869:",
   " LITC:  for literal with replaceable character data",
   " LITP:  for literal with replaceable parameter data",
   " ASL:   for attribute specification list strated with DSO",
   " RCD:   for replaceable character data in context (RCDATA)",
   " FCD:   for fixed character data in context (CDATA)",
   " RCDMS: for replaceable character data in MS (RCDATA)",
   " FCDMS: for fixed character data in MS (CDATA)",
   " IGNMS: for an IGNOREd MS (marked section)",
   " INI:   when the parse of the document starts"
};

static char *quantity_en_tete[] = {
   " Quantities",
   "",
   " These values are either static, or dynamic (customizable)"
};

static char *quantity_intro[] = {
   "typedef struct {",
   "   uint value;          /* assigned value */",
   "}QNTY;",
   ""
};

#define LISTE_NB      (sizeof(liste)/sizeof(LISTE))
#define DLISTE_NB     (sizeof(dliste)/sizeof(DLISTE))
#define DDLISTE_NB    (sizeof(ddliste)/sizeof(DDLISTE))
#define CAPLISTE_NB   (sizeof(capliste)/sizeof(CAPLISTE))
#define QNTYLISTE_NB  (sizeof(qntyliste)/sizeof(QNTYLISTE))
#define nbrlines(L)   (sizeof(L)/sizeof(char *))

/*--------------+
|Local Functions|
+--------------*/
static FILE *  open_file             (char *filename);
static void    printLstrs            (char **, int);
static void    print_en_tete         (char **, int);
static void    print_dlstr_ix        (void);
static void    print_capa_ix         (void);
static void    print_qnty_ix         (void);
static void    print_quantity_h      (void);
static void    print_alwd_h          (LISTE *, int);
static void    print_gnwd_h          (LISTE *, int);
static void    print_mode_h          (void);
static void    print_ocsmin_static   (void);
static void    print_ocsmin_alwdtab  (void);
static void    print_ocsmin_dlmvtab  (void);
static void    print_ocsmin_ddlmvtab (void);
static void    print_ocsmin_cappoint (void);
static void    print_dv_updates      (void);

/*******************************************************************************
* Code                                                                         *
*******************************************************************************/
int gnwd_count;
int dlstr_count;
FILE *cfile;

/*----------------------------------------------------------------------------*/
static FILE *open_file (char *filename)
{
   FILE *file_p;

   if ((file_p = fopen(filename, "w")) == NULL) {
      printf("Can't open \"%s\"\n", filename);
      exit(8);
   }else {
      printf("Creating \"%s\"\n",filename);
   }
   return(file_p);
}
/*----------------------------------------------------------------------------*/
/* print an array of string */
static void printLstrs(char **line, int  count)
{
   for ( ; count--; ++line) fprintf(cfile, "%s\n",*line);
}
/*----------------------------------------------------------------------------*/
/* print an "en_tete" */
static void print_en_tete(char **line, int  count)
{
   int i;

   fprintf(cfile, "/*");
   for (i=0; i<77; ++i) fprintf(cfile, "-");
   fprintf(cfile, "+\n");
   for ( ; count--; ++line) fprintf(cfile, "|%-78s|\n",*line);
   fprintf(cfile, "+");
   for (i=0; i<77; ++i) fprintf(cfile, "-");
   fprintf(cfile, "*/\n");
}

/*----------------------------------------------------------------------------*/
static void print_dlstr_ix(void)
{
   DLISTE  *dlst_p;
   DDLISTE *ddlst_p;
   int count;

   char st1[30];
   dlstr_count = 0;
   for (dlst_p=dliste, count=DLISTE_NB; count--; ++dlst_p) {
      if (dlst_p->wh & DSTAB) {
         sprintf(st1,"%s_ix",dlst_p->name);
         fprintf(cfile, "#define %-23s %2d\n",st1,dlstr_count++);
      }
   }
   for (ddlst_p=ddliste, count=DDLISTE_NB; count--; ++ddlst_p) {
      if (ddlst_p->wh & DSTAB) {
         sprintf(st1,"%s_%s_ix",ddlst_p->name_1,ddlst_p->name_2);
         fprintf(cfile, "#define %-23s %2d\n",st1,dlstr_count++);
      }
   }
}

/*----------------------------------------------------------------------------*/
static void print_capa_ix(void)
{
   CAPLISTE  *caplst_p;
   int count;
   int ix = -1;

   char st1[30];
   for (caplst_p=capliste, count=CAPLISTE_NB; count--; ++caplst_p) {
      sprintf(st1,"%s_ix",caplst_p->name);
      fprintf(cfile, "#define %-15s %2d\n",st1,++ix);
   }
   fprintf(cfile, "#define CAP_MAX_SIZE    %2d\n",++ix);
}

/*----------------------------------------------------------------------------*/
static void print_qnty_ix(void)
{
   QNTYLISTE  *qntylst_p;
   int count;
   int ix = -1;
   char st1[30];

   for (qntylst_p=qntyliste, count=QNTYLISTE_NB; count--; ++qntylst_p) {
      sprintf(st1,"%s_ix",qntylst_p->name);
      fprintf(cfile, "#define %-23s %2d\n",st1,++ix);
   }
}

/*----------------------------------------------------------------------------*/
static void print_quantity_h(void)
{
   QNTYLISTE  *qntylst_p;
   int count;
   char st1[30];

   printLstrs(quantity_intro,nbrlines(quantity_intro));
   fprintf(cfile, "typedef QNTY QNTYTAB[%2d];\n\n",QNTYLISTE_NB);

   for (qntylst_p=qntyliste, count=QNTYLISTE_NB; count--; ++qntylst_p) {
      sprintf(st1,"%s",qntylst_p->name);
      fprintf(cfile, "#define %-20s ",st1);
      if (!qntylst_p->min) {
         fprintf(cfile, "%4d\n",qntylst_p->value);
      }else {
         fprintf(cfile, "GA(qntytab)[%s_ix].value\n",qntylst_p->name);
         if (qntylst_p->is_RCS_used) {
            sprintf(st1,"%s_RCS",qntylst_p->name);
            fprintf(cfile, "#define %-20s %4d\n",st1,qntylst_p->value);
         }
      }
   }
   fprintf(cfile, "\n#if %s /* for 16-bits systems */\n", def_16_bits_systems);
   for (qntylst_p=qntyliste, count=QNTYLISTE_NB; count--; ++qntylst_p) {
      if (qntylst_p->min) {
         sprintf(st1,"%s_MAX",qntylst_p->name);
         fprintf(cfile, "#define %-20s ",st1);
         fprintf(cfile, "%5d\n",qntylst_p->max_16);
      }
   }
   fprintf(cfile, "\n#else /* for 32-bits systems */\n");
   for (qntylst_p=qntyliste, count=QNTYLISTE_NB; count--; ++qntylst_p) {
      if (qntylst_p->min) {
         sprintf(st1,"%s_MAX",qntylst_p->name);
         fprintf(cfile, "#define %-20s ",st1);
         fprintf(cfile, "%5d\n",qntylst_p->max_32);
      }
   }
   fprintf(cfile, "#endif\n\n");
}

/*----------------------------------------------------------------------------*/
static void print_alwd_h(LISTE *lst_p, int  count)
{
   int i;
   fprintf(cfile,"#if (defined (WATC))\n");
   fprintf(cfile,"#define OPT X_OPT        /* WATC Compiler Bug? */\n");
   fprintf(cfile,"#endif\n");
   fprintf(cfile, "typedef struct {\n");
#define HOWMUCH 4
   for (i=0, lst_p=liste, count=LISTE_NB; count--; ++lst_p) {
      if (!(lst_p->wh & NON_ISO_CAP)) {
         fprintf(cfile, "%sGNWD %s; ",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",lst_p->name);
         ++i;
      }
   }
#undef HOWMUCH
   fprintf(cfile, "\n}ALWDTAB;\n");
   fprintf(cfile,"#if (defined (WATC))\n");
   fprintf(cfile,"#undef OPT               /* WATC Compiler Bug? */\n");
   fprintf(cfile,"#endif\n");
}

/*----------------------------------------------------------------------------*/
static void print_gnwd_h(LISTE *lst_p, int  count)
{
   int i;

   fprintf(cfile, "typedef struct {\n");
#define HOWMUCH 4
   for (i=0, lst_p=liste, count=LISTE_NB; count--; ++lst_p) {
      if (lst_p->wh & GEN) {
         ++gnwd_count;
         fprintf(cfile, "%sGNWD %s; ",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",lst_p->name);
         ++i;
      }
   }
#undef HOWMUCH
   fprintf(cfile, "\n}GNWDTAB;\n");
}

/*----------------------------------------------------------------------------*/
static void print_mode_h(void)
{
   MODES *mode_p;
   int count, i;
   char st1[20];

   for (i=0, mode_p = modes, count=NBR_OF_MODES; count--; ++mode_p) {
      sprintf(st1,"%s_MODE",mode_p->name);
      fprintf(cfile, "#define %-10s %4d\n",st1,i++);
   }
   fprintf(cfile, "#define %-10s %d\n\n","NBR_OF_MODES",NBR_OF_MODES);
}

/*----------------------------------------------------------------------------*/
static char get_charid(uint wh)
{
   switch (wh) {
   case DLIM:     return(DLIM_CHARID);
   case QNTY:     return(QNTY_CHARID);
   case NON_ISO_CAP:
   case CAPA:     return(CAPA_CHARID);
   case FCLS:     return(FCLS_CHARID);
   case SYST:     return(SYST_CHARID);
   default:   return((char)((wh & GEN) ? GEN_CHARID : SGML_CHARID));
   }
}

/*----------------------------------------------------------------------------*/
static void print_ocsmin_static(void)  /* print the local data */
{
   char st1[20];
   int i;
   int count;
   LISTE *lst_p;
   DLISTE *dlst_p;
   CAPLISTE *caplst_p;
   QNTYLISTE *qntylst_p;

   fprintf(cfile, "static struct t_GML_RSSTR { char  /* Reference Syntax Strings */\n");
   fprintf(cfile, "   iso_bnr[%d],\n",sizeof(ISO_banner));
#define HOWMUCH 5
   for (i=0, lst_p=liste, count=LISTE_NB; count--; ++lst_p) {
      sprintf(
         st1, "%c%s[%d]",
         get_charid(lst_p->wh),
         lst_p->name,
         2+strlen(lst_p->name)
      );
      fprintf(cfile,
         "%s%-13s, ",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",st1
      );
      ++i;
   }
   fprintf(cfile, "\n");
   for (i=0, dlst_p=dliste, count=DLISTE_NB; count--; ++dlst_p) {
      if (*dlst_p->assign) {
         sprintf(st1,"%c%s[%d]",
         DLVL_CHARID,dlst_p->name,1+strlen(dlst_p->assign));
         fprintf(cfile, "%s%-13s, ",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",st1);
         ++i;
      }
   }
#undef HOWMUCH
   fprintf(cfile, "\n   *cap_names[%2d],",CAPLISTE_NB);
   fprintf(cfile, "\n   *qnty_names[%2d],",QNTYLISTE_NB);
   fprintf(cfile, "\n   *gnwd_names[%2d];",gnwd_count);
   fprintf(cfile, "\n   QNTYTAB qntytab;");
   fprintf(cfile, "\n} const st = {\n");
   fprintf(cfile, "   \"%s\",\n",ISO_banner);
   fprintf(cfile, "   /* --- names --- */\n");
#define HOWMUCH 5
   for (i=0, lst_p=liste, count=LISTE_NB; count--; ++lst_p) {
      sprintf(st1, "\"%c%s\"", get_charid(lst_p->wh), lst_p->name);
      fprintf(cfile,
         "%s%-11s, ",
          i ? ((i%HOWMUCH)? "":"\n   "):"   ", st1
      );
      ++i;
   }
   fprintf(cfile, "\n   /* --- default delimiters --- */\n");
   for (i=0, dlst_p=dliste, count=DLISTE_NB; count--; ++dlst_p) {
      if (*dlst_p->assign) {
         sprintf(st1, "\"%s\"", dlst_p->assign);
         fprintf(cfile,
            "%s%-10s, ",
             i ? ((i%HOWMUCH)? "":"\n   "):"   ", st1
         );
         ++i;
      }
   }
#undef HOWMUCH
#define HOWMUCH 3
   fprintf(cfile, "\n   /* --- cap_names --- */\n");
   for (i=0, caplst_p=capliste, count=CAPLISTE_NB; count--; ++caplst_p) {
      sprintf(st1, "st.%c%s+1", CAPA_CHARID, caplst_p->name);
      fprintf(cfile,
         "%s(uchar *)%-14s, ",
          i ? ((i%HOWMUCH)? "":"\n   "):"   ", st1
      );
      ++i;
   }
   fprintf(cfile, "\n   /* --- qnty_names --- */\n");
   for (i=0,qntylst_p=qntyliste, count=QNTYLISTE_NB; count--; ++qntylst_p) {
      sprintf(st1, "st.%c%s+1", QNTY_CHARID, qntylst_p->name);
      fprintf(cfile,
         "%s(uchar *)%-14s, ",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",
         st1
      );
      ++i;
   }
   fprintf(cfile, "\n   /* --- gnwd_names --- */\n");
   for (i=0, lst_p = liste, count = gnwd_count; count; ++lst_p) {
      if (lst_p->wh & GEN) {
         --count;
         sprintf(st1, "st.%c%s+1", GEN_CHARID, lst_p->name);
         fprintf(cfile,
            "%s(uchar *)%-14s, ",
            i ? ((i%HOWMUCH)? "":"\n   "):"   ",
            st1
         );
         ++i;
      }
   }
#undef HOWMUCH
   fprintf(cfile, "\n   /* ----- qntytab ---- */\n   { ");
   for (qntylst_p=qntyliste, count=QNTYLISTE_NB; count--; ++qntylst_p) {
      fprintf(cfile, "%d%s",qntylst_p->value,(count)? ", ":" }");
   }
   fprintf(cfile, "\n};\n");
}

/*----------------------------------------------------------------------------*/
static void print_ocsmin_dlmvtab(void)
{
   DLISTE *dlst_p;
   int  count, i;
   char st1[20];
   char st2[20];
   char st3[20];
   char st4[20];
   char st5[20];

   fprintf(cfile, "\nstatic DLMV const dlmv_tab[] = {\n");
#define HOWMUCH 1
   for (i=0, count = DLISTE_NB, dlst_p = dliste; count--; ++dlst_p) {
      sprintf(st2,"%s_TK",dlst_p->name);
      sprintf(st3,"%4d",dlst_p->mode);
      if (*dlst_p->assign) {
         sprintf(st1,"st.%c%s+1",DLIM_CHARID,dlst_p->name);
         sprintf(st4,"st.%c%s",DLVL_CHARID,dlst_p->name);
      }else {
         sprintf(st1,"st.%c%s+1",GEN_CHARID,dlst_p->name); /* SHORTREF */
         sprintf(st4,"%s","0");
      }
      if (dlst_p->wh & DSTAB) {
         sprintf(st5,"%s_ix",dlst_p->name);
      }else {
         sprintf(st5,"%s","-1");
      }
      fprintf(cfile,
         "%s{ (uchar *)%-14s, %-11s, %-4s, (uchar *)%-9s, %-9s}%c",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",
         st1, st2, st3, st4, st5,
         (count)? ',':' '
      );
      ++i;
   }
#undef HOWMUCH
   fprintf(cfile, "\n};\n");
}

/*----------------------------------------------------------------------------*/
static void print_ocsmin_ddlmvtab(void)
{
   DDLISTE *ddlst_p;
   int  count, i;
   char st1[20];
   char st2[20];
   char st3[20];
   char st4[20];

   fprintf(cfile, "\nstatic DDLMV const ddlmv_tab[] = { /* Combined delimiters */\n");
#define HOWMUCH 1
   for (i=0, count = DDLISTE_NB, ddlst_p = ddliste; count--; ++ddlst_p) {
      sprintf(st1,"%s_TK",ddlst_p->name_1);
      sprintf(st2,", %s_TK",ddlst_p->name_2);
      sprintf(st3,", %s_%s_TK",ddlst_p->name_1,ddlst_p->name_2);
      sprintf(st4,", %4d",ddlst_p->mode);
      fprintf(cfile,
         "%s{ %-11s%-13s%-21s%-6s }%c ",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",
         st1, st2, st3, st4, (count)? ',':' '
      );
      ++i;
   }
#undef HOWMUCH
   fprintf(cfile, "\n};\n");
}

/*----------------------------------------------------------------------------*/
static void print_ocsmin_alwdtab(void)
{
   LISTE *lst_p;
   int  count, i;
   char st1[30];

   fprintf(cfile, "\nstatic ALWDTAB const alwdtab = {\n");
#define HOWMUCH 3
   for (i=0, lst_p = liste, count = LISTE_NB; count--; ++lst_p) {
      if (!(lst_p->wh & NON_ISO_CAP)) {
         sprintf(st1, "(uchar *)st.%c%s+1", get_charid(lst_p->wh), lst_p->name);
         fprintf(cfile,
            "%s%-23s%c ",
            i ? ((i%HOWMUCH)? "":"\n   "):"   ", st1, (count)? ',':' '
         );
         ++i;
      }
   }
#undef HOWMUCH
   fprintf(cfile, "\n};\n");
}

/*----------------------------------------------------------------------------*/
static void print_ocsmin_cappoint(void)
{
   CAPLISTE  *caplst_p;
   int count;
   int i;

   fprintf(cfile, "#define NAMELEN_RCS %3d\n",NAMELEN_RCS);
   fprintf(cfile, "\nstatic uint const cap_points[%2d] = {\n",CAPLISTE_NB);
#define HOWMUCH 5

   for (i=0, caplst_p=capliste, count=CAPLISTE_NB; count--; ++caplst_p) {
      fprintf(cfile,
         "%s%-12s%c ",
         i ? ((i%HOWMUCH)? "":"\n   "):"   ",
         caplst_p->points,(count)? ',':' '
      );
      ++i;
   }
#undef HOWMUCH
   fprintf(cfile, "\n};\n");
}

/*----------------------------------------------------------------------------*/
static void print_dv_updates(void)
{
   MODES *mode_p;
   int count;
   char st1[20];

   for (mode_p = modes, count=NBR_OF_MODES; count--; ++mode_p) {
      sprintf(st1,"%s_MO",mode_p->name);
      fprintf(cfile, "#define %-10s %4d\n",st1,mode_p->val);
   }
   fprintf(cfile, "\n#define NBR_OF_DLMV  %d\n",DLISTE_NB);
   fprintf(cfile, "#define NBR_OF_DDLMV %d\n",DDLISTE_NB);
#if (NBR_OF_MODES <= 8)
   fprintf(cfile, "typedef unsigned char ALLMO;\n");
#else
   fprintf(cfile, "typedef unsigned int ALLMO;\n\n");
#endif
}

/*----------------------------------------------------------------------------*/
void print_charid(void)
{
   fprintf(cfile, "#define DLVL_CHARID     \'%c\'\n", DLVL_CHARID);
   fprintf(cfile, "#define CAPA_CHARID     \'%c\'\n", CAPA_CHARID);
   fprintf(cfile, "#define DLIM_CHARID     \'%c\'\n", DLIM_CHARID);
   fprintf(cfile, "#define FCLS_CHARID     \'%c\'\n", FCLS_CHARID);
   fprintf(cfile, "#define GEN_CHARID      \'%c\'\n", GEN_CHARID);
   fprintf(cfile, "#define QNTY_CHARID     \'%c\'\n", QNTY_CHARID);
   fprintf(cfile, "#define SGML_CHARID     \'%c\'\n", SGML_CHARID);
   fprintf(cfile, "#define SYST_CHARID     \'%c\'\n", SYST_CHARID);
}

/*----------------------------------------------------------------------------*/
int main(void)
{
   time_t ltime;
   char time_stamp[100];

   time(&ltime);
   sprintf(time_stamp,beg_of_prod,ctime(&ltime));

   /*======================== PSE.H =======================*/
   cfile = open_file("pse.h");
   fprintf(cfile, time_stamp);
   printLstrs(pse_banner,nbrlines(pse_banner));

   /*---------- DLSTR ----*/
   print_en_tete(dlstr_ix_en_tete,nbrlines(dlstr_ix_en_tete));
   print_dlstr_ix();
   fprintf(cfile, "\n");

   /*---------- CAPACITY -*/
   print_en_tete(capa_ix_en_tete,nbrlines(capa_ix_en_tete));
   print_capa_ix();
   fprintf(cfile, "\n");

   /*---------- QUANTITY -*/
   print_en_tete(qnty_ix_en_tete,nbrlines(qnty_ix_en_tete));
   print_qnty_ix();

   fprintf(cfile, "\n#endif /* YASP_PSE_INCLUDED */\n");
   fprintf(cfile, end_of_prod);
   fclose(cfile);

   /*======================== GEN.H =======================*/
   cfile = open_file("gen.h");
   fprintf(cfile, time_stamp);

   /*---------- DLSTR ----*/
   print_en_tete(dlstr_en_tete,nbrlines(dlstr_en_tete));
   printLstrs(dlstr_intro,nbrlines(dlstr_intro));
   fprintf(cfile, "typedef DSTAB_ITM DSTAB[%2d];\n\n",dlstr_count);

   /*---------- ALWD/GNWD --*/
   print_en_tete(gnwd_en_tete,nbrlines(gnwd_en_tete));
   printLstrs(gnwd_intro,nbrlines(gnwd_intro));
   print_alwd_h(liste,LISTE_NB);
   fprintf(cfile, "\n");
   print_gnwd_h(liste,LISTE_NB);
   fprintf(cfile, "\n");
   print_charid();
   fprintf(cfile, "\n");

   /*---------- MODE -----*/
   print_en_tete(mode_en_tete,nbrlines(mode_en_tete));
   print_mode_h();

   /*----------- DV ----*/
   print_dv_updates();

   /*---------- QUANTITY -*/
   print_en_tete(quantity_en_tete,nbrlines(quantity_en_tete));
   print_quantity_h();

   fprintf(cfile, end_of_prod);
   fclose(cfile);

   /*===================== OCSMIN.H =======================*/

   cfile = open_file("ocsmin.h");
   fprintf(cfile, time_stamp);
   print_ocsmin_static();
   print_ocsmin_dlmvtab();
   print_ocsmin_ddlmvtab();
   print_ocsmin_alwdtab();
   print_ocsmin_cappoint();
   fprintf(cfile, end_of_prod);
   fclose(cfile);

   return(0);
}
/******************************************************************************/
