dbhistry.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /******************************************************************************
  2.  *
  3.  * Module Name: dbhistry - debugger HISTORY command
  4.  *              $Revision: 19 $
  5.  *
  6.  *****************************************************************************/
  7. /*
  8.  *  Copyright (C) 2000, 2001 R. Byron Moore
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  */
  24. #include "acpi.h"
  25. #include "acparser.h"
  26. #include "acdispat.h"
  27. #include "amlcode.h"
  28. #include "acnamesp.h"
  29. #include "acparser.h"
  30. #include "acevents.h"
  31. #include "acinterp.h"
  32. #include "acdebug.h"
  33. #include "actables.h"
  34. #ifdef ENABLE_DEBUGGER
  35. #define _COMPONENT          ACPI_DEBUGGER
  36.  MODULE_NAME         ("dbhistry")
  37. #define HI_NO_HISTORY       0
  38. #define HI_RECORD_HISTORY   1
  39. #define HISTORY_SIZE        20
  40. typedef struct history_info
  41. {
  42. NATIVE_CHAR             command[80];
  43. u32                     cmd_num;
  44. } HISTORY_INFO;
  45. HISTORY_INFO                acpi_gbl_history_buffer[HISTORY_SIZE];
  46. u16                         acpi_gbl_lo_history = 0;
  47. u16                         acpi_gbl_num_history = 0;
  48. u16                         acpi_gbl_next_history_index = 0;
  49. u32                         acpi_gbl_next_cmd_num = 1;
  50. /*******************************************************************************
  51.  *
  52.  * FUNCTION:    Acpi_db_add_to_history
  53.  *
  54.  * PARAMETERS:  Command_line    - Command to add
  55.  *
  56.  * RETURN:      None
  57.  *
  58.  * DESCRIPTION: Add a command line to the history buffer.
  59.  *
  60.  ******************************************************************************/
  61. void
  62. acpi_db_add_to_history (
  63. NATIVE_CHAR             *command_line)
  64. {
  65. /* Put command into the next available slot */
  66. STRCPY (acpi_gbl_history_buffer[acpi_gbl_next_history_index].command, command_line);
  67. acpi_gbl_history_buffer[acpi_gbl_next_history_index].cmd_num = acpi_gbl_next_cmd_num;
  68. /* Adjust indexes */
  69. if ((acpi_gbl_num_history == HISTORY_SIZE) &&
  70. (acpi_gbl_next_history_index == acpi_gbl_lo_history)) {
  71. acpi_gbl_lo_history++;
  72. if (acpi_gbl_lo_history >= HISTORY_SIZE) {
  73. acpi_gbl_lo_history = 0;
  74. }
  75. }
  76. acpi_gbl_next_history_index++;
  77. if (acpi_gbl_next_history_index >= HISTORY_SIZE) {
  78. acpi_gbl_next_history_index = 0;
  79. }
  80. acpi_gbl_next_cmd_num++;
  81. if (acpi_gbl_num_history < HISTORY_SIZE) {
  82. acpi_gbl_num_history++;
  83. }
  84. }
  85. /*******************************************************************************
  86.  *
  87.  * FUNCTION:    Acpi_db_display_history
  88.  *
  89.  * PARAMETERS:  None
  90.  *
  91.  * RETURN:      None
  92.  *
  93.  * DESCRIPTION: Display the contents of the history buffer
  94.  *
  95.  ******************************************************************************/
  96. void
  97. acpi_db_display_history (void)
  98. {
  99. NATIVE_UINT             i;
  100. u16                     history_index;
  101. history_index = acpi_gbl_lo_history;
  102. /* Dump entire history buffer */
  103. for (i = 0; i < acpi_gbl_num_history; i++) {
  104. acpi_os_printf ("%ld %sn", acpi_gbl_history_buffer[history_index].cmd_num,
  105.  acpi_gbl_history_buffer[history_index].command);
  106. history_index++;
  107. if (history_index >= HISTORY_SIZE) {
  108. history_index = 0;
  109. }
  110. }
  111. }
  112. /*******************************************************************************
  113.  *
  114.  * FUNCTION:    Acpi_db_get_from_history
  115.  *
  116.  * PARAMETERS:  Command_num_arg         - String containing the number of the
  117.  *                                        command to be retrieved
  118.  *
  119.  * RETURN:      None
  120.  *
  121.  * DESCRIPTION: Get a command from the history buffer
  122.  *
  123.  ******************************************************************************/
  124. NATIVE_CHAR *
  125. acpi_db_get_from_history (
  126. NATIVE_CHAR             *command_num_arg)
  127. {
  128. NATIVE_UINT             i;
  129. u16                     history_index;
  130. u32                     cmd_num;
  131. if (command_num_arg == NULL) {
  132. cmd_num = acpi_gbl_next_cmd_num - 1;
  133. }
  134. else {
  135. cmd_num = STRTOUL (command_num_arg, NULL, 0);
  136. }
  137. /* Search history buffer */
  138. history_index = acpi_gbl_lo_history;
  139. for (i = 0; i < acpi_gbl_num_history; i++) {
  140. if (acpi_gbl_history_buffer[history_index].cmd_num == cmd_num) {
  141. /* Found the commnad, return it */
  142. return (acpi_gbl_history_buffer[history_index].command);
  143. }
  144. history_index++;
  145. if (history_index >= HISTORY_SIZE) {
  146. history_index = 0;
  147. }
  148. }
  149. acpi_os_printf ("Invalid history number: %dn", history_index);
  150. return (NULL);
  151. }
  152. #endif /* ENABLE_DEBUGGER */