shell_new.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /* Create internal ptypes */
  39. /* const char *ptype_name = "__SUBCOMMAND";
  40. clish_param_t *opt_param = NULL;
  41. tmp = clish_shell_find_create_ptype(this,
  42. ptype_name, "Depth", "[^\\]+",
  43. CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
  44. assert(tmp);
  45. opt_param = clish_param_new(prefix, help, tmp);
  46. clish_param__set_mode(opt_param,
  47. CLISH_PARAM_SUBCOMMAND);
  48. clish_param__set_optional(opt_param, BOOL_TRUE);
  49. */
  50. }
  51. /*-------------------------------------------------------- */
  52. clish_shell_t *clish_shell_new(const clish_shell_hooks_t * hooks,
  53. void *cookie, FILE * istream, FILE * ostream)
  54. {
  55. clish_shell_t *this = malloc(sizeof(clish_shell_t));
  56. if (this) {
  57. clish_shell_init(this, hooks, cookie,
  58. istream, ostream);
  59. if (hooks->init_fn) {
  60. /* now call the client initialisation */
  61. if (BOOL_TRUE != hooks->init_fn(this)) {
  62. this->state = SHELL_STATE_CLOSING;
  63. }
  64. }
  65. }
  66. return this;
  67. }
  68. /*-------------------------------------------------------- */