1256655Sjkim/****************************************************************************** 2256655Sjkim * 3256655Sjkim * Module Name: acgetline - local line editing 4256655Sjkim * 5256655Sjkim *****************************************************************************/ 6256655Sjkim 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12256655Sjkim * All rights reserved. 13256655Sjkim * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119256655Sjkim * Redistribution and use in source and binary forms, with or without 120256655Sjkim * modification, are permitted provided that the following conditions 121256655Sjkim * are met: 122256655Sjkim * 1. Redistributions of source code must retain the above copyright 123256655Sjkim * notice, this list of conditions, and the following disclaimer, 124256655Sjkim * without modification. 125256655Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126256655Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127256655Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128256655Sjkim * including a substantially similar Disclaimer requirement for further 129256655Sjkim * binary redistribution. 130256655Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131256655Sjkim * of any contributors may be used to endorse or promote products derived 132256655Sjkim * from this software without specific prior written permission. 133256655Sjkim * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147256655Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148256655Sjkim * Software Foundation. 149256655Sjkim * 150316303Sjkim *****************************************************************************/ 151256655Sjkim 152272444Sjkim#include <contrib/dev/acpica/include/acpi.h> 153272444Sjkim#include <contrib/dev/acpica/include/accommon.h> 154272444Sjkim#include <contrib/dev/acpica/include/amlcode.h> 155272444Sjkim#include <contrib/dev/acpica/include/acparser.h> 156272444Sjkim#include <contrib/dev/acpica/include/acdebug.h> 157256655Sjkim 158256655Sjkim/* 159256655Sjkim * This is an os-independent implementation of line-editing services needed 160256655Sjkim * by the AcpiExec utility. It uses getchar() and putchar() and the existing 161256655Sjkim * history support provided by the AML debugger. It assumes that the terminal 162256655Sjkim * is in the correct line-editing mode such as raw and noecho. The OSL 163256655Sjkim * interface AcpiOsInitialize should do this. AcpiOsTerminate should put the 164256655Sjkim * terminal back into the original mode. 165256655Sjkim */ 166256655Sjkim#define _COMPONENT ACPI_OS_SERVICES 167256655Sjkim ACPI_MODULE_NAME ("acgetline") 168256655Sjkim 169256655Sjkim 170256655Sjkim/* Local prototypes */ 171256655Sjkim 172256655Sjkimstatic void 173256655SjkimAcpiAcClearLine ( 174256655Sjkim UINT32 EndOfLine, 175256655Sjkim UINT32 CursorPosition); 176256655Sjkim 177256655Sjkim/* Various ASCII constants */ 178256655Sjkim 179256655Sjkim#define _ASCII_NUL 0 180256655Sjkim#define _ASCII_BACKSPACE 0x08 181256655Sjkim#define _ASCII_TAB 0x09 182256655Sjkim#define _ASCII_ESCAPE 0x1B 183256655Sjkim#define _ASCII_SPACE 0x20 184256655Sjkim#define _ASCII_LEFT_BRACKET 0x5B 185256655Sjkim#define _ASCII_DEL 0x7F 186256655Sjkim#define _ASCII_UP_ARROW 'A' 187256655Sjkim#define _ASCII_DOWN_ARROW 'B' 188256655Sjkim#define _ASCII_RIGHT_ARROW 'C' 189256655Sjkim#define _ASCII_LEFT_ARROW 'D' 190256655Sjkim#define _ASCII_NEWLINE '\n' 191256655Sjkim 192256655Sjkimextern UINT32 AcpiGbl_NextCmdNum; 193256655Sjkim 194256655Sjkim/* Erase a single character on the input command line */ 195256655Sjkim 196256655Sjkim#define ACPI_CLEAR_CHAR() \ 197256655Sjkim putchar (_ASCII_BACKSPACE); \ 198256655Sjkim putchar (_ASCII_SPACE); \ 199256655Sjkim putchar (_ASCII_BACKSPACE); 200256655Sjkim 201256655Sjkim/* Backup cursor by Count positions */ 202256655Sjkim 203256655Sjkim#define ACPI_BACKUP_CURSOR(i, Count) \ 204256655Sjkim for (i = 0; i < (Count); i++) \ 205256655Sjkim {putchar (_ASCII_BACKSPACE);} 206256655Sjkim 207256655Sjkim 208256655Sjkim/****************************************************************************** 209256655Sjkim * 210256655Sjkim * FUNCTION: AcpiAcClearLine 211256655Sjkim * 212256655Sjkim * PARAMETERS: EndOfLine - Current end-of-line index 213256655Sjkim * CursorPosition - Current cursor position within line 214256655Sjkim * 215256655Sjkim * RETURN: None 216256655Sjkim * 217256655Sjkim * DESCRIPTION: Clear the entire command line the hard way, but probably the 218256655Sjkim * most portable. 219256655Sjkim * 220256655Sjkim *****************************************************************************/ 221256655Sjkim 222256655Sjkimstatic void 223256655SjkimAcpiAcClearLine ( 224256655Sjkim UINT32 EndOfLine, 225256655Sjkim UINT32 CursorPosition) 226256655Sjkim{ 227256655Sjkim UINT32 i; 228256655Sjkim 229256655Sjkim 230256655Sjkim if (CursorPosition < EndOfLine) 231256655Sjkim { 232256655Sjkim /* Clear line from current position to end of line */ 233256655Sjkim 234256655Sjkim for (i = 0; i < (EndOfLine - CursorPosition); i++) 235256655Sjkim { 236256655Sjkim putchar (' '); 237256655Sjkim } 238256655Sjkim } 239256655Sjkim 240256655Sjkim /* Clear the entire line */ 241256655Sjkim 242256655Sjkim for (; EndOfLine > 0; EndOfLine--) 243256655Sjkim { 244256655Sjkim ACPI_CLEAR_CHAR (); 245256655Sjkim } 246256655Sjkim} 247256655Sjkim 248256655Sjkim 249256655Sjkim/****************************************************************************** 250256655Sjkim * 251256655Sjkim * FUNCTION: AcpiOsGetLine 252256655Sjkim * 253256655Sjkim * PARAMETERS: Buffer - Where to return the command line 254256655Sjkim * BufferLength - Maximum length of Buffer 255256655Sjkim * BytesRead - Where the actual byte count is returned 256256655Sjkim * 257256655Sjkim * RETURN: Status and actual bytes read 258256655Sjkim * 259256655Sjkim * DESCRIPTION: Get the next input line from the terminal. NOTE: terminal 260256655Sjkim * is expected to be in a mode that supports line-editing (raw, 261256655Sjkim * noecho). This function is intended to be very portable. Also, 262256655Sjkim * it uses the history support implemented in the AML debugger. 263256655Sjkim * 264256655Sjkim *****************************************************************************/ 265256655Sjkim 266256655SjkimACPI_STATUS 267256655SjkimAcpiOsGetLine ( 268256655Sjkim char *Buffer, 269256655Sjkim UINT32 BufferLength, 270256655Sjkim UINT32 *BytesRead) 271256655Sjkim{ 272256655Sjkim char *NextCommand; 273256655Sjkim UINT32 MaxCommandIndex = AcpiGbl_NextCmdNum - 1; 274256655Sjkim UINT32 CurrentCommandIndex = MaxCommandIndex; 275256655Sjkim UINT32 PreviousCommandIndex = MaxCommandIndex; 276256655Sjkim int InputChar; 277256655Sjkim UINT32 CursorPosition = 0; 278256655Sjkim UINT32 EndOfLine = 0; 279256655Sjkim UINT32 i; 280256655Sjkim 281256655Sjkim 282256655Sjkim /* Always clear the line buffer before we read a new line */ 283256655Sjkim 284256655Sjkim memset (Buffer, 0, BufferLength); 285256655Sjkim 286256655Sjkim /* 287256655Sjkim * This loop gets one character at a time (except for esc sequences) 288256655Sjkim * until a newline or error is detected. 289256655Sjkim * 290256655Sjkim * Note: Don't attempt to write terminal control ESC sequences, even 291256655Sjkim * though it makes certain things more difficult. 292256655Sjkim */ 293256655Sjkim while (1) 294256655Sjkim { 295256655Sjkim if (EndOfLine >= (BufferLength - 1)) 296256655Sjkim { 297256655Sjkim return (AE_BUFFER_OVERFLOW); 298256655Sjkim } 299256655Sjkim 300256655Sjkim InputChar = getchar (); 301256655Sjkim switch (InputChar) 302256655Sjkim { 303256655Sjkim default: /* This is the normal character case */ 304256655Sjkim 305256655Sjkim /* Echo the character (at EOL) and copy it to the line buffer */ 306256655Sjkim 307256655Sjkim if (EndOfLine == CursorPosition) 308256655Sjkim { 309256655Sjkim putchar (InputChar); 310256655Sjkim Buffer[EndOfLine] = (char) InputChar; 311256655Sjkim 312256655Sjkim EndOfLine++; 313256655Sjkim CursorPosition++; 314256655Sjkim Buffer[EndOfLine] = 0; 315256655Sjkim continue; 316256655Sjkim } 317256655Sjkim 318256655Sjkim /* Insert character into the middle of the buffer */ 319256655Sjkim 320256655Sjkim memmove (&Buffer[CursorPosition + 1], &Buffer[CursorPosition], 321256655Sjkim (EndOfLine - CursorPosition + 1)); 322256655Sjkim 323256655Sjkim Buffer [CursorPosition] = (char) InputChar; 324256655Sjkim Buffer [EndOfLine + 1] = 0; 325256655Sjkim 326256655Sjkim /* Display the new part of line starting at the new character */ 327256655Sjkim 328256655Sjkim fprintf (stdout, "%s", &Buffer[CursorPosition]); 329256655Sjkim 330256655Sjkim /* Restore cursor */ 331256655Sjkim 332256655Sjkim ACPI_BACKUP_CURSOR (i, EndOfLine - CursorPosition); 333256655Sjkim CursorPosition++; 334256655Sjkim EndOfLine++; 335256655Sjkim continue; 336256655Sjkim 337256655Sjkim case _ASCII_DEL: /* Backspace key */ 338256655Sjkim 339256655Sjkim if (!EndOfLine) /* Any characters on the command line? */ 340256655Sjkim { 341256655Sjkim continue; 342256655Sjkim } 343256655Sjkim 344256655Sjkim if (EndOfLine == CursorPosition) /* Erase the final character */ 345256655Sjkim { 346256655Sjkim ACPI_CLEAR_CHAR (); 347256655Sjkim EndOfLine--; 348256655Sjkim CursorPosition--; 349256655Sjkim continue; 350256655Sjkim } 351256655Sjkim 352256655Sjkim if (!CursorPosition) /* Do not backup beyond start of line */ 353256655Sjkim { 354256655Sjkim continue; 355256655Sjkim } 356256655Sjkim 357256655Sjkim /* Remove the character from the line */ 358256655Sjkim 359256655Sjkim memmove (&Buffer[CursorPosition - 1], &Buffer[CursorPosition], 360256655Sjkim (EndOfLine - CursorPosition + 1)); 361256655Sjkim 362256655Sjkim /* Display the new part of line starting at the new character */ 363256655Sjkim 364256655Sjkim putchar (_ASCII_BACKSPACE); 365256655Sjkim fprintf (stdout, "%s ", &Buffer[CursorPosition - 1]); 366256655Sjkim 367256655Sjkim /* Restore cursor */ 368256655Sjkim 369256655Sjkim ACPI_BACKUP_CURSOR (i, EndOfLine - CursorPosition + 1); 370256655Sjkim EndOfLine--; 371298714Sjkim 372256655Sjkim if (CursorPosition > 0) 373256655Sjkim { 374256655Sjkim CursorPosition--; 375256655Sjkim } 376256655Sjkim continue; 377256655Sjkim 378256655Sjkim case _ASCII_NEWLINE: /* Normal exit case at end of command line */ 379256655Sjkim case _ASCII_NUL: 380256655Sjkim 381256655Sjkim /* Return the number of bytes in the command line string */ 382256655Sjkim 383256655Sjkim if (BytesRead) 384256655Sjkim { 385256655Sjkim *BytesRead = EndOfLine; 386256655Sjkim } 387256655Sjkim 388256655Sjkim /* Echo, terminate string buffer, and exit */ 389256655Sjkim 390256655Sjkim putchar (InputChar); 391256655Sjkim Buffer[EndOfLine] = 0; 392256655Sjkim return (AE_OK); 393256655Sjkim 394256655Sjkim case _ASCII_TAB: 395256655Sjkim 396256655Sjkim /* Ignore */ 397256655Sjkim 398256655Sjkim continue; 399256655Sjkim 400256655Sjkim case EOF: 401256655Sjkim 402256655Sjkim return (AE_ERROR); 403256655Sjkim 404256655Sjkim case _ASCII_ESCAPE: 405256655Sjkim 406256655Sjkim /* Check for escape sequences of the form "ESC[x" */ 407256655Sjkim 408256655Sjkim InputChar = getchar (); 409256655Sjkim if (InputChar != _ASCII_LEFT_BRACKET) 410256655Sjkim { 411256655Sjkim continue; /* Ignore this ESC, does not have the '[' */ 412256655Sjkim } 413256655Sjkim 414256655Sjkim /* Get the code following the ESC [ */ 415256655Sjkim 416256655Sjkim InputChar = getchar (); /* Backup one character */ 417256655Sjkim switch (InputChar) 418256655Sjkim { 419256655Sjkim case _ASCII_LEFT_ARROW: 420256655Sjkim 421256655Sjkim if (CursorPosition > 0) 422256655Sjkim { 423256655Sjkim putchar (_ASCII_BACKSPACE); 424256655Sjkim CursorPosition--; 425256655Sjkim } 426256655Sjkim continue; 427256655Sjkim 428256655Sjkim case _ASCII_RIGHT_ARROW: 429256655Sjkim /* 430256655Sjkim * Move one character forward. Do this without sending 431256655Sjkim * ESC sequence to the terminal for max portability. 432256655Sjkim */ 433256655Sjkim if (CursorPosition < EndOfLine) 434256655Sjkim { 435256655Sjkim /* Backup to start of line and print the entire line */ 436256655Sjkim 437256655Sjkim ACPI_BACKUP_CURSOR (i, CursorPosition); 438256655Sjkim fprintf (stdout, "%s", Buffer); 439256655Sjkim 440256655Sjkim /* Backup to where the cursor should be */ 441256655Sjkim 442256655Sjkim CursorPosition++; 443256655Sjkim ACPI_BACKUP_CURSOR (i, EndOfLine - CursorPosition); 444256655Sjkim } 445256655Sjkim continue; 446256655Sjkim 447256655Sjkim case _ASCII_UP_ARROW: 448256655Sjkim 449256655Sjkim /* If no commands available or at start of history list, ignore */ 450256655Sjkim 451256655Sjkim if (!CurrentCommandIndex) 452256655Sjkim { 453256655Sjkim continue; 454256655Sjkim } 455256655Sjkim 456256655Sjkim /* Manage our up/down progress */ 457256655Sjkim 458256655Sjkim if (CurrentCommandIndex > PreviousCommandIndex) 459256655Sjkim { 460256655Sjkim CurrentCommandIndex = PreviousCommandIndex; 461256655Sjkim } 462256655Sjkim 463256655Sjkim /* Get the historical command from the debugger */ 464256655Sjkim 465256655Sjkim NextCommand = AcpiDbGetHistoryByIndex (CurrentCommandIndex); 466256655Sjkim if (!NextCommand) 467256655Sjkim { 468256655Sjkim return (AE_ERROR); 469256655Sjkim } 470256655Sjkim 471256655Sjkim /* Make this the active command and echo it */ 472256655Sjkim 473256655Sjkim AcpiAcClearLine (EndOfLine, CursorPosition); 474256655Sjkim strcpy (Buffer, NextCommand); 475256655Sjkim fprintf (stdout, "%s", Buffer); 476256655Sjkim EndOfLine = CursorPosition = strlen (Buffer); 477256655Sjkim 478256655Sjkim PreviousCommandIndex = CurrentCommandIndex; 479256655Sjkim CurrentCommandIndex--; 480256655Sjkim continue; 481256655Sjkim 482256655Sjkim case _ASCII_DOWN_ARROW: 483256655Sjkim 484256655Sjkim if (!MaxCommandIndex) /* Any commands available? */ 485256655Sjkim { 486256655Sjkim continue; 487256655Sjkim } 488256655Sjkim 489256655Sjkim /* Manage our up/down progress */ 490256655Sjkim 491256655Sjkim if (CurrentCommandIndex < PreviousCommandIndex) 492256655Sjkim { 493256655Sjkim CurrentCommandIndex = PreviousCommandIndex; 494256655Sjkim } 495256655Sjkim 496256655Sjkim /* If we are the end of the history list, output a clear new line */ 497256655Sjkim 498256655Sjkim if ((CurrentCommandIndex + 1) > MaxCommandIndex) 499256655Sjkim { 500256655Sjkim AcpiAcClearLine (EndOfLine, CursorPosition); 501256655Sjkim EndOfLine = CursorPosition = 0; 502256655Sjkim PreviousCommandIndex = CurrentCommandIndex; 503256655Sjkim continue; 504256655Sjkim } 505256655Sjkim 506256655Sjkim PreviousCommandIndex = CurrentCommandIndex; 507256655Sjkim CurrentCommandIndex++; 508256655Sjkim 509256655Sjkim /* Get the historical command from the debugger */ 510256655Sjkim 511256655Sjkim NextCommand = AcpiDbGetHistoryByIndex (CurrentCommandIndex); 512256655Sjkim if (!NextCommand) 513256655Sjkim { 514256655Sjkim return (AE_ERROR); 515256655Sjkim } 516256655Sjkim 517256655Sjkim /* Make this the active command and echo it */ 518256655Sjkim 519256655Sjkim AcpiAcClearLine (EndOfLine, CursorPosition); 520256655Sjkim strcpy (Buffer, NextCommand); 521256655Sjkim fprintf (stdout, "%s", Buffer); 522256655Sjkim EndOfLine = CursorPosition = strlen (Buffer); 523256655Sjkim continue; 524256655Sjkim 525256655Sjkim case 0x31: 526256655Sjkim case 0x32: 527256655Sjkim case 0x33: 528256655Sjkim case 0x34: 529256655Sjkim case 0x35: 530256655Sjkim case 0x36: 531256655Sjkim /* 532256655Sjkim * Ignore the various keys like insert/delete/home/end, etc. 533256655Sjkim * But we must eat the final character of the ESC sequence. 534256655Sjkim */ 535256655Sjkim InputChar = getchar (); 536256655Sjkim continue; 537256655Sjkim 538256655Sjkim default: 539256655Sjkim 540256655Sjkim /* Ignore random escape sequences that we don't care about */ 541256655Sjkim 542256655Sjkim continue; 543256655Sjkim } 544256655Sjkim continue; 545256655Sjkim } 546256655Sjkim } 547256655Sjkim} 548