clish.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 in the file */
  42. result = clish_shell_spawn_from_file(shell,
  43. NULL, argv[i++]);
  44. }
  45. } else {
  46. /* spawn the shell */
  47. result = clish_shell_spawn_and_wait(shell, NULL);
  48. }
  49. /* Cleanup */
  50. clish_shell_delete(shell);
  51. return result ? 0 : -1;
  52. }
  53. //---------------------------------------------------------