shell_spawn.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * shell_new.c
  3. */
  4. #include "private.h"
  5. #include "lub/string.h"
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <assert.h>
  10. #include <unistd.h>
  11. /*-------------------------------------------------------- */
  12. int clish_shell_loop(clish_shell_t *this)
  13. {
  14. int running = 0;
  15. int retval = SHELL_STATE_OK;
  16. assert(this);
  17. if (!tinyrl__get_istream(this->tinyrl))
  18. return SHELL_STATE_IO_ERROR;
  19. /* Check the shell isn't closing down */
  20. if (this && (SHELL_STATE_CLOSING == this->state))
  21. return retval;
  22. /* Loop reading and executing lines until the user quits */
  23. while (!running) {
  24. retval = SHELL_STATE_OK;
  25. /* Get input from the stream */
  26. running = clish_shell_readline(this, NULL);
  27. if (running) {
  28. switch (this->state) {
  29. case SHELL_STATE_SCRIPT_ERROR:
  30. case SHELL_STATE_SYNTAX_ERROR:
  31. /* Interactive session doesn't exit on error */
  32. if (tinyrl__get_isatty(this->tinyrl) ||
  33. (this->current_file &&
  34. !this->current_file->stop_on_error))
  35. running = 0;
  36. retval = this->state;
  37. default:
  38. break;
  39. }
  40. }
  41. if (SHELL_STATE_CLOSING == this->state)
  42. running = -1;
  43. if (running)
  44. running = clish_shell_pop_file(this);
  45. }
  46. return retval;
  47. }
  48. /*-------------------------------------------------------- */