You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <readline/readline.h>
  23. #include <gpxe/command.h>
  24. #include <gpxe/shell.h>
  25. /** @file
  26. *
  27. * Minimal command shell
  28. *
  29. */
  30. /** The shell prompt string */
  31. static const char shell_prompt[] = "gPXE> ";
  32. /** Flag set in order to exit shell */
  33. static int exit_flag = 0;
  34. /** "exit" command body */
  35. static int exit_exec ( int argc, char **argv __unused ) {
  36. if ( argc == 1 ) {
  37. exit_flag = 1;
  38. } else {
  39. printf ( "Usage: exit\n"
  40. "Exits the command shell\n" );
  41. }
  42. return 0;
  43. }
  44. /** "exit" command definition */
  45. struct command exit_command __command = {
  46. .name = "exit",
  47. .exec = exit_exec,
  48. };
  49. /** "help" command body */
  50. static int help_exec ( int argc __unused, char **argv __unused ) {
  51. struct command *command;
  52. unsigned int hpos = 0;
  53. printf ( "\nAvailable commands:\n\n" );
  54. for_each_table_entry ( command, COMMANDS ) {
  55. hpos += printf ( " %s", command->name );
  56. if ( hpos > ( 16 * 4 ) ) {
  57. printf ( "\n" );
  58. hpos = 0;
  59. } else {
  60. while ( hpos % 16 ) {
  61. printf ( " " );
  62. hpos++;
  63. }
  64. }
  65. }
  66. printf ( "\n\nType \"<command> --help\" for further information\n\n" );
  67. return 0;
  68. }
  69. /** "help" command definition */
  70. struct command help_command __command = {
  71. .name = "help",
  72. .exec = help_exec,
  73. };
  74. /**
  75. * Start command shell
  76. *
  77. */
  78. void shell ( void ) {
  79. char *line;
  80. exit_flag = 0;
  81. while ( ! exit_flag ) {
  82. line = readline ( shell_prompt );
  83. if ( line ) {
  84. system ( line );
  85. free ( line );
  86. }
  87. }
  88. }