Add ecpg --help and --version. Renumber the exit status codes, which were
documented wrong.
This commit is contained in:
parent
9cf701f324
commit
7e20c35e1c
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/ecpg-ref.sgml,v 1.8 2001/07/11 03:43:52 momjian Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/ecpg-ref.sgml,v 1.9 2001/08/24 22:37:36 petere Exp $
|
||||||
Postgres documentation
|
Postgres documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ ecpg [ -v ] [ -t ] [ -I include-path ] [ -o outfile ] file1 [ file2 ] [ ... ]
|
|||||||
<term><replaceable>return value</replaceable></term>
|
<term><replaceable>return value</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<application>ecpg</application> returns 0 to the shell on successful completion, -1
|
<application>ecpg</application> returns 0 to the shell on successful completion, non-zero
|
||||||
for errors.
|
for errors.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.47 2001/08/24 22:37:36 petere Exp $ */
|
||||||
|
|
||||||
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
|
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
|
||||||
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
|
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
|
||||||
/* Placed under the same copyright as PostgresSQL */
|
/* Placed under the same license as PostgresSQL */
|
||||||
|
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -10,9 +12,12 @@
|
|||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern int optind;
|
||||||
|
extern char *optarg;
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
int ret_value = OK,
|
int ret_value = 0,
|
||||||
autocommit = 0;
|
autocommit = 0;
|
||||||
struct _include_path *include_paths = NULL;
|
struct _include_path *include_paths = NULL;
|
||||||
struct cursor *cur = NULL;
|
struct cursor *cur = NULL;
|
||||||
@ -20,14 +25,29 @@ struct typedefs *types = NULL;
|
|||||||
struct _defines *defines = NULL;
|
struct _defines *defines = NULL;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(char *progname)
|
help(const char *progname)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
printf("%s is the PostgreSQL embedded SQL preprocessor for C programs.\n\n",
|
||||||
fprintf(stderr, "Usage: %s: "
|
progname);
|
||||||
|
printf("Usage:\n"
|
||||||
|
" %s %s[-I DIRECTORY] [-o OUTFILE] [-t] file1 [file2...]\n\n",
|
||||||
|
progname,
|
||||||
#ifdef YYDEBUG
|
#ifdef YYDEBUG
|
||||||
"[-d]"
|
"[-d] "
|
||||||
|
#else
|
||||||
|
""
|
||||||
#endif
|
#endif
|
||||||
" [-v] [-t] [-I include path] [ -o output file name] [-D define name] file1 [file2] ...\n", progname);
|
);
|
||||||
|
printf("Options:\n");
|
||||||
|
#ifdef YYDEBUG
|
||||||
|
printf(" -d generate parser debug output\n");
|
||||||
|
#endif
|
||||||
|
printf(" -I DIRECTORY search DIRECTORY for include files\n");
|
||||||
|
printf(" -o OUTFILE write result to OUTFILE\n");
|
||||||
|
printf(" -t turn on autocommit of transactions\n");
|
||||||
|
printf("\nIf no output file is specified, the name is formed by adding .c\n"
|
||||||
|
"to the input file name, after stripping off .pgc if present.\n");
|
||||||
|
printf("\nReport bugs to <pgsql-bugs@postgresql.org>.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -60,9 +80,27 @@ main(int argc, char *const argv[])
|
|||||||
verbose = false,
|
verbose = false,
|
||||||
out_option = 0;
|
out_option = 0;
|
||||||
struct _include_path *ip;
|
struct _include_path *ip;
|
||||||
|
char *progname;
|
||||||
|
|
||||||
extern int optind;
|
if (!strrchr(argv[0], '/'))
|
||||||
extern char *optarg;
|
progname = argv[0];
|
||||||
|
else
|
||||||
|
progname = strrchr(argv[0], '/') + 1;
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-?")==0)
|
||||||
|
{
|
||||||
|
help(progname);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
else if (strcmp(argv[1], "--version")==0)
|
||||||
|
{
|
||||||
|
printf("ecpg (PostgreSQL %s) %d.%d.%d\n", PG_VERSION,
|
||||||
|
MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
add_include_path("/usr/include");
|
add_include_path("/usr/include");
|
||||||
add_include_path(INCLUDE_PATH);
|
add_include_path(INCLUDE_PATH);
|
||||||
@ -90,32 +128,38 @@ main(int argc, char *const argv[])
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
|
/* XXX not documented */
|
||||||
add_preprocessor_define(optarg);
|
add_preprocessor_define(optarg);
|
||||||
break;
|
break;
|
||||||
#ifdef YYDEBUG
|
|
||||||
case 'd':
|
case 'd':
|
||||||
|
#ifdef YYDEBUG
|
||||||
yydebug = 1;
|
yydebug = 1;
|
||||||
break;
|
#else
|
||||||
|
fprintf(stderr, "%s: parser debug support (-d) not available\n",
|
||||||
|
progname);
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(argv[0]);
|
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
|
||||||
return ILLEGAL_OPTION;
|
return ILLEGAL_OPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
fprintf(stderr, "%s, the PostgreSQL embedded C preprocessor, version %d.%d.%d\n",
|
||||||
|
progname, MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
||||||
fprintf(stderr, "exec sql include ... search starts here:\n");
|
fprintf(stderr, "exec sql include ... search starts here:\n");
|
||||||
for (ip = include_paths; ip != NULL; ip = ip->next)
|
for (ip = include_paths; ip != NULL; ip = ip->next)
|
||||||
fprintf(stderr, " %s\n", ip->path);
|
fprintf(stderr, " %s\n", ip->path);
|
||||||
fprintf(stderr, "End of search list.\n");
|
fprintf(stderr, "end of search list\n");
|
||||||
return OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind >= argc) /* no files specified */
|
if (optind >= argc) /* no files specified */
|
||||||
{
|
{
|
||||||
usage(argv[0]);
|
fprintf(stderr, "%s: no input files specified\n", progname);
|
||||||
|
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
|
||||||
return (ILLEGAL_OPTION);
|
return (ILLEGAL_OPTION);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -80,10 +80,8 @@ extern ScanKeyword *ScanKeywordLookup(char *text);
|
|||||||
|
|
||||||
/* return codes */
|
/* return codes */
|
||||||
|
|
||||||
#define OK 0
|
#define ILLEGAL_OPTION 1
|
||||||
#define PARSE_ERROR -1
|
#define NO_INCLUDE_FILE 2
|
||||||
#define ILLEGAL_OPTION -2
|
#define PARSE_ERROR 3
|
||||||
#define INDICATOR_NOT_ARRAY -3
|
#define INDICATOR_NOT_ARRAY 4
|
||||||
|
#define OUT_OF_MEMORY 5
|
||||||
#define NO_INCLUDE_FILE ENOENT
|
|
||||||
#define OUT_OF_MEMORY ENOMEM
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user