ReactOS
0.4.16-dev-847-g386fccd
getopt.c
Go to the documentation of this file.
1
2
/* jgaa oct 9th 2000: Found this on www.
3
* No copyright information given.
4
* Slightly modidied.
5
*
6
* Origin: http://www.winsite.com/info/pc/win3/winsock/sossntr4.zip/SOSSNT/SRC/GETOPT.C.html
7
*/
8
9
/* got this off net.sources */
10
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <string.h>
14
15
#include "
getopt.h
"
16
17
18
/*
19
* get option letter from argument vector
20
*/
21
int
opterr
= 1,
/* useless, never set or used */
22
optind
= 1,
/* index into parent argv vector */
23
optopt
;
/* character checked for validity */
24
char
*
optarg
;
/* argument associated with option */
25
26
#define BADCH (int)'?'
27
#define EMSG ""
28
#define tell(s) fputs(*argv,stderr);fputs(s,stderr); \
29
fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);
30
31
int
getopt
(
int
argc
,
char
*
const
*
argv
,
const
char
*optstring)
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
}
argc
static int argc
Definition:
ServiceArgs.c:12
strchr
char * strchr(const char *String, int ch)
Definition:
utclib.c:501
optopt
int optopt
Definition:
getopt.c:48
EMSG
#define EMSG
Definition:
getopt.c:52
getopt
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition:
getopt.c:55
optarg
const char * optarg
Definition:
getopt.c:49
optind
int optind
Definition:
getopt.c:47
opterr
int opterr
Definition:
getopt.c:46
NULL
#define NULL
Definition:
types.h:112
EOF
#define EOF
Definition:
stdio.h:24
argv
#define argv
Definition:
mplay32.c:18
tell
#define tell(s)
Definition:
getopt.c:28
place
static char * place
Definition:
getopt.c:55
getopt.h
sdk
lib
3rdparty
adns
adns_win32
getopt.c
Generated on Sat Mar 22 2025 06:15:20 for ReactOS by
1.9.6