From a656bb4f72c450f8feb66411402ab4b4e07ea019 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 20 Mar 2016 09:37:13 -0500 Subject: [PATCH] Lemon update 2010-02-14 00:48:50 on branch lemon-update-2010 - Added -T option, to specify a template filename on the command line. The default is still "lempar.c", though. (user: icculus) --- tools/lemon/lemon.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index ec16de534..ca928bd35 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -1446,6 +1446,14 @@ static void handle_D_option(char *z){ *z = 0; } +static char *user_templatename = NULL; +static void handle_T_option(char *z){ + user_templatename = malloc( lemonStrlen(z)+1 ); + if( user_templatename==0 ){ + memory_error(); + } + strcpy(user_templatename, z); +} /* The main program. Parse the command line and do it... */ int main(argc,argv) @@ -1464,6 +1472,7 @@ char **argv; {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."}, {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."}, {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."}, + {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."}, {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."}, {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."}, {OPT_FLAG, "l", (char*)&nolinenosflag, "Do not print #line statements."}, @@ -3147,6 +3156,23 @@ struct lemon *lemp; char *cp; Boolean tpltnameinbuf; + /* first, see if user specified a template filename on the command line. */ + if (user_templatename != 0) { + if( access(user_templatename,004)==-1 ){ + fprintf(stderr,"Can't find the parser driver template file \"%s\".\n", + user_templatename); + lemp->errorcnt++; + return 0; + } + in = fopen(user_templatename,"rb"); + if( in==0 ){ + fprintf(stderr,"Can't open the template file \"%s\".\n",user_templatename); + lemp->errorcnt++; + return 0; + } + return in; + } + cp = strrchr(lemp->filename,'.'); if( cp ){ sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename);