diff options
author | jkim <jkim@FreeBSD.org> | 2013-05-20 23:52:49 +0000 |
---|---|---|
committer | jkim <jkim@FreeBSD.org> | 2013-05-20 23:52:49 +0000 |
commit | ca7944e4059769f0f5788417db3d8f3b2a8e7996 (patch) | |
tree | 3858a454e4df3ea62639923664ce32f0d9706e26 /sys/contrib/dev/acpica/common/getopt.c | |
parent | 4cdc15c1f748d4763888b9351c2316a878059a87 (diff) | |
parent | af69f95bba3597db53a980597cfd371c9f6ee7cf (diff) | |
download | FreeBSD-src-ca7944e4059769f0f5788417db3d8f3b2a8e7996.zip FreeBSD-src-ca7944e4059769f0f5788417db3d8f3b2a8e7996.tar.gz |
Merge ACPICA 20130517.
Diffstat (limited to 'sys/contrib/dev/acpica/common/getopt.c')
-rw-r--r-- | sys/contrib/dev/acpica/common/getopt.c | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/sys/contrib/dev/acpica/common/getopt.c b/sys/contrib/dev/acpica/common/getopt.c index 6bedff6..a4ad288 100644 --- a/sys/contrib/dev/acpica/common/getopt.c +++ b/sys/contrib/dev/acpica/common/getopt.c @@ -41,6 +41,15 @@ * POSSIBILITY OF SUCH DAMAGES. */ +/* + * ACPICA getopt() implementation + * + * Option strings: + * "f" - Option has no arguments + * "f:" - Option requires an argument + * "f^" - Option has optional single-char sub-options + * "f|" - Option has required single-char sub-options + */ #include <stdio.h> #include <string.h> @@ -52,9 +61,59 @@ if (AcpiGbl_Opterr) {fprintf (stderr, "%s%c\n", msg, badchar);} -int AcpiGbl_Opterr = 1; -int AcpiGbl_Optind = 1; -char *AcpiGbl_Optarg; +int AcpiGbl_Opterr = 1; +int AcpiGbl_Optind = 1; +int AcpiGbl_SubOptChar = 0; +char *AcpiGbl_Optarg; + +static int CurrentCharPtr = 1; + + +/******************************************************************************* + * + * FUNCTION: AcpiGetoptArgument + * + * PARAMETERS: argc, argv - from main + * + * RETURN: 0 if an argument was found, -1 otherwise. Sets AcpiGbl_Optarg + * to point to the next argument. + * + * DESCRIPTION: Get the next argument. Used to obtain arguments for the + * two-character options after the original call to AcpiGetopt. + * Note: Either the argument starts at the next character after + * the option, or it is pointed to by the next argv entry. + * (After call to AcpiGetopt, we need to backup to the previous + * argv entry). + * + ******************************************************************************/ + +int +AcpiGetoptArgument ( + int argc, + char **argv) +{ + AcpiGbl_Optind--; + CurrentCharPtr++; + + if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0') + { + AcpiGbl_Optarg = &argv[AcpiGbl_Optind++][(int) (CurrentCharPtr+1)]; + } + else if (++AcpiGbl_Optind >= argc) + { + ACPI_OPTION_ERROR ("Option requires an argument: -", 'v'); + + CurrentCharPtr = 1; + return (-1); + } + else + { + AcpiGbl_Optarg = argv[AcpiGbl_Optind++]; + } + + CurrentCharPtr = 1; + return (0); +} /******************************************************************************* @@ -76,7 +135,6 @@ AcpiGetopt( char **argv, char *opts) { - static int CurrentCharPtr = 1; int CurrentChar; char *OptsPtr; @@ -152,6 +210,7 @@ AcpiGetopt( AcpiGbl_Optarg = "^"; } + AcpiGbl_SubOptChar = AcpiGbl_Optarg[0]; AcpiGbl_Optind++; CurrentCharPtr = 1; } @@ -172,6 +231,7 @@ AcpiGetopt( return ('?'); } + AcpiGbl_SubOptChar = AcpiGbl_Optarg[0]; AcpiGbl_Optind++; CurrentCharPtr = 1; } |