summaryrefslogtreecommitdiffstats
path: root/sys/contrib/dev/acpica/common/getopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/dev/acpica/common/getopt.c')
-rw-r--r--sys/contrib/dev/acpica/common/getopt.c68
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;
}
OpenPOWER on IntegriCloud