diff options
Diffstat (limited to 'src/interfaces/ecpg/preproc/ecpg.c')
-rw-r--r-- | src/interfaces/ecpg/preproc/ecpg.c | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 08f4a395250..e4a1a78812a 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -7,25 +7,22 @@ #include <stdlib.h> #include <strings.h> -extern void lex_init(void); -extern FILE *yyin, *yyout; -extern char * input_filename; -extern int yyparse(void); +#include "extern.h" static void usage(char *progname) { - fprintf(stderr, "Usage: %s: [ -o outout file name] file1 [file2] ...\n", progname); + fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); + fprintf(stderr, "Usage: %s: [-v] [-d] [ -o outout file name] file1 [file2] ...\n", progname); } int main(int argc, char *const argv[]) { - char c, - out_option = 0; + char c, out_option = 0; int fnr; - while ((c = getopt(argc, argv, "o:")) != EOF) + while ((c = getopt(argc, argv, "vdo:")) != EOF) { switch (c) { @@ -36,71 +33,77 @@ main(int argc, char *const argv[]) else out_option = 1; break; + case 'd': + debugging = 1; + break; + case 'v': default: usage(argv[0]); } } - /* after the options there must not be anything but filenames */ - for (fnr = optind; fnr < argc; fnr++) + if (optind >= argc) /* no files specified */ + usage(argv[0]); + else { - char *filename, - *ptr2ext; - - filename = malloc(strlen(argv[fnr]) + 2); - if (filename == NULL) + /* after the options there must not be anything but filenames */ + for (fnr = optind; fnr < argc; fnr++) { - perror("malloc"); - continue; - } + char *filename, *ptr2ext; - strcpy(filename, argv[fnr]); + filename = malloc(strlen(argv[fnr]) + 2); + if (filename == NULL) + { + perror("malloc"); + continue; + } - ptr2ext = strrchr(filename, '.'); - /* no extension or extension not equal .pgc */ - if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0) - { - ptr2ext = filename + strlen(filename); - ptr2ext[0] = '.'; - } + strcpy(filename, argv[fnr]); - /* make extension = .c */ - ptr2ext[1] = 'c'; - ptr2ext[2] = '\0'; + ptr2ext = strrchr(filename, '.'); + /* no extension or extension not equal .pgc */ + if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0) + { + ptr2ext = filename + strlen(filename); + ptr2ext[0] = '.'; + } - if (out_option == 0) /* calculate the output name */ - { - yyout = fopen(filename, "w"); - if (yyout == NULL) + /* make extension = .c */ + ptr2ext[1] = 'c'; + ptr2ext[2] = '\0'; + + if (out_option == 0) /* calculate the output name */ { - perror(filename); - free(filename); - continue; + yyout = fopen(filename, "w"); + if (yyout == NULL) + { + perror(filename); + free(filename); + continue; + } } - } - yyin = fopen(input_filename = argv[fnr], "r"); - if (yyin == NULL) - { - perror(argv[fnr]); - } - else - { - /* initialize lex */ - lex_init(); + yyin = fopen(input_filename = argv[fnr], "r"); + if (yyin == NULL) + perror(argv[fnr]); + else + { + /* initialize lex */ + lex_init(); - /* we need two includes everytime */ - fprintf(yyout, "/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n"); + /* 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", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); - /* and parse the source */ - yyparse(); + /* and parse the source */ + yyparse(); - fclose(yyin); - if (out_option == 0) - fclose(yyout); - } + fclose(yyin); + if (out_option == 0) + fclose(yyout); + } - free(filename); + free(filename); + } } return (0); } |