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

Go to the source code of this file.

Functions

void GetoptReset (void)
 
static charNextOption (const char *const ostr)
 
int Getopt (int nargc, const char **const nargv, const char *const ostr)
 

Variables

int gOptErr = 1
 
int gOptInd = 1
 
int gOptOpt
 
const chargOptArg
 
const chargOptPlace = kGetoptErrMsg
 

Function Documentation

◆ Getopt()

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

Definition at line 42 of file getopt.c.

43{
44 const char *oli; /* Option letter list index */
45
46 if (!*gOptPlace) { /* update scanning pointer */
47 if (gOptInd >= nargc || *(gOptPlace = nargv[gOptInd]) != '-')
48 return (EOF);
49 if (gOptPlace[1] && *++gOptPlace == '-') { /* found "--" */
50 ++gOptInd;
51 return (EOF);
52 }
53 } /* Option letter okay? */
54 oli = NextOption(ostr);
55 if (oli == NULL) {
56 if (!*gOptPlace)
57 ++gOptInd;
58 if (gOptErr)
59 (void) fprintf(stderr, "%s%s%c\n", *nargv, ": illegal option -- ", gOptOpt);
60 return(kGetoptBadChar);
61 }
62 if (*++oli != ':') { /* don't need argument */
63 gOptArg = NULL;
64 if (!*gOptPlace)
65 ++gOptInd;
66 } else { /* need an argument */
67 if (*gOptPlace) /* no white space */
69 else if (nargc <= ++gOptInd) { /* no arg */
71 if (gOptErr)
72 (void) fprintf(stderr, "%s%s%c\n", *nargv, ": option requires an argument -- ", gOptOpt);
73 return(kGetoptBadChar);
74 } else /* white space */
75 gOptArg = nargv[gOptInd];
77 ++gOptInd;
78 }
79 return (gOptOpt); /* dump back Option letter */
80} /* Getopt */
#define NULL
Definition: types.h:112
#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,...)
int gOptErr
Definition: getopt.c:13
const char * gOptArg
Definition: getopt.c:16
int gOptInd
Definition: getopt.c:14
int gOptOpt
Definition: getopt.c:15
static char * NextOption(const char *const ostr)
Definition: getopt.c:31
const char * gOptPlace
Definition: getopt.c:17
#define kGetoptErrMsg
Definition: getopt.h:9
#define kGetoptBadChar
Definition: getopt.h:8

Referenced by DeleteCmd(), GetCmd(), LookupCmd(), main(), MkdirCmd(), MlsCmd(), OpenCmd(), PutCmd(), RmdirCmd(), SpoolGetCmd(), and SpoolPutCmd().

◆ GetoptReset()

void GetoptReset ( void  )

Definition at line 21 of file getopt.c.

22{
23 gOptInd = 1;
25} /* GetoptReset */

Referenced by DeleteCmd(), GetCmd(), LookupCmd(), main(), MkdirCmd(), MlsCmd(), OpenCmd(), PreInit(), PutCmd(), RmdirCmd(), SpoolGetCmd(), and SpoolPutCmd().

◆ NextOption()

static char * NextOption ( const char *const  ostr)
static

Definition at line 31 of file getopt.c.

32{
33 if ((gOptOpt = (int) *gOptPlace++) == (int) ':')
34 return 0;
35 return strchr(ostr, gOptOpt);
36} /* NextOption */
char * strchr(const char *String, int ch)
Definition: utclib.c:501

Referenced by BlAppendBootOptions(), BlGetBootOptionListSize(), ChooseGinaUI(), Getopt(), IsConsoleBoot(), IsConsoleShell(), IsLiveCD(), MiscGetBootOption(), and NtLdrGetNextOption().

Variable Documentation

◆ gOptArg

const char* gOptArg

Definition at line 16 of file getopt.c.

Referenced by Getopt(), main(), OpenCmd(), SpoolGetCmd(), and SpoolPutCmd().

◆ gOptErr

int gOptErr = 1

Definition at line 13 of file getopt.c.

Referenced by Getopt().

◆ gOptInd

◆ gOptOpt

int gOptOpt

Definition at line 15 of file getopt.c.

Referenced by Getopt(), and NextOption().

◆ gOptPlace

const char* gOptPlace = kGetoptErrMsg

Definition at line 17 of file getopt.c.

Referenced by Getopt(), GetoptReset(), and NextOption().