aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-02-15 06:01:23 +0000
committerGuy Harris <guy@alum.mit.edu>2001-02-15 06:01:23 +0000
commitefabd0321522b6fff1bc47ee191a2f34622a939b (patch)
tree99b21c2dbb0db4ec0fd540ef4a1c65aa6025de96
parent737add8165cf211ab9072dedd4d73ef563e49c02 (diff)
Change "lemon" *NOT* to cast pointers to "int", as that doesn't work on
LP64 platforms. Change "lemon" to use function prototypes and the official ANSI C style of variable-argument-list functions, and to include various system header files rather than to use non-prototype declaration of various system functions, to do a lot more type checking. svn path=/trunk/; revision=3037
-rw-r--r--tools/lemon/lemon.c595
1 files changed, 232 insertions, 363 deletions
diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c
index b3cca8df79..b99b0de646 100644
--- a/tools/lemon/lemon.c
+++ b/tools/lemon/lemon.c
@@ -25,10 +25,11 @@
** drh@acm.org
** http://www.hwaci.com/drh/
**
-** $Id: lemon.c,v 1.2 2001/02/01 21:46:48 guy Exp $
+** $Id: lemon.c,v 1.3 2001/02/15 06:01:23 guy Exp $
*/
#include <stdio.h>
-#include <varargs.h>
+#include <stdarg.h>
+#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -43,12 +44,7 @@
#define safe_isalnum(c) isalnum((unsigned char)(c))
#define safe_isspace(c) isspace((unsigned char)(c))
-extern void qsort();
-extern double strtod();
-extern long strtol();
-extern void free();
-extern int access();
-extern int atoi();
+extern int access(const char *, int);
#ifndef __WIN32__
# if defined(_WIN32) || defined(WIN32)
@@ -65,84 +61,8 @@ extern int atoi();
#define MAXRHS 1000
#endif
-char *msort();
-extern void *malloc();
+char *msort(char *, char **, int (*)(void *, void *));
-/******** From the file "action.h" *************************************/
-struct action *Action_new();
-struct action *Action_sort();
-void Action_add();
-
-/********* From the file "assert.h" ************************************/
-void myassert();
-#ifndef NDEBUG
-# define assert(X) if(!(X))myassert(__FILE__,__LINE__)
-#else
-# define assert(X)
-#endif
-
-/********** From the file "build.h" ************************************/
-void FindRulePrecedences();
-void FindFirstSets();
-void FindStates();
-void FindLinks();
-void FindFollowSets();
-void FindActions();
-
-/********* From the file "configlist.h" *********************************/
-void Configlist_init(/* void */);
-struct config *Configlist_add(/* struct rule *, int */);
-struct config *Configlist_addbasis(/* struct rule *, int */);
-void Configlist_closure(/* void */);
-void Configlist_sort(/* void */);
-void Configlist_sortbasis(/* void */);
-struct config *Configlist_return(/* void */);
-struct config *Configlist_basis(/* void */);
-void Configlist_eat(/* struct config * */);
-void Configlist_reset(/* void */);
-
-/********* From the file "error.h" ***************************************/
-void ErrorMsg( /* char *, int, char *, ... */ );
-
-/****** From the file "option.h" ******************************************/
-struct s_options {
- enum { OPT_FLAG=1, OPT_INT, OPT_DBL, OPT_STR,
- OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR} type;
- char *label;
- char *arg;
- char *message;
-};
-int optinit(/* char**,struct s_options*,FILE* */);
-int optnargs(/* void */);
-char *get_optarg(/* int */);
-void get_opterr(/* int */);
-void optprint(/* void */);
-
-/******** From the file "parse.h" *****************************************/
-void Parse(/* struct lemon *lemp */);
-
-/********* From the file "plink.h" ***************************************/
-struct plink *Plink_new(/* void */);
-void Plink_add(/* struct plink **, struct config * */);
-void Plink_copy(/* struct plink **, struct plink * */);
-void Plink_delete(/* struct plink * */);
-
-/********** From the file "report.h" *************************************/
-void Reprint(/* struct lemon * */);
-void ReportOutput(/* struct lemon * */);
-void ReportTable(/* struct lemon * */);
-void ReportHeader(/* struct lemon * */);
-void CompressTables(/* struct lemon * */);
-
-/********** From the file "set.h" ****************************************/
-void SetSize(/* int N */); /* All sets will be of size N */
-char *SetNew(/* void */); /* A new set for element 0..N */
-void SetFree(/* char* */); /* Deallocate a set */
-
-int SetAdd(/* char*,int */); /* Add element to a set */
-int SetUnion(/* char *A,char *B */); /* A <- A U B, thru element N */
-
-#define SetFind(X,Y) (X[Y]) /* True if Y is in set X */
/********** From the file "struct.h" *************************************/
/*
@@ -305,10 +225,86 @@ struct lemon {
};
#define MemoryCheck(X) if((X)==0){ \
- extern void memory_error(); \
+ extern void memory_error(void); \
memory_error(); \
}
+/******** From the file "action.h" *************************************/
+struct action *Action_new(void);
+struct action *Action_sort(struct action *);
+void Action_add(struct action **, enum e_action, struct symbol *, void *);
+
+/********* From the file "assert.h" ************************************/
+void myassert(char *, int);
+#ifndef NDEBUG
+# define assert(X) if(!(X))myassert(__FILE__,__LINE__)
+#else
+# define assert(X)
+#endif
+
+/********** From the file "build.h" ************************************/
+void FindRulePrecedences(struct lemon *);
+void FindFirstSets(struct lemon *);
+void FindStates(struct lemon *);
+void FindLinks(struct lemon *);
+void FindFollowSets(struct lemon *);
+void FindActions(struct lemon *);
+
+/********* From the file "configlist.h" *********************************/
+void Configlist_init(void);
+struct config *Configlist_add(struct rule *, int);
+struct config *Configlist_addbasis(struct rule *, int);
+void Configlist_closure(struct lemon *);
+void Configlist_sort(void);
+void Configlist_sortbasis(void);
+struct config *Configlist_return(void);
+struct config *Configlist_basis(void);
+void Configlist_eat(struct config *);
+void Configlist_reset(void);
+
+/********* From the file "error.h" ***************************************/
+void ErrorMsg( char *, int, char *, ... );
+
+/****** From the file "option.h" ******************************************/
+struct s_options {
+ enum { OPT_FLAG=1, OPT_INT, OPT_DBL, OPT_STR,
+ OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR} type;
+ char *label;
+ char *arg;
+ char *message;
+};
+int optinit(char**,struct s_options*,FILE*);
+int optnargs(void);
+char *get_optarg(int);
+void get_opterr(int);
+void optprint(void);
+
+/******** From the file "parse.h" *****************************************/
+void Parse(struct lemon *lemp);
+
+/********* From the file "plink.h" ***************************************/
+struct plink *Plink_new(void);
+void Plink_add(struct plink **, struct config *);
+void Plink_copy(struct plink **, struct plink *);
+void Plink_delete(struct plink *);
+
+/********** From the file "report.h" *************************************/
+void Reprint(struct lemon *);
+void ReportOutput(struct lemon *);
+void ReportTable(struct lemon *, int);
+void ReportHeader(struct lemon *);
+void CompressTables(struct lemon *);
+
+/********** From the file "set.h" ****************************************/
+void SetSize(int N); /* All sets will be of size N */
+char *SetNew(void); /* A new set for element 0..N */
+void SetFree(char*); /* Deallocate a set */
+
+int SetAdd(char*,int); /* Add element to a set */
+int SetUnion(char *A,char *B); /* A <- A U B, thru element N */
+
+#define SetFind(X,Y) (X[Y]) /* True if Y is in set X */
+
/**************** From the file "table.h" *********************************/
/*
** All code in this file has been automatically generated
@@ -324,45 +320,45 @@ struct lemon {
/* Routines for handling a strings */
-char *Strsafe();
+char *Strsafe(char *);
-void Strsafe_init(/* void */);
-int Strsafe_insert(/* char * */);
-char *Strsafe_find(/* char * */);
+void Strsafe_init(void);
+int Strsafe_insert(char *);
+char *Strsafe_find(char *);
/* Routines for handling symbols of the grammar */
-struct symbol *Symbol_new();
-int Symbolcmpp(/* struct symbol **, struct symbol ** */);
-void Symbol_init(/* void */);
-int Symbol_insert(/* struct symbol *, char * */);
-struct symbol *Symbol_find(/* char * */);
-struct symbol *Symbol_Nth(/* int */);
-int Symbol_count(/* */);
-struct symbol **Symbol_arrayof(/* */);
+struct symbol *Symbol_new(char *x);
+int Symbolcmpp(struct symbol **, struct symbol **);
+void Symbol_init(void);
+int Symbol_insert(struct symbol *, char *);
+struct symbol *Symbol_find(char *);
+struct symbol *Symbol_Nth(int);
+int Symbol_count(void);
+struct symbol **Symbol_arrayof(void);
/* Routines to manage the state table */
-int Configcmp(/* struct config *, struct config * */);
-struct state *State_new();
-void State_init(/* void */);
-int State_insert(/* struct state *, struct config * */);
-struct state *State_find(/* struct config * */);
-struct state **State_arrayof(/* */);
+int Configcmp(void *, void *);
+struct state *State_new(void);
+void State_init(void);
+int State_insert(struct state *, struct config *);
+struct state *State_find(struct config *);
+struct state **State_arrayof(void);
/* Routines used for efficiency in Configlist_add */
-void Configtable_init(/* void */);
-int Configtable_insert(/* struct config * */);
-struct config *Configtable_find(/* struct config * */);
-void Configtable_clear(/* int(*)(struct config *) */);
+void Configtable_init(void);
+int Configtable_insert(struct config *);
+struct config *Configtable_find(struct config *);
+void Configtable_clear(int(*)(struct config *));
/****************** From the file "action.c" *******************************/
/*
** Routines processing parser actions in the LEMON parser generator.
*/
/* Allocate a new parser action */
-struct action *Action_new(){
+struct action *Action_new(void){
static struct action *freelist = 0;
struct action *new;
@@ -383,10 +379,9 @@ struct action *Action_new(){
}
/* Compare two actions */
-static int actioncmp(ap1,ap2)
-struct action *ap1;
-struct action *ap2;
+static int actioncmp(void *ap1_arg, void *ap2_arg)
{
+ struct action *ap1 = ap1_arg, *ap2 = ap2_arg;
int rc;
rc = ap1->sp->index - ap2->sp->index;
if( rc==0 ) rc = (int)ap1->type - (int)ap2->type;
@@ -398,18 +393,14 @@ struct action *ap2;
}
/* Sort parser actions */
-struct action *Action_sort(ap)
-struct action *ap;
+struct action *Action_sort(struct action *ap)
{
- ap = (struct action *)msort(ap,&ap->next,actioncmp);
+ ap = (struct action *)msort((char *)ap,(char **)&ap->next,actioncmp);
return ap;
}
-void Action_add(app,type,sp,arg)
-struct action **app;
-enum e_action type;
-struct symbol *sp;
-char *arg;
+void Action_add(struct action **app, enum e_action type, struct symbol *sp,
+ void *arg)
{
struct action *new;
new = Action_new();
@@ -427,9 +418,7 @@ char *arg;
/*
** A more efficient way of handling assertions.
*/
-void myassert(file,line)
-char *file;
-int line;
+void myassert(char *file, int line)
{
fprintf(stderr,"Assertion failed on line %d of file \"%s\"\n",line,file);
exit(1);
@@ -449,8 +438,7 @@ int line;
** are not RHS symbols with a defined precedence, the precedence
** symbol field is left blank.
*/
-void FindRulePrecedences(xp)
-struct lemon *xp;
+void FindRulePrecedences(struct lemon *xp)
{
struct rule *rp;
for(rp=xp->rule; rp; rp=rp->next){
@@ -472,8 +460,7 @@ struct lemon *xp;
** The first set is the set of all terminal symbols which can begin
** a string generated by that nonterminal.
*/
-void FindFirstSets(lemp)
-struct lemon *lemp;
+void FindFirstSets(struct lemon *lemp)
{
int i;
struct rule *rp;
@@ -528,7 +515,7 @@ struct lemon *lemp;
** are added to between some states so that the LR(1) follow sets
** can be computed later.
*/
-PRIVATE struct state *getstate(/* struct lemon * */); /* forward reference */
+PRIVATE struct state *getstate(struct lemon *); /* forward reference */
void FindStates(lemp)
struct lemon *lemp;
{
@@ -587,9 +574,8 @@ does not work properly.",sp->name);
/* Return a pointer to a state which is described by the configuration
** list which has been built from calls to Configlist_add.
*/
-PRIVATE void buildshifts(/* struct lemon *, struct state * */); /* Forwd ref */
-PRIVATE struct state *getstate(lemp)
-struct lemon *lemp;
+PRIVATE void buildshifts(struct lemon *, struct state *); /* Forwd ref */
+PRIVATE struct state *getstate(struct lemon *lemp)
{
struct config *cfp, *bp;
struct state *stp;
@@ -633,9 +619,9 @@ struct lemon *lemp;
/* Construct all successor states to the given state. A "successor"
** state is any state which can be reached by a shift action.
*/
-PRIVATE void buildshifts(lemp,stp)
-struct lemon *lemp;
-struct state *stp; /* The state from which successors are computed */
+PRIVATE void buildshifts(
+ struct lemon *lemp,
+ struct state *stp) /* The state from which successors are computed */
{
struct config *cfp; /* For looping thru the config closure of "stp" */
struct config *bcfp; /* For the inner loop on config closure of "stp" */
@@ -681,8 +667,7 @@ struct state *stp; /* The state from which successors are computed */
/*
** Construct the propagation links
*/
-void FindLinks(lemp)
-struct lemon *lemp;
+void FindLinks(struct lemon *lemp)
{
int i;
struct config *cfp, *other;
@@ -717,8 +702,7 @@ struct lemon *lemp;
** A followset is the set of all symbols which can come immediately
** after a configuration.
*/
-void FindFollowSets(lemp)
-struct lemon *lemp;
+void FindFollowSets(struct lemon *lemp)
{
int i;
struct config *cfp;
@@ -750,12 +734,11 @@ struct lemon *lemp;
}while( progress );
}
-static int resolve_conflict();
+static int resolve_conflict(struct action *, struct action *, struct symbol *);
/* Compute the reduce actions, and resolve conflicts.
*/
-void FindActions(lemp)
-struct lemon *lemp;
+void FindActions(struct lemon *lemp)
{
int i,j;
struct config *cfp;
@@ -838,10 +821,10 @@ struct lemon *lemp;
** If either action is a SHIFT, then it must be apx. This
** function won't work if apx->type==REDUCE and apy->type==SHIFT.
*/
-static int resolve_conflict(apx,apy,errsym)
-struct action *apx;
-struct action *apy;
-struct symbol *errsym; /* The error symbol (if defined. NULL otherwise) */
+static int resolve_conflict(
+ struct action *apx,
+ struct action *apy,
+ struct symbol *errsym) /* The error symbol (if defined. NULL otherwise) */
{
struct symbol *spx, *spy;
int errcnt = 0;
@@ -898,7 +881,7 @@ static struct config *basis = 0; /* Top of list of basis configs */
static struct config **basisend = 0; /* End of list of basis configs */
/* Return a pointer to a new configuration */
-PRIVATE struct config *newconfig(){
+PRIVATE struct config *newconfig(void){
struct config *new;
if( freelist==0 ){
int i;
@@ -917,15 +900,14 @@ PRIVATE struct config *newconfig(){
}
/* The configuration "old" is no longer used */
-PRIVATE void deleteconfig(old)
-struct config *old;
+PRIVATE void deleteconfig(struct config *old)
{
old->next = freelist;
freelist = old;
}
/* Initialized the configuration list builder */
-void Configlist_init(){
+void Configlist_init(void){
current = 0;
currentend = &current;
basis = 0;
@@ -935,7 +917,7 @@ void Configlist_init(){
}
/* Initialized the configuration list builder */
-void Configlist_reset(){
+void Configlist_reset(void){
current = 0;
currentend = &current;
basis = 0;
@@ -945,9 +927,9 @@ void Configlist_reset(){
}
/* Add another configuration to the configuration list */
-struct config *Configlist_add(rp,dot)
-struct rule *rp; /* The rule */
-int dot; /* Index into the RHS of the rule where the dot goes */
+struct config *Configlist_add(
+ struct rule *rp, /* The rule */
+ int dot) /* Index into the RHS of the rule where the dot goes */
{
struct config *cfp, model;
@@ -972,9 +954,7 @@ int dot; /* Index into the RHS of the rule where the dot goes */
}
/* Add a basis configuration to the configuration list */
-struct config *Configlist_addbasis(rp,dot)
-struct rule *rp;
-int dot;
+struct config *Configlist_addbasis(struct rule *rp, int dot)
{
struct config *cfp, model;
@@ -1002,8 +982,7 @@ int dot;
}
/* Compute the closure of the configuration list */
-void Configlist_closure(lemp)
-struct lemon *lemp;
+void Configlist_closure(struct lemon *lemp)
{
struct config *cfp, *newcfp;
struct rule *rp, *newrp;
@@ -1042,22 +1021,22 @@ struct lemon *lemp;
}
/* Sort the configuration list */
-void Configlist_sort(){
- current = (struct config *)msort(current,&(current->next),Configcmp);
+void Configlist_sort(void){
+ current = (struct config *)msort((char *)current,(char **)&(current->next),Configcmp);
currentend = 0;
return;
}
/* Sort the basis configuration list */
-void Configlist_sortbasis(){
- basis = (struct config *)msort(current,&(current->bp),Configcmp);
+void Configlist_sortbasis(void){
+ basis = (struct config *)msort((char *)current,(char **)&(current->bp),Configcmp);
basisend = 0;
return;
}
/* Return a pointer to the head of the configuration list and
** reset the list */
-struct config *Configlist_return(){
+struct config *Configlist_return(void){
struct config *old;
old = current;
current = 0;
@@ -1067,7 +1046,7 @@ struct config *Configlist_return(){
/* Return a pointer to the head of the configuration list and
** reset the list */
-struct config *Configlist_basis(){
+struct config *Configlist_basis(void){
struct config *old;
old = basis;
basis = 0;
@@ -1076,8 +1055,7 @@ struct config *Configlist_basis(){
}
/* Free all elements of the given configuration list */
-void Configlist_eat(cfp)
-struct config *cfp;
+void Configlist_eat(struct config *cfp)
{
struct config *nextcfp;
for(; cfp; cfp=nextcfp){
@@ -1097,10 +1075,7 @@ struct config *cfp;
/* Find a good place to break "msg" so that its length is at least "min"
** but no more than "max". Make the point as close to max as possible.
*/
-static int findbreak(msg,min,max)
-char *msg;
-int min;
-int max;
+static int findbreak(char *msg, int min, int max)
{
int i,spot;
char c;
@@ -1123,12 +1098,8 @@ int max;
#define ERRMSGSIZE 10000 /* Hope this is big enough. No way to error check */
#define LINEWIDTH 79 /* Max width of any output line */
#define PREFIXLIMIT 30 /* Max width of the prefix on each line */
-void ErrorMsg(va_alist)
-va_dcl
+void ErrorMsg(char *filename, int lineno, char *format, ...)
{
- char *filename;
- int lineno;
- char *format;
char errmsg[ERRMSGSIZE];
char prefix[PREFIXLIMIT+10];
int errmsgsize;
@@ -1137,10 +1108,7 @@ va_dcl
va_list ap;
int end, restart, base;
- va_start(ap);
- filename = va_arg(ap,char*);
- lineno = va_arg(ap,int);
- format = va_arg(ap,char*);
+ va_start(ap, format);
/* Prepare a prefix to be prepended to every output line */
if( lineno>0 ){
sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno);
@@ -1177,7 +1145,7 @@ va_dcl
/* Report an out-of-memory condition and abort. This function
** is used mostly by the "MemoryCheck" macro in struct.h
*/
-void memory_error(){
+void memory_error(void){
fprintf(stderr,"Out of memory. Aborting...\n");
exit(1);
}
@@ -1221,9 +1189,7 @@ make_basename(char* fullname)
/* The main program. Parse the command line and do it... */
-int main(argc,argv)
-int argc;
-char **argv;
+int main(int argc, char **argv)
{
static int version = 0;
static int rpflag = 0;
@@ -1381,7 +1347,7 @@ char **argv;
/*
** Return a pointer to the next structure in the linked list.
*/
-#define NEXT(A) (*(char**)(((int)A)+offset))
+#define NEXT(A) (*(char**)(((char *)A)+offset))
/*
** Inputs:
@@ -1398,11 +1364,7 @@ char **argv;
** The "next" pointers for elements in the lists a and b are
** changed.
*/
-static char *merge(a,b,cmp,offset)
-char *a;
-char *b;
-int (*cmp)();
-int offset;
+static char *merge(char *a, char *b, int (*cmp)(void *, void *), int offset)
{
char *ptr, *head;
@@ -1450,16 +1412,13 @@ int offset;
** The "next" pointers for elements in list are changed.
*/
#define LISTSIZE 30
-char *msort(list,next,cmp)
-char *list;
-char **next;
-int (*cmp)();
+char *msort(char *list, char **next, int (*cmp)(void *, void *))
{
int offset;
char *ep;
char *set[LISTSIZE];
int i;
- offset = (int)next - (int)list;
+ offset = (char *)next - (char *)list;
for(i=0; i<LISTSIZE; i++) set[i] = 0;
while( list ){
ep = list;
@@ -1486,10 +1445,7 @@ static FILE *errstream;
** Print the command line with a carrot pointing to the k-th character
** of the n-th field.
*/
-static void errline(n,k,err)
-int n;
-int k;
-FILE *err;
+static void errline(int n, int k, FILE *err)
{
int spcnt, i;
spcnt = 0;
@@ -1512,8 +1468,7 @@ FILE *err;
** Return the index of the N-th non-switch argument. Return -1
** if N is out of range.
*/
-static int argindex(n)
-int n;
+static int argindex(int n)
{
int i;
int dashdash = 0;
@@ -1534,9 +1489,7 @@ static char emsg[] = "Command line syntax error: ";
/*
** Process a flag command line argument.
*/
-static int handleflags(i,err)
-int i;
-FILE *err;
+static int handleflags(int i, FILE *err)
{
int v;
int errcnt = 0;
@@ -1568,9 +1521,7 @@ FILE *err;
/*
** Process a command line switch which has an argument.
*/
-static int handleswitch(i,err)
-int i;
-FILE *err;
+static int handleswitch(int i, FILE *err)
{
int lv = 0;
double dv = 0.0;
@@ -1607,7 +1558,7 @@ FILE *err;
if( *end ){
if( err ){
fprintf(err,"%sillegal character in floating-point argument.\n",emsg);
- errline(i,((int)end)-(int)argv[i],err);
+ errline(i,(int)(end-argv[i]),err);
}
errcnt++;
}
@@ -1618,7 +1569,7 @@ FILE *err;
if( *end ){
if( err ){
fprintf(err,"%sillegal character in integer argument.\n",emsg);
- errline(i,((int)end)-(int)argv[i],err);
+ errline(i,(int)(end-argv[i]),err);
}
errcnt++;
}
@@ -1655,10 +1606,7 @@ FILE *err;
return errcnt;
}
-int optinit(a,o,err)
-char **a;
-struct s_options *o;
-FILE *err;
+int optinit(char **a, struct s_options *o, FILE *err)
{
int errcnt = 0;
argv = a;
@@ -1682,7 +1630,7 @@ FILE *err;
return 0;
}
-int optnargs(){
+int optnargs(void){
int cnt = 0;
int dashdash = 0;
int i;
@@ -1695,23 +1643,21 @@ int optnargs(){
return cnt;
}
-char *get_optarg(n)
-int n;
+char *get_optarg(int n)
{
int i;
i = argindex(n);
return i>=0 ? argv[i] : 0;
}
-void get_opterr(n)
-int n;
+void get_opterr(int n)
{
int i;
i = argindex(n);
if( i>=0 ) errline(i,0,errstream);
}
-void optprint(){
+void optprint(void){
int i;
int max, len;
max = 0;
@@ -1808,8 +1754,7 @@ struct pstate {
};
/* Parse a single token */
-static void parseonetoken(psp)
-struct pstate *psp;
+static void parseonetoken(struct pstate *psp)
{
char *x;
x = Strsafe(psp->tokenstart); /* Save the token permanently */
@@ -2158,8 +2103,7 @@ to follow the previous rule.");
** token is passed to the function "parseonetoken" which builds all
** the appropriate data structures in the global state vector "gp".
*/
-void Parse(gp)
-struct lemon *gp;
+void Parse(struct lemon *gp)
{
struct pstate ps;
FILE *fp;
@@ -2304,7 +2248,7 @@ struct lemon *gp;
static struct plink *plink_freelist = 0;
/* Allocate a new plink */
-struct plink *Plink_new(){
+struct plink *Plink_new(void){
struct plink *new;
if( plink_freelist==0 ){
@@ -2325,9 +2269,7 @@ struct plink *Plink_new(){
}
/* Add a plink to a plink list */
-void Plink_add(plpp,cfp)
-struct plink **plpp;
-struct config *cfp;
+void Plink_add(struct plink **plpp, struct config *cfp)
{
struct plink *new;
new = Plink_new();
@@ -2337,9 +2279,7 @@ struct config *cfp;
}
/* Transfer every plink on the list "from" to the list "to" */
-void Plink_copy(to,from)
-struct plink **to;
-struct plink *from;
+void Plink_copy(struct plink **to, struct plink *from)
{
struct plink *nextpl;
while( from ){
@@ -2351,8 +2291,7 @@ struct plink *from;
}
/* Delete every plink on the list */
-void Plink_delete(plp)
-struct plink *plp;
+void Plink_delete(struct plink *plp)
{
struct plink *nextpl;
@@ -2372,9 +2311,7 @@ struct plink *plp;
** name comes from malloc() and must be freed by the calling
** function.
*/
-PRIVATE char *file_makename(pattern,suffix)
-char *pattern;
-char *suffix;
+PRIVATE char *file_makename(char *pattern, char *suffix)
{
char *name;
char *cp;
@@ -2397,9 +2334,7 @@ char *suffix;
** Space to hold this name comes from malloc() and must be
** freed by the calling function.
*/
-PRIVATE char *file_makename_using_basename(lemp,suffix)
-struct lemon *lemp;
-char *suffix;
+PRIVATE char *file_makename_using_basename(struct lemon *lemp, char *suffix)
{
return file_makename(lemp->basename, suffix);
}
@@ -2413,10 +2348,7 @@ char *suffix;
** side, we should add another arg to file_open() indicating which
** directory, ("input, "output", or "other") we should deal with.
*/
-PRIVATE FILE *file_open(lemp,suffix,mode)
-struct lemon *lemp;
-char *suffix;
-char *mode;
+PRIVATE FILE *file_open(struct lemon *lemp, char *suffix, char *mode)
{
FILE *fp;
char *name;
@@ -2454,8 +2386,7 @@ char *mode;
/* Duplicate the input file without comments and without actions
** on rules */
-void Reprint(lemp)
-struct lemon *lemp;
+void Reprint(struct lemon *lemp)
{
struct rule *rp;
struct symbol *sp;
@@ -2494,9 +2425,7 @@ struct lemon *lemp;
}
}
-void ConfigPrint(fp,cfp)
-FILE *fp;
-struct config *cfp;
+void ConfigPrint(FILE *fp, struct config *cfp)
{
struct rule *rp;
int i;
@@ -2512,10 +2441,7 @@ struct config *cfp;
/* #define TEST */
#ifdef TEST
/* Print a set */
-PRIVATE void SetPrint(out,set,lemp)
-FILE *out;
-char *set;
-struct lemon *lemp;
+PRIVATE void SetPrint(FILE *out, char *set, struct lemon *lemp)
{
int i;
char *spacer;
@@ -2531,10 +2457,7 @@ struct lemon *lemp;
}
/* Print a plink chain */
-PRIVATE void PlinkPrint(out,plp,tag)
-FILE *out;
-struct plink *plp;
-char *tag;
+PRIVATE void PlinkPrint(FILE *out, struct plink *plp, char *tag)
{
while( plp ){
fprintf(out,"%12s%s (state %2d) ","",tag,plp->cfp->stp->index);
@@ -2577,8 +2500,7 @@ int PrintAction(struct action *ap, FILE *fp, int indent){
}
/* Generate the "y.output" log file */
-void ReportOutput(lemp)
-struct lemon *lemp;
+void ReportOutput(struct lemon *lemp)
{
int i;
struct state *stp;
@@ -2624,15 +2546,11 @@ struct lemon *lemp;
/* Search for the file "name" which is in the same directory as
** the exacutable */
-PRIVATE char *pathsearch(argv0,name,modemask)
-char *argv0;
-char *name;
-int modemask;
+PRIVATE char *pathsearch(char *argv0, char *name, int modemask)
{
char *pathlist;
char *path,*cp;
char c;
- extern int access();
#ifdef __WIN32__
cp = strrchr(argv0,'\\');
@@ -2671,9 +2589,7 @@ int modemask;
** which is to be put in the action table of the generated machine.
** Return negative if no action should be generated.
*/
-PRIVATE int compute_action(lemp,ap)
-struct lemon *lemp;
-struct action *ap;
+PRIVATE int compute_action(struct lemon *lemp, struct action *ap)
{
int act;
switch( ap->type ){
@@ -2696,11 +2612,7 @@ struct action *ap;
** if name!=0, then any word that begin with "Parse" is changed to
** begin with *name instead.
*/
-PRIVATE void tplt_xfer(name,in,out,lineno)
-char *name;
-FILE *in;
-FILE *out;
-int *lineno;
+PRIVATE void tplt_xfer(char *name, FILE *in, FILE *out, int *lineno)
{
int i, iStart;
char line[LINESIZE];
@@ -2725,8 +2637,7 @@ int *lineno;
/* The next function finds the template file and opens it, returning
** a pointer to the opened file. */
-PRIVATE FILE *tplt_open(lemp)
-struct lemon *lemp;
+PRIVATE FILE *tplt_open(struct lemon *lemp)
{
static char templatename[] = "lempar.c";
char buf[1000];
@@ -2740,7 +2651,7 @@ struct lemon *lemp;
else {
cp = strrchr(lemp->filename,'.');
if( cp ){
- sprintf(buf,"%.*s.lt",(int)cp-(int)lemp->filename,lemp->filename);
+ sprintf(buf,"%.*s.lt",(int)(cp - lemp->filename),lemp->filename);
}else{
sprintf(buf,"%s.lt",lemp->filename);
}
@@ -2766,12 +2677,8 @@ struct lemon *lemp;
}
/* Print a string to the file and keep the linenumber up to date */
-PRIVATE void tplt_print(out,lemp,str,strln,lineno)
-FILE *out;
-struct lemon *lemp;
-char *str;
-int strln;
-int *lineno;
+PRIVATE void tplt_print(FILE *out, struct lemon *lemp, char *str,
+ int strln, int *lineno)
{
if( str==0 ) return;
fprintf(out,"#line %d \"%s\"\n",strln,lemp->filename); (*lineno)++;
@@ -2788,11 +2695,8 @@ int *lineno;
** The following routine emits code for the destructor for the
** symbol sp
*/
-void emit_destructor_code(out,sp,lemp,lineno)
-FILE *out;
-struct symbol *sp;
-struct lemon *lemp;
-int *lineno;
+void emit_destructor_code(FILE *out, struct symbol *sp, struct lemon *lemp,
+ int *lineno)
{
char *cp;
@@ -2823,9 +2727,7 @@ int *lineno;
/*
** Return TRUE (non-zero) if the given symbol has a distructor.
*/
-int has_destructor(sp, lemp)
-struct symbol *sp;
-struct lemon *lemp;
+int has_destructor(struct symbol *sp, struct lemon *lemp)
{
int ret;
if( sp->type==TERMINAL ){
@@ -2840,11 +2742,8 @@ struct lemon *lemp;
** Generate code which executes when the rule "rp" is reduced. Write
** the code to "out". Make sure lineno stays up-to-date.
*/
-PRIVATE void emit_code(out,rp,lemp,lineno)
-FILE *out;
-struct rule *rp;
-struct lemon *lemp;
-int *lineno;
+PRIVATE void emit_code(FILE *out, struct rule *rp, struct lemon *lemp,
+ int *lineno)
{
char *cp, *xp;
int linecnt = 0;
@@ -2924,11 +2823,11 @@ int *lineno;
** union, also set the ".dtnum" field of every terminal and nonterminal
** symbol.
*/
-void print_stack_union(out,lemp,plineno,mhflag)
-FILE *out; /* The output stream */
-struct lemon *lemp; /* The main info structure for this parser */
-int *plineno; /* Pointer to the line number */
-int mhflag; /* True if generating makeheaders output */
+void print_stack_union(
+ FILE *out, /* The output stream */
+ struct lemon *lemp, /* The main info structure for this parser */
+ int *plineno, /* Pointer to the line number */
+ int mhflag) /* True if generating makeheaders output */
{
int lineno = *plineno; /* The line number of the output */
char **types; /* A hash table of datatypes */
@@ -3025,9 +2924,9 @@ int mhflag; /* True if generating makeheaders output */
}
/* Generate C source code for the parser */
-void ReportTable(lemp, mhflag)
-struct lemon *lemp;
-int mhflag; /* Output in makeheaders format if true */
+void ReportTable(
+ struct lemon *lemp,
+ int mhflag) /* Output in makeheaders format if true */
{
FILE *out, *in;
char line[LINESIZE];
@@ -3311,8 +3210,7 @@ int mhflag; /* Output in makeheaders format if true */
}
/* Generate a header file for the parser */
-void ReportHeader(lemp)
-struct lemon *lemp;
+void ReportHeader(struct lemon *lemp)
{
FILE *out, *in;
char *prefix;
@@ -3350,8 +3248,7 @@ struct lemon *lemp;
** In this version, if all REDUCE actions use the same rule, make
** them the default. Only default them if there are more than one.
*/
-void CompressTables(lemp)
-struct lemon *lemp;
+void CompressTables(struct lemon *lemp)
{
struct state *stp;
struct action *ap;
@@ -3397,14 +3294,13 @@ struct lemon *lemp;
static int size = 0;
/* Set the set size */
-void SetSize(n)
-int n;
+void SetSize(int n)
{
size = n+1;
}
/* Allocate a new set */
-char *SetNew(){
+char *SetNew(void){
char *s;
int i;
s = (char*)malloc( size );
@@ -3417,17 +3313,14 @@ char *SetNew(){
}
/* Deallocate a set */
-void SetFree(s)
-char *s;
+void SetFree(char *s)
{
free(s);
}
/* Add a new element to the set. Return TRUE if the element was added
** and FALSE if it was already there. */
-int SetAdd(s,e)
-char *s;
-int e;
+int SetAdd(char *s, int e)
{
int rv;
rv = s[e];
@@ -3436,9 +3329,7 @@ int e;
}
/* Add every element of s2 to s1. Return TRUE if s1 changes. */
-int SetUnion(s1,s2)
-char *s1;
-char *s2;
+int SetUnion(char *s1, char *s2)
{
int i, progress;
progress = 0;
@@ -3464,8 +3355,7 @@ char *s2;
** Code for processing tables in the LEMON parser generator.
*/
-PRIVATE int strhash(x)
-char *x;
+PRIVATE int strhash(char *x)
{
int h = 0;
while( *x) h = h*13 + *(x++);
@@ -3476,8 +3366,7 @@ char *x;
** keep strings in a table so that the same string is not in more
** than one place.
*/
-char *Strsafe(y)
-char *y;
+char *Strsafe(char *y)
{
char *z;
@@ -3515,7 +3404,7 @@ typedef struct s_x1node {
static struct s_x1 *x1a;
/* Allocate a new associative array */
-void Strsafe_init(){
+void Strsafe_init(void){
if( x1a ) return;
x1a = (struct s_x1*)malloc( sizeof(struct s_x1) );
if( x1a ){
@@ -3535,8 +3424,7 @@ void Strsafe_init(){
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
-int Strsafe_insert(data)
-char *data;
+int Strsafe_insert(char *data)
{
x1node *np;
int h;
@@ -3592,8 +3480,7 @@ char *data;
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
-char *Strsafe_find(key)
-char *key;
+char *Strsafe_find(char *key)
{
int h;
x1node *np;
@@ -3611,8 +3498,7 @@ char *key;
/* Return a pointer to the (terminal or nonterminal) symbol "x".
** Create a new symbol if this is the first time "x" has been seen.
*/
-struct symbol *Symbol_new(x)
-char *x;
+struct symbol *Symbol_new(char *x)
{
struct symbol *sp;
@@ -3635,9 +3521,7 @@ char *x;
}
/* Compare two symbols */
-int Symbolcmpp(a,b)
-struct symbol **a;
-struct symbol **b;
+int Symbolcmpp(struct symbol **a, struct symbol **b)
{
return strcmp((**a).name,(**b).name);
}
@@ -3668,7 +3552,7 @@ typedef struct s_x2node {
static struct s_x2 *x2a;
/* Allocate a new associative array */
-void Symbol_init(){
+void Symbol_init(void){
if( x2a ) return;
x2a = (struct s_x2*)malloc( sizeof(struct s_x2) );
if( x2a ){
@@ -3688,9 +3572,7 @@ void Symbol_init(){
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
-int Symbol_insert(data,key)
-struct symbol *data;
-char *key;
+int Symbol_insert(struct symbol *data, char *key)
{
x2node *np;
int h;
@@ -3748,8 +3630,7 @@ char *key;
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
-struct symbol *Symbol_find(key)
-char *key;
+struct symbol *Symbol_find(char *key)
{
int h;
x2node *np;
@@ -3765,8 +3646,7 @@ char *key;
}
/* Return the n-th data. Return NULL if n is out of range. */
-struct symbol *Symbol_Nth(n)
-int n;
+struct symbol *Symbol_Nth(int n)
{
struct symbol *data;
if( x2a && n>0 && n<=x2a->count ){
@@ -3778,7 +3658,7 @@ int n;
}
/* Return the size of the array */
-int Symbol_count()
+int Symbol_count(void)
{
return x2a ? x2a->count : 0;
}
@@ -3786,7 +3666,7 @@ int Symbol_count()
/* Return an array of pointers to all data in the table.
** The array is obtained from malloc. Return NULL if memory allocation
** problems, or if the array is empty. */
-struct symbol **Symbol_arrayof()
+struct symbol **Symbol_arrayof(void)
{
struct symbol **array;
int i,size;
@@ -3800,10 +3680,9 @@ struct symbol **Symbol_arrayof()
}
/* Compare two configurations */
-int Configcmp(a,b)
-struct config *a;
-struct config *b;
+int Configcmp(void *a_arg, void *b_arg)
{
+ struct config *a = a_arg, *b = b_arg;
int x;
x = a->rp->index - b->rp->index;
if( x==0 ) x = a->dot - b->dot;
@@ -3811,9 +3690,7 @@ struct config *b;
}
/* Compare two states */
-PRIVATE int statecmp(a,b)
-struct config *a;
-struct config *b;
+PRIVATE int statecmp(struct config *a, struct config *b)
{
int rc;
for(rc=0; rc==0 && a && b; a=a->bp, b=b->bp){
@@ -3828,8 +3705,7 @@ struct config *b;
}
/* Hash a state */
-PRIVATE int statehash(a)
-struct config *a;
+PRIVATE int statehash(struct config *a)
{
int h=0;
while( a ){
@@ -3840,7 +3716,7 @@ struct config *a;
}
/* Allocate a new state structure */
-struct state *State_new()
+struct state *State_new(void)
{
struct state *new;
new = (struct state *)malloc( sizeof(struct state) );
@@ -3874,7 +3750,7 @@ typedef struct s_x3node {
static struct s_x3 *x3a;
/* Allocate a new associative array */
-void State_init(){
+void State_init(void){
if( x3a ) return;
x3a = (struct s_x3*)malloc( sizeof(struct s_x3) );
if( x3a ){
@@ -3894,9 +3770,7 @@ void State_init(){
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
-int State_insert(data,key)
-struct state *data;
-struct config *key;
+int State_insert(struct state *data, struct config *key)
{
x3node *np;
int h;
@@ -3954,8 +3828,7 @@ struct config *key;
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
-struct state *State_find(key)
-struct config *key;
+struct state *State_find(struct config *key)
{
int h;
x3node *np;
@@ -3973,7 +3846,7 @@ struct config *key;
/* Return an array of pointers to all data in the table.
** The array is obtained from malloc. Return NULL if memory allocation
** problems, or if the array is empty. */
-struct state **State_arrayof()
+struct state **State_arrayof(void)
{
struct state **array;
int i,size;
@@ -3987,8 +3860,7 @@ struct state **State_arrayof()
}
/* Hash a configuration */
-PRIVATE int confighash(a)
-struct config *a;
+PRIVATE int confighash(struct config *a)
{
int h=0;
h = h*571 + a->rp->index*37 + a->dot;
@@ -4020,7 +3892,7 @@ typedef struct s_x4node {
static struct s_x4 *x4a;
/* Allocate a new associative array */
-void Configtable_init(){
+void Configtable_init(void){
if( x4a ) return;
x4a = (struct s_x4*)malloc( sizeof(struct s_x4) );
if( x4a ){
@@ -4040,8 +3912,7 @@ void Configtable_init(){
}
/* Insert a new record into the array. Return TRUE if successful.
** Prior data with the same key is NOT overwritten */
-int Configtable_insert(data)
-struct config *data;
+int Configtable_insert(struct config *data)
{
x4node *np;
int h;
@@ -4097,8 +3968,7 @@ struct config *data;
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
-struct config *Configtable_find(key)
-struct config *key;
+struct config *Configtable_find(struct config *key)
{
int h;
x4node *np;
@@ -4115,8 +3985,7 @@ struct config *key;
/* Remove all data from the table. Pass each data to the function "f"
** as it is removed. ("f" may be null to avoid this step.) */
-void Configtable_clear(f)
-int(*f)(/* struct config * */);
+void Configtable_clear(int(*f)(struct config *))
{
int i;
if( x4a==0 || x4a->count==0 ) return;