diff options
Diffstat (limited to 'src/interfaces/ecpg/preproc/ecpg.c')
-rw-r--r-- | src/interfaces/ecpg/preproc/ecpg.c | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 938559670f3..a49cc6b60d5 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -12,7 +12,9 @@ #include "extern.h" struct _include_path *include_paths; -int ret_value = OK, autocommit = 0; +struct _defines *defines = NULL; +int autocommit = 0; +int ret_value = OK; struct cursor *cur = NULL; struct typedefs *types = NULL; @@ -20,7 +22,7 @@ static void usage(char *progname) { fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); - fprintf(stderr, "Usage: %s: [-v] [-t] [-I include path] [ -o output file name] file1 [file2] ...\n", progname); + fprintf(stderr, "Usage: %s: [-v] [-t] [-I include path] [ -o output file name] [-D define name] file1 [file2] ...\n", progname); } static void @@ -33,6 +35,18 @@ add_include_path(char *path) include_paths->next = ip; } +static void +add_preprocessor_define(char *define) +{ + struct _defines *pd = defines; + + defines = mm_alloc(sizeof(struct _defines)); + defines->old = strdup(define); + defines->new = strdup(""); + defines->pertinent = true; + defines->next = pd; +} + int main(int argc, char *const argv[]) { @@ -46,7 +60,7 @@ main(int argc, char *const argv[]) add_include_path("/usr/local/include"); add_include_path("."); - while ((c = getopt(argc, argv, "vo:I:t")) != EOF) + while ((c = getopt(argc, argv, "vo:I:tD:")) != EOF) { switch (c) { @@ -74,6 +88,9 @@ main(int argc, char *const argv[]) fprintf(stderr, " %s\n", ip->path); fprintf(stderr, "End of search list.\n"); return OK; + case 'D': + add_preprocessor_define(optarg); + break; default: usage(argv[0]); return ILLEGAL_OPTION; @@ -97,7 +114,9 @@ main(int argc, char *const argv[]) strcpy(input_filename, argv[fnr]); - ptr2ext = strrchr(input_filename, '.'); + /* take care of relative paths */ + ptr2ext = strrchr(input_filename, '/'); + ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.')); /* no extension? */ if (ptr2ext == NULL) { @@ -170,16 +189,29 @@ main(int argc, char *const argv[]) ptr = ptr->next; free(this); } + cur = NULL; + + /* remove non-pertinent old defines as well */ + while ( defines && !defines->pertinent ) { + defptr = defines; + defines = defines->next; + + free(defptr->new); + free(defptr->old); + free(defptr); + } - /* remove old defines as well */ - for (defptr = defines; defptr != NULL;) + for (defptr = defines; defptr != NULL; defptr = defptr->next ) { - struct _defines *this = defptr; + struct _defines *this = defptr->next; + + if ( this && !this->pertinent ) { + defptr->next = this->next; - free(defptr->new); - free(defptr->old); - defptr = defptr->next; + free(this->new); + free(this->old); free(this); + } } /* and old typedefs */ @@ -193,12 +225,13 @@ main(int argc, char *const argv[]) typeptr = typeptr->next; free(this); } + types = NULL; /* initialize lex */ lex_init(); /* we need two includes */ - fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); + fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n#line 1 \"%s\"\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL, input_filename); /* and parse the source */ yyparse(); |