PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
getopt.c File Reference
#include "c.h"
#include "pg_getopt.h"
Include dependency graph for getopt.c:

Go to the source code of this file.

Macros

#define BADCH   (int)'?'
 
#define BADARG   (int)':'
 
#define EMSG   ""
 

Functions

int getopt (int nargc, char *const *nargv, const char *ostr)
 

Variables

int opterr = 1
 
int optind = 1
 
int optopt
 
char * optarg
 

Macro Definition Documentation

#define BADARG   (int)':'

Definition at line 58 of file getopt.c.

Referenced by getopt().

#define BADCH   (int)'?'

Definition at line 57 of file getopt.c.

Referenced by getopt().

#define EMSG   ""

Definition at line 59 of file getopt.c.

Referenced by getopt().

Function Documentation

int getopt ( int  nargc,
char *const *  nargv,
const char *  ostr 
)

Definition at line 72 of file getopt.c.

References BADARG, BADCH, EMSG, NULL, optarg, opterr, optind, and optopt.

Referenced by AuxiliaryProcessMain(), get_opts(), main(), PostmasterMain(), and process_postgres_switches().

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

Variable Documentation

int opterr = 1

Definition at line 50 of file getopt.c.

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

int optopt

Definition at line 51 of file getopt.c.

Referenced by getopt(), and getopt_long().