shell_startup.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. int res = 0;
  13. assert(this->startup);
  14. banner = clish_command__get_detail(this->startup);
  15. if (banner)
  16. tinyrl_printf(this->tinyrl, "%s\n", banner);
  17. /* Prepare context */
  18. context.shell = this;
  19. context.cmd = this->startup;
  20. context.action = clish_command__get_action(this->startup);
  21. context.pargv = NULL;
  22. /* Call log initialize */
  23. if (clish_shell__get_log(this) && this->hooks_log)
  24. SYM_FN(log,this->hooks_log)(&context, NULL, 0);
  25. /* Call startup script */
  26. res = clish_shell_execute(&context, NULL);
  27. return res;
  28. }
  29. /*----------------------------------------------------------- */
  30. void clish_shell__set_startup_view(clish_shell_t * this, const char * viewname)
  31. {
  32. clish_view_t *view;
  33. assert(this);
  34. assert(this->startup);
  35. /* Search for the view */
  36. view = clish_shell_find_create_view(this, viewname, NULL);
  37. clish_command__force_view(this->startup, view);
  38. }
  39. /*----------------------------------------------------------- */
  40. void clish_shell__set_startup_viewid(clish_shell_t * this, const char * viewid)
  41. {
  42. assert(this);
  43. assert(this->startup);
  44. clish_command__force_viewid(this->startup, viewid);
  45. }
  46. /*----------------------------------------------------------- */
  47. void clish_shell__set_default_shebang(clish_shell_t * this, const char * shebang)
  48. {
  49. assert(this);
  50. lub_string_free(this->default_shebang);
  51. this->default_shebang = lub_string_dup(shebang);
  52. }
  53. /*----------------------------------------------------------- */
  54. const char * clish_shell__get_default_shebang(const clish_shell_t * this)
  55. {
  56. assert(this);
  57. return this->default_shebang;
  58. }
  59. /*----------------------------------------------------------- */