PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_getopt_ctx.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pg_getopt_ctx
 

Functions

void pg_getopt_start (pg_getopt_ctx *ctx, int nargc, char *const *nargv, const char *ostr)
 
int pg_getopt_next (pg_getopt_ctx *ctx)
 

Function Documentation

◆ pg_getopt_next()

int pg_getopt_next ( pg_getopt_ctx ctx)
extern

Definition at line 72 of file pg_getopt_ctx.c.

73{
74 const char *oli; /* option letter list index */
75
76 if (!*ctx->place)
77 { /* update scanning pointer */
78 if (ctx->optind >= ctx->nargc || *(ctx->place = ctx->nargv[ctx->optind]) != '-')
79 {
80 ctx->place = EMSG;
81 return -1;
82 }
83 if (ctx->place[1] && *++ctx->place == '-' && ctx->place[1] == '\0')
84 { /* found "--" */
85 ++ctx->optind;
86 ctx->place = EMSG;
87 return -1;
88 }
89 } /* option letter okay? */
90 if ((ctx->optopt = (int) *ctx->place++) == (int) ':' ||
91 !(oli = strchr(ctx->ostr, ctx->optopt)))
92 {
93 /*
94 * if the user didn't specify '-' as an option, assume it means -1.
95 */
96 if (ctx->optopt == (int) '-')
97 {
98 ctx->place = EMSG;
99 return -1;
100 }
101 if (!*ctx->place)
102 ++ctx->optind;
103 if (ctx->opterr && *ctx->ostr != ':')
105 "illegal option -- %c\n", ctx->optopt);
106 return BADCH;
107 }
108 if (*++oli != ':')
109 { /* don't need argument */
110 ctx->optarg = NULL;
111 if (!*ctx->place)
112 ++ctx->optind;
113 }
114 else
115 { /* need an argument */
116 if (*ctx->place) /* no white space */
117 ctx->optarg = ctx->place;
118 else if (ctx->nargc <= ++ctx->optind)
119 { /* no arg */
120 ctx->place = EMSG;
121 if (*ctx->ostr == ':')
122 return BADARG;
123 if (ctx->opterr)
125 "option requires an argument -- %c\n",
126 ctx->optopt);
127 return BADCH;
128 }
129 else
130 /* white space */
131 ctx->optarg = ctx->nargv[ctx->optind];
132 ctx->place = EMSG;
133 ++ctx->optind;
134 }
135 return ctx->optopt; /* dump back option letter */
136}
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
#define BADCH
#define BADARG
#define EMSG
static int fb(int x)
char *const * nargv
const char * ostr

References BADARG, BADCH, EMSG, fb(), fprintf, pg_getopt_ctx::nargc, pg_getopt_ctx::nargv, pg_getopt_ctx::optarg, pg_getopt_ctx::opterr, pg_getopt_ctx::optind, pg_getopt_ctx::optopt, pg_getopt_ctx::ostr, and pg_getopt_ctx::place.

Referenced by BootstrapModeMain(), getopt(), PostmasterMain(), and process_postgres_switches().

◆ pg_getopt_start()

void pg_getopt_start ( pg_getopt_ctx ctx,
int  nargc,
char *const nargv,
const char ostr 
)
extern

Definition at line 54 of file pg_getopt_ctx.c.

55{
56 ctx->nargc = nargc;
57 ctx->nargv = nargv;
58 ctx->ostr = ostr;
59
60 ctx->optind = 1;
61 ctx->optarg = NULL;
62 ctx->opterr = 1; /* Caller may clear this after the call */
63 ctx->optopt = 0;
64
65 ctx->place = EMSG; /* option letter processing */
66}

References EMSG, fb(), pg_getopt_ctx::nargc, pg_getopt_ctx::nargv, pg_getopt_ctx::optarg, pg_getopt_ctx::opterr, pg_getopt_ctx::optind, pg_getopt_ctx::optopt, pg_getopt_ctx::ostr, and pg_getopt_ctx::place.

Referenced by BootstrapModeMain(), getopt(), PostmasterMain(), and process_postgres_switches().