private.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * shell/private.h - private interface to the shell class
  3. */
  4. #include "lub/bintree.h"
  5. #include "lub/list.h"
  6. #include "tinyrl/tinyrl.h"
  7. #include "clish/shell.h"
  8. #include "clish/pargv.h"
  9. #include "clish/var.h"
  10. #include "clish/action.h"
  11. #include "clish/plugin.h"
  12. #include "clish/udata.h"
  13. /*-------------------------------------
  14. * PRIVATE TYPES
  15. *------------------------------------- */
  16. /*-------------------------------------------------------- */
  17. /*
  18. * iterate around commands
  19. */
  20. typedef struct {
  21. const char *last_cmd;
  22. clish_nspace_visibility_e field;
  23. } clish_shell_iterator_t;
  24. /* this is used to maintain a stack of file handles */
  25. typedef struct clish_shell_file_s clish_shell_file_t;
  26. struct clish_shell_file_s {
  27. clish_shell_file_t *next;
  28. FILE *file;
  29. char *fname;
  30. unsigned int line;
  31. bool_t stop_on_error; /* stop on error for file input */
  32. };
  33. typedef struct {
  34. char *line;
  35. clish_view_t *view;
  36. lub_bintree_t viewid;
  37. clish_pargv_t *pargv;
  38. } clish_shell_pwd_t;
  39. /* Context structure */
  40. struct clish_context_s {
  41. clish_shell_t *shell;
  42. const clish_command_t *cmd;
  43. clish_pargv_t *pargv;
  44. const clish_action_t *action;
  45. };
  46. /* Shell structure */
  47. struct clish_shell_s {
  48. lub_bintree_t view_tree; /* Tree of views */
  49. lub_bintree_t ptype_tree; /* Tree of ptypes */
  50. lub_bintree_t var_tree; /* Tree of global variables */
  51. /* Hooks */
  52. clish_sym_t *hooks[CLISH_SYM_TYPE_MAX]; /* Callback hooks */
  53. bool_t hooks_use[CLISH_SYM_TYPE_MAX]; /* Is hook defined */
  54. clish_view_t *global; /* Reference to the global view. */
  55. clish_command_t *startup; /* This is the startup command */
  56. unsigned int idle_timeout; /* This is the idle timeout */
  57. /* Watchdog */
  58. clish_command_t *wdog; /* Watchdog command */
  59. unsigned int wdog_timeout; /* Watchdog timeout */
  60. bool_t wdog_active; /* If watchdog is active now */
  61. clish_shell_state_e state; /* The current state */
  62. char *overview; /* Overview text for this shell */
  63. tinyrl_t *tinyrl; /* Tiny readline instance */
  64. clish_shell_file_t *current_file; /* file currently in use for input */
  65. clish_shell_pwd_t **pwdv; /* Levels for the config file structure */
  66. unsigned int pwdc;
  67. int depth;
  68. konf_client_t *client;
  69. char *lockfile;
  70. char *default_shebang;
  71. char *fifo_name; /* The name of temporary fifo file. */
  72. struct passwd *user; /* Current user information */
  73. /* Boolean flags */
  74. bool_t interactive; /* Is shell interactive. */
  75. bool_t log; /* If command logging is enabled */
  76. int log_facility; /* Syslog facility */
  77. bool_t dryrun; /* Is this a dry-running */
  78. bool_t default_plugin; /* Use or not default plugin */
  79. /* Plugins and symbols */
  80. lub_list_t *plugins; /* List of plugins */
  81. lub_list_t *syms; /* List of all used symbols. Must be resolved. */
  82. /* Userdata list holder */
  83. lub_list_t *udata;
  84. };
  85. /**
  86. * Initialise a command iterator structure
  87. */
  88. void
  89. clish_shell_iterator_init(clish_shell_iterator_t * iter,
  90. clish_nspace_visibility_e field);
  91. /**
  92. * get the next command which is an extension of the specified line
  93. */
  94. const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
  95. instance, const char *line, clish_shell_iterator_t * iter);
  96. /**
  97. * Pop the current file handle from the stack of file handles, shutting
  98. * the file down and freeing any associated memory. The next file handle
  99. * in the stack becomes associated with the input stream for this shell.
  100. *
  101. * \return
  102. * BOOL_TRUE - the current file handle has been replaced.
  103. * BOOL_FALSE - there is only one handle on the stack which cannot be replaced.
  104. */
  105. int clish_shell_pop_file(clish_shell_t * instance);
  106. clish_view_t *clish_shell_find_view(clish_shell_t * instance, const char *name);
  107. void clish_shell_insert_view(clish_shell_t * instance, clish_view_t * view);
  108. clish_pargv_status_e clish_shell_parse(clish_shell_t * instance,
  109. const char *line, const clish_command_t ** cmd, clish_pargv_t ** pargv);
  110. clish_pargv_status_e clish_shell_parse_pargv(clish_pargv_t *pargv,
  111. const clish_command_t *cmd,
  112. void *context,
  113. clish_paramv_t *paramv,
  114. const lub_argv_t *argv,
  115. unsigned *idx, clish_pargv_t *last, unsigned need_index);
  116. char *clish_shell_word_generator(clish_shell_t * instance,
  117. const char *line, unsigned offset, unsigned state);
  118. const clish_command_t *clish_shell_resolve_command(const clish_shell_t *
  119. instance, const char *line);
  120. const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t *
  121. instance, const char *line);
  122. void clish_shell_insert_ptype(clish_shell_t * instance, clish_ptype_t * ptype);
  123. void clish_shell_tinyrl_history(clish_shell_t * instance, unsigned int *limit);
  124. tinyrl_t *clish_shell_tinyrl_new(FILE * instream,
  125. FILE * outstream, unsigned stifle);
  126. void clish_shell_tinyrl_delete(tinyrl_t * instance);
  127. void clish_shell_param_generator(clish_shell_t * instance, lub_argv_t *matches,
  128. const clish_command_t * cmd, const char *line, unsigned offset);
  129. char **clish_shell_tinyrl_completion(tinyrl_t * tinyrl,
  130. const char *line, unsigned start, unsigned end);
  131. void clish_shell__expand_viewid(const char *viewid, lub_bintree_t *tree,
  132. clish_context_t *context);
  133. void clish_shell__init_pwd(clish_shell_pwd_t *pwd);
  134. void clish_shell__fini_pwd(clish_shell_pwd_t *pwd);
  135. int clish_shell_timeout_fn(tinyrl_t *tinyrl);
  136. int clish_shell_keypress_fn(tinyrl_t *tinyrl, int key);