X-Git-Url: https://pd.if.org/git/?p=pccts;a=blobdiff_plain;f=support%2Fgenmk%2Fgenmk.c;fp=support%2Fgenmk%2Fgenmk.c;h=71516a644245043920d2e30e1b0c42b411f2c1fd;hp=0000000000000000000000000000000000000000;hb=56dd00148e59773742903ee71be791eaa49a8616;hpb=cb15b978c765a661bf3154d865fa3e2401d649f5 diff --git a/support/genmk/genmk.c b/support/genmk/genmk.c new file mode 100755 index 0000000..71516a6 --- /dev/null +++ b/support/genmk/genmk.c @@ -0,0 +1,681 @@ +/* + * genmk -- a program to make makefiles for PCCTS + * + * ANTLR 1.32 + * Terence John Parr 1989 - 1994 + * Purdue University + * U of MN + */ +#include +#include "config.h" /* be sensitive to what ANTLR/DLG call the files */ + +#ifdef VAXC +#define DIE return 0; +#define DONE return 1; +#else +#define DIE return 1; +#define DONE return 0; +#endif + +#ifndef require +#define require(expr, err) {if ( !(expr) ) fatal(err);} +#endif + +#define MAX_FILES 50 +#define MAX_CLASSES 50 + +char *RENAME_OBJ_FLAG="-o", + *RENAME_EXE_FLAG="-o"; + +char *dlg = "parser.dlg"; +char *err = "err.c"; +char *hdr = "stdpccts.h"; +char *tok = "tokens.h"; +char *mode = "mode.h"; +char *scan = "scan"; + +char ATOKENBUFFER_O[100]; +char APARSER_O[100]; +char ASTBASE_O[100]; +char PCCTSAST_O[100]; +char LIST_O[100]; +char DLEXERBASE_O[100]; + +/* Option flags */ +static char *project="t", *files[MAX_FILES], *classes[MAX_CLASSES]; +static int num_files = 0; +static int num_classes = 0; +static int user_lexer = 0; +static char *user_token_types = NULL; +static int gen_CPP = 0; +static char *outdir="."; +static char *dlg_class = "DLGLexer"; +static int gen_trees = 0; + +typedef struct _Opt { + char *option; + int arg; +#ifdef __cplusplus + void (*process)(...); +#else + void (*process)(); +#endif + char *descr; + } Opt; + +#ifdef __STDC__ +static void ProcessArgs(int, char **, Opt *); +#else +static void ProcessArgs(); +#endif + +static void +pProj( s, t ) +char *s; +char *t; +{ + project = t; +} + +static void +pUL( s ) +char *s; +{ + user_lexer = 1; +} + +static void +pCPP( s ) +char *s; +{ + gen_CPP = 1; +} + +static void +pUT( s, t ) +char *s; +char *t; +{ + user_token_types = t; +} + +static void +pTrees( s ) +char *s; +{ + gen_trees = 1; +} + +static void +#ifdef __STDC__ +pFile( char *s ) +#else +pFile( s ) +char *s; +#endif +{ + if ( *s=='-' ) + { + fprintf(stderr, "invalid option: '%s'; ignored...",s); + return; + } + + require(num_files0 ) { + warn("can't define classes w/o C++ mode; turning on C++ mode...\n"); + gen_CPP=1; + } + if ( gen_CPP && num_classes==0 ) { + fatal("must define classes >0 grammar classes in C++ mode\n"); + } + + mk(project, files, num_files, argc, argv); + DONE; +} + +help() +{ + Opt *p = options; + static char buf[1000+1]; + + fprintf(stderr, "genmk [options] f1.g ... fn.g\n"); + while ( p->option!=NULL && *(p->option) != '*' ) + { + buf[0]='\0'; + if ( p->arg ) sprintf(buf, "%s ___", p->option); + else strcpy(buf, p->option); + fprintf(stderr, "\t%-16s %s\n", buf, p->descr); + p++; + } +} + +mk(project, files, n, argc, argv) +char *project; +char **files; +int n; +int argc; +char **argv; +{ + int i; + + printf("#\n"); + printf("# PCCTS makefile for: "); + pfiles(files, n, NULL); + printf("\n"); + printf("#\n"); + printf("# Created from:"); + for (i=0; i0 ) + { + char *p = &(*files)[strlen(*files)-1]; + if ( !first ) putchar(' '); + first=0; + while ( p > *files && *p != '.' ) --p; + if ( p == *files ) + { + fprintf(stderr, + "genmk: filenames must be file.suffix format: %s\n", + *files); + exit(-1); + } + if ( suffix == NULL ) printf("%s", *files); + else + { + *p = '\0'; + printf("%s", DIR()); + if ( strcmp(suffix, "o")==0 ) printf("%s%s", *files, OBJ_FILE_SUFFIX); + else printf("%s.%s", *files, suffix); + *p = '.'; + } + files++; + --n; + } +} + +pclasses(classes, n, suffix) +char **classes; +int n; +char *suffix; +{ + int first=1; + + while ( n>0 ) + { + if ( !first ) putchar(' '); + first=0; + if ( suffix == NULL ) printf("%s", *classes); + else { + printf("%s", DIR()); + if ( strcmp(suffix, "o")==0 ) printf("%s%s", *classes, OBJ_FILE_SUFFIX); + else printf("%s.%s", *classes, suffix); + } + classes++; + --n; + } +} + +static void +#ifdef __STDC__ +ProcessArgs( int argc, char **argv, Opt *options ) +#else +ProcessArgs( argc, argv, options ) +int argc; +char **argv; +Opt *options; +#endif +{ + Opt *p; + require(argv!=NULL, "ProcessArgs: command line NULL"); + + while ( argc-- > 0 ) + { + p = options; + while ( p->option != NULL ) + { + if ( strcmp(p->option, "*") == 0 || + strcmp(p->option, *argv) == 0 ) + { + if ( p->arg ) + { + (*p->process)( *argv, *(argv+1) ); + argv++; + argc--; + } + else + (*p->process)( *argv ); + break; + } + p++; + } + argv++; + } +} + +fatal( err_) +char *err_; +{ + fprintf(stderr, "genmk: %s\n", err_); + exit(1); +} + +warn( err_) +char *err_; +{ + fprintf(stderr, "genmk: %s\n", err_); +} + +char *DIR() +{ + static char buf[200+1]; + + if ( strcmp(outdir,TopDirectory)==0 ) return ""; + sprintf(buf, "%s%s", outdir, DirectorySymbol); + return buf; +}