1
0

private.h 5.0 KB

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