clish.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //-------------------------------------
  2. // clish.cpp
  3. //
  4. // A simple client for libclish
  5. //-------------------------------------
  6. #include "clish/private.h"
  7. static
  8. clish_shell_hooks_t my_hooks =
  9. {
  10. NULL, /* don't worry about init callback */
  11. clish_access_callback,
  12. NULL, /* don't worry about cmd_line callback */
  13. clish_script_callback,
  14. NULL, /* don't worry about fini callback */
  15. clish_config_callback,
  16. NULL /* don't register any builtin functions */
  17. };
  18. //---------------------------------------------------------
  19. int main(int argc, const char **argv)
  20. {
  21. bool_t running;
  22. int result = -1;
  23. clish_shell_t * shell;
  24. shell = clish_shell_new(&my_hooks, NULL, stdin, stdout);
  25. if (!shell) {
  26. fprintf(stderr, "Cannot run clish.\n");
  27. return -1;
  28. }
  29. /* Load the XML files */
  30. clish_shell_load_files(shell);
  31. /* Execute startup */
  32. running = clish_shell_startup(shell);
  33. if (!running) {
  34. fprintf(stderr, "Cannot startup clish.\n");
  35. clish_shell_delete(shell);
  36. return -1;
  37. }
  38. if(argc > 1) {
  39. int i = 1;
  40. while(argc--) {
  41. /* Run the commands from the file */
  42. result = clish_shell_from_file(shell, argv[i++]);
  43. }
  44. } else {
  45. /* The interactive shell */
  46. result = clish_shell_loop(shell);
  47. }
  48. /* Cleanup */
  49. clish_shell_delete(shell);
  50. return result ? 0 : -1;
  51. }
  52. //---------------------------------------------------------