diff options
author | fcolin | 2008-04-21 15:33:21 +0000 |
---|---|---|
committer | fcolin | 2008-04-21 15:33:21 +0000 |
commit | eef724f3d0e751fb61be907c09d553a4beab4501 (patch) | |
tree | 9c33706979dd675731665ae64d47112ad19538f0 /tools/getopt.c | |
parent | 50b963828e46b8e64b934b16a1c4d67adfdf9d88 (diff) | |
download | ivy-c-eef724f3d0e751fb61be907c09d553a4beab4501.zip ivy-c-eef724f3d0e751fb61be907c09d553a4beab4501.tar.gz ivy-c-eef724f3d0e751fb61be907c09d553a4beab4501.tar.bz2 ivy-c-eef724f3d0e751fb61be907c09d553a4beab4501.tar.xz |
compilation sous WINDOWS
Diffstat (limited to 'tools/getopt.c')
-rw-r--r-- | tools/getopt.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/getopt.c b/tools/getopt.c new file mode 100644 index 0000000..36a9bc1 --- /dev/null +++ b/tools/getopt.c @@ -0,0 +1,76 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +int optind = 1; +char *optarg = (char *)NULL; + +int getopt (int argc, char **argv, char *optstring) +{ + int cur_option; /* Current option */ + char *cp; /* Character pointer */ + static int GetOptionPosition = 1; + + if (GetOptionPosition == 1) + { + +/* Check for out of range, correct start character and not single */ + + if ((optind >= argc) || (*argv[optind] != '-') || !argv[optind][1]) + return EOF; + + if (!strcmp (argv[optind], "--")) + return EOF; + } + +/* Get the current character from the current argument vector */ + + cur_option = argv[optind][GetOptionPosition]; + +/* Validate it */ + + if ((cur_option == ':') || + ((cp = strchr (optstring, cur_option)) == (char *)NULL)) + { + +/* Move to the next offset */ + + if (!argv[optind][++GetOptionPosition]) + { + optind++; + GetOptionPosition = 1; + } + + return '?'; + } + +/* Parameters following ? */ + + optarg = (char *)NULL; + + if (*(++cp) == ':') + { + if (argv[optind][GetOptionPosition + 1]) + optarg = &argv[optind++][GetOptionPosition + 1]; + + else if (++optind >= argc) + { + optarg = (char *)NULL; + GetOptionPosition = 1; + return '?'; + } + + else + optarg = argv[optind++]; + + GetOptionPosition = 1; + } + + else if (!argv[optind][++GetOptionPosition]) + { + GetOptionPosition = 1; + optind++; + } + + return cur_option; +} |