ReactOS  0.4.15-dev-3324-gda4e15f
getopt.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
Include dependency graph for getopt.c:

Go to the source code of this file.

Macros

#define BADCH   (int)'?'
 
#define EMSG   ""
 
#define tell(s)
 

Functions

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

Variables

int opterr = 1
 
int optind = 1
 
int optopt
 
charoptarg
 

Macro Definition Documentation

◆ BADCH

#define BADCH   (int)'?'

Definition at line 26 of file getopt.c.

◆ EMSG

#define EMSG   ""

Definition at line 27 of file getopt.c.

◆ tell

#define tell (   s)
Value:
fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);
_Check_return_opt_ _CRTIMP int __cdecl fputc(_In_ int _Ch, _Inout_ FILE *_File)
int optopt
Definition: getopt.c:47
#define argv
Definition: mplay32.c:18
GLdouble s
Definition: gl.h:2039
#define BADCH
Definition: getopt.c:26
FILE * stderr
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)

Definition at line 28 of file getopt.c.

Function Documentation

◆ getopt()

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

Definition at line 31 of file getopt.c.

32 {
33  static char *place = EMSG; /* option letter processing */
34  register char *oli; /* option letter list index */
35 
36  if(!*place) { /* update scanning pointer */
37  if(optind >= argc || *(place = argv[optind]) != '-' || !*++place)
38  return(EOF);
39  if (*place == '-') { /* found "--" */
40  ++optind;
41  return(EOF);
42  }
43  } /* option letter okay? */
44  if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(optstring,optopt)))
45  {
46  if(!*place) ++optind;
47  tell(": illegal option -- ");
48  }
49  if (*++oli != ':') { /* don't need argument */
50  optarg = NULL;
51  if (!*place) ++optind;
52  }
53  else { /* need an argument */
54  if (*place) optarg = place; /* no white space */
55  else if (argc <= ++optind) { /* no arg */
56  place = EMSG;
57  tell(": option requires an argument -- ");
58  }
59  else optarg = argv[optind]; /* white space */
60  place = EMSG;
61  ++optind;
62  }
63  return(optopt); /* dump back option letter */
64 }
static int argc
Definition: ServiceArgs.c:12
int optopt
Definition: getopt.c:47
#define tell(s)
Definition: getopt.c:28
int optind
Definition: getopt.c:47
#define argv
Definition: mplay32.c:18
static char * place
Definition: getopt.c:55
#define EMSG
Definition: getopt.c:27
const char * optarg
Definition: getopt.c:49
#define NULL
Definition: types.h:112
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define EOF
Definition: stdio.h:24

Variable Documentation

◆ optarg

char* optarg

Definition at line 24 of file getopt.c.

◆ opterr

int opterr = 1

Definition at line 21 of file getopt.c.

◆ optind

int optind = 1

Definition at line 22 of file getopt.c.

◆ optopt

int optopt

Definition at line 22 of file getopt.c.