ReactOS  0.4.15-dev-1177-g6cb3b62
getopt.c File Reference
#include <stdio.h>
#include <string.h>
Include dependency graph for getopt.c:

Go to the source code of this file.

Functions

int getopt (int argc, char *const argv[], const char *optstring)
 

Variables

charoptarg
 
int optind = 1
 
int opterr = 1
 
int optopt
 
static int subopt
 
static int suboptind = 1
 

Function Documentation

◆ getopt()

int getopt ( int  argc,
char *const  argv[],
const char optstring 
)

Definition at line 20 of file getopt.c.

21 {
22  char *curopt;
23  char *p;
24  int cursubopt;
25 
26  if (suboptind == optind-1 && argv[suboptind][subopt] != '\0') {
27  curopt = (char *)argv[suboptind];
28  } else {
29  curopt = (char *)argv[optind];
30  if (curopt == NULL || curopt[0] != '-' || strcmp(curopt, "-") == 0)
31  return -1;
32  suboptind = optind;
33  subopt = 1;
34  optind++;
35  if (strcmp(curopt, "--") == 0)
36  return -1;
37  }
38  cursubopt = subopt++;
39  if ((p = strchr(optstring, curopt[cursubopt])) == NULL) {
40  optopt = curopt[cursubopt];
41  if (opterr)
42  fprintf(stderr, "%s: illegal option -- %c\n", argv[0], optopt);
43  return '?';
44  }
45  if (p[1] == ':') {
46  if (curopt[cursubopt+1] != '\0') {
47  optarg = curopt+cursubopt+1;
48  suboptind++;
49  return p[0];
50  }
51  if (argv[optind] == NULL) {
52  optopt = p[0];
53  if (opterr)
54  fprintf(stderr, "%s: option requires an argument -- %c\n", argv[0], optopt);
55  if (*optstring == ':')
56  return ':';
57  return '?';
58  }
59  optarg = argv[optind++];
60  }
61  return p[0];
62 }
int optopt
Definition: getopt.c:47
int optind
Definition: getopt.c:47
#define argv
Definition: mplay32.c:18
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static int suboptind
Definition: getopt.c:18
smooth NULL
Definition: ftsmooth.c:416
int opterr
Definition: getopt.c:46
const char * optarg
Definition: getopt.c:49
char * strchr(const char *String, int ch)
Definition: utclib.c:501
FILE * stderr
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLfloat GLfloat p
Definition: glext.h:8902
static int subopt
Definition: getopt.c:17

Referenced by main().

Variable Documentation

◆ optarg

char* optarg

Definition at line 13 of file getopt.c.

◆ opterr

int opterr = 1

Definition at line 15 of file getopt.c.

◆ optind

int optind = 1

Definition at line 14 of file getopt.c.

◆ optopt

int optopt

Definition at line 16 of file getopt.c.

◆ subopt

int subopt
static

Definition at line 17 of file getopt.c.

Referenced by getopt().

◆ suboptind

int suboptind = 1
static

Definition at line 18 of file getopt.c.

Referenced by getopt().