#include "extern.h"
struct _include_path *include_paths;
-struct _defines *defines = NULL;
-int autocommit = 0;
-int ret_value = OK;
+int ret_value = OK, autocommit = 0;
struct cursor *cur = NULL;
struct typedefs *types = NULL;
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] [-D define name] file1 [file2] ...\n", progname);
+ fprintf(stderr, "Usage: %s: [-v] [-t] [-I include path] [ -o output file name] file1 [file2] ...\n", progname);
}
static void
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[])
{
int fnr,
c,
+ verbose = false,
out_option = 0;
struct _include_path *ip;
add_include_path("/usr/local/include");
add_include_path(".");
- while ((c = getopt(argc, argv, "vo:I:tD:")) != EOF)
+ while ((c = getopt(argc, argv, "vo:I:t")) != EOF)
{
switch (c)
{
autocommit = 1;
break;
case 'v':
- fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
- fprintf(stderr, "exec sql include ... search starts here:\n");
- for (ip = include_paths; ip != NULL; ip = ip->next)
- fprintf(stderr, " %s\n", ip->path);
- fprintf(stderr, "End of search list.\n");
- return OK;
- case 'D':
- add_preprocessor_define(optarg);
+ verbose = true;
break;
default:
usage(argv[0]);
}
}
+ if (verbose)
+ {
+ fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
+ fprintf(stderr, "exec sql include ... search starts here:\n");
+ for (ip = include_paths; ip != NULL; ip = ip->next)
+ fprintf(stderr, " %s\n", ip->path);
+ fprintf(stderr, "End of search list.\n");
+ return OK;
+ }
+
if (optind >= argc) /* no files specified */
{
usage(argv[0]);
strcpy(input_filename, argv[fnr]);
- /* take care of relative paths */
- ptr2ext = strrchr(input_filename, '/');
- ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.'));
+ ptr2ext = strrchr(input_filename, '.');
/* no extension? */
if (ptr2ext == NULL)
{
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);
- }
- for (defptr = defines; defptr != NULL; defptr = defptr->next )
+ /* remove old defines as well */
+ for (defptr = defines; defptr != NULL;)
{
- struct _defines *this = defptr->next;
-
- if ( this && !this->pertinent ) {
- defptr->next = this->next;
+ struct _defines *this = defptr;
- free(this->new);
- free(this->old);
+ free(defptr->new);
+ free(defptr->old);
+ defptr = defptr->next;
free(this);
- }
}
/* and old typedefs */
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#line 1 \"%s\"\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL, input_filename);
+ 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);
/* and parse the source */
yyparse();