shell_startup.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * shell_startup.c
  3. */
  4. #include "private.h"
  5. #include <assert.h>
  6. #include "lub/string.h"
  7. /*----------------------------------------------------------- */
  8. int clish_shell_startup(clish_shell_t *this)
  9. {
  10. const char *banner;
  11. clish_context_t context;
  12. if (!this->startup) {
  13. fprintf(stderr, "Error: Can't get valid STARTUP tag.\n");
  14. return -1;
  15. }
  16. /* Prepare context */
  17. context.shell = this;
  18. context.cmd = this->startup;
  19. context.action = clish_command__get_action(this->startup);
  20. context.pargv = NULL;
  21. /* If an init hook exists - call it. */
  22. if (clish_shell_exec_init(&context)) {
  23. fprintf(stderr, "Error: Init hook returned error code.\n");
  24. return -1;
  25. }
  26. banner = clish_command__get_detail(this->startup);
  27. if (banner)
  28. tinyrl_printf(this->tinyrl, "%s\n", banner);
  29. /* Call log initialize */
  30. if (clish_shell__get_log(this))
  31. clish_shell_exec_log(&context, NULL, 0);
  32. /* Call startup script */
  33. return clish_shell_execute(&context, NULL);
  34. }
  35. /*----------------------------------------------------------- */
  36. void clish_shell__set_startup_view(clish_shell_t * this, const char * viewname)
  37. {
  38. clish_view_t *view;
  39. assert(this);
  40. assert(this->startup);
  41. /* Search for the view */
  42. view = clish_shell_find_create_view(this, viewname, NULL);
  43. clish_command__force_view(this->startup, view);
  44. }
  45. /*----------------------------------------------------------- */
  46. void clish_shell__set_startup_viewid(clish_shell_t * this, const char * viewid)
  47. {
  48. assert(this);
  49. assert(this->startup);
  50. clish_command__force_viewid(this->startup, viewid);
  51. }
  52. /*----------------------------------------------------------- */
  53. void clish_shell__set_default_shebang(clish_shell_t * this, const char * shebang)
  54. {
  55. assert(this);
  56. lub_string_free(this->default_shebang);
  57. this->default_shebang = lub_string_dup(shebang);
  58. }
  59. /*----------------------------------------------------------- */
  60. const char * clish_shell__get_default_shebang(const clish_shell_t * this)
  61. {
  62. assert(this);
  63. return this->default_shebang;
  64. }
  65. /*----------------------------------------------------------- */