1
0

shell_startup.c 1.9 KB

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