Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7e20c35

Browse files
committed
Add ecpg --help and --version. Renumber the exit status codes, which were
documented wrong.
1 parent 9cf701f commit 7e20c35

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

doc/src/sgml/ref/ecpg-ref.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/ecpg-ref.sgml,v 1.8 2001/07/11 03:43:52 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/ecpg-ref.sgml,v 1.9 2001/08/24 22:37:36 petere Exp $
33
Postgres documentation
44
-->
55

@@ -116,7 +116,7 @@ ecpg [ -v ] [ -t ] [ -I include-path ] [ -o outfile ] file1 [ file2 ] [ ... ]
116116
<term><replaceable>return value</replaceable></term>
117117
<listitem>
118118
<para>
119-
<application>ecpg</application> returns 0 to the shell on successful completion, -1
119+
<application>ecpg</application> returns 0 to the shell on successful completion, non-zero
120120
for errors.
121121
</para>
122122
</listitem>

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.47 2001/08/24 22:37:36 petere Exp $ */
2+
13
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
24
/* (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 */
46

57
#include "postgres_fe.h"
68

@@ -10,24 +12,42 @@
1012
#include "getopt.h"
1113
#endif
1214

15+
extern int optind;
16+
extern char *optarg;
17+
1318
#include "extern.h"
1419

15-
int ret_value = OK,
20+
int ret_value = 0,
1621
autocommit = 0;
1722
struct _include_path *include_paths = NULL;
1823
struct cursor *cur = NULL;
1924
struct typedefs *types = NULL;
2025
struct _defines *defines = NULL;
2126

2227
static void
23-
usage(char *progname)
28+
help(const char *progname)
2429
{
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");
2742
#ifdef YYDEBUG
28-
"[-d]"
43+
printf(" -d generate parser debug output\n");
2944
#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");
3151
}
3252

3353
static void
@@ -60,9 +80,27 @@ main(int argc, char *const argv[])
6080
verbose = false,
6181
out_option = 0;
6282
struct _include_path *ip;
83+
char *progname;
6384

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+
}
66104

67105
add_include_path("/usr/include");
68106
add_include_path(INCLUDE_PATH);
@@ -90,32 +128,38 @@ main(int argc, char *const argv[])
90128
verbose = true;
91129
break;
92130
case 'D':
131+
/* XXX not documented */
93132
add_preprocessor_define(optarg);
94133
break;
95-
#ifdef YYDEBUG
96134
case 'd':
135+
#ifdef YYDEBUG
97136
yydebug = 1;
98-
break;
137+
#else
138+
fprintf(stderr, "%s: parser debug support (-d) not available\n",
139+
progname);
99140
#endif
141+
break;
100142
default:
101-
usage(argv[0]);
143+
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
102144
return ILLEGAL_OPTION;
103145
}
104146
}
105147

106148
if (verbose)
107149
{
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);
109152
fprintf(stderr, "exec sql include ... search starts here:\n");
110153
for (ip = include_paths; ip != NULL; ip = ip->next)
111154
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;
114157
}
115158

116159
if (optind >= argc) /* no files specified */
117160
{
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]);
119163
return (ILLEGAL_OPTION);
120164
}
121165
else

src/interfaces/ecpg/preproc/extern.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ extern ScanKeyword *ScanKeywordLookup(char *text);
8080

8181
/* return codes */
8282

83-
#define OK 0
84-
#define PARSE_ERROR -1
85-
#define ILLEGAL_OPTION -2
86-
#define INDICATOR_NOT_ARRAY -3
87-
88-
#define NO_INCLUDE_FILE ENOENT
89-
#define OUT_OF_MEMORY ENOMEM
83+
#define ILLEGAL_OPTION 1
84+
#define NO_INCLUDE_FILE 2
85+
#define PARSE_ERROR 3
86+
#define INDICATOR_NOT_ARRAY 4
87+
#define OUT_OF_MEMORY 5

0 commit comments

Comments
 (0)