1
0

private.h 4.9 KB

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