|
| 1 | +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.47 2001/08/24 22:37:36 petere Exp $ */ |
| 2 | + |
1 | 3 | /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
|
2 | 4 | /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
|
3 |
| -/* Placed under the same copyright as PostgresSQL */ |
| 5 | +/* Placed under the same license as PostgresSQL */ |
4 | 6 |
|
5 | 7 | #include "postgres_fe.h"
|
6 | 8 |
|
|
10 | 12 | #include "getopt.h"
|
11 | 13 | #endif
|
12 | 14 |
|
| 15 | +extern int optind; |
| 16 | +extern char *optarg; |
| 17 | + |
13 | 18 | #include "extern.h"
|
14 | 19 |
|
15 |
| -int ret_value = OK, |
| 20 | +int ret_value = 0, |
16 | 21 | autocommit = 0;
|
17 | 22 | struct _include_path *include_paths = NULL;
|
18 | 23 | struct cursor *cur = NULL;
|
19 | 24 | struct typedefs *types = NULL;
|
20 | 25 | struct _defines *defines = NULL;
|
21 | 26 |
|
22 | 27 | static void
|
23 |
| -usage(char *progname) |
| 28 | +help(const char *progname) |
24 | 29 | {
|
25 |
| - fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); |
26 |
| - fprintf(stderr, "Usage: %s: " |
| 30 | + printf("%s is the PostgreSQL embedded SQL preprocessor for C programs.\n\n", |
| 31 | + progname); |
| 32 | + printf("Usage:\n" |
| 33 | + " %s %s[-I DIRECTORY] [-o OUTFILE] [-t] file1 [file2...]\n\n", |
| 34 | + progname, |
| 35 | +#ifdef YYDEBUG |
| 36 | + "[-d] " |
| 37 | +#else |
| 38 | + "" |
| 39 | +#endif |
| 40 | + ); |
| 41 | + printf("Options:\n"); |
27 | 42 | #ifdef YYDEBUG
|
28 |
| - "[-d]" |
| 43 | + printf(" -d generate parser debug output\n"); |
29 | 44 | #endif
|
30 |
| - " [-v] [-t] [-I include path] [ -o output file name] [-D define name] file1 [file2] ...\n", progname); |
| 45 | + printf(" -I DIRECTORY search DIRECTORY for include files\n"); |
| 46 | + printf(" -o OUTFILE write result to OUTFILE\n"); |
| 47 | + printf(" -t turn on autocommit of transactions\n"); |
| 48 | + printf("\nIf no output file is specified, the name is formed by adding .c\n" |
| 49 | + "to the input file name, after stripping off .pgc if present.\n"); |
| 50 | + printf("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"); |
31 | 51 | }
|
32 | 52 |
|
33 | 53 | static void
|
@@ -60,9 +80,27 @@ main(int argc, char *const argv[])
|
60 | 80 | verbose = false,
|
61 | 81 | out_option = 0;
|
62 | 82 | struct _include_path *ip;
|
| 83 | + char *progname; |
63 | 84 |
|
64 |
| - extern int optind; |
65 |
| - extern char *optarg; |
| 85 | + if (!strrchr(argv[0], '/')) |
| 86 | + progname = argv[0]; |
| 87 | + else |
| 88 | + progname = strrchr(argv[0], '/') + 1; |
| 89 | + |
| 90 | + if (argc > 1) |
| 91 | + { |
| 92 | + if (strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-?")==0) |
| 93 | + { |
| 94 | + help(progname); |
| 95 | + exit(0); |
| 96 | + } |
| 97 | + else if (strcmp(argv[1], "--version")==0) |
| 98 | + { |
| 99 | + printf("ecpg (PostgreSQL %s) %d.%d.%d\n", PG_VERSION, |
| 100 | + MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); |
| 101 | + exit(0); |
| 102 | + } |
| 103 | + } |
66 | 104 |
|
67 | 105 | add_include_path("/usr/include");
|
68 | 106 | add_include_path(INCLUDE_PATH);
|
@@ -90,32 +128,38 @@ main(int argc, char *const argv[])
|
90 | 128 | verbose = true;
|
91 | 129 | break;
|
92 | 130 | case 'D':
|
| 131 | + /* XXX not documented */ |
93 | 132 | add_preprocessor_define(optarg);
|
94 | 133 | break;
|
95 |
| -#ifdef YYDEBUG |
96 | 134 | case 'd':
|
| 135 | +#ifdef YYDEBUG |
97 | 136 | yydebug = 1;
|
98 |
| - break; |
| 137 | +#else |
| 138 | + fprintf(stderr, "%s: parser debug support (-d) not available\n", |
| 139 | + progname); |
99 | 140 | #endif
|
| 141 | + break; |
100 | 142 | default:
|
101 |
| - usage(argv[0]); |
| 143 | + fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
102 | 144 | return ILLEGAL_OPTION;
|
103 | 145 | }
|
104 | 146 | }
|
105 | 147 |
|
106 | 148 | if (verbose)
|
107 | 149 | {
|
108 |
| - fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); |
| 150 | + fprintf(stderr, "%s, the PostgreSQL embedded C preprocessor, version %d.%d.%d\n", |
| 151 | + progname, MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); |
109 | 152 | fprintf(stderr, "exec sql include ... search starts here:\n");
|
110 | 153 | for (ip = include_paths; ip != NULL; ip = ip->next)
|
111 | 154 | fprintf(stderr, " %s\n", ip->path);
|
112 |
| - fprintf(stderr, "End of search list.\n"); |
113 |
| - return OK; |
| 155 | + fprintf(stderr, "end of search list\n"); |
| 156 | + return 0; |
114 | 157 | }
|
115 | 158 |
|
116 | 159 | if (optind >= argc) /* no files specified */
|
117 | 160 | {
|
118 |
| - usage(argv[0]); |
| 161 | + fprintf(stderr, "%s: no input files specified\n", progname); |
| 162 | + fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
119 | 163 | return (ILLEGAL_OPTION);
|
120 | 164 | }
|
121 | 165 | else
|
|
0 commit comments