Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7e20c35

Browse files
committed
Add ecpg --help and --version. Renumber the exit status codes, which were
documented wrong.
1 parent9cf701f commit7e20c35

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 samecopyright as PostgresSQL */
5+
/* Placed under the samelicense as PostgresSQL */
46

57
#include"postgres_fe.h"
68

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

15+
externintoptind;
16+
externchar*optarg;
17+
1318
#include"extern.h"
1419

15-
intret_value=OK,
20+
intret_value=0,
1621
autocommit=0;
1722
struct_include_path*include_paths=NULL;
1823
structcursor*cur=NULL;
1924
structtypedefs*types=NULL;
2025
struct_defines*defines=NULL;
2126

2227
staticvoid
23-
usage(char*progname)
28+
help(constchar*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+
#ifdefYYDEBUG
36+
"[-d] "
37+
#else
38+
""
39+
#endif
40+
);
41+
printf("Options:\n");
2742
#ifdefYYDEBUG
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
staticvoid
@@ -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-
externintoptind;
65-
externchar*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+
elseif (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-
#ifdefYYDEBUG
96134
case'd':
135+
#ifdefYYDEBUG
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
returnILLEGAL_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-
returnOK;
155+
fprintf(stderr,"end of search list\n");
156+
return0;
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-
#defineOK 0
84-
#definePARSE_ERROR-1
85-
#defineILLEGAL_OPTION-2
86-
#defineINDICATOR_NOT_ARRAY -3
87-
88-
#defineNO_INCLUDE_FILEENOENT
89-
#defineOUT_OF_MEMORYENOMEM
83+
#defineILLEGAL_OPTION1
84+
#defineNO_INCLUDE_FILE2
85+
#definePARSE_ERROR3
86+
#defineINDICATOR_NOT_ARRAY 4
87+
#defineOUT_OF_MEMORY5

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp