Test initialisation of MUIA_List_AdjustWidth and MUIA_List_AdjustHeight, and
[AROS.git] / workbench / libs / lcms2 / utils / common / xgetopt.c
blob7f3dc548a75bd87f877714caed27ca702fec1d1c
1 /*
2 getopt.c
4 */
6 #include <errno.h>
7 #include <string.h>
8 #include <stdio.h>
10 int xoptind = 1; /* index of which argument is next */
11 char *xoptarg; /* pointer to argument of current option */
12 int xopterr = 0; /* allow error message */
14 static char *letP = NULL; /* remember next option char's location */
15 char SW = '-'; /* DOS switch character, either '-' or '/' */
18 Parse the command line options, System V style.
20 Standard option syntax is:
22 option ::= SW [optLetter]* [argLetter space* argument]
26 int xgetopt(int argc, char *argv[], char *optionS)
28 unsigned char ch;
29 char *optP;
31 if (SW == 0) {
32 SW = '/';
35 if (argc > xoptind) {
36 if (letP == NULL) {
37 if ((letP = argv[xoptind]) == NULL ||
38 *(letP++) != SW) goto gopEOF;
39 if (*letP == SW) {
40 xoptind++; goto gopEOF;
43 if (0 == (ch = *(letP++))) {
44 xoptind++; goto gopEOF;
46 if (':' == ch || (optP = strchr(optionS, ch)) == NULL)
47 goto gopError;
48 if (':' == *(++optP)) {
49 xoptind++;
50 if (0 == *letP) {
51 if (argc <= xoptind) goto gopError;
52 letP = argv[xoptind++];
54 xoptarg = letP;
55 letP = NULL;
56 } else {
57 if (0 == *letP) {
58 xoptind++;
59 letP = NULL;
61 xoptarg = NULL;
63 return ch;
65 gopEOF:
66 xoptarg = letP = NULL;
67 return EOF;
69 gopError:
70 xoptarg = NULL;
71 errno = EINVAL;
72 if (xopterr)
73 perror ("get command line option");
74 return ('?');