2 /******************************************************************************
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
48 #include <contrib/dev/acpica/include/acpi.h>
49 #include <contrib/dev/acpica/include/accommon.h>
50 #include <contrib/dev/acpica/include/acapps.h>
52 #define ERR(szz,czz) if(AcpiGbl_Opterr){fprintf(stderr,"%s%s%c\n",argv[0],szz,czz);}
55 int AcpiGbl_Opterr = 1;
56 int AcpiGbl_Optind = 1;
60 /*******************************************************************************
62 * FUNCTION: AcpiGetopt
64 * PARAMETERS: argc, argv - from main
65 * opts - options info list
67 * RETURN: Option character or EOF
69 * DESCRIPTION: Get the next option
71 ******************************************************************************/
79 static int CurrentCharPtr = 1;
84 if (CurrentCharPtr == 1)
86 if (AcpiGbl_Optind >= argc ||
87 argv[AcpiGbl_Optind][0] != '-' ||
88 argv[AcpiGbl_Optind][1] == '\0')
92 else if (strcmp (argv[AcpiGbl_Optind], "--") == 0)
101 CurrentChar = argv[AcpiGbl_Optind][CurrentCharPtr];
103 /* Make sure that the option is legal */
105 if (CurrentChar == ':' ||
106 (OptsPtr = strchr (opts, CurrentChar)) == NULL)
108 ERR (": illegal option -- ", CurrentChar);
110 if (argv[AcpiGbl_Optind][++CurrentCharPtr] == '\0')
119 /* Option requires an argument? */
121 if (*++OptsPtr == ':')
123 if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0')
125 AcpiGbl_Optarg = &argv[AcpiGbl_Optind++][(int) (CurrentCharPtr+1)];
127 else if (++AcpiGbl_Optind >= argc)
129 ERR (": option requires an argument -- ", CurrentChar);
136 AcpiGbl_Optarg = argv[AcpiGbl_Optind++];
142 /* Option has optional single-char arguments? */
144 else if (*OptsPtr == '^')
146 if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0')
148 AcpiGbl_Optarg = &argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)];
152 AcpiGbl_Optarg = "^";
159 /* Option with no arguments */
163 if (argv[AcpiGbl_Optind][++CurrentCharPtr] == '\0')
169 AcpiGbl_Optarg = NULL;
172 return (CurrentChar);