shell_new.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /* initialise the tree of views */
  14. lub_bintree_init(&this->view_tree,
  15. clish_view_bt_offset(),
  16. clish_view_bt_compare, clish_view_bt_getkey);
  17. /* initialise the tree of ptypes */
  18. lub_bintree_init(&this->ptype_tree,
  19. clish_ptype_bt_offset(),
  20. clish_ptype_bt_compare, clish_ptype_bt_getkey);
  21. assert((NULL != hooks) && (NULL != hooks->script_fn));
  22. /* set up defaults */
  23. this->client_hooks = hooks;
  24. this->client_cookie = cookie;
  25. this->view = NULL;
  26. this->viewid = NULL;
  27. this->global = NULL;
  28. this->startup = NULL;
  29. this->state = SHELL_STATE_INITIALISING;
  30. this->overview = NULL;
  31. clish_shell_iterator_init(&this->iter, CLISH_NSPACE_NONE);
  32. this->tinyrl = clish_shell_tinyrl_new(istream, ostream, 0);
  33. this->current_file = NULL;
  34. this->cfg_pwdv = NULL;
  35. this->cfg_pwdc = 0;
  36. this->client = konf_client_new(KONFD_SOCKET_PATH);
  37. this->completion_pargv = NULL;
  38. }
  39. /*-------------------------------------------------------- */
  40. clish_shell_t *clish_shell_new(const clish_shell_hooks_t * hooks,
  41. void *cookie, FILE * istream, FILE * ostream)
  42. {
  43. clish_shell_t *this = malloc(sizeof(clish_shell_t));
  44. if (this) {
  45. clish_shell_init(this, hooks, cookie,
  46. istream, ostream);
  47. if (hooks->init_fn) {
  48. /* now call the client initialisation */
  49. if (BOOL_TRUE != hooks->init_fn(this)) {
  50. this->state = SHELL_STATE_CLOSING;
  51. }
  52. }
  53. }
  54. return this;
  55. }
  56. /*-------------------------------------------------------- */