ReactOS 0.4.16-dev-329-g9223134
getopt.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  option
 

Macros

#define __GETOPT_LONG_H__
 
#define HAVE_DECL_GETOPT   1
 
#define no_argument   0
 
#define required_argument   1
 
#define optional_argument   2
 

Functions

int getopt (int, char *const *, const char *)
 
int getopt_long (int, char *const *, const char *, const struct option *, int *)
 

Variables

int opterr
 
int optind
 
int optopt
 
int optreset
 
charoptarg
 

Macro Definition Documentation

◆ __GETOPT_LONG_H__

#define __GETOPT_LONG_H__

Definition at line 57 of file getopt.h.

◆ HAVE_DECL_GETOPT

#define HAVE_DECL_GETOPT   1

Definition at line 72 of file getopt.h.

◆ no_argument

#define no_argument   0

Definition at line 75 of file getopt.h.

◆ optional_argument

#define optional_argument   2

Definition at line 77 of file getopt.h.

◆ required_argument

#define required_argument   1

Definition at line 76 of file getopt.h.

Function Documentation

◆ getopt()

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

Definition at line 55 of file getopt.c.

56{
57 static const char *place = EMSG; /* option letter processing */
58 register char *oli; /* option letter list index */
59 char *p;
60
61 if (!*place) { /* update scanning pointer */
62 if (optind >= nargc || *(place = nargv[optind]) != '-') {
63 place = EMSG;
64 return(EOF);
65 }
66 if (place[1] && *++place == '-') { /* found "--" */
67 ++optind;
68 place = EMSG;
69 return(EOF);
70 }
71 } /* option letter okay? */
72 if ((optopt = (int)*place++) == (int)':' ||
73 !(oli = strchr(ostr, optopt))) {
74 /*
75 * if the user didn't specify '-' as an option,
76 * assume it means EOF.
77 */
78 if (optopt == (int)'-')
79 return(EOF);
80 if (!*place)
81 ++optind;
82 if (opterr) {
83 if (!(p = strrchr(*nargv, '/')))
84 p = *nargv;
85 else
86 ++p;
87 (void)fprintf(stderr, "%s: illegal option -- %c\n",
88 p, optopt);
89 }
90 return(BADCH);
91 }
92 if (*++oli != ':') { /* don't need argument */
93 optarg = NULL;
94 if (!*place)
95 ++optind;
96 }
97 else { /* need an argument */
98 if (*place) /* no white space */
99 optarg = place;
100 else if (nargc <= ++optind) { /* no arg */
101 place = EMSG;
102 if (!(p = strrchr(*nargv, '/')))
103 p = *nargv;
104 else
105 ++p;
106 if (opterr)
108 "%s: option requires an argument -- %c\n",
109 p, optopt);
110 return(BADCH);
111 }
112 else /* white space */
113 optarg = nargv[optind];
114 place = EMSG;
115 ++optind;
116 }
117 return(optopt); /* dump back option letter */
118}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define BADCH
Definition: getopt.c:51
int optopt
Definition: getopt.c:48
#define EMSG
Definition: getopt.c:52
const char * optarg
Definition: getopt.c:49
int optind
Definition: getopt.c:47
int opterr
Definition: getopt.c:46
#define NULL
Definition: types.h:112
GLfloat GLfloat p
Definition: glext.h:8902
#define EOF
Definition: stdio.h:24
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
static char * place
Definition: getopt.c:55

◆ getopt_long()

int getopt_long ( int  nargc,
char *const nargv,
const char options,
const struct option long_options,
int idx 
)

Definition at line 283 of file getopt.c.

289{
290 int retval;
291
292 _DIAGASSERT(nargv != NULL);
295
296 if ((retval = getopt_internal(nargc,nargv,options)) == -2) {
297 char *current_argv,*has_equal;
298 size_t current_argv_len;
299 int i,match;
300
301 current_argv = place;
302 match = -1;
303
304 optind++;
305 place = EMSG;
306
307 if (*current_argv == '\0') {
308
309 if (nonopt_end != -1) {
312 }
314 return -1;
315 }
316 if ((has_equal = strchr(current_argv,'=')) != NULL) {
317
318 current_argv_len = has_equal - current_argv;
319 has_equal++;
320 } else
321 current_argv_len = strlen(current_argv);
322
323 for (i = 0; long_options[i].name; i++) {
324
325 if (strncmp(current_argv,long_options[i].name,current_argv_len))
326 continue;
327
328 if (strlen(long_options[i].name) ==
329 (unsigned)current_argv_len) {
330
331 match = i;
332 break;
333 }
334 if (match == -1)
335 match = i;
336 else {
337
338 if (PRINT_ERROR)
339 warnx(ambig,(int)current_argv_len,current_argv);
340 optopt = 0;
341 return BADCH;
342 }
343 }
344 if (match != -1) {
345 if (long_options[match].has_arg == no_argument
346 && has_equal) {
347 if (PRINT_ERROR)
348 warnx(noarg,(int)current_argv_len,current_argv);
349
350 if (long_options[match].flag == NULL)
352 else
353 optopt = 0;
354 return BADARG;
355 }
356 if (long_options[match].has_arg == required_argument ||
358 if (has_equal)
359 optarg = has_equal;
360 else if (long_options[match].has_arg ==
362
363 optarg = nargv[optind++];
364 }
365 }
366 if ((long_options[match].has_arg == required_argument)
367 && (optarg == NULL)) {
368
369 if (PRINT_ERROR)
370 warnx(recargstring,current_argv);
371
372 if (long_options[match].flag == NULL)
374 else
375 optopt = 0;
376 --optind;
377 return BADARG;
378 }
379 } else {
380 if (PRINT_ERROR)
381 warnx(illoptstring,current_argv);
382 optopt = 0;
383 return BADCH;
384 }
385 if (long_options[match].flag) {
386 *long_options[match].flag = long_options[match].val;
387 retval = 0;
388 } else
389 retval = long_options[match].val;
390 if (idx)
391 *idx = match;
392 }
393 return retval;
394}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned int idx
Definition: utils.c:41
#define no_argument
Definition: getopt.h:122
#define required_argument
Definition: getopt.h:123
#define optional_argument
Definition: getopt.h:124
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define warnx(...)
static const char noarg[]
Definition: getopt.c:63
static const char recargstring[]
Definition: getopt.c:61
static int getopt_internal(int, char *const *, const char *)
Definition: getopt.c:137
static const char illoptstring[]
Definition: getopt.c:65
static int nonopt_start
Definition: getopt.c:57
static int nonopt_end
Definition: getopt.c:58
static void permute_args(int, int, int, char *const *)
Definition: getopt.c:103
#define PRINT_ERROR
Definition: getopt.c:35
#define BADARG
Definition: getopt.c:46
static const char ambig[]
Definition: getopt.c:62
#define _DIAGASSERT(x)
Definition: getopt.c:11
Definition: match.c:28
Definition: name.c:39
static const struct option long_options[]
Definition: widl.c:185

Variable Documentation

◆ optarg

char* optarg
extern

Definition at line 49 of file getopt.c.

◆ opterr

int opterr
extern

Definition at line 46 of file getopt.c.

◆ optind

int optind
extern

Definition at line 47 of file getopt.c.

◆ optopt

int optopt
extern

Definition at line 48 of file getopt.c.

◆ optreset

int optreset
extern

Definition at line 20 of file getopt.c.

Referenced by getopt_internal().