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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include <stdint.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <readline/readline.h>
  22. #include <gpxe/command.h>
  23. #include <gpxe/shell.h>
  24. /** @file
  25. *
  26. * Minimal command shell
  27. *
  28. */
  29. static struct command commands[0]
  30. __table_start ( struct command, commands );
  31. static struct command commands_end[0]
  32. __table_end ( struct command, commands );
  33. /** The shell prompt string */
  34. static const char shell_prompt[] = "gPXE> ";
  35. /** Flag set in order to exit shell */
  36. static int exit_flag = 0;
  37. /** "exit" command body */
  38. static int exit_exec ( int argc, char **argv __unused ) {
  39. if ( argc == 1 ) {
  40. exit_flag = 1;
  41. } else {
  42. printf ( "Usage: exit\n"
  43. "Exits the command shell\n" );
  44. }
  45. return 0;
  46. }
  47. /** "exit" command definition */
  48. struct command exit_command __command = {
  49. .name = "exit",
  50. .exec = exit_exec,
  51. };
  52. /** "help" command body */
  53. static int help_exec ( int argc __unused, char **argv __unused ) {
  54. struct command *command;
  55. printf ( "\nAvailable commands:\n\n" );
  56. for ( command = commands ; command < commands_end ; command++ ) {
  57. printf ( " %s\n", command->name );
  58. }
  59. printf ( "\nType \"<command> --help\" for further information\n\n" );
  60. return 0;
  61. }
  62. /** "help" command definition */
  63. struct command help_command __command = {
  64. .name = "help",
  65. .exec = help_exec,
  66. };
  67. /**
  68. * Start command shell
  69. *
  70. */
  71. void shell ( void ) {
  72. char *line;
  73. exit_flag = 0;
  74. while ( ! exit_flag ) {
  75. line = readline ( shell_prompt );
  76. if ( line ) {
  77. system ( line );
  78. free ( line );
  79. }
  80. }
  81. }