1212#include "extern.h"
1313
1414struct _include_path * include_paths ;
15- struct _defines * defines = NULL ;
16- int autocommit = 0 ;
17- int ret_value = OK ;
15+ int ret_value = OK ,autocommit = 0 ;
1816struct cursor * cur = NULL ;
1917struct typedefs * types = NULL ;
2018
2119static void
2220usage (char * progname )
2321{
2422fprintf (stderr ,"ecpg - the postgresql preprocessor, version: %d.%d.%d\n" ,MAJOR_VERSION ,MINOR_VERSION ,PATCHLEVEL );
25- fprintf (stderr ,"Usage: %s: [-v] [-t] [-I include path] [ -o output file name][-D define name] file1 [file2] ...\n" ,progname );
23+ fprintf (stderr ,"Usage: %s: [-v] [-t] [-I include path] [ -o output file name] file1 [file2] ...\n" ,progname );
2624}
2725
2826static void
@@ -35,23 +33,12 @@ add_include_path(char *path)
3533include_paths -> next = ip ;
3634}
3735
38- static void
39- add_preprocessor_define (char * define )
40- {
41- struct _defines * pd = defines ;
42-
43- defines = mm_alloc (sizeof (struct _defines ));
44- defines -> old = strdup (define );
45- defines -> new = strdup ("" );
46- defines -> pertinent = true;
47- defines -> next = pd ;
48- }
49-
5036int
5137main (int argc ,char * const argv [])
5238{
5339int fnr ,
5440c ,
41+ verbose = false,
5542out_option = 0 ;
5643struct _include_path * ip ;
5744
@@ -60,7 +47,7 @@ main(int argc, char *const argv[])
6047add_include_path ("/usr/local/include" );
6148add_include_path ("." );
6249
63- while ((c = getopt (argc ,argv ,"vo:I:tD: " ))!= EOF )
50+ while ((c = getopt (argc ,argv ,"vo:I:t " ))!= EOF )
6451{
6552switch (c )
6653{
@@ -82,21 +69,24 @@ main(int argc, char *const argv[])
8269autocommit = 1 ;
8370break ;
8471case 'v' :
85- fprintf (stderr ,"ecpg - the postgresql preprocessor, version: %d.%d.%d\n" ,MAJOR_VERSION ,MINOR_VERSION ,PATCHLEVEL );
86- fprintf (stderr ,"exec sql include ... search starts here:\n" );
87- for (ip = include_paths ;ip != NULL ;ip = ip -> next )
88- fprintf (stderr ," %s\n" ,ip -> path );
89- fprintf (stderr ,"End of search list.\n" );
90- return OK ;
91- case 'D' :
92- add_preprocessor_define (optarg );
72+ verbose = true;
9373break ;
9474default :
9575usage (argv [0 ]);
9676return ILLEGAL_OPTION ;
9777}
9878}
9979
80+ if (verbose )
81+ {
82+ fprintf (stderr ,"ecpg - the postgresql preprocessor, version: %d.%d.%d\n" ,MAJOR_VERSION ,MINOR_VERSION ,PATCHLEVEL );
83+ fprintf (stderr ,"exec sql include ... search starts here:\n" );
84+ for (ip = include_paths ;ip != NULL ;ip = ip -> next )
85+ fprintf (stderr ," %s\n" ,ip -> path );
86+ fprintf (stderr ,"End of search list.\n" );
87+ return OK ;
88+ }
89+
10090if (optind >=argc )/* no files specified */
10191{
10292usage (argv [0 ]);
@@ -114,9 +104,7 @@ main(int argc, char *const argv[])
114104
115105strcpy (input_filename ,argv [fnr ]);
116106
117- /* take care of relative paths */
118- ptr2ext = strrchr (input_filename ,'/' );
119- ptr2ext = (ptr2ext ?strrchr (ptr2ext ,'.' ) :strrchr (input_filename ,'.' ));
107+ ptr2ext = strrchr (input_filename ,'.' );
120108/* no extension? */
121109if (ptr2ext == NULL )
122110{
@@ -189,29 +177,16 @@ main(int argc, char *const argv[])
189177ptr = ptr -> next ;
190178free (this );
191179}
192- cur = NULL ;
193-
194- /* remove non-pertinent old defines as well */
195- while (defines && !defines -> pertinent ) {
196- defptr = defines ;
197- defines = defines -> next ;
198-
199- free (defptr -> new );
200- free (defptr -> old );
201- free (defptr );
202- }
203180
204- for (defptr = defines ;defptr != NULL ;defptr = defptr -> next )
181+ /* remove old defines as well */
182+ for (defptr = defines ;defptr != NULL ;)
205183{
206- struct _defines * this = defptr -> next ;
207-
208- if (this && !this -> pertinent ) {
209- defptr -> next = this -> next ;
184+ struct _defines * this = defptr ;
210185
211- free (this -> new );
212- free (this -> old );
186+ free (defptr -> new );
187+ free (defptr -> old );
188+ defptr = defptr -> next ;
213189free (this );
214- }
215190}
216191
217192/* and old typedefs */
@@ -225,13 +200,12 @@ main(int argc, char *const argv[])
225200typeptr = typeptr -> next ;
226201free (this );
227202}
228- types = NULL ;
229203
230204/* initialize lex */
231205lex_init ();
232206
233207/* we need two includes */
234- 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 );
208+ 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 );
235209
236210/* and parse the source */
237211yyparse ();