/ Check-in [75a1060b]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make Lemon able to compile as C++ code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | lemon-update-2010
Files: files | file ages | folders
SHA1: 75a1060b29eb4122487152b068e7d1073eb0ccab
User & Date: icculus 2010-02-14 17:14:23
Context
2010-02-15
00:01
Removed the 80-char line formatting for ErrorMsg(), on dhr's suggestion. check-in: 132ea4e5 user: icculus tags: lemon-update-2010
2010-02-14
17:14
Make Lemon able to compile as C++ code. check-in: 75a1060b user: icculus tags: lemon-update-2010
05:42
Added option to not clip error output.

This is useful for IDEs and other tools that benefit from full path information, so they can jump directly to the error line in the source code. check-in: 90602030 user: icculus tags: lemon-update-2010

Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/lemon.c.

    56     56   
    57     57   /*
    58     58   ** Compilers are getting increasingly pedantic about type conversions
    59     59   ** as C evolves ever closer to Ada....  To work around the latest problems
    60     60   ** we have to define the following variant of strlen().
    61     61   */
    62     62   #define lemonStrlen(X)   ((int)strlen(X))
           63  +
           64  +/* a few forward declarations... */
           65  +struct rule;
           66  +struct lemon;
           67  +struct action;
    63     68   
    64     69   static struct action *Action_new(void);
    65     70   static struct action *Action_sort(struct action *);
    66     71   
    67     72   /********** From the file "build.h" ************************************/
    68     73   void FindRulePrecedences();
    69     74   void FindFirstSets();
    70     75   void FindStates();
    71     76   void FindLinks();
    72     77   void FindFollowSets();
    73     78   void FindActions();
    74     79   
    75     80   /********* From the file "configlist.h" *********************************/
    76         -void Configlist_init(/* void */);
    77         -struct config *Configlist_add(/* struct rule *, int */);
    78         -struct config *Configlist_addbasis(/* struct rule *, int */);
    79         -void Configlist_closure(/* void */);
    80         -void Configlist_sort(/* void */);
    81         -void Configlist_sortbasis(/* void */);
    82         -struct config *Configlist_return(/* void */);
    83         -struct config *Configlist_basis(/* void */);
    84         -void Configlist_eat(/* struct config * */);
    85         -void Configlist_reset(/* void */);
           81  +void Configlist_init(void);
           82  +struct config *Configlist_add(struct rule *, int);
           83  +struct config *Configlist_addbasis(struct rule *, int);
           84  +void Configlist_closure(struct lemon *);
           85  +void Configlist_sort(void);
           86  +void Configlist_sortbasis(void);
           87  +struct config *Configlist_return(void);
           88  +struct config *Configlist_basis(void);
           89  +void Configlist_eat(struct config *);
           90  +void Configlist_reset(void);
    86     91   
    87     92   /********* From the file "error.h" ***************************************/
    88     93   void ErrorMsg(const char *, int,const char *, ...);
    89     94   
    90     95   /****** From the file "option.h" ******************************************/
           96  +enum option_type { OPT_FLAG=1,  OPT_INT,  OPT_DBL,  OPT_STR,
           97  +         OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR};
    91     98   struct s_options {
    92         -  enum { OPT_FLAG=1,  OPT_INT,  OPT_DBL,  OPT_STR,
    93         -         OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR} type;
    94         -  char *label;
           99  +  enum option_type type;
          100  +  const char *label;
    95    101     char *arg;
    96         -  char *message;
          102  +  const char *message;
    97    103   };
    98         -int    OptInit(/* char**,struct s_options*,FILE* */);
    99         -int    OptNArgs(/* void */);
   100         -char  *OptArg(/* int */);
   101         -void   OptErr(/* int */);
   102         -void   OptPrint(/* void */);
          104  +int    OptInit(char**,struct s_options*,FILE*);
          105  +int    OptNArgs(void);
          106  +char  *OptArg(int);
          107  +void   OptErr(int);
          108  +void   OptPrint(void);
   103    109   
   104    110   /******** From the file "parse.h" *****************************************/
   105         -void Parse(/* struct lemon *lemp */);
          111  +void Parse(struct lemon *lemp);
   106    112   
   107    113   /********* From the file "plink.h" ***************************************/
   108         -struct plink *Plink_new(/* void */);
   109         -void Plink_add(/* struct plink **, struct config * */);
   110         -void Plink_copy(/* struct plink **, struct plink * */);
   111         -void Plink_delete(/* struct plink * */);
          114  +struct plink *Plink_new(void);
          115  +void Plink_add(struct plink **, struct config *);
          116  +void Plink_copy(struct plink **, struct plink *);
          117  +void Plink_delete(struct plink *);
   112    118   
   113    119   /********** From the file "report.h" *************************************/
   114         -void Reprint(/* struct lemon * */);
   115         -void ReportOutput(/* struct lemon * */);
   116         -void ReportTable(/* struct lemon * */);
   117         -void ReportHeader(/* struct lemon * */);
   118         -void CompressTables(/* struct lemon * */);
   119         -void ResortStates(/* struct lemon * */);
          120  +void Reprint(struct lemon *);
          121  +void ReportOutput(struct lemon *);
          122  +void ReportTable(struct lemon *, int);
          123  +void ReportHeader(struct lemon *);
          124  +void CompressTables(struct lemon *);
          125  +void ResortStates(struct lemon *);
   120    126   
   121    127   /********** From the file "set.h" ****************************************/
   122         -void  SetSize(/* int N */);             /* All sets will be of size N */
   123         -char *SetNew(/* void */);               /* A new set for element 0..N */
   124         -void  SetFree(/* char* */);             /* Deallocate a set */
          128  +void  SetSize(int);             /* All sets will be of size N */
          129  +char *SetNew(void);               /* A new set for element 0..N */
          130  +void  SetFree(char*);             /* Deallocate a set */
   125    131   
   126         -int SetAdd(/* char*,int */);            /* Add element to a set */
   127         -int SetUnion(/* char *A,char *B */);    /* A <- A U B, thru element N */
   128         -
          132  +char *SetNew(void);               /* A new set for element 0..N */
          133  +int SetAdd(char*,int);            /* Add element to a set */
          134  +int SetUnion(char *,char *);    /* A <- A U B, thru element N */
   129    135   #define SetFind(X,Y) (X[Y])       /* True if Y is in set X */
   130    136   
   131    137   /********** From the file "struct.h" *************************************/
   132    138   /*
   133    139   ** Principal data structures for the LEMON parser generator.
   134    140   */
   135    141   
   136    142   typedef enum {LEMON_FALSE=0, LEMON_TRUE} Boolean;
   137    143   
   138    144   /* Symbols (terminals and nonterminals) of the grammar are stored
   139    145   ** in the following: */
   140         -struct symbol {
   141         -  char *name;              /* Name of the symbol */
   142         -  int index;               /* Index number for this symbol */
   143         -  enum {
   144         -    TERMINAL,
   145         -    NONTERMINAL,
   146         -    MULTITERMINAL
   147         -  } type;                  /* Symbols are all either TERMINALS or NTs */
   148         -  struct rule *rule;       /* Linked list of rules of this (if an NT) */
   149         -  struct symbol *fallback; /* fallback token in case this token doesn't parse */
   150         -  int prec;                /* Precedence if defined (-1 otherwise) */
   151         -  enum e_assoc {
          146  +enum symbol_type {
          147  +  TERMINAL,
          148  +  NONTERMINAL,
          149  +  MULTITERMINAL
          150  +};
          151  +enum e_assoc {
   152    152       LEFT,
   153    153       RIGHT,
   154    154       NONE,
   155    155       UNK
   156         -  } assoc;                 /* Associativity if precedence is defined */
          156  +};
          157  +struct symbol {
          158  +  const char *name;        /* Name of the symbol */
          159  +  int index;               /* Index number for this symbol */
          160  +  enum symbol_type type;   /* Symbols are all either TERMINALS or NTs */
          161  +  struct rule *rule;       /* Linked list of rules of this (if an NT) */
          162  +  struct symbol *fallback; /* fallback token in case this token doesn't parse */
          163  +  int prec;                /* Precedence if defined (-1 otherwise) */
          164  +  enum e_assoc assoc;      /* Associativity if precedence is defined */
   157    165     char *firstset;          /* First-set for all rules of this symbol */
   158    166     Boolean lambda;          /* True if NT and can generate an empty string */
   159    167     int useCnt;              /* Number of times used */
   160    168     char *destructor;        /* Code which executes whenever this symbol is
   161    169                              ** popped from the stack during error processing */
   162    170     int destLineno;          /* Line number for start of destructor */
   163    171     char *datatype;          /* The data type of information held by this
................................................................................
   170    178     struct symbol **subsym;  /* Array of constituent symbols */
   171    179   };
   172    180   
   173    181   /* Each production rule in the grammar is stored in the following
   174    182   ** structure.  */
   175    183   struct rule {
   176    184     struct symbol *lhs;      /* Left-hand side of the rule */
   177         -  char *lhsalias;          /* Alias for the LHS (NULL if none) */
          185  +  const char *lhsalias;    /* Alias for the LHS (NULL if none) */
   178    186     int lhsStart;            /* True if left-hand side is the start symbol */
   179    187     int ruleline;            /* Line number for the rule */
   180    188     int nrhs;                /* Number of RHS symbols */
   181    189     struct symbol **rhs;     /* The RHS symbols */
   182         -  char **rhsalias;         /* An alias for each RHS symbol (NULL if none) */
          190  +  const char **rhsalias;   /* An alias for each RHS symbol (NULL if none) */
   183    191     int line;                /* Line number at which code begins */
   184         -  char *code;              /* The code executed when this rule is reduced */
          192  +  const char *code;        /* The code executed when this rule is reduced */
   185    193     struct symbol *precsym;  /* Precedence symbol for this rule */
   186    194     int index;               /* An index number for this rule */
   187    195     Boolean canReduce;       /* True if this rule is ever reduced */
   188    196     struct rule *nextlhs;    /* Next rule with the same LHS */
   189    197     struct rule *next;       /* Next rule in the global list */
   190    198   };
   191    199   
   192    200   /* A configuration is a production rule of the grammar together with
   193    201   ** a mark (dot) showing how much of that rule has been processed so far.
   194    202   ** Configurations also contain a follow-set which is a list of terminal
   195    203   ** symbols which are allowed to immediately follow the end of the rule.
   196    204   ** Every configuration is recorded as an instance of the following: */
          205  +enum cfgstatus {
          206  +  COMPLETE,
          207  +  INCOMPLETE
          208  +};
   197    209   struct config {
   198    210     struct rule *rp;         /* The rule upon which the configuration is based */
   199    211     int dot;                 /* The parse point */
   200    212     char *fws;               /* Follow-set for this configuration only */
   201    213     struct plink *fplp;      /* Follow-set forward propagation links */
   202    214     struct plink *bplp;      /* Follow-set backwards propagation links */
   203    215     struct state *stp;       /* Pointer to state which contains this */
   204         -  enum {
   205         -    COMPLETE,              /* The status is used during followset and */
   206         -    INCOMPLETE             /*    shift computations */
   207         -  } status;
          216  +  enum cfgstatus status;   /* used during followset and shift computations */
   208    217     struct config *next;     /* Next configuration in the state */
   209    218     struct config *bp;       /* The next basis configuration */
   210    219   };
          220  +
          221  +enum e_action {
          222  +  SHIFT,
          223  +  ACCEPT,
          224  +  REDUCE,
          225  +  ERROR,
          226  +  SSCONFLICT,              /* A shift/shift conflict */
          227  +  SRCONFLICT,              /* Was a reduce, but part of a conflict */
          228  +  RRCONFLICT,              /* Was a reduce, but part of a conflict */
          229  +  SH_RESOLVED,             /* Was a shift.  Precedence resolved conflict */
          230  +  RD_RESOLVED,             /* Was reduce.  Precedence resolved conflict */
          231  +  NOT_USED                 /* Deleted by compression */
          232  +};
   211    233   
   212    234   /* Every shift or reduce operation is stored as one of the following */
   213    235   struct action {
   214    236     struct symbol *sp;       /* The look-ahead symbol */
   215         -  enum e_action {
   216         -    SHIFT,
   217         -    ACCEPT,
   218         -    REDUCE,
   219         -    ERROR,
   220         -    SSCONFLICT,              /* A shift/shift conflict */
   221         -    SRCONFLICT,              /* Was a reduce, but part of a conflict */
   222         -    RRCONFLICT,              /* Was a reduce, but part of a conflict */
   223         -    SH_RESOLVED,             /* Was a shift.  Precedence resolved conflict */
   224         -    RD_RESOLVED,             /* Was reduce.  Precedence resolved conflict */
   225         -    NOT_USED                 /* Deleted by compression */
   226         -  } type;
          237  +  enum e_action type;
   227    238     union {
   228    239       struct state *stp;     /* The new state, if a shift */
   229    240       struct rule *rp;       /* The rule, if a reduce */
   230    241     } x;
   231    242     struct action *next;     /* Next action for this state */
   232    243     struct action *collide;  /* Next action with the same hash */
   233    244   };
................................................................................
   307    318   ** by the associative array code building program "aagen".
   308    319   ** Do not edit this file!  Instead, edit the specification
   309    320   ** file, then rerun aagen.
   310    321   */
   311    322   /*
   312    323   ** Code for processing tables in the LEMON parser generator.
   313    324   */
   314         -
   315    325   /* Routines for handling a strings */
   316    326   
   317         -char *Strsafe();
          327  +const char *Strsafe(const char *);
   318    328   
   319         -void Strsafe_init(/* void */);
   320         -int Strsafe_insert(/* char * */);
   321         -char *Strsafe_find(/* char * */);
          329  +void Strsafe_init(void);
          330  +int Strsafe_insert(const char *);
          331  +const char *Strsafe_find(const char *);
   322    332   
   323    333   /* Routines for handling symbols of the grammar */
   324    334   
   325         -struct symbol *Symbol_new();
   326         -int Symbolcmpp(/* struct symbol **, struct symbol ** */);
   327         -void Symbol_init(/* void */);
   328         -int Symbol_insert(/* struct symbol *, char * */);
   329         -struct symbol *Symbol_find(/* char * */);
   330         -struct symbol *Symbol_Nth(/* int */);
   331         -int Symbol_count(/*  */);
   332         -struct symbol **Symbol_arrayof(/*  */);
          335  +struct symbol *Symbol_new(const char *);
          336  +int Symbolcmpp(const void *, const void *);
          337  +void Symbol_init(void);
          338  +int Symbol_insert(struct symbol *, const char *);
          339  +struct symbol *Symbol_find(const char *);
          340  +struct symbol *Symbol_Nth(int);
          341  +int Symbol_count(void);
          342  +struct symbol **Symbol_arrayof(void);
   333    343   
   334    344   /* Routines to manage the state table */
   335    345   
   336         -int Configcmp(/* struct config *, struct config * */);
   337         -struct state *State_new();
   338         -void State_init(/* void */);
   339         -int State_insert(/* struct state *, struct config * */);
   340         -struct state *State_find(/* struct config * */);
          346  +int Configcmp(const char *, const char *);
          347  +struct state *State_new(void);
          348  +void State_init(void);
          349  +int State_insert(struct state *, struct config *);
          350  +struct state *State_find(struct config *);
   341    351   struct state **State_arrayof(/*  */);
   342    352   
   343    353   /* Routines used for efficiency in Configlist_add */
   344    354   
   345         -void Configtable_init(/* void */);
   346         -int Configtable_insert(/* struct config * */);
   347         -struct config *Configtable_find(/* struct config * */);
   348         -void Configtable_clear(/* int(*)(struct config *) */);
          355  +void Configtable_init(void);
          356  +int Configtable_insert(struct config *);
          357  +struct config *Configtable_find(struct config *);
          358  +void Configtable_clear(int(*)(struct config *));
          359  +
   349    360   /****************** From the file "action.c" *******************************/
   350    361   /*
   351    362   ** Routines processing parser actions in the LEMON parser generator.
   352    363   */
   353    364   
   354    365   /* Allocate a new parser action */
   355    366   static struct action *Action_new(void){
   356    367     static struct action *freelist = 0;
   357         -  struct action *new;
          368  +  struct action *newaction;
   358    369   
   359    370     if( freelist==0 ){
   360    371       int i;
   361    372       int amt = 100;
   362    373       freelist = (struct action *)calloc(amt, sizeof(struct action));
   363    374       if( freelist==0 ){
   364    375         fprintf(stderr,"Unable to allocate memory for a new parser action.");
   365    376         exit(1);
   366    377       }
   367    378       for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1];
   368    379       freelist[amt-1].next = 0;
   369    380     }
   370         -  new = freelist;
          381  +  newaction = freelist;
   371    382     freelist = freelist->next;
   372         -  return new;
          383  +  return newaction;
   373    384   }
   374    385   
   375    386   /* Compare two actions for sorting purposes.  Return negative, zero, or
   376    387   ** positive if the first action is less than, equal to, or greater than
   377    388   ** the first
   378    389   */
   379    390   static int actioncmp(
................................................................................
   399    410     struct action *ap
   400    411   ){
   401    412     ap = (struct action *)msort((char *)ap,(char **)&ap->next,
   402    413                                 (int(*)(const char*,const char*))actioncmp);
   403    414     return ap;
   404    415   }
   405    416   
   406         -void Action_add(app,type,sp,arg)
   407         -struct action **app;
   408         -enum e_action type;
   409         -struct symbol *sp;
   410         -char *arg;
   411         -{
   412         -  struct action *new;
   413         -  new = Action_new();
   414         -  new->next = *app;
   415         -  *app = new;
   416         -  new->type = type;
   417         -  new->sp = sp;
          417  +void Action_add(
          418  +  struct action **app,
          419  +  enum e_action type,
          420  +  struct symbol *sp,
          421  +  char *arg
          422  +){
          423  +  struct action *newaction;
          424  +  newaction = Action_new();
          425  +  newaction->next = *app;
          426  +  *app = newaction;
          427  +  newaction->type = type;
          428  +  newaction->sp = sp;
   418    429     if( type==SHIFT ){
   419         -    new->x.stp = (struct state *)arg;
          430  +    newaction->x.stp = (struct state *)arg;
   420    431     }else{
   421         -    new->x.rp = (struct rule *)arg;
          432  +    newaction->x.rp = (struct rule *)arg;
   422    433     }
   423    434   }
   424    435   /********************** New code to implement the "acttab" module ***********/
   425    436   /*
   426    437   ** This module implements routines use to construct the yy_action[] table.
   427    438   */
   428    439   
................................................................................
   442    453   ** All actions associated with a single state_number are first entered
   443    454   ** into aLookahead[] using multiple calls to acttab_action().  Then the 
   444    455   ** actions for that single state_number are placed into the aAction[] 
   445    456   ** array with a single call to acttab_insert().  The acttab_insert() call
   446    457   ** also resets the aLookahead[] array in preparation for the next
   447    458   ** state number.
   448    459   */
          460  +struct lookahead_action {
          461  +  int lookahead;             /* Value of the lookahead token */
          462  +  int action;                /* Action to take on the given lookahead */
          463  +};
   449    464   typedef struct acttab acttab;
   450    465   struct acttab {
   451    466     int nAction;                 /* Number of used slots in aAction[] */
   452    467     int nActionAlloc;            /* Slots allocated for aAction[] */
   453         -  struct {
   454         -    int lookahead;             /* Value of the lookahead token */
   455         -    int action;                /* Action to take on the given lookahead */
   456         -  } *aAction,                  /* The yy_action[] table under construction */
          468  +  struct lookahead_action
          469  +    *aAction,                  /* The yy_action[] table under construction */
   457    470       *aLookahead;               /* A single new transaction set */
   458    471     int mnLookahead;             /* Minimum aLookahead[].lookahead */
   459    472     int mnAction;                /* Action associated with mnLookahead */
   460    473     int mxLookahead;             /* Maximum aLookahead[].lookahead */
   461    474     int nLookahead;              /* Used slots in aLookahead[] */
   462    475     int nLookaheadAlloc;         /* Slots allocated in aLookahead[] */
   463    476   };
................................................................................
   476    489     free( p->aAction );
   477    490     free( p->aLookahead );
   478    491     free( p );
   479    492   }
   480    493   
   481    494   /* Allocate a new acttab structure */
   482    495   acttab *acttab_alloc(void){
   483         -  acttab *p = calloc( 1, sizeof(*p) );
          496  +  acttab *p = (acttab *) calloc( 1, sizeof(*p) );
   484    497     if( p==0 ){
   485    498       fprintf(stderr,"Unable to allocate memory for a new acttab.");
   486    499       exit(1);
   487    500     }
   488    501     memset(p, 0, sizeof(*p));
   489    502     return p;
   490    503   }
................................................................................
   493    506   **
   494    507   ** This routine is called once for each lookahead for a particular
   495    508   ** state.
   496    509   */
   497    510   void acttab_action(acttab *p, int lookahead, int action){
   498    511     if( p->nLookahead>=p->nLookaheadAlloc ){
   499    512       p->nLookaheadAlloc += 25;
   500         -    p->aLookahead = realloc( p->aLookahead,
          513  +    p->aLookahead = (struct lookahead_action *) realloc( p->aLookahead,
   501    514                                sizeof(p->aLookahead[0])*p->nLookaheadAlloc );
   502    515       if( p->aLookahead==0 ){
   503    516         fprintf(stderr,"malloc failed\n");
   504    517         exit(1);
   505    518       }
   506    519     }
   507    520     if( p->nLookahead==0 ){
................................................................................
   535    548     ** in the worst case.  The worst case occurs if the transaction set
   536    549     ** must be appended to the current action table
   537    550     */
   538    551     n = p->mxLookahead + 1;
   539    552     if( p->nAction + n >= p->nActionAlloc ){
   540    553       int oldAlloc = p->nActionAlloc;
   541    554       p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20;
   542         -    p->aAction = realloc( p->aAction,
          555  +    p->aAction = (struct lookahead_action *) realloc( p->aAction,
   543    556                             sizeof(p->aAction[0])*p->nActionAlloc);
   544    557       if( p->aAction==0 ){
   545    558         fprintf(stderr,"malloc failed\n");
   546    559         exit(1);
   547    560       }
   548    561       for(i=oldAlloc; i<p->nActionAlloc; i++){
   549    562         p->aAction[i].lookahead = -1;
................................................................................
   633    646   ** Those rules which have a precedence symbol coded in the input
   634    647   ** grammar using the "[symbol]" construct will already have the
   635    648   ** rp->precsym field filled.  Other rules take as their precedence
   636    649   ** symbol the first RHS symbol with a defined precedence.  If there
   637    650   ** are not RHS symbols with a defined precedence, the precedence
   638    651   ** symbol field is left blank.
   639    652   */
   640         -void FindRulePrecedences(xp)
   641         -struct lemon *xp;
          653  +void FindRulePrecedences(struct lemon *xp)
   642    654   {
   643    655     struct rule *rp;
   644    656     for(rp=xp->rule; rp; rp=rp->next){
   645    657       if( rp->precsym==0 ){
   646    658         int i, j;
   647    659         for(i=0; i<rp->nrhs && rp->precsym==0; i++){
   648    660           struct symbol *sp = rp->rhs[i];
................................................................................
   663    675   }
   664    676   
   665    677   /* Find all nonterminals which will generate the empty string.
   666    678   ** Then go back and compute the first sets of every nonterminal.
   667    679   ** The first set is the set of all terminal symbols which can begin
   668    680   ** a string generated by that nonterminal.
   669    681   */
   670         -void FindFirstSets(lemp)
   671         -struct lemon *lemp;
          682  +void FindFirstSets(struct lemon *lemp)
   672    683   {
   673    684     int i, j;
   674    685     struct rule *rp;
   675    686     int progress;
   676    687   
   677    688     for(i=0; i<lemp->nsymbol; i++){
   678    689       lemp->symbols[i]->lambda = LEMON_FALSE;
................................................................................
   725    736     return;
   726    737   }
   727    738   
   728    739   /* Compute all LR(0) states for the grammar.  Links
   729    740   ** are added to between some states so that the LR(1) follow sets
   730    741   ** can be computed later.
   731    742   */
   732         -PRIVATE struct state *getstate(/* struct lemon * */);  /* forward reference */
   733         -void FindStates(lemp)
   734         -struct lemon *lemp;
          743  +PRIVATE struct state *getstate(struct lemon *);  /* forward reference */
          744  +void FindStates(struct lemon *lemp)
   735    745   {
   736    746     struct symbol *sp;
   737    747     struct rule *rp;
   738    748   
   739    749     Configlist_init();
   740    750   
   741    751     /* Find the start symbol */
................................................................................
   785    795     (void)getstate(lemp);
   786    796     return;
   787    797   }
   788    798   
   789    799   /* Return a pointer to a state which is described by the configuration
   790    800   ** list which has been built from calls to Configlist_add.
   791    801   */
   792         -PRIVATE void buildshifts(/* struct lemon *, struct state * */); /* Forwd ref */
   793         -PRIVATE struct state *getstate(lemp)
   794         -struct lemon *lemp;
          802  +PRIVATE void buildshifts(struct lemon *, struct state *); /* Forwd ref */
          803  +PRIVATE struct state *getstate(struct lemon *lemp)
   795    804   {
   796    805     struct config *cfp, *bp;
   797    806     struct state *stp;
   798    807   
   799    808     /* Extract the sorted basis of the new state.  The basis was constructed
   800    809     ** by prior calls to "Configlist_addbasis()". */
   801    810     Configlist_sortbasis();
................................................................................
   831    840     }
   832    841     return stp;
   833    842   }
   834    843   
   835    844   /*
   836    845   ** Return true if two symbols are the same.
   837    846   */
   838         -int same_symbol(a,b)
   839         -struct symbol *a;
   840         -struct symbol *b;
          847  +int same_symbol(struct symbol *a, struct symbol *b)
   841    848   {
   842    849     int i;
   843    850     if( a==b ) return 1;
   844    851     if( a->type!=MULTITERMINAL ) return 0;
   845    852     if( b->type!=MULTITERMINAL ) return 0;
   846    853     if( a->nsubsym!=b->nsubsym ) return 0;
   847    854     for(i=0; i<a->nsubsym; i++){
................................................................................
   849    856     }
   850    857     return 1;
   851    858   }
   852    859   
   853    860   /* Construct all successor states to the given state.  A "successor"
   854    861   ** state is any state which can be reached by a shift action.
   855    862   */
   856         -PRIVATE void buildshifts(lemp,stp)
   857         -struct lemon *lemp;
   858         -struct state *stp;     /* The state from which successors are computed */
          863  +PRIVATE void buildshifts(struct lemon *lemp, struct state *stp)
   859    864   {
   860    865     struct config *cfp;  /* For looping thru the config closure of "stp" */
   861    866     struct config *bcfp; /* For the inner loop on config closure of "stp" */
   862         -  struct config *new;  /* */
          867  +  struct config *newcfg;  /* */
   863    868     struct symbol *sp;   /* Symbol following the dot in configuration "cfp" */
   864    869     struct symbol *bsp;  /* Symbol following the dot in configuration "bcfp" */
   865    870     struct state *newstp; /* A pointer to a successor state */
   866    871   
   867    872     /* Each configuration becomes complete after it contibutes to a successor
   868    873     ** state.  Initially, all configurations are incomplete */
   869    874     for(cfp=stp->cfp; cfp; cfp=cfp->next) cfp->status = INCOMPLETE;
................................................................................
   880    885       ** construction but with the dot shifted one symbol to the right. */
   881    886       for(bcfp=cfp; bcfp; bcfp=bcfp->next){
   882    887         if( bcfp->status==COMPLETE ) continue;    /* Already used */
   883    888         if( bcfp->dot>=bcfp->rp->nrhs ) continue; /* Can't shift this one */
   884    889         bsp = bcfp->rp->rhs[bcfp->dot];           /* Get symbol after dot */
   885    890         if( !same_symbol(bsp,sp) ) continue;      /* Must be same as for "cfp" */
   886    891         bcfp->status = COMPLETE;                  /* Mark this config as used */
   887         -      new = Configlist_addbasis(bcfp->rp,bcfp->dot+1);
   888         -      Plink_add(&new->bplp,bcfp);
          892  +      newcfg = Configlist_addbasis(bcfp->rp,bcfp->dot+1);
          893  +      Plink_add(&newcfg->bplp,bcfp);
   889    894       }
   890    895   
   891    896       /* Get a pointer to the state described by the basis configuration set
   892    897       ** constructed in the preceding loop */
   893    898       newstp = getstate(lemp);
   894    899   
   895    900       /* The state "newstp" is reached from the state "stp" by a shift action
................................................................................
   904    909       }
   905    910     }
   906    911   }
   907    912   
   908    913   /*
   909    914   ** Construct the propagation links
   910    915   */
   911         -void FindLinks(lemp)
   912         -struct lemon *lemp;
          916  +void FindLinks(struct lemon *lemp)
   913    917   {
   914    918     int i;
   915    919     struct config *cfp, *other;
   916    920     struct state *stp;
   917    921     struct plink *plp;
   918    922   
   919    923     /* Housekeeping detail:
................................................................................
   940    944   }
   941    945   
   942    946   /* Compute all followsets.
   943    947   **
   944    948   ** A followset is the set of all symbols which can come immediately
   945    949   ** after a configuration.
   946    950   */
   947         -void FindFollowSets(lemp)
   948         -struct lemon *lemp;
          951  +void FindFollowSets(struct lemon *lemp)
   949    952   {
   950    953     int i;
   951    954     struct config *cfp;
   952    955     struct plink *plp;
   953    956     int progress;
   954    957     int change;
   955    958   
................................................................................
   973    976   	}
   974    977           cfp->status = COMPLETE;
   975    978         }
   976    979       }
   977    980     }while( progress );
   978    981   }
   979    982   
   980         -static int resolve_conflict();
          983  +static int resolve_conflict(struct action *,struct action *, struct symbol *);
   981    984   
   982    985   /* Compute the reduce actions, and resolve conflicts.
   983    986   */
   984         -void FindActions(lemp)
   985         -struct lemon *lemp;
          987  +void FindActions(struct lemon *lemp)
   986    988   {
   987    989     int i,j;
   988    990     struct config *cfp;
   989    991     struct state *stp;
   990    992     struct symbol *sp;
   991    993     struct rule *rp;
   992    994   
................................................................................
  1061   1063   **   is not associated with the error rule.  If neither or both
  1062   1064   **   actions are associated with an error rule, then try to
  1063   1065   **   use precedence to resolve the conflict.
  1064   1066   **
  1065   1067   ** If either action is a SHIFT, then it must be apx.  This
  1066   1068   ** function won't work if apx->type==REDUCE and apy->type==SHIFT.
  1067   1069   */
  1068         -static int resolve_conflict(apx,apy,errsym)
  1069         -struct action *apx;
  1070         -struct action *apy;
  1071         -struct symbol *errsym;   /* The error symbol (if defined.  NULL otherwise) */
  1072         -{
         1070  +static int resolve_conflict(
         1071  +  struct action *apx,
         1072  +  struct action *apy,
         1073  +  struct symbol *errsym   /* The error symbol (if defined.  NULL otherwise) */
         1074  +){
  1073   1075     struct symbol *spx, *spy;
  1074   1076     int errcnt = 0;
  1075   1077     assert( apx->sp==apy->sp );  /* Otherwise there would be no conflict */
  1076   1078     if( apx->type==SHIFT && apy->type==SHIFT ){
  1077   1079       apy->type = SSCONFLICT;
  1078   1080       errcnt++;
  1079   1081     }
................................................................................
  1138   1140   static struct config *current = 0;       /* Top of list of configurations */
  1139   1141   static struct config **currentend = 0;   /* Last on list of configs */
  1140   1142   static struct config *basis = 0;         /* Top of list of basis configs */
  1141   1143   static struct config **basisend = 0;     /* End of list of basis configs */
  1142   1144   
  1143   1145   /* Return a pointer to a new configuration */
  1144   1146   PRIVATE struct config *newconfig(){
  1145         -  struct config *new;
         1147  +  struct config *newcfg;
  1146   1148     if( freelist==0 ){
  1147   1149       int i;
  1148   1150       int amt = 3;
  1149   1151       freelist = (struct config *)calloc( amt, sizeof(struct config) );
  1150   1152       if( freelist==0 ){
  1151   1153         fprintf(stderr,"Unable to allocate memory for a new configuration.");
  1152   1154         exit(1);
  1153   1155       }
  1154   1156       for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1];
  1155   1157       freelist[amt-1].next = 0;
  1156   1158     }
  1157         -  new = freelist;
         1159  +  newcfg = freelist;
  1158   1160     freelist = freelist->next;
  1159         -  return new;
         1161  +  return newcfg;
  1160   1162   }
  1161   1163   
  1162   1164   /* The configuration "old" is no longer used */
  1163         -PRIVATE void deleteconfig(old)
  1164         -struct config *old;
         1165  +PRIVATE void deleteconfig(struct config *old)
  1165   1166   {
  1166   1167     old->next = freelist;
  1167   1168     freelist = old;
  1168   1169   }
  1169   1170   
  1170   1171   /* Initialized the configuration list builder */
  1171   1172   void Configlist_init(){
................................................................................
  1184   1185     basis = 0;
  1185   1186     basisend = &basis;
  1186   1187     Configtable_clear(0);
  1187   1188     return;
  1188   1189   }
  1189   1190   
  1190   1191   /* Add another configuration to the configuration list */
  1191         -struct config *Configlist_add(rp,dot)
  1192         -struct rule *rp;    /* The rule */
  1193         -int dot;            /* Index into the RHS of the rule where the dot goes */
  1194         -{
         1192  +struct config *Configlist_add(
         1193  +  struct rule *rp,    /* The rule */
         1194  +  int dot             /* Index into the RHS of the rule where the dot goes */
         1195  +){
  1195   1196     struct config *cfp, model;
  1196   1197   
  1197   1198     assert( currentend!=0 );
  1198   1199     model.rp = rp;
  1199   1200     model.dot = dot;
  1200   1201     cfp = Configtable_find(&model);
  1201   1202     if( cfp==0 ){
................................................................................
  1211   1212       currentend = &cfp->next;
  1212   1213       Configtable_insert(cfp);
  1213   1214     }
  1214   1215     return cfp;
  1215   1216   }
  1216   1217   
  1217   1218   /* Add a basis configuration to the configuration list */
  1218         -struct config *Configlist_addbasis(rp,dot)
  1219         -struct rule *rp;
  1220         -int dot;
         1219  +struct config *Configlist_addbasis(struct rule *rp, int dot)
  1221   1220   {
  1222   1221     struct config *cfp, model;
  1223   1222   
  1224   1223     assert( basisend!=0 );
  1225   1224     assert( currentend!=0 );
  1226   1225     model.rp = rp;
  1227   1226     model.dot = dot;
................................................................................
  1241   1240       basisend = &cfp->bp;
  1242   1241       Configtable_insert(cfp);
  1243   1242     }
  1244   1243     return cfp;
  1245   1244   }
  1246   1245   
  1247   1246   /* Compute the closure of the configuration list */
  1248         -void Configlist_closure(lemp)
  1249         -struct lemon *lemp;
         1247  +void Configlist_closure(struct lemon *lemp)
  1250   1248   {
  1251   1249     struct config *cfp, *newcfp;
  1252   1250     struct rule *rp, *newrp;
  1253   1251     struct symbol *sp, *xsp;
  1254   1252     int i, dot;
  1255   1253   
  1256   1254     assert( currentend!=0 );
................................................................................
  1321   1319     old = basis;
  1322   1320     basis = 0;
  1323   1321     basisend = 0;
  1324   1322     return old;
  1325   1323   }
  1326   1324   
  1327   1325   /* Free all elements of the given configuration list */
  1328         -void Configlist_eat(cfp)
  1329         -struct config *cfp;
         1326  +void Configlist_eat(struct config *cfp)
  1330   1327   {
  1331   1328     struct config *nextcfp;
  1332   1329     for(; cfp; cfp=nextcfp){
  1333   1330       nextcfp = cfp->next;
  1334   1331       assert( cfp->fplp==0 );
  1335   1332       assert( cfp->bplp==0 );
  1336   1333       if( cfp->fws ) SetFree(cfp->fws);
................................................................................
  1342   1339   /*
  1343   1340   ** Code for printing error message.
  1344   1341   */
  1345   1342   
  1346   1343   /* Find a good place to break "msg" so that its length is at least "min"
  1347   1344   ** but no more than "max".  Make the point as close to max as possible.
  1348   1345   */
  1349         -static int findbreak(msg,min,max)
  1350         -char *msg;
  1351         -int min;
  1352         -int max;
         1346  +static int findbreak(char *msg, int min, int max)
  1353   1347   {
  1354   1348     int i,spot;
  1355   1349     char c;
  1356   1350     for(i=spot=min; i<=max; i++){
  1357   1351       c = msg[i];
  1358   1352       if( c=='\t' ) msg[i] = ' ';
  1359   1353       if( c=='\n' ){ msg[i] = ' '; spot = i; break; }
................................................................................
  1437   1431   
  1438   1432   /* This routine is called with the argument to each -D command-line option.
  1439   1433   ** Add the macro defined to the azDefine array.
  1440   1434   */
  1441   1435   static void handle_D_option(char *z){
  1442   1436     char **paz;
  1443   1437     nDefine++;
  1444         -  azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine);
         1438  +  azDefine = (char **) realloc(azDefine, sizeof(azDefine[0])*nDefine);
  1445   1439     if( azDefine==0 ){
  1446   1440       fprintf(stderr,"out of memory\n");
  1447   1441       exit(1);
  1448   1442     }
  1449   1443     paz = &azDefine[nDefine-1];
  1450         -  *paz = malloc( lemonStrlen(z)+1 );
         1444  +  *paz = (char *) malloc( lemonStrlen(z)+1 );
  1451   1445     if( *paz==0 ){
  1452   1446       fprintf(stderr,"out of memory\n");
  1453   1447       exit(1);
  1454   1448     }
  1455   1449     strcpy(*paz, z);
  1456   1450     for(z=*paz; *z && *z!='='; z++){}
  1457   1451     *z = 0;
  1458   1452   }
  1459   1453   
  1460   1454   static char *user_templatename = NULL;
  1461   1455   static void handle_T_option(char *z){
  1462         -  user_templatename = malloc( lemonStrlen(z)+1 );
         1456  +  user_templatename = (char *) malloc( lemonStrlen(z)+1 );
  1463   1457     if( user_templatename==0 ){
  1464   1458       memory_error();
  1465   1459     }
  1466   1460     strcpy(user_templatename, z);
  1467   1461   }
  1468   1462   
  1469   1463   /* The main program.  Parse the command line and do it... */
  1470         -int main(argc,argv)
  1471         -int argc;
  1472         -char **argv;
         1464  +int main(int argc, char **argv)
  1473   1465   {
  1474   1466     static int version = 0;
  1475   1467     static int rpflag = 0;
  1476   1468     static int basisflag = 0;
  1477   1469     static int compress = 0;
  1478   1470     static int quiet = 0;
  1479   1471     static int statistics = 0;
................................................................................
  1534   1526     }
  1535   1527   
  1536   1528     /* Count and index the symbols of the grammar */
  1537   1529     lem.nsymbol = Symbol_count();
  1538   1530     Symbol_new("{default}");
  1539   1531     lem.symbols = Symbol_arrayof();
  1540   1532     for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
  1541         -  qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*),
  1542         -        (int(*)())Symbolcmpp);
         1533  +  qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*), Symbolcmpp);
  1543   1534     for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
  1544   1535     for(i=1; isupper(lem.symbols[i]->name[0]); i++);
  1545   1536     lem.nterminal = i;
  1546   1537   
  1547   1538     /* Generate a reprint of the grammar, if requested on the command line */
  1548   1539     if( rpflag ){
  1549   1540       Reprint(&lem);
................................................................................
  1738   1729   
  1739   1730   #define ISOPT(X) ((X)[0]=='-'||(X)[0]=='+'||strchr((X),'=')!=0)
  1740   1731   
  1741   1732   /*
  1742   1733   ** Print the command line with a carrot pointing to the k-th character
  1743   1734   ** of the n-th field.
  1744   1735   */
  1745         -static void errline(n,k,err)
  1746         -int n;
  1747         -int k;
  1748         -FILE *err;
         1736  +static void errline(int n, int k, FILE *err)
  1749   1737   {
  1750   1738     int spcnt, i;
  1751   1739     if( argv[0] ) fprintf(err,"%s",argv[0]);
  1752   1740     spcnt = lemonStrlen(argv[0]) + 1;
  1753   1741     for(i=1; i<n && argv[i]; i++){
  1754   1742       fprintf(err," %s",argv[i]);
  1755   1743       spcnt += lemonStrlen(argv[i])+1;
................................................................................
  1763   1751     }
  1764   1752   }
  1765   1753   
  1766   1754   /*
  1767   1755   ** Return the index of the N-th non-switch argument.  Return -1
  1768   1756   ** if N is out of range.
  1769   1757   */
  1770         -static int argindex(n)
  1771         -int n;
         1758  +static int argindex(int n)
  1772   1759   {
  1773   1760     int i;
  1774   1761     int dashdash = 0;
  1775   1762     if( argv!=0 && *argv!=0 ){
  1776   1763       for(i=1; argv[i]; i++){
  1777   1764         if( dashdash || !ISOPT(argv[i]) ){
  1778   1765           if( n==0 ) return i;
................................................................................
  1785   1772   }
  1786   1773   
  1787   1774   static char emsg[] = "Command line syntax error: ";
  1788   1775   
  1789   1776   /*
  1790   1777   ** Process a flag command line argument.
  1791   1778   */
  1792         -static int handleflags(i,err)
  1793         -int i;
  1794         -FILE *err;
         1779  +static int handleflags(int i, FILE *err)
  1795   1780   {
  1796   1781     int v;
  1797   1782     int errcnt = 0;
  1798   1783     int j;
  1799   1784     for(j=0; op[j].label; j++){
  1800   1785       if( strncmp(&argv[i][1],op[j].label,lemonStrlen(op[j].label))==0 ) break;
  1801   1786     }
................................................................................
  1805   1790         fprintf(err,"%sundefined option.\n",emsg);
  1806   1791         errline(i,1,err);
  1807   1792       }
  1808   1793       errcnt++;
  1809   1794     }else if( op[j].type==OPT_FLAG ){
  1810   1795       *((int*)op[j].arg) = v;
  1811   1796     }else if( op[j].type==OPT_FFLAG ){
  1812         -    (*(void(*)())(op[j].arg))(v);
         1797  +    (*(void(*)(int))(op[j].arg))(v);
  1813   1798     }else if( op[j].type==OPT_FSTR ){
  1814         -    (*(void(*)())(op[j].arg))(&argv[i][2]);
         1799  +    (*(void(*)(char *))(op[j].arg))(&argv[i][2]);
  1815   1800     }else{
  1816   1801       if( err ){
  1817   1802         fprintf(err,"%smissing argument on switch.\n",emsg);
  1818   1803         errline(i,1,err);
  1819   1804       }
  1820   1805       errcnt++;
  1821   1806     }
  1822   1807     return errcnt;
  1823   1808   }
  1824   1809   
  1825   1810   /*
  1826   1811   ** Process a command line switch which has an argument.
  1827   1812   */
  1828         -static int handleswitch(i,err)
  1829         -int i;
  1830         -FILE *err;
         1813  +static int handleswitch(int i, FILE *err)
  1831   1814   {
  1832   1815     int lv = 0;
  1833   1816     double dv = 0.0;
  1834   1817     char *sv = 0, *end;
  1835   1818     char *cp;
  1836   1819     int j;
  1837   1820     int errcnt = 0;
................................................................................
  1890   1873         case OPT_FLAG:
  1891   1874         case OPT_FFLAG:
  1892   1875           break;
  1893   1876         case OPT_DBL:
  1894   1877           *(double*)(op[j].arg) = dv;
  1895   1878           break;
  1896   1879         case OPT_FDBL:
  1897         -        (*(void(*)())(op[j].arg))(dv);
         1880  +        (*(void(*)(double))(op[j].arg))(dv);
  1898   1881           break;
  1899   1882         case OPT_INT:
  1900   1883           *(int*)(op[j].arg) = lv;
  1901   1884           break;
  1902   1885         case OPT_FINT:
  1903         -        (*(void(*)())(op[j].arg))((int)lv);
         1886  +        (*(void(*)(int))(op[j].arg))((int)lv);
  1904   1887           break;
  1905   1888         case OPT_STR:
  1906   1889           *(char**)(op[j].arg) = sv;
  1907   1890           break;
  1908   1891         case OPT_FSTR:
  1909         -        (*(void(*)())(op[j].arg))(sv);
         1892  +        (*(void(*)(char *))(op[j].arg))(sv);
  1910   1893           break;
  1911   1894       }
  1912   1895     }
  1913   1896     return errcnt;
  1914   1897   }
  1915   1898   
  1916         -int OptInit(a,o,err)
  1917         -char **a;
  1918         -struct s_options *o;
  1919         -FILE *err;
         1899  +int OptInit(char **a, struct s_options *o, FILE *err)
  1920   1900   {
  1921   1901     int errcnt = 0;
  1922   1902     argv = a;
  1923   1903     op = o;
  1924   1904     errstream = err;
  1925   1905     if( argv && *argv && op ){
  1926   1906       int i;
................................................................................
  1949   1929         if( dashdash || !ISOPT(argv[i]) ) cnt++;
  1950   1930         if( strcmp(argv[i],"--")==0 ) dashdash = 1;
  1951   1931       }
  1952   1932     }
  1953   1933     return cnt;
  1954   1934   }
  1955   1935   
  1956         -char *OptArg(n)
  1957         -int n;
         1936  +char *OptArg(int n)
  1958   1937   {
  1959   1938     int i;
  1960   1939     i = argindex(n);
  1961   1940     return i>=0 ? argv[i] : 0;
  1962   1941   }
  1963   1942   
  1964         -void OptErr(n)
  1965         -int n;
         1943  +void OptErr(int n)
  1966   1944   {
  1967   1945     int i;
  1968   1946     i = argindex(n);
  1969   1947     if( i>=0 ) errline(i,0,errstream);
  1970   1948   }
  1971   1949   
  1972   1950   void OptPrint(){
................................................................................
  2020   1998   }
  2021   1999   /*********************** From the file "parse.c" ****************************/
  2022   2000   /*
  2023   2001   ** Input file parser for the LEMON parser generator.
  2024   2002   */
  2025   2003   
  2026   2004   /* The state of the parser */
         2005  +enum e_state {
         2006  +  INITIALIZE,
         2007  +  WAITING_FOR_DECL_OR_RULE,
         2008  +  WAITING_FOR_DECL_KEYWORD,
         2009  +  WAITING_FOR_DECL_ARG,
         2010  +  WAITING_FOR_PRECEDENCE_SYMBOL,
         2011  +  WAITING_FOR_ARROW,
         2012  +  IN_RHS,
         2013  +  LHS_ALIAS_1,
         2014  +  LHS_ALIAS_2,
         2015  +  LHS_ALIAS_3,
         2016  +  RHS_ALIAS_1,
         2017  +  RHS_ALIAS_2,
         2018  +  PRECEDENCE_MARK_1,
         2019  +  PRECEDENCE_MARK_2,
         2020  +  RESYNC_AFTER_RULE_ERROR,
         2021  +  RESYNC_AFTER_DECL_ERROR,
         2022  +  WAITING_FOR_DESTRUCTOR_SYMBOL,
         2023  +  WAITING_FOR_DATATYPE_SYMBOL,
         2024  +  WAITING_FOR_FALLBACK_ID,
         2025  +  WAITING_FOR_EXPECT_VALUE,
         2026  +  WAITING_FOR_WILDCARD_ID
         2027  +};
  2027   2028   struct pstate {
  2028   2029     char *filename;       /* Name of the input file */
  2029   2030     int tokenlineno;      /* Linenumber at which current token starts */
  2030   2031     int errorcnt;         /* Number of errors so far */
  2031   2032     char *tokenstart;     /* Text of current token */
  2032   2033     struct lemon *gp;     /* Global state vector */
  2033         -  enum e_state {
  2034         -    INITIALIZE,
  2035         -    WAITING_FOR_DECL_OR_RULE,
  2036         -    WAITING_FOR_DECL_KEYWORD,
  2037         -    WAITING_FOR_DECL_ARG,
  2038         -    WAITING_FOR_PRECEDENCE_SYMBOL,
  2039         -    WAITING_FOR_ARROW,
  2040         -    IN_RHS,
  2041         -    LHS_ALIAS_1,
  2042         -    LHS_ALIAS_2,
  2043         -    LHS_ALIAS_3,
  2044         -    RHS_ALIAS_1,
  2045         -    RHS_ALIAS_2,
  2046         -    PRECEDENCE_MARK_1,
  2047         -    PRECEDENCE_MARK_2,
  2048         -    RESYNC_AFTER_RULE_ERROR,
  2049         -    RESYNC_AFTER_DECL_ERROR,
  2050         -    WAITING_FOR_DESTRUCTOR_SYMBOL,
  2051         -    WAITING_FOR_DATATYPE_SYMBOL,
  2052         -    WAITING_FOR_FALLBACK_ID,
  2053         -    WAITING_FOR_EXPECT_VALUE,
  2054         -    WAITING_FOR_WILDCARD_ID
  2055         -  } state;                   /* The state of the parser */
         2034  +  enum e_state state;        /* The state of the parser */
  2056   2035     struct symbol *fallback;   /* The fallback token */
  2057   2036     struct symbol *lhs;        /* Left-hand side of current rule */
  2058         -  char *lhsalias;            /* Alias for the LHS */
         2037  +  const char *lhsalias;      /* Alias for the LHS */
  2059   2038     int nrhs;                  /* Number of right-hand side symbols seen */
  2060   2039     struct symbol *rhs[MAXRHS];  /* RHS symbols */
  2061         -  char *alias[MAXRHS];       /* Aliases for each RHS symbol (or NULL) */
         2040  +  const char *alias[MAXRHS]; /* Aliases for each RHS symbol (or NULL) */
  2062   2041     struct rule *prevrule;     /* Previous rule parsed */
  2063         -  char *declkeyword;         /* Keyword of a declaration */
         2042  +  const char *declkeyword;   /* Keyword of a declaration */
  2064   2043     char **declargslot;        /* Where the declaration argument should be put */
  2065   2044     int insertLineMacro;       /* Add #line before declaration insert */
  2066   2045     int *decllinenoslot;       /* Where to write declaration line number */
  2067   2046     enum e_assoc declassoc;    /* Assign this association to decl arguments */
  2068   2047     int preccounter;           /* Assign this precedence to decl arguments */
  2069   2048     struct rule *firstrule;    /* Pointer to first rule in the grammar */
  2070   2049     struct rule *lastrule;     /* Pointer to the most recently parsed rule */
  2071   2050   };
  2072   2051   
  2073   2052   /* Parse a single token */
  2074         -static void parseonetoken(psp)
  2075         -struct pstate *psp;
         2053  +static void parseonetoken(struct pstate *psp)
  2076   2054   {
  2077   2055     char *endptr;
  2078         -  char *x;
         2056  +  const char *x;
  2079   2057     x = Strsafe(psp->tokenstart);     /* Save the token permanently */
  2080   2058   #if 0
  2081   2059     printf("%s:%d: Token=[%s] state=%d\n",psp->filename,psp->tokenlineno,
  2082   2060       x,psp->state);
  2083   2061   #endif
  2084   2062     switch( psp->state ){
  2085   2063       case INITIALIZE:
................................................................................
  2203   2181               "Can't allocate enough memory for this rule.");
  2204   2182             psp->errorcnt++;
  2205   2183             psp->prevrule = 0;
  2206   2184   	}else{
  2207   2185             int i;
  2208   2186             rp->ruleline = psp->tokenlineno;
  2209   2187             rp->rhs = (struct symbol**)&rp[1];
  2210         -          rp->rhsalias = (char**)&(rp->rhs[psp->nrhs]);
         2188  +          rp->rhsalias = (const char**)&(rp->rhs[psp->nrhs]);
  2211   2189             for(i=0; i<psp->nrhs; i++){
  2212   2190               rp->rhs[i] = psp->rhs[i];
  2213   2191               rp->rhsalias[i] = psp->alias[i];
  2214   2192   	  }
  2215   2193             rp->lhs = psp->lhs;
  2216   2194             rp->lhsalias = psp->lhsalias;
  2217   2195             rp->nrhs = psp->nrhs;
................................................................................
  2242   2220             psp->alias[psp->nrhs] = 0;
  2243   2221             psp->nrhs++;
  2244   2222   	}
  2245   2223         }else if( (x[0]=='|' || x[0]=='/') && psp->nrhs>0 ){
  2246   2224           struct symbol *msp = psp->rhs[psp->nrhs-1];
  2247   2225           if( msp->type!=MULTITERMINAL ){
  2248   2226             struct symbol *origsp = msp;
  2249         -          msp = calloc(1,sizeof(*msp));
         2227  +          msp = (struct symbol *) calloc(1,sizeof(*msp));
  2250   2228             memset(msp, 0, sizeof(*msp));
  2251   2229             msp->type = MULTITERMINAL;
  2252   2230             msp->nsubsym = 1;
  2253         -          msp->subsym = calloc(1,sizeof(struct symbol*));
         2231  +          msp->subsym = (struct symbol **) calloc(1,sizeof(struct symbol*));
  2254   2232             msp->subsym[0] = origsp;
  2255   2233             msp->name = origsp->name;
  2256   2234             psp->rhs[psp->nrhs-1] = msp;
  2257   2235           }
  2258   2236           msp->nsubsym++;
  2259         -        msp->subsym = realloc(msp->subsym, sizeof(struct symbol*)*msp->nsubsym);
         2237  +        msp->subsym = (struct symbol **) realloc(msp->subsym,
         2238  +          sizeof(struct symbol*)*msp->nsubsym);
  2260   2239           msp->subsym[msp->nsubsym-1] = Symbol_new(&x[1]);
  2261   2240           if( islower(x[1]) || islower(msp->subsym[0]->name[0]) ){
  2262   2241             ErrorMsg(psp->filename,psp->tokenlineno,
  2263   2242               "Cannot form a compound containing a non-terminal");
  2264   2243             psp->errorcnt++;
  2265   2244           }
  2266   2245         }else if( x[0]=='(' && psp->nrhs>0 ){
................................................................................
  2438   2417           ErrorMsg(psp->filename,psp->tokenlineno,
  2439   2418             "Can't assign a precedence to \"%s\".",x);
  2440   2419           psp->errorcnt++;
  2441   2420         }
  2442   2421         break;
  2443   2422       case WAITING_FOR_DECL_ARG:
  2444   2423         if( x[0]=='{' || x[0]=='\"' || isalnum(x[0]) ){
  2445         -        char *zOld, *zNew, *zBuf, *z;
         2424  +        const char *zOld, *zNew;
         2425  +        char *zBuf, *z;
  2446   2426           int nOld, n, nLine, nNew, nBack;
  2447   2427           int addLineMacro;
  2448   2428           char zLine[50];
  2449   2429           zNew = x;
  2450   2430           if( zNew[0]=='"' || zNew[0]=='{' ) zNew++;
  2451   2431           nNew = lemonStrlen(zNew);
  2452   2432           if( *psp->declargslot ){
................................................................................
  2462   2442             for(z=psp->filename, nBack=0; *z; z++){
  2463   2443               if( *z=='\\' ) nBack++;
  2464   2444             }
  2465   2445             sprintf(zLine, "#line %d ", psp->tokenlineno);
  2466   2446             nLine = lemonStrlen(zLine);
  2467   2447             n += nLine + lemonStrlen(psp->filename) + nBack;
  2468   2448           }
  2469         -        *psp->declargslot = zBuf = realloc(*psp->declargslot, n);
  2470         -        zBuf += nOld;
         2449  +        *psp->declargslot = (char *) realloc(*psp->declargslot, n);
         2450  +        zBuf = *psp->declargslot + nOld;
  2471   2451           if( addLineMacro ){
  2472   2452             if( nOld && zBuf[-1]!='\n' ){
  2473   2453               *(zBuf++) = '\n';
  2474   2454             }
  2475   2455             memcpy(zBuf, zLine, nLine);
  2476   2456             zBuf += nLine;
  2477   2457             *(zBuf++) = '"';
................................................................................
  2599   2579   }
  2600   2580   
  2601   2581   /* In spite of its name, this function is really a scanner.  It read
  2602   2582   ** in the entire input file (all at once) then tokenizes it.  Each
  2603   2583   ** token is passed to the function "parseonetoken" which builds all
  2604   2584   ** the appropriate data structures in the global state vector "gp".
  2605   2585   */
  2606         -void Parse(gp)
  2607         -struct lemon *gp;
         2586  +void Parse(struct lemon *gp)
  2608   2587   {
  2609   2588     struct pstate ps;
  2610   2589     FILE *fp;
  2611   2590     char *filebuf;
  2612   2591     int filesize;
  2613   2592     int lineno;
  2614   2593     int c;
................................................................................
  2754   2733   ** Routines processing configuration follow-set propagation links
  2755   2734   ** in the LEMON parser generator.
  2756   2735   */
  2757   2736   static struct plink *plink_freelist = 0;
  2758   2737   
  2759   2738   /* Allocate a new plink */
  2760   2739   struct plink *Plink_new(){
  2761         -  struct plink *new;
         2740  +  struct plink *newlink;
  2762   2741   
  2763   2742     if( plink_freelist==0 ){
  2764   2743       int i;
  2765   2744       int amt = 100;
  2766   2745       plink_freelist = (struct plink *)calloc( amt, sizeof(struct plink) );
  2767   2746       if( plink_freelist==0 ){
  2768   2747         fprintf(stderr,
  2769   2748         "Unable to allocate memory for a new follow-set propagation link.\n");
  2770   2749         exit(1);
  2771   2750       }
  2772   2751       for(i=0; i<amt-1; i++) plink_freelist[i].next = &plink_freelist[i+1];
  2773   2752       plink_freelist[amt-1].next = 0;
  2774   2753     }
  2775         -  new = plink_freelist;
         2754  +  newlink = plink_freelist;
  2776   2755     plink_freelist = plink_freelist->next;
  2777         -  return new;
         2756  +  return newlink;
  2778   2757   }
  2779   2758   
  2780   2759   /* Add a plink to a plink list */
  2781         -void Plink_add(plpp,cfp)
  2782         -struct plink **plpp;
  2783         -struct config *cfp;
         2760  +void Plink_add(struct plink **plpp, struct config *cfp)
  2784   2761   {
  2785         -  struct plink *new;
  2786         -  new = Plink_new();
  2787         -  new->next = *plpp;
  2788         -  *plpp = new;
  2789         -  new->cfp = cfp;
         2762  +  struct plink *newlink;
         2763  +  newlink = Plink_new();
         2764  +  newlink->next = *plpp;
         2765  +  *plpp = newlink;
         2766  +  newlink->cfp = cfp;
  2790   2767   }
  2791   2768   
  2792   2769   /* Transfer every plink on the list "from" to the list "to" */
  2793         -void Plink_copy(to,from)
  2794         -struct plink **to;
  2795         -struct plink *from;
         2770  +void Plink_copy(struct plink **to, struct plink *from)
  2796   2771   {
  2797   2772     struct plink *nextpl;
  2798   2773     while( from ){
  2799   2774       nextpl = from->next;
  2800   2775       from->next = *to;
  2801   2776       *to = from;
  2802   2777       from = nextpl;
  2803   2778     }
  2804   2779   }
  2805   2780   
  2806   2781   /* Delete every plink on the list */
  2807         -void Plink_delete(plp)
  2808         -struct plink *plp;
         2782  +void Plink_delete(struct plink *plp)
  2809   2783   {
  2810   2784     struct plink *nextpl;
  2811   2785   
  2812   2786     while( plp ){
  2813   2787       nextpl = plp->next;
  2814   2788       plp->next = plink_freelist;
  2815   2789       plink_freelist = plp;
................................................................................
  2821   2795   ** Procedures for generating reports and tables in the LEMON parser generator.
  2822   2796   */
  2823   2797   
  2824   2798   /* Generate a filename with the given suffix.  Space to hold the
  2825   2799   ** name comes from malloc() and must be freed by the calling
  2826   2800   ** function.
  2827   2801   */
  2828         -PRIVATE char *file_makename(lemp,suffix)
  2829         -struct lemon *lemp;
  2830         -char *suffix;
         2802  +PRIVATE char *file_makename(struct lemon *lemp, const char *suffix)
  2831   2803   {
  2832   2804     char *name;
  2833   2805     char *cp;
  2834   2806   
  2835         -  name = malloc( lemonStrlen(lemp->filename) + lemonStrlen(suffix) + 5 );
         2807  +  name = (char*)malloc( lemonStrlen(lemp->filename) + lemonStrlen(suffix) + 5 );
  2836   2808     if( name==0 ){
  2837   2809       fprintf(stderr,"Can't allocate space for a filename.\n");
  2838   2810       exit(1);
  2839   2811     }
  2840   2812     strcpy(name,lemp->filename);
  2841   2813     cp = strrchr(name,'.');
  2842   2814     if( cp ) *cp = 0;
................................................................................
  2843   2815     strcat(name,suffix);
  2844   2816     return name;
  2845   2817   }
  2846   2818   
  2847   2819   /* Open a file with a name based on the name of the input file,
  2848   2820   ** but with a different (specified) suffix, and return a pointer
  2849   2821   ** to the stream */
  2850         -PRIVATE FILE *file_open(lemp,suffix,mode)
  2851         -struct lemon *lemp;
  2852         -char *suffix;
  2853         -char *mode;
  2854         -{
         2822  +PRIVATE FILE *file_open(
         2823  +  struct lemon *lemp,
         2824  +  const char *suffix,
         2825  +  const char *mode
         2826  +){
  2855   2827     FILE *fp;
  2856   2828   
  2857   2829     if( lemp->outname ) free(lemp->outname);
  2858   2830     lemp->outname = file_makename(lemp, suffix);
  2859   2831     fp = fopen(lemp->outname,mode);
  2860   2832     if( fp==0 && *mode=='w' ){
  2861   2833       fprintf(stderr,"Can't open file \"%s\".\n",lemp->outname);
................................................................................
  2881   2853       made_files[made_files_count++] = fname;
  2882   2854     }
  2883   2855     return fp;
  2884   2856   }
  2885   2857   
  2886   2858   /* Duplicate the input file without comments and without actions 
  2887   2859   ** on rules */
  2888         -void Reprint(lemp)
  2889         -struct lemon *lemp;
         2860  +void Reprint(struct lemon *lemp)
  2890   2861   {
  2891   2862     struct rule *rp;
  2892   2863     struct symbol *sp;
  2893   2864     int i, j, maxlen, len, ncolumns, skip;
  2894   2865     printf("// Reprint of input file \"%s\".\n// Symbols:\n",lemp->filename);
  2895   2866     maxlen = 10;
  2896   2867     for(i=0; i<lemp->nsymbol; i++){
................................................................................
  2927   2898       printf(".");
  2928   2899       if( rp->precsym ) printf(" [%s]",rp->precsym->name);
  2929   2900       /* if( rp->code ) printf("\n    %s",rp->code); */
  2930   2901       printf("\n");
  2931   2902     }
  2932   2903   }
  2933   2904   
  2934         -void ConfigPrint(fp,cfp)
  2935         -FILE *fp;
  2936         -struct config *cfp;
         2905  +void ConfigPrint(FILE *fp, struct config *cfp)
  2937   2906   {
  2938   2907     struct rule *rp;
  2939   2908     struct symbol *sp;
  2940   2909     int i, j;
  2941   2910     rp = cfp->rp;
  2942   2911     fprintf(fp,"%s ::=",rp->lhs->name);
  2943   2912     for(i=0; i<=rp->nrhs; i++){
................................................................................
  3022   2991         result = 0;
  3023   2992         break;
  3024   2993     }
  3025   2994     return result;
  3026   2995   }
  3027   2996   
  3028   2997   /* Generate the "y.output" log file */
  3029         -void ReportOutput(lemp)
  3030         -struct lemon *lemp;
         2998  +void ReportOutput(struct lemon *lemp)
  3031   2999   {
  3032   3000     int i;
  3033   3001     struct state *stp;
  3034   3002     struct config *cfp;
  3035   3003     struct action *ap;
  3036   3004     FILE *fp;
  3037   3005   
................................................................................
  3089   3057     }
  3090   3058     fclose(fp);
  3091   3059     return;
  3092   3060   }
  3093   3061   
  3094   3062   /* Search for the file "name" which is in the same directory as
  3095   3063   ** the exacutable */
  3096         -PRIVATE char *pathsearch(argv0,name,modemask)
  3097         -char *argv0;
  3098         -char *name;
  3099         -int modemask;
         3064  +PRIVATE char *pathsearch(char *argv0, char *name, int modemask)
  3100   3065   {
  3101         -  char *pathlist;
         3066  +  const char *pathlist;
         3067  +  char *pathbufptr;
         3068  +  char *pathbuf;
  3102   3069     char *path,*cp;
  3103   3070     char c;
  3104   3071   
  3105   3072   #ifdef __WIN32__
  3106   3073     cp = strrchr(argv0,'\\');
  3107   3074   #else
  3108   3075     cp = strrchr(argv0,'/');
................................................................................
  3110   3077     if( cp ){
  3111   3078       c = *cp;
  3112   3079       *cp = 0;
  3113   3080       path = (char *)malloc( lemonStrlen(argv0) + lemonStrlen(name) + 2 );
  3114   3081       if( path ) sprintf(path,"%s/%s",argv0,name);
  3115   3082       *cp = c;
  3116   3083     }else{
  3117         -    extern char *getenv();
  3118   3084       pathlist = getenv("PATH");
  3119   3085       if( pathlist==0 ) pathlist = ".:/bin:/usr/bin";
         3086  +    pathbuf = (char *) malloc( lemonStrlen(pathlist) + 1 );
  3120   3087       path = (char *)malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2 );
  3121         -    if( path!=0 ){
  3122         -      while( *pathlist ){
  3123         -        cp = strchr(pathlist,':');
  3124         -        if( cp==0 ) cp = &pathlist[lemonStrlen(pathlist)];
         3088  +    if( (pathbuf != 0) && (path!=0) ){
         3089  +      pathbufptr = pathbuf;
         3090  +      strcpy(pathbuf, pathlist);
         3091  +      while( *pathbuf ){
         3092  +        cp = strchr(pathbuf,':');
         3093  +        if( cp==0 ) cp = &pathbuf[lemonStrlen(pathbuf)];
  3125   3094           c = *cp;
  3126   3095           *cp = 0;
  3127         -        sprintf(path,"%s/%s",pathlist,name);
         3096  +        sprintf(path,"%s/%s",pathbuf,name);
  3128   3097           *cp = c;
  3129         -        if( c==0 ) pathlist = "";
  3130         -        else pathlist = &cp[1];
         3098  +        if( c==0 ) pathbuf[0] = 0;
         3099  +        else pathbuf = &cp[1];
  3131   3100           if( access(path,modemask)==0 ) break;
  3132   3101         }
         3102  +      free(pathbufptr);
  3133   3103       }
  3134   3104     }
  3135   3105     return path;
  3136   3106   }
  3137   3107   
  3138   3108   /* Given an action, compute the integer value for that action
  3139   3109   ** which is to be put in the action table of the generated machine.
  3140   3110   ** Return negative if no action should be generated.
  3141   3111   */
  3142         -PRIVATE int compute_action(lemp,ap)
  3143         -struct lemon *lemp;
  3144         -struct action *ap;
         3112  +PRIVATE int compute_action(struct lemon *lemp, struct action *ap)
  3145   3113   {
  3146   3114     int act;
  3147   3115     switch( ap->type ){
  3148   3116       case SHIFT:  act = ap->x.stp->statenum;            break;
  3149   3117       case REDUCE: act = ap->x.rp->index + lemp->nstate; break;
  3150   3118       case ERROR:  act = lemp->nstate + lemp->nrule;     break;
  3151   3119       case ACCEPT: act = lemp->nstate + lemp->nrule + 1; break;
................................................................................
  3160   3128   /* The first function transfers data from "in" to "out" until
  3161   3129   ** a line is seen which begins with "%%".  The line number is
  3162   3130   ** tracked.
  3163   3131   **
  3164   3132   ** if name!=0, then any word that begin with "Parse" is changed to
  3165   3133   ** begin with *name instead.
  3166   3134   */
  3167         -PRIVATE void tplt_xfer(name,in,out,lineno)
  3168         -char *name;
  3169         -FILE *in;
  3170         -FILE *out;
  3171         -int *lineno;
         3135  +PRIVATE void tplt_xfer(char *name, FILE *in, FILE *out, int *lineno)
  3172   3136   {
  3173   3137     int i, iStart;
  3174   3138     char line[LINESIZE];
  3175   3139     while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){
  3176   3140       (*lineno)++;
  3177   3141       iStart = 0;
  3178   3142       if( name ){
................................................................................
  3189   3153       }
  3190   3154       fprintf(out,"%s",&line[iStart]);
  3191   3155     }
  3192   3156   }
  3193   3157   
  3194   3158   /* The next function finds the template file and opens it, returning
  3195   3159   ** a pointer to the opened file. */
  3196         -PRIVATE FILE *tplt_open(lemp)
  3197         -struct lemon *lemp;
         3160  +PRIVATE FILE *tplt_open(struct lemon *lemp)
  3198   3161   {
  3199   3162     static char templatename[] = "lempar.c";
  3200   3163     char buf[1000];
  3201   3164     FILE *in;
  3202   3165     char *tpltname;
  3203   3166     char *cp;
  3204   3167   
................................................................................
  3244   3207       lemp->errorcnt++;
  3245   3208       return 0;
  3246   3209     }
  3247   3210     return in;
  3248   3211   }
  3249   3212   
  3250   3213   /* Print a #line directive line to the output file. */
  3251         -PRIVATE void tplt_linedir(out,lineno,filename)
  3252         -FILE *out;
  3253         -int lineno;
  3254         -char *filename;
         3214  +PRIVATE void tplt_linedir(FILE *out, int lineno, char *filename)
  3255   3215   {
  3256   3216     fprintf(out,"#line %d \"",lineno);
  3257   3217     while( *filename ){
  3258   3218       if( *filename == '\\' ) putc('\\',out);
  3259   3219       putc(*filename,out);
  3260   3220       filename++;
  3261   3221     }
  3262   3222     fprintf(out,"\"\n");
  3263   3223   }
  3264   3224   
  3265   3225   /* Print a string to the file and keep the linenumber up to date */
  3266         -PRIVATE void tplt_print(out,lemp,str,lineno)
  3267         -FILE *out;
  3268         -struct lemon *lemp;
  3269         -char *str;
  3270         -int *lineno;
         3226  +PRIVATE void tplt_print(FILE *out, struct lemon *lemp, char *str, int *lineno)
  3271   3227   {
  3272   3228     if( str==0 ) return;
  3273   3229     while( *str ){
  3274   3230       putc(*str,out);
  3275   3231       if( *str=='\n' ) (*lineno)++;
  3276   3232       str++;
  3277   3233     }
................................................................................
  3285   3241     return;
  3286   3242   }
  3287   3243   
  3288   3244   /*
  3289   3245   ** The following routine emits code for the destructor for the
  3290   3246   ** symbol sp
  3291   3247   */
  3292         -void emit_destructor_code(out,sp,lemp,lineno)
  3293         -FILE *out;
  3294         -struct symbol *sp;
  3295         -struct lemon *lemp;
  3296         -int *lineno;
  3297         -{
         3248  +void emit_destructor_code(
         3249  +  FILE *out,
         3250  +  struct symbol *sp,
         3251  +  struct lemon *lemp,
         3252  +  int *lineno
         3253  +){
  3298   3254    char *cp = 0;
  3299   3255   
  3300   3256    if( sp->type==TERMINAL ){
  3301   3257      cp = lemp->tokendest;
  3302   3258      if( cp==0 ) return;
  3303   3259      fprintf(out,"{\n"); (*lineno)++;
  3304   3260    }else if( sp->destructor ){
................................................................................
  3328   3284    fprintf(out,"}\n"); (*lineno)++;
  3329   3285    return;
  3330   3286   }
  3331   3287   
  3332   3288   /*
  3333   3289   ** Return TRUE (non-zero) if the given symbol has a destructor.
  3334   3290   */
  3335         -int has_destructor(sp, lemp)
  3336         -struct symbol *sp;
  3337         -struct lemon *lemp;
         3291  +int has_destructor(struct symbol *sp, struct lemon *lemp)
  3338   3292   {
  3339   3293     int ret;
  3340   3294     if( sp->type==TERMINAL ){
  3341   3295       ret = lemp->tokendest!=0;
  3342   3296     }else{
  3343   3297       ret = lemp->vardest!=0 || sp->destructor!=0;
  3344   3298     }
................................................................................
  3353   3307   ** n bytes of zText are stored.  If n==0 then all of zText up to the first
  3354   3308   ** \000 terminator is stored.  zText can contain up to two instances of
  3355   3309   ** %d.  The values of p1 and p2 are written into the first and second
  3356   3310   ** %d.
  3357   3311   **
  3358   3312   ** If n==-1, then the previous character is overwritten.
  3359   3313   */
  3360         -PRIVATE char *append_str(char *zText, int n, int p1, int p2){
         3314  +PRIVATE char *append_str(const char *zText, int n, int p1, int p2){
         3315  +  static char empty[1] = { 0 };
  3361   3316     static char *z = 0;
  3362   3317     static int alloced = 0;
  3363   3318     static int used = 0;
  3364   3319     int c;
  3365   3320     char zInt[40];
  3366         -
  3367   3321     if( zText==0 ){
  3368   3322       used = 0;
  3369   3323       return z;
  3370   3324     }
  3371   3325     if( n<=0 ){
  3372   3326       if( n<0 ){
  3373   3327         used += n;
  3374   3328         assert( used>=0 );
  3375   3329       }
  3376   3330       n = lemonStrlen(zText);
  3377   3331     }
  3378   3332     if( n+sizeof(zInt)*2+used >= alloced ){
  3379   3333       alloced = n + sizeof(zInt)*2 + used + 200;
  3380         -    z = realloc(z,  alloced);
         3334  +    z = (char *) realloc(z,  alloced);
  3381   3335     }
  3382         -  if( z==0 ) return "";
         3336  +  if( z==0 ) return empty;
  3383   3337     while( n-- > 0 ){
  3384   3338       c = *(zText++);
  3385   3339       if( c=='%' && n>0 && zText[0]=='d' ){
  3386   3340         sprintf(zInt, "%d", p1);
  3387   3341         p1 = p2;
  3388   3342         strcpy(&z[used], zInt);
  3389   3343         used += lemonStrlen(&z[used]);
................................................................................
  3408   3362     char lhsused = 0;    /* True if the LHS element has been used */
  3409   3363     char used[MAXRHS];   /* True for each RHS element which is used */
  3410   3364   
  3411   3365     for(i=0; i<rp->nrhs; i++) used[i] = 0;
  3412   3366     lhsused = 0;
  3413   3367   
  3414   3368     if( rp->code==0 ){
  3415         -    rp->code = "\n";
         3369  +    static char newlinestr[2] = { '\n', '\0' };
         3370  +    rp->code = newlinestr;
  3416   3371       rp->line = rp->ruleline;
  3417   3372     }
  3418   3373   
  3419   3374     append_str(0,0,0,0);
  3420         -  for(cp=rp->code; *cp; cp++){
         3375  +
         3376  +  /* This const cast is wrong but harmless, if we're careful. */
         3377  +  for(cp=(char *)rp->code; *cp; cp++){
  3421   3378       if( isalpha(*cp) && (cp==rp->code || (!isalnum(cp[-1]) && cp[-1]!='_')) ){
  3422   3379         char saved;
  3423   3380         for(xp= &cp[1]; isalnum(*xp) || *xp=='_'; xp++);
  3424   3381         saved = *xp;
  3425   3382         *xp = 0;
  3426   3383         if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){
  3427   3384           append_str("yygotominor.yy%d",0,rp->lhs->dtnum,0);
................................................................................
  3486   3443     }
  3487   3444   }
  3488   3445   
  3489   3446   /* 
  3490   3447   ** Generate code which executes when the rule "rp" is reduced.  Write
  3491   3448   ** the code to "out".  Make sure lineno stays up-to-date.
  3492   3449   */
  3493         -PRIVATE void emit_code(out,rp,lemp,lineno)
  3494         -FILE *out;
  3495         -struct rule *rp;
  3496         -struct lemon *lemp;
  3497         -int *lineno;
  3498         -{
  3499         - char *cp;
         3450  +PRIVATE void emit_code(
         3451  +  FILE *out,
         3452  +  struct rule *rp,
         3453  +  struct lemon *lemp,
         3454  +  int *lineno
         3455  +){
         3456  + const char *cp;
  3500   3457   
  3501   3458    /* Generate code to do the reduce action */
  3502   3459    if( rp->code ){
  3503   3460      if (!lemp->nolinenosflag) { (*lineno)++; tplt_linedir(out,rp->line,lemp->filename); }
  3504   3461      fprintf(out,"{%s",rp->code);
  3505   3462      for(cp=rp->code; *cp; cp++){
  3506   3463        if( *cp=='\n' ) (*lineno)++;
................................................................................
  3515   3472   /*
  3516   3473   ** Print the definition of the union used for the parser's data stack.
  3517   3474   ** This union contains fields for every possible data type for tokens
  3518   3475   ** and nonterminals.  In the process of computing and printing this
  3519   3476   ** union, also set the ".dtnum" field of every terminal and nonterminal
  3520   3477   ** symbol.
  3521   3478   */
  3522         -void print_stack_union(out,lemp,plineno,mhflag)
  3523         -FILE *out;                  /* The output stream */
  3524         -struct lemon *lemp;         /* The main info structure for this parser */
  3525         -int *plineno;               /* Pointer to the line number */
  3526         -int mhflag;                 /* True if generating makeheaders output */
  3527         -{
         3479  +void print_stack_union(
         3480  +  FILE *out,                  /* The output stream */
         3481  +  struct lemon *lemp,         /* The main info structure for this parser */
         3482  +  int *plineno,               /* Pointer to the line number */
         3483  +  int mhflag                  /* True if generating makeheaders output */
         3484  +){
  3528   3485     int lineno = *plineno;    /* The line number of the output */
  3529   3486     char **types;             /* A hash table of datatypes */
  3530   3487     int arraysize;            /* Size of the "types" array */
  3531   3488     int maxdtlength;          /* Maximum length of any ".datatype" field. */
  3532   3489     char *stddt;              /* Standardized name for a datatype */
  3533   3490     int i,j;                  /* Loop counters */
  3534   3491     int hash;                 /* For hashing the name of a type */
  3535         -  char *name;               /* Name of the parser */
         3492  +  const char *name;         /* Name of the parser */
  3536   3493   
  3537   3494     /* Allocate and initialize types[] and allocate stddt[] */
  3538   3495     arraysize = lemp->nsymbol * 2;
  3539   3496     types = (char**)calloc( arraysize, sizeof(char*) );
  3540   3497     for(i=0; i<arraysize; i++) types[i] = 0;
  3541   3498     maxdtlength = 0;
  3542   3499     if( lemp->vartype ){
................................................................................
  3697   3654         }
  3698   3655       }
  3699   3656     }
  3700   3657   }
  3701   3658   
  3702   3659   
  3703   3660   /* Generate C source code for the parser */
  3704         -void ReportTable(lemp, mhflag)
  3705         -struct lemon *lemp;
  3706         -int mhflag;     /* Output in makeheaders format if true */
  3707         -{
         3661  +void ReportTable(
         3662  +  struct lemon *lemp,
         3663  +  int mhflag     /* Output in makeheaders format if true */
         3664  +){
  3708   3665     FILE *out, *in;
  3709   3666     char line[LINESIZE];
  3710   3667     int  lineno;
  3711   3668     struct state *stp;
  3712   3669     struct action *ap;
  3713   3670     struct rule *rp;
  3714   3671     struct acttab *pActtab;
  3715   3672     int i, j, k, n;
  3716         -  char *name;
         3673  +  const char *name;
  3717   3674     int mnTknOfst, mxTknOfst;
  3718   3675     int mnNtOfst, mxNtOfst;
  3719   3676     struct axset *ax;
  3720   3677   
  3721   3678     in = tplt_open(lemp);
  3722   3679     if( in==0 ) return;
  3723   3680     out = file_open(lemp,".c","wb");
................................................................................
  3735   3692       fprintf(out,"#include \"%s\"\n", name); lineno++;
  3736   3693       free(name);
  3737   3694     }
  3738   3695     tplt_xfer(lemp->name,in,out,&lineno);
  3739   3696   
  3740   3697     /* Generate #defines for all tokens */
  3741   3698     if( mhflag ){
  3742         -    char *prefix;
         3699  +    const char *prefix;
  3743   3700       fprintf(out,"#if INTERFACE\n"); lineno++;
  3744   3701       if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
  3745   3702       else                    prefix = "";
  3746   3703       for(i=1; i<lemp->nterminal; i++){
  3747   3704         fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
  3748   3705         lineno++;
  3749   3706       }
................................................................................
  3813   3770     **                     shifting terminals.
  3814   3771     **  yy_reduce_ofst[]   For each state, the offset into yy_action for
  3815   3772     **                     shifting non-terminals after a reduce.
  3816   3773     **  yy_default[]       Default action for each state.
  3817   3774     */
  3818   3775   
  3819   3776     /* Compute the actions on all states and count them up */
  3820         -  ax = calloc(lemp->nstate*2, sizeof(ax[0]));
         3777  +  ax = (struct axset *) calloc(lemp->nstate*2, sizeof(ax[0]));
  3821   3778     if( ax==0 ){
  3822   3779       fprintf(stderr,"malloc failed\n");
  3823   3780       exit(1);
  3824   3781     }
  3825   3782     for(i=0; i<lemp->nstate; i++){
  3826   3783       stp = lemp->sorted[i];
  3827   3784       ax[i*2].stp = stp;
................................................................................
  4141   4098   
  4142   4099     fclose(in);
  4143   4100     fclose(out);
  4144   4101     return;
  4145   4102   }
  4146   4103   
  4147   4104   /* Generate a header file for the parser */
  4148         -void ReportHeader(lemp)
  4149         -struct lemon *lemp;
         4105  +void ReportHeader(struct lemon *lemp)
  4150   4106   {
  4151   4107     FILE *out, *in;
  4152         -  char *prefix;
         4108  +  const char *prefix;
  4153   4109     char line[LINESIZE];
  4154   4110     char pattern[LINESIZE];
  4155   4111     int i;
  4156   4112   
  4157   4113     if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
  4158   4114     else                    prefix = "";
  4159   4115     in = file_open(lemp,".h","rb");
................................................................................
  4181   4137   /* Reduce the size of the action tables, if possible, by making use
  4182   4138   ** of defaults.
  4183   4139   **
  4184   4140   ** In this version, we take the most frequent REDUCE action and make
  4185   4141   ** it the default.  Except, there is no default if the wildcard token
  4186   4142   ** is a possible look-ahead.
  4187   4143   */
  4188         -void CompressTables(lemp)
  4189         -struct lemon *lemp;
         4144  +void CompressTables(struct lemon *lemp)
  4190   4145   {
  4191   4146     struct state *stp;
  4192   4147     struct action *ap, *ap2;
  4193   4148     struct rule *rp, *rp2, *rbest;
  4194   4149     int nbest, n;
  4195   4150     int i;
  4196   4151     int usesWildcard;
................................................................................
  4266   4221   }
  4267   4222   
  4268   4223   
  4269   4224   /*
  4270   4225   ** Renumber and resort states so that states with fewer choices
  4271   4226   ** occur at the end.  Except, keep state 0 as the first state.
  4272   4227   */
  4273         -void ResortStates(lemp)
  4274         -struct lemon *lemp;
         4228  +void ResortStates(struct lemon *lemp)
  4275   4229   {
  4276   4230     int i;
  4277   4231     struct state *stp;
  4278   4232     struct action *ap;
  4279   4233   
  4280   4234     for(i=0; i<lemp->nstate; i++){
  4281   4235       stp = lemp->sorted[i];
................................................................................
  4307   4261   /*
  4308   4262   ** Set manipulation routines for the LEMON parser generator.
  4309   4263   */
  4310   4264   
  4311   4265   static int size = 0;
  4312   4266   
  4313   4267   /* Set the set size */
  4314         -void SetSize(n)
  4315         -int n;
         4268  +void SetSize(int n)
  4316   4269   {
  4317   4270     size = n+1;
  4318   4271   }
  4319   4272   
  4320   4273   /* Allocate a new set */
  4321   4274   char *SetNew(){
  4322   4275     char *s;
................................................................................
  4325   4278       extern void memory_error();
  4326   4279       memory_error();
  4327   4280     }
  4328   4281     return s;
  4329   4282   }
  4330   4283   
  4331   4284   /* Deallocate a set */
  4332         -void SetFree(s)
  4333         -char *s;
         4285  +void SetFree(char *s)
  4334   4286   {
  4335   4287     free(s);
  4336   4288   }
  4337   4289   
  4338   4290   /* Add a new element to the set.  Return TRUE if the element was added
  4339   4291   ** and FALSE if it was already there. */
  4340         -int SetAdd(s,e)
  4341         -char *s;
  4342         -int e;
         4292  +int SetAdd(char *s, int e)
  4343   4293   {
  4344   4294     int rv;
  4345   4295     assert( e>=0 && e<size );
  4346   4296     rv = s[e];
  4347   4297     s[e] = 1;
  4348   4298     return !rv;
  4349   4299   }
  4350   4300   
  4351   4301   /* Add every element of s2 to s1.  Return TRUE if s1 changes. */
  4352         -int SetUnion(s1,s2)
  4353         -char *s1;
  4354         -char *s2;
         4302  +int SetUnion(char *s1, char *s2)
  4355   4303   {
  4356   4304     int i, progress;
  4357   4305     progress = 0;
  4358   4306     for(i=0; i<size; i++){
  4359   4307       if( s2[i]==0 ) continue;
  4360   4308       if( s1[i]==0 ){
  4361   4309         progress = 1;
................................................................................
  4373   4321   ** Do not edit this file!  Instead, edit the specification
  4374   4322   ** file, then rerun aagen.
  4375   4323   */
  4376   4324   /*
  4377   4325   ** Code for processing tables in the LEMON parser generator.
  4378   4326   */
  4379   4327   
  4380         -PRIVATE int strhash(x)
  4381         -char *x;
         4328  +PRIVATE int strhash(const char *x)
  4382   4329   {
  4383   4330     int h = 0;
  4384   4331     while( *x) h = h*13 + *(x++);
  4385   4332     return h;
  4386   4333   }
  4387   4334   
  4388   4335   /* Works like strdup, sort of.  Save a string in malloced memory, but
  4389   4336   ** keep strings in a table so that the same string is not in more
  4390   4337   ** than one place.
  4391   4338   */
  4392         -char *Strsafe(y)
  4393         -char *y;
         4339  +const char *Strsafe(const char *y)
  4394   4340   {
  4395         -  char *z;
         4341  +  const char *z;
         4342  +  char *cpy;
  4396   4343   
  4397   4344     if( y==0 ) return 0;
  4398   4345     z = Strsafe_find(y);
  4399         -  if( z==0 && (z=malloc( lemonStrlen(y)+1 ))!=0 ){
  4400         -    strcpy(z,y);
         4346  +  if( z==0 && (cpy=(char *)malloc( lemonStrlen(y)+1 ))!=0 ){
         4347  +    strcpy(cpy,y);
         4348  +    z = cpy;
  4401   4349       Strsafe_insert(z);
  4402   4350     }
  4403   4351     MemoryCheck(z);
  4404   4352     return z;
  4405   4353   }
  4406   4354   
  4407   4355   /* There is one instance of the following structure for each
................................................................................
  4416   4364     struct s_x1node **ht;  /* Hash table for lookups */
  4417   4365   };
  4418   4366   
  4419   4367   /* There is one instance of this structure for every data element
  4420   4368   ** in an associative array of type "x1".
  4421   4369   */
  4422   4370   typedef struct s_x1node {
  4423         -  char *data;                  /* The data */
         4371  +  const char *data;        /* The data */
  4424   4372     struct s_x1node *next;   /* Next entry with the same hash */
  4425   4373     struct s_x1node **from;  /* Previous link */
  4426   4374   } x1node;
  4427   4375   
  4428   4376   /* There is only one instance of the array, which is the following */
  4429   4377   static struct s_x1 *x1a;
  4430   4378   
................................................................................
  4445   4393         x1a->ht = (x1node**)&(x1a->tbl[1024]);
  4446   4394         for(i=0; i<1024; i++) x1a->ht[i] = 0;
  4447   4395       }
  4448   4396     }
  4449   4397   }
  4450   4398   /* Insert a new record into the array.  Return TRUE if successful.
  4451   4399   ** Prior data with the same key is NOT overwritten */
  4452         -int Strsafe_insert(data)
  4453         -char *data;
         4400  +int Strsafe_insert(const char *data)
  4454   4401   {
  4455   4402     x1node *np;
  4456   4403     int h;
  4457   4404     int ph;
  4458   4405   
  4459   4406     if( x1a==0 ) return 0;
  4460   4407     ph = strhash(data);
................................................................................
  4502   4449     x1a->ht[h] = np;
  4503   4450     np->from = &(x1a->ht[h]);
  4504   4451     return 1;
  4505   4452   }
  4506   4453   
  4507   4454   /* Return a pointer to data assigned to the given key.  Return NULL
  4508   4455   ** if no such key. */
  4509         -char *Strsafe_find(key)
  4510         -char *key;
         4456  +const char *Strsafe_find(const char *key)
  4511   4457   {
  4512   4458     int h;
  4513   4459     x1node *np;
  4514   4460   
  4515   4461     if( x1a==0 ) return 0;
  4516   4462     h = strhash(key) & (x1a->size-1);
  4517   4463     np = x1a->ht[h];
................................................................................
  4521   4467     }
  4522   4468     return np ? np->data : 0;
  4523   4469   }
  4524   4470   
  4525   4471   /* Return a pointer to the (terminal or nonterminal) symbol "x".
  4526   4472   ** Create a new symbol if this is the first time "x" has been seen.
  4527   4473   */
  4528         -struct symbol *Symbol_new(x)
  4529         -char *x;
         4474  +struct symbol *Symbol_new(const char *x)
  4530   4475   {
  4531   4476     struct symbol *sp;
  4532   4477   
  4533   4478     sp = Symbol_find(x);
  4534   4479     if( sp==0 ){
  4535   4480       sp = (struct symbol *)calloc(1, sizeof(struct symbol) );
  4536   4481       MemoryCheck(sp);
................................................................................
  4558   4503   ** must sort before symbols that begin with lower case letters
  4559   4504   ** (non-terminals).  Other than that, the order does not matter.
  4560   4505   **
  4561   4506   ** We find experimentally that leaving the symbols in their original
  4562   4507   ** order (the order they appeared in the grammar file) gives the
  4563   4508   ** smallest parser tables in SQLite.
  4564   4509   */
  4565         -int Symbolcmpp(struct symbol **a, struct symbol **b){
         4510  +int Symbolcmpp(const void *_a, const void *_b)
         4511  +{
         4512  +  const struct symbol **a = (const struct symbol **) _a;
         4513  +  const struct symbol **b = (const struct symbol **) _b;
  4566   4514     int i1 = (**a).index + 10000000*((**a).name[0]>'Z');
  4567   4515     int i2 = (**b).index + 10000000*((**b).name[0]>'Z');
  4568   4516     assert( i1!=i2 || strcmp((**a).name,(**b).name)==0 );
  4569   4517     return i1-i2;
  4570   4518   }
  4571   4519   
  4572   4520   /* There is one instance of the following structure for each
................................................................................
  4581   4529     struct s_x2node **ht;  /* Hash table for lookups */
  4582   4530   };
  4583   4531   
  4584   4532   /* There is one instance of this structure for every data element
  4585   4533   ** in an associative array of type "x2".
  4586   4534   */
  4587   4535   typedef struct s_x2node {
  4588         -  struct symbol *data;                  /* The data */
  4589         -  char *key;                   /* The key */
         4536  +  struct symbol *data;     /* The data */
         4537  +  const char *key;         /* The key */
  4590   4538     struct s_x2node *next;   /* Next entry with the same hash */
  4591   4539     struct s_x2node **from;  /* Previous link */
  4592   4540   } x2node;
  4593   4541   
  4594   4542   /* There is only one instance of the array, which is the following */
  4595   4543   static struct s_x2 *x2a;
  4596   4544   
................................................................................
  4611   4559         x2a->ht = (x2node**)&(x2a->tbl[128]);
  4612   4560         for(i=0; i<128; i++) x2a->ht[i] = 0;
  4613   4561       }
  4614   4562     }
  4615   4563   }
  4616   4564   /* Insert a new record into the array.  Return TRUE if successful.
  4617   4565   ** Prior data with the same key is NOT overwritten */
  4618         -int Symbol_insert(data,key)
  4619         -struct symbol *data;
  4620         -char *key;
         4566  +int Symbol_insert(struct symbol *data, const char *key)
  4621   4567   {
  4622   4568     x2node *np;
  4623   4569     int h;
  4624   4570     int ph;
  4625   4571   
  4626   4572     if( x2a==0 ) return 0;
  4627   4573     ph = strhash(key);
................................................................................
  4671   4617     x2a->ht[h] = np;
  4672   4618     np->from = &(x2a->ht[h]);
  4673   4619     return 1;
  4674   4620   }
  4675   4621   
  4676   4622   /* Return a pointer to data assigned to the given key.  Return NULL
  4677   4623   ** if no such key. */
  4678         -struct symbol *Symbol_find(key)
  4679         -char *key;
         4624  +struct symbol *Symbol_find(const char *key)
  4680   4625   {
  4681   4626     int h;
  4682   4627     x2node *np;
  4683   4628   
  4684   4629     if( x2a==0 ) return 0;
  4685   4630     h = strhash(key) & (x2a->size-1);
  4686   4631     np = x2a->ht[h];
................................................................................
  4688   4633       if( strcmp(np->key,key)==0 ) break;
  4689   4634       np = np->next;
  4690   4635     }
  4691   4636     return np ? np->data : 0;
  4692   4637   }
  4693   4638   
  4694   4639   /* Return the n-th data.  Return NULL if n is out of range. */
  4695         -struct symbol *Symbol_Nth(n)
  4696         -int n;
         4640  +struct symbol *Symbol_Nth(int n)
  4697   4641   {
  4698   4642     struct symbol *data;
  4699   4643     if( x2a && n>0 && n<=x2a->count ){
  4700   4644       data = x2a->tbl[n-1].data;
  4701   4645     }else{
  4702   4646       data = 0;
  4703   4647     }
................................................................................
  4723   4667     if( array ){
  4724   4668       for(i=0; i<size; i++) array[i] = x2a->tbl[i].data;
  4725   4669     }
  4726   4670     return array;
  4727   4671   }
  4728   4672   
  4729   4673   /* Compare two configurations */
  4730         -int Configcmp(a,b)
  4731         -struct config *a;
  4732         -struct config *b;
         4674  +int Configcmp(const char *_a,const char *_b)
  4733   4675   {
         4676  +  const struct config *a = (struct config *) _a;
         4677  +  const struct config *b = (struct config *) _b;
  4734   4678     int x;
  4735   4679     x = a->rp->index - b->rp->index;
  4736   4680     if( x==0 ) x = a->dot - b->dot;
  4737   4681     return x;
  4738   4682   }
  4739   4683   
  4740   4684   /* Compare two states */
  4741         -PRIVATE int statecmp(a,b)
  4742         -struct config *a;
  4743         -struct config *b;
         4685  +PRIVATE int statecmp(struct config *a, struct config *b)
  4744   4686   {
  4745   4687     int rc;
  4746   4688     for(rc=0; rc==0 && a && b;  a=a->bp, b=b->bp){
  4747   4689       rc = a->rp->index - b->rp->index;
  4748   4690       if( rc==0 ) rc = a->dot - b->dot;
  4749   4691     }
  4750   4692     if( rc==0 ){
................................................................................
  4751   4693       if( a ) rc = 1;
  4752   4694       if( b ) rc = -1;
  4753   4695     }
  4754   4696     return rc;
  4755   4697   }
  4756   4698   
  4757   4699   /* Hash a state */
  4758         -PRIVATE int statehash(a)
  4759         -struct config *a;
         4700  +PRIVATE int statehash(struct config *a)
  4760   4701   {
  4761   4702     int h=0;
  4762   4703     while( a ){
  4763   4704       h = h*571 + a->rp->index*37 + a->dot;
  4764   4705       a = a->bp;
  4765   4706     }
  4766   4707     return h;
  4767   4708   }
  4768   4709   
  4769   4710   /* Allocate a new state structure */
  4770   4711   struct state *State_new()
  4771   4712   {
  4772         -  struct state *new;
  4773         -  new = (struct state *)calloc(1, sizeof(struct state) );
  4774         -  MemoryCheck(new);
  4775         -  return new;
         4713  +  struct state *newstate;
         4714  +  newstate = (struct state *)calloc(1, sizeof(struct state) );
         4715  +  MemoryCheck(newstate);
         4716  +  return newstate;
  4776   4717   }
  4777   4718   
  4778   4719   /* There is one instance of the following structure for each
  4779   4720   ** associative array of type "x3".
  4780   4721   */
  4781   4722   struct s_x3 {
  4782   4723     int size;               /* The number of available slots. */
................................................................................
  4817   4758         x3a->ht = (x3node**)&(x3a->tbl[128]);
  4818   4759         for(i=0; i<128; i++) x3a->ht[i] = 0;
  4819   4760       }
  4820   4761     }
  4821   4762   }
  4822   4763   /* Insert a new record into the array.  Return TRUE if successful.
  4823   4764   ** Prior data with the same key is NOT overwritten */
  4824         -int State_insert(data,key)
  4825         -struct state *data;
  4826         -struct config *key;
         4765  +int State_insert(struct state *data, struct config *key)
  4827   4766   {
  4828   4767     x3node *np;
  4829   4768     int h;
  4830   4769     int ph;
  4831   4770   
  4832   4771     if( x3a==0 ) return 0;
  4833   4772     ph = statehash(key);
................................................................................
  4877   4816     x3a->ht[h] = np;
  4878   4817     np->from = &(x3a->ht[h]);
  4879   4818     return 1;
  4880   4819   }
  4881   4820   
  4882   4821   /* Return a pointer to data assigned to the given key.  Return NULL
  4883   4822   ** if no such key. */
  4884         -struct state *State_find(key)
  4885         -struct config *key;
         4823  +struct state *State_find(struct config *key)
  4886   4824   {
  4887   4825     int h;
  4888   4826     x3node *np;
  4889   4827   
  4890   4828     if( x3a==0 ) return 0;
  4891   4829     h = statehash(key) & (x3a->size-1);
  4892   4830     np = x3a->ht[h];
................................................................................
  4910   4848     if( array ){
  4911   4849       for(i=0; i<size; i++) array[i] = x3a->tbl[i].data;
  4912   4850     }
  4913   4851     return array;
  4914   4852   }
  4915   4853   
  4916   4854   /* Hash a configuration */
  4917         -PRIVATE int confighash(a)
  4918         -struct config *a;
         4855  +PRIVATE int confighash(struct config *a)
  4919   4856   {
  4920   4857     int h=0;
  4921   4858     h = h*571 + a->rp->index*37 + a->dot;
  4922   4859     return h;
  4923   4860   }
  4924   4861   
  4925   4862   /* There is one instance of the following structure for each
................................................................................
  4963   4900         x4a->ht = (x4node**)&(x4a->tbl[64]);
  4964   4901         for(i=0; i<64; i++) x4a->ht[i] = 0;
  4965   4902       }
  4966   4903     }
  4967   4904   }
  4968   4905   /* Insert a new record into the array.  Return TRUE if successful.
  4969   4906   ** Prior data with the same key is NOT overwritten */
  4970         -int Configtable_insert(data)
  4971         -struct config *data;
         4907  +int Configtable_insert(struct config *data)
  4972   4908   {
  4973   4909     x4node *np;
  4974   4910     int h;
  4975   4911     int ph;
  4976   4912   
  4977   4913     if( x4a==0 ) return 0;
  4978   4914     ph = confighash(data);
  4979   4915     h = ph & (x4a->size-1);
  4980   4916     np = x4a->ht[h];
  4981   4917     while( np ){
  4982         -    if( Configcmp(np->data,data)==0 ){
         4918  +    if( Configcmp((const char *) np->data,(const char *) data)==0 ){
  4983   4919         /* An existing entry with the same key is found. */
  4984   4920         /* Fail because overwrite is not allows. */
  4985   4921         return 0;
  4986   4922       }
  4987   4923       np = np->next;
  4988   4924     }
  4989   4925     if( x4a->count>=x4a->size ){
................................................................................
  5020   4956     x4a->ht[h] = np;
  5021   4957     np->from = &(x4a->ht[h]);
  5022   4958     return 1;
  5023   4959   }
  5024   4960   
  5025   4961   /* Return a pointer to data assigned to the given key.  Return NULL
  5026   4962   ** if no such key. */
  5027         -struct config *Configtable_find(key)
  5028         -struct config *key;
         4963  +struct config *Configtable_find(struct config *key)
  5029   4964   {
  5030   4965     int h;
  5031   4966     x4node *np;
  5032   4967   
  5033   4968     if( x4a==0 ) return 0;
  5034   4969     h = confighash(key) & (x4a->size-1);
  5035   4970     np = x4a->ht[h];
  5036   4971     while( np ){
  5037         -    if( Configcmp(np->data,key)==0 ) break;
         4972  +    if( Configcmp((const char *) np->data,(const char *) key)==0 ) break;
  5038   4973       np = np->next;
  5039   4974     }
  5040   4975     return np ? np->data : 0;
  5041   4976   }
  5042   4977   
  5043   4978   /* Remove all data from the table.  Pass each data to the function "f"
  5044   4979   ** as it is removed.  ("f" may be null to avoid this step.) */
  5045         -void Configtable_clear(f)
  5046         -int(*f)(/* struct config * */);
         4980  +void Configtable_clear(int(*f)(struct config *))
  5047   4981   {
  5048   4982     int i;
  5049   4983     if( x4a==0 || x4a->count==0 ) return;
  5050   4984     if( f ) for(i=0; i<x4a->count; i++) (*f)(x4a->tbl[i].data);
  5051   4985     for(i=0; i<x4a->size; i++) x4a->ht[i] = 0;
  5052   4986     x4a->count = 0;
  5053   4987     return;
  5054   4988   }