Bump for 3.6-28
[LibreOffice.git] / soltools / cpp / _getopt.c
blob65c5d5179a208fb746690157a381580757faf662
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include <stdio.h>
3 #include <string.h>
5 #define EPR fprintf(stderr,
6 #define ERR(str, chr) if(opterr) { EPR "%s%c\n", str, chr); }
8 int opterr = 1;
9 int optind = 1;
10 int optopt;
11 char *optarg;
13 int
14 stgetopt(int argc, char *const argv[], const char *opts)
16 static int sp = 1;
17 register int c;
18 register char *cp;
20 if (sp == 1)
22 if (optind >= argc ||
23 argv[optind][0] != '-' || argv[optind][1] == '\0')
24 return -1;
25 else if (strcmp(argv[optind], "--") == 0)
27 optind++;
28 return -1;
30 else if (strcmp(argv[optind], "-isysroot") == 0)
32 // skip Mac OS X SDK selection flags
33 optind++; optind++;
36 optopt = c = argv[optind][sp];
37 if (c == ':' || (cp = strchr(opts, c)) == 0)
39 ERR(": illegal option -- ", c);
40 if (argv[optind][++sp] == '\0')
42 optind++;
43 sp = 1;
45 return '?';
47 if (*++cp == ':')
49 if (argv[optind][sp + 1] != '\0')
50 optarg = &argv[optind++][sp + 1];
51 else
52 if (++optind >= argc)
54 ERR(": option requires an argument -- ", c);
55 sp = 1;
56 return '?';
58 else
59 optarg = argv[optind++];
60 sp = 1;
62 else
64 if (argv[optind][++sp] == '\0')
66 sp = 1;
67 optind++;
69 optarg = 0;
71 return c;
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */