| 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 |
#include "acpi.h" |
| 45 |
#include "accommon.h" |
| 46 |
#include "amlcode.h" |
| 47 |
#include "acparser.h" |
| 48 |
#include "acdebug.h" |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
#define _COMPONENT ACPI_OS_SERVICES |
| 59 |
ACPI_MODULE_NAME ("acgetline") |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
static void |
| 65 |
AcpiAcClearLine ( |
| 66 |
UINT32 EndOfLine, |
| 67 |
UINT32 CursorPosition); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
#define _ASCII_NUL 0 |
| 72 |
#define _ASCII_BACKSPACE 0x08 |
| 73 |
#define _ASCII_TAB 0x09 |
| 74 |
#define _ASCII_ESCAPE 0x1B |
| 75 |
#define _ASCII_SPACE 0x20 |
| 76 |
#define _ASCII_LEFT_BRACKET 0x5B |
| 77 |
#define _ASCII_DEL 0x7F |
| 78 |
#define _ASCII_UP_ARROW 'A' |
| 79 |
#define _ASCII_DOWN_ARROW 'B' |
| 80 |
#define _ASCII_RIGHT_ARROW 'C' |
| 81 |
#define _ASCII_LEFT_ARROW 'D' |
| 82 |
#define _ASCII_NEWLINE '\n' |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
#define ACPI_CLEAR_CHAR() \ |
| 87 |
putchar (_ASCII_BACKSPACE); \ |
| 88 |
putchar (_ASCII_SPACE); \ |
| 89 |
putchar (_ASCII_BACKSPACE); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
#define ACPI_BACKUP_CURSOR(i, Count) \ |
| 94 |
for (i = 0; i < (Count); i++) \ |
| 95 |
{putchar (_ASCII_BACKSPACE);} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
static void |
| 113 |
AcpiAcClearLine ( |
| 114 |
UINT32 EndOfLine, |
| 115 |
UINT32 CursorPosition) |
| 116 |
{ |
| 117 |
UINT32 i; |
| 118 |
|
| 119 |
|
| 120 |
if (CursorPosition < EndOfLine) |
| 121 |
{ |
| 122 |
|
| 123 |
|
| 124 |
for (i = 0; i < (EndOfLine - CursorPosition); i++) |
| 125 |
{ |
| 126 |
putchar (' '); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
for (; EndOfLine > 0; EndOfLine--) |
| 133 |
{ |
| 134 |
ACPI_CLEAR_CHAR (); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
ACPI_STATUS |
| 157 |
AcpiOsGetLine ( |
| 158 |
char *Buffer, |
| 159 |
UINT32 BufferLength, |
| 160 |
UINT32 *BytesRead) |
| 161 |
{ |
| 162 |
char *NextCommand; |
| 163 |
UINT32 MaxCommandIndex = AcpiGbl_NextCmdNum - 1; |
| 164 |
UINT32 CurrentCommandIndex = MaxCommandIndex; |
| 165 |
UINT32 PreviousCommandIndex = MaxCommandIndex; |
| 166 |
int InputChar; |
| 167 |
UINT32 CursorPosition = 0; |
| 168 |
UINT32 EndOfLine = 0; |
| 169 |
UINT32 i; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
memset (Buffer, 0, BufferLength); |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
while (1) |
| 184 |
{ |
| 185 |
if (EndOfLine >= (BufferLength - 1)) |
| 186 |
{ |
| 187 |
return (AE_BUFFER_OVERFLOW); |
| 188 |
} |
| 189 |
|
| 190 |
InputChar = getchar (); |
| 191 |
switch (InputChar) |
| 192 |
{ |
| 193 |
default: |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
if (EndOfLine == CursorPosition) |
| 198 |
{ |
| 199 |
putchar (InputChar); |
| 200 |
Buffer[EndOfLine] = (char) InputChar; |
| 201 |
|
| 202 |
EndOfLine++; |
| 203 |
CursorPosition++; |
| 204 |
Buffer[EndOfLine] = 0; |
| 205 |
continue; |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
memmove (&Buffer[CursorPosition + 1], &Buffer[CursorPosition], |
| 211 |
(EndOfLine - CursorPosition + 1)); |
| 212 |
|
| 213 |
Buffer [CursorPosition] = (char) InputChar; |
| 214 |
Buffer [EndOfLine + 1] = 0; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
fprintf (stdout, "%s", &Buffer[CursorPosition]); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
ACPI_BACKUP_CURSOR (i, EndOfLine - CursorPosition); |
| 223 |
CursorPosition++; |
| 224 |
EndOfLine++; |
| 225 |
continue; |
| 226 |
|
| 227 |
case _ASCII_DEL: |
| 228 |
|
| 229 |
if (!EndOfLine) |
| 230 |
{ |
| 231 |
continue; |
| 232 |
} |
| 233 |
|
| 234 |
if (EndOfLine == CursorPosition) |
| 235 |
{ |
| 236 |
ACPI_CLEAR_CHAR (); |
| 237 |
EndOfLine--; |
| 238 |
CursorPosition--; |
| 239 |
continue; |
| 240 |
} |
| 241 |
|
| 242 |
if (!CursorPosition) |
| 243 |
{ |
| 244 |
continue; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
memmove (&Buffer[CursorPosition - 1], &Buffer[CursorPosition], |
| 250 |
(EndOfLine - CursorPosition + 1)); |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
putchar (_ASCII_BACKSPACE); |
| 255 |
fprintf (stdout, "%s ", &Buffer[CursorPosition - 1]); |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
ACPI_BACKUP_CURSOR (i, EndOfLine - CursorPosition + 1); |
| 260 |
EndOfLine--; |
| 261 |
|
| 262 |
if (CursorPosition > 0) |
| 263 |
{ |
| 264 |
CursorPosition--; |
| 265 |
} |
| 266 |
continue; |
| 267 |
|
| 268 |
case _ASCII_NEWLINE: |
| 269 |
case _ASCII_NUL: |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
if (BytesRead) |
| 274 |
{ |
| 275 |
*BytesRead = EndOfLine; |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
putchar (InputChar); |
| 281 |
Buffer[EndOfLine] = 0; |
| 282 |
return (AE_OK); |
| 283 |
|
| 284 |
case _ASCII_TAB: |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
continue; |
| 289 |
|
| 290 |
case EOF: |
| 291 |
|
| 292 |
return (AE_ERROR); |
| 293 |
|
| 294 |
case _ASCII_ESCAPE: |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
InputChar = getchar (); |
| 299 |
if (InputChar != _ASCII_LEFT_BRACKET) |
| 300 |
{ |
| 301 |
continue; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
InputChar = getchar (); |
| 307 |
switch (InputChar) |
| 308 |
{ |
| 309 |
case _ASCII_LEFT_ARROW: |
| 310 |
|
| 311 |
if (CursorPosition > 0) |
| 312 |
{ |
| 313 |
putchar (_ASCII_BACKSPACE); |
| 314 |
CursorPosition--; |
| 315 |
} |
| 316 |
continue; |
| 317 |
|
| 318 |
case _ASCII_RIGHT_ARROW: |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
if (CursorPosition < EndOfLine) |
| 324 |
{ |
| 325 |
|
| 326 |
|
| 327 |
ACPI_BACKUP_CURSOR (i, CursorPosition); |
| 328 |
fprintf (stdout, "%s", Buffer); |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
CursorPosition++; |
| 333 |
ACPI_BACKUP_CURSOR (i, EndOfLine - CursorPosition); |
| 334 |
} |
| 335 |
continue; |
| 336 |
|
| 337 |
case _ASCII_UP_ARROW: |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
if (!CurrentCommandIndex) |
| 342 |
{ |
| 343 |
continue; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
if (CurrentCommandIndex > PreviousCommandIndex) |
| 349 |
{ |
| 350 |
CurrentCommandIndex = PreviousCommandIndex; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
NextCommand = AcpiDbGetHistoryByIndex (CurrentCommandIndex); |
| 356 |
if (!NextCommand) |
| 357 |
{ |
| 358 |
return (AE_ERROR); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
AcpiAcClearLine (EndOfLine, CursorPosition); |
| 364 |
strcpy (Buffer, NextCommand); |
| 365 |
fprintf (stdout, "%s", Buffer); |
| 366 |
EndOfLine = CursorPosition = strlen (Buffer); |
| 367 |
|
| 368 |
PreviousCommandIndex = CurrentCommandIndex; |
| 369 |
CurrentCommandIndex--; |
| 370 |
continue; |
| 371 |
|
| 372 |
case _ASCII_DOWN_ARROW: |
| 373 |
|
| 374 |
if (!MaxCommandIndex) |
| 375 |
{ |
| 376 |
continue; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
if (CurrentCommandIndex < PreviousCommandIndex) |
| 382 |
{ |
| 383 |
CurrentCommandIndex = PreviousCommandIndex; |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
if ((CurrentCommandIndex + 1) > MaxCommandIndex) |
| 389 |
{ |
| 390 |
AcpiAcClearLine (EndOfLine, CursorPosition); |
| 391 |
EndOfLine = CursorPosition = 0; |
| 392 |
PreviousCommandIndex = CurrentCommandIndex; |
| 393 |
continue; |
| 394 |
} |
| 395 |
|
| 396 |
PreviousCommandIndex = CurrentCommandIndex; |
| 397 |
CurrentCommandIndex++; |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
NextCommand = AcpiDbGetHistoryByIndex (CurrentCommandIndex); |
| 402 |
if (!NextCommand) |
| 403 |
{ |
| 404 |
return (AE_ERROR); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
AcpiAcClearLine (EndOfLine, CursorPosition); |
| 410 |
strcpy (Buffer, NextCommand); |
| 411 |
fprintf (stdout, "%s", Buffer); |
| 412 |
EndOfLine = CursorPosition = strlen (Buffer); |
| 413 |
continue; |
| 414 |
|
| 415 |
case 0x31: |
| 416 |
case 0x32: |
| 417 |
case 0x33: |
| 418 |
case 0x34: |
| 419 |
case 0x35: |
| 420 |
case 0x36: |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
(void) getchar (); |
| 426 |
continue; |
| 427 |
|
| 428 |
default: |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
continue; |
| 433 |
} |
| 434 |
continue; |
| 435 |
} |
| 436 |
} |
| 437 |
} |