1
0

shell_new.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * shell_new.c
  3. */
  4. #include "private.h"
  5. #include <assert.h>
  6. #include <stdlib.h>
  7. /*-------------------------------------------------------- */
  8. static void
  9. clish_shell_init(clish_shell_t * this,
  10. const clish_shell_hooks_t * hooks,
  11. void *cookie, FILE * istream, FILE * ostream)
  12. {
  13. clish_ptype_t *tmp_ptype = NULL;
  14. /* initialise the tree of views */
  15. lub_bintree_init(&this->view_tree,
  16. clish_view_bt_offset(),
  17. clish_view_bt_compare, clish_view_bt_getkey);
  18. /* initialise the tree of ptypes */
  19. lub_bintree_init(&this->ptype_tree,
  20. clish_ptype_bt_offset(),
  21. clish_ptype_bt_compare, clish_ptype_bt_getkey);
  22. assert((NULL != hooks) && (NULL != hooks->script_fn));
  23. /* set up defaults */
  24. this->client_hooks = hooks;
  25. this->client_cookie = cookie;
  26. this->view = NULL;
  27. this->viewid = NULL;
  28. this->global = NULL;
  29. this->startup = NULL;
  30. this->state = SHELL_STATE_INITIALISING;
  31. this->overview = NULL;
  32. clish_shell_iterator_init(&this->iter, CLISH_NSPACE_NONE);
  33. this->tinyrl = clish_shell_tinyrl_new(istream, ostream, 0);
  34. this->current_file = NULL;
  35. this->cfg_pwdv = NULL;
  36. this->cfg_pwdc = 0;
  37. this->client = konf_client_new(KONFD_SOCKET_PATH);
  38. this->completion_pargv = NULL;
  39. /* Create internal ptypes and params */
  40. /* Current depth */
  41. tmp_ptype = clish_shell_find_create_ptype(this,
  42. "__DEPTH", "Depth", "[0-9]+",
  43. CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
  44. assert(tmp_ptype);
  45. this->param_depth = clish_param_new("__cur_depth",
  46. "Current depth", tmp_ptype);
  47. clish_param__set_hidden(this->param_depth, BOOL_TRUE);
  48. /* Current pwd */
  49. tmp_ptype = clish_shell_find_create_ptype(this,
  50. "__PWD", "Path", ".+",
  51. CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
  52. assert(tmp_ptype);
  53. this->param_pwd = clish_param_new("__cur_pwd",
  54. "Current path", tmp_ptype);
  55. clish_param__set_hidden(this->param_pwd, BOOL_TRUE);
  56. }
  57. /*-------------------------------------------------------- */
  58. clish_shell_t *clish_shell_new(const clish_shell_hooks_t * hooks,
  59. void *cookie, FILE * istream, FILE * ostream)
  60. {
  61. clish_shell_t *this = malloc(sizeof(clish_shell_t));
  62. if (this) {
  63. clish_shell_init(this, hooks, cookie,
  64. istream, ostream);
  65. if (hooks->init_fn) {
  66. /* now call the client initialisation */
  67. if (BOOL_TRUE != hooks->init_fn(this)) {
  68. this->state = SHELL_STATE_CLOSING;
  69. }
  70. }
  71. }
  72. return this;
  73. }
  74. /*-------------------------------------------------------- */