| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
#include "acpi.h" |
| 56 |
#include "accommon.h" |
| 57 |
#include "acapps.h" |
| 58 |
|
| 59 |
#define ACPI_OPTION_ERROR(msg, badchar) \ |
| 60 |
if (AcpiGbl_Opterr) {fprintf (stderr, "%s%c\n", msg, badchar);} |
| 61 |
|
| 62 |
|
| 63 |
int AcpiGbl_Opterr = 1; |
| 64 |
int AcpiGbl_Optind = 1; |
| 65 |
int AcpiGbl_SubOptChar = 0; |
| 66 |
char *AcpiGbl_Optarg; |
| 67 |
|
| 68 |
static int CurrentCharPtr = 1; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
int |
| 90 |
AcpiGetoptArgument ( |
| 91 |
int argc, |
| 92 |
char **argv) |
| 93 |
{ |
| 94 |
|
| 95 |
AcpiGbl_Optind--; |
| 96 |
CurrentCharPtr++; |
| 97 |
|
| 98 |
if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0') |
| 99 |
{ |
| 100 |
AcpiGbl_Optarg = &argv[AcpiGbl_Optind++][(int) (CurrentCharPtr+1)]; |
| 101 |
} |
| 102 |
else if (++AcpiGbl_Optind >= argc) |
| 103 |
{ |
| 104 |
ACPI_OPTION_ERROR ("\nOption requires an argument", 0); |
| 105 |
|
| 106 |
CurrentCharPtr = 1; |
| 107 |
return (-1); |
| 108 |
} |
| 109 |
else |
| 110 |
{ |
| 111 |
AcpiGbl_Optarg = argv[AcpiGbl_Optind++]; |
| 112 |
} |
| 113 |
|
| 114 |
CurrentCharPtr = 1; |
| 115 |
return (0); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
int |
| 133 |
AcpiGetopt( |
| 134 |
int argc, |
| 135 |
char **argv, |
| 136 |
char *opts) |
| 137 |
{ |
| 138 |
int CurrentChar; |
| 139 |
char *OptsPtr; |
| 140 |
|
| 141 |
|
| 142 |
if (CurrentCharPtr == 1) |
| 143 |
{ |
| 144 |
if (AcpiGbl_Optind >= argc || |
| 145 |
argv[AcpiGbl_Optind][0] != '-' || |
| 146 |
argv[AcpiGbl_Optind][1] == '\0') |
| 147 |
{ |
| 148 |
return (ACPI_OPT_END); |
| 149 |
} |
| 150 |
else if (strcmp (argv[AcpiGbl_Optind], "--") == 0) |
| 151 |
{ |
| 152 |
AcpiGbl_Optind++; |
| 153 |
return (ACPI_OPT_END); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
CurrentChar = argv[AcpiGbl_Optind][CurrentCharPtr]; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
if (CurrentChar == ':' || |
| 164 |
(OptsPtr = strchr (opts, CurrentChar)) == NULL) |
| 165 |
{ |
| 166 |
ACPI_OPTION_ERROR ("Illegal option: -", CurrentChar); |
| 167 |
|
| 168 |
if (argv[AcpiGbl_Optind][++CurrentCharPtr] == '\0') |
| 169 |
{ |
| 170 |
AcpiGbl_Optind++; |
| 171 |
CurrentCharPtr = 1; |
| 172 |
} |
| 173 |
|
| 174 |
return ('?'); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
if (*++OptsPtr == ':') |
| 180 |
{ |
| 181 |
if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0') |
| 182 |
{ |
| 183 |
AcpiGbl_Optarg = &argv[AcpiGbl_Optind++][(int) (CurrentCharPtr+1)]; |
| 184 |
} |
| 185 |
else if (++AcpiGbl_Optind >= argc) |
| 186 |
{ |
| 187 |
ACPI_OPTION_ERROR ( |
| 188 |
"Option requires an argument: -", CurrentChar); |
| 189 |
|
| 190 |
CurrentCharPtr = 1; |
| 191 |
return ('?'); |
| 192 |
} |
| 193 |
else |
| 194 |
{ |
| 195 |
AcpiGbl_Optarg = argv[AcpiGbl_Optind++]; |
| 196 |
} |
| 197 |
|
| 198 |
CurrentCharPtr = 1; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
else if (*OptsPtr == '+') |
| 204 |
{ |
| 205 |
if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0') |
| 206 |
{ |
| 207 |
AcpiGbl_Optarg = &argv[AcpiGbl_Optind++][(int) (CurrentCharPtr+1)]; |
| 208 |
} |
| 209 |
else if (++AcpiGbl_Optind >= argc) |
| 210 |
{ |
| 211 |
AcpiGbl_Optarg = NULL; |
| 212 |
} |
| 213 |
else |
| 214 |
{ |
| 215 |
AcpiGbl_Optarg = argv[AcpiGbl_Optind++]; |
| 216 |
} |
| 217 |
|
| 218 |
CurrentCharPtr = 1; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
else if (*OptsPtr == '^') |
| 224 |
{ |
| 225 |
if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0') |
| 226 |
{ |
| 227 |
AcpiGbl_Optarg = &argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)]; |
| 228 |
} |
| 229 |
else |
| 230 |
{ |
| 231 |
AcpiGbl_Optarg = "^"; |
| 232 |
} |
| 233 |
|
| 234 |
AcpiGbl_SubOptChar = AcpiGbl_Optarg[0]; |
| 235 |
AcpiGbl_Optind++; |
| 236 |
CurrentCharPtr = 1; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
else if (*OptsPtr == '|') |
| 242 |
{ |
| 243 |
if (argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)] != '\0') |
| 244 |
{ |
| 245 |
AcpiGbl_Optarg = &argv[AcpiGbl_Optind][(int) (CurrentCharPtr+1)]; |
| 246 |
} |
| 247 |
else |
| 248 |
{ |
| 249 |
ACPI_OPTION_ERROR ( |
| 250 |
"Option requires a single-character suboption: -", |
| 251 |
CurrentChar); |
| 252 |
|
| 253 |
CurrentCharPtr = 1; |
| 254 |
return ('?'); |
| 255 |
} |
| 256 |
|
| 257 |
AcpiGbl_SubOptChar = AcpiGbl_Optarg[0]; |
| 258 |
AcpiGbl_Optind++; |
| 259 |
CurrentCharPtr = 1; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
else |
| 265 |
{ |
| 266 |
if (argv[AcpiGbl_Optind][++CurrentCharPtr] == '\0') |
| 267 |
{ |
| 268 |
CurrentCharPtr = 1; |
| 269 |
AcpiGbl_Optind++; |
| 270 |
} |
| 271 |
|
| 272 |
AcpiGbl_Optarg = NULL; |
| 273 |
} |
| 274 |
|
| 275 |
return (CurrentChar); |
| 276 |
} |