clish.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. int result = -1;
  22. clish_context_t * context;
  23. context = clish_context_new(&my_hooks, NULL, stdin, stdout);
  24. if (!context) {
  25. fprintf(stderr, "Cannot run clish.\n");
  26. return -1;
  27. }
  28. if(argc > 1) {
  29. int i = 1;
  30. while(argc--) {
  31. /* run the commands in the file */
  32. result = clish_context_spawn_from_file(context,
  33. NULL, argv[i++]);
  34. }
  35. } else {
  36. /* spawn the shell */
  37. result = clish_context_spawn_and_wait(context, NULL);
  38. }
  39. /* Cleanup */
  40. clish_context_free(context);
  41. return result ? 0 : -1;
  42. }
  43. //---------------------------------------------------------