12
12
#include "extern.h"
13
13
14
14
struct _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 ;
18
16
struct cursor * cur = NULL ;
19
17
struct typedefs * types = NULL ;
20
18
21
19
static void
22
20
usage (char * progname )
23
21
{
24
22
fprintf (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 );
26
24
}
27
25
28
26
static void
@@ -35,23 +33,12 @@ add_include_path(char *path)
35
33
include_paths -> next = ip ;
36
34
}
37
35
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
-
50
36
int
51
37
main (int argc , char * const argv [])
52
38
{
53
39
int fnr ,
54
40
c ,
41
+ verbose = false,
55
42
out_option = 0 ;
56
43
struct _include_path * ip ;
57
44
@@ -60,7 +47,7 @@ main(int argc, char *const argv[])
60
47
add_include_path ("/usr/local/include" );
61
48
add_include_path ("." );
62
49
63
- while ((c = getopt (argc , argv , "vo:I:tD: " )) != EOF )
50
+ while ((c = getopt (argc , argv , "vo:I:t " )) != EOF )
64
51
{
65
52
switch (c )
66
53
{
@@ -82,21 +69,24 @@ main(int argc, char *const argv[])
82
69
autocommit = 1 ;
83
70
break ;
84
71
case '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;
93
73
break ;
94
74
default :
95
75
usage (argv [0 ]);
96
76
return ILLEGAL_OPTION ;
97
77
}
98
78
}
99
79
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
+
100
90
if (optind >= argc ) /* no files specified */
101
91
{
102
92
usage (argv [0 ]);
@@ -114,9 +104,7 @@ main(int argc, char *const argv[])
114
104
115
105
strcpy (input_filename , argv [fnr ]);
116
106
117
- /* take care of relative paths */
118
- ptr2ext = strrchr (input_filename , '/' );
119
- ptr2ext = (ptr2ext ? strrchr (ptr2ext , '.' ) : strrchr (input_filename , '.' ));
107
+ ptr2ext = strrchr (input_filename , '.' );
120
108
/* no extension? */
121
109
if (ptr2ext == NULL )
122
110
{
@@ -189,29 +177,16 @@ main(int argc, char *const argv[])
189
177
ptr = ptr -> next ;
190
178
free (this );
191
179
}
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
- }
203
180
204
- for (defptr = defines ; defptr != NULL ; defptr = defptr -> next )
181
+ /* remove old defines as well */
182
+ for (defptr = defines ; defptr != NULL ;)
205
183
{
206
- struct _defines * this = defptr -> next ;
207
-
208
- if ( this && !this -> pertinent ) {
209
- defptr -> next = this -> next ;
184
+ struct _defines * this = defptr ;
210
185
211
- free (this -> new );
212
- free (this -> old );
186
+ free (defptr -> new );
187
+ free (defptr -> old );
188
+ defptr = defptr -> next ;
213
189
free (this );
214
- }
215
190
}
216
191
217
192
/* and old typedefs */
@@ -225,13 +200,12 @@ main(int argc, char *const argv[])
225
200
typeptr = typeptr -> next ;
226
201
free (this );
227
202
}
228
- types = NULL ;
229
203
230
204
/* initialize lex */
231
205
lex_init ();
232
206
233
207
/* 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 );
235
209
236
210
/* and parse the source */
237
211
yyparse ();
0 commit comments