private.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * shell.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. /*-------------------------------------
  13. * PRIVATE TYPES
  14. *------------------------------------- */
  15. /*-------------------------------------------------------- */
  16. /*
  17. * iterate around commands
  18. */
  19. typedef struct {
  20. const char *last_cmd;
  21. clish_nspace_visibility_t field;
  22. } clish_shell_iterator_t;
  23. /* this is used to maintain a stack of file handles */
  24. typedef struct clish_shell_file_s clish_shell_file_t;
  25. struct clish_shell_file_s {
  26. clish_shell_file_t *next;
  27. FILE *file;
  28. char *fname;
  29. unsigned int line;
  30. bool_t stop_on_error; /* stop on error for file input */
  31. };
  32. typedef struct {
  33. char *line;
  34. clish_view_t *view;
  35. lub_bintree_t viewid;
  36. } clish_shell_pwd_t;
  37. struct clish_shell_s {
  38. lub_bintree_t view_tree; /* Tree of views */
  39. lub_bintree_t ptype_tree; /* Tree of ptypes */
  40. lub_bintree_t var_tree; /* Tree of global variables */
  41. const clish_shell_hooks_t *client_hooks; /* Client callback hooks */
  42. void *client_cookie; /* Client callback cookie */
  43. clish_view_t *global; /* Reference to the global view. */
  44. clish_command_t *startup; /* This is the startup command */
  45. unsigned int idle_timeout; /* This is the idle timeout */
  46. /* Watchdog */
  47. clish_command_t *wdog; /* Watchdog command */
  48. unsigned int wdog_timeout; /* Watchdog timeout */
  49. bool_t wdog_active; /* If watchdog is active now */
  50. clish_shell_state_t state; /* The current state */
  51. char *overview; /* Overview text for this shell */
  52. tinyrl_t *tinyrl; /* Tiny readline instance */
  53. clish_shell_file_t *current_file; /* file currently in use for input */
  54. clish_shell_pwd_t **pwdv; /* Levels for the config file structure */
  55. unsigned int pwdc;
  56. int depth;
  57. konf_client_t *client;
  58. char *lockfile;
  59. char *default_shebang;
  60. char *fifo_name; /* The name of temporary fifo file. */
  61. bool_t interactive; /* Is shell interactive. */
  62. bool_t log; /* If command logging is enabled */
  63. struct passwd *user; /* Current user information */
  64. /* Plugins and symbols */
  65. lub_list_t *plugins; /* List of plugins */
  66. lub_list_t *syms; /* List of all used symbols. Must be resolved. */
  67. clish_sym_t *default_sym; /* The sym to use when builtin is not specified */
  68. /* Static params for var expanding. The refactoring is needed. */
  69. clish_param_t *param_depth;
  70. clish_param_t *param_pwd;
  71. };
  72. /**
  73. * Initialise a command iterator structure
  74. */
  75. void
  76. clish_shell_iterator_init(clish_shell_iterator_t * iter,
  77. clish_nspace_visibility_t field);
  78. /**
  79. * get the next command which is an extension of the specified line
  80. */
  81. const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
  82. instance, const char *line, clish_shell_iterator_t * iter);
  83. /**
  84. * Pop the current file handle from the stack of file handles, shutting
  85. * the file down and freeing any associated memory. The next file handle
  86. * in the stack becomes associated with the input stream for this shell.
  87. *
  88. * \return
  89. * BOOL_TRUE - the current file handle has been replaced.
  90. * BOOL_FALSE - there is only one handle on the stack which cannot be replaced.
  91. */
  92. int clish_shell_pop_file(clish_shell_t * instance);
  93. clish_view_t *clish_shell_find_view(clish_shell_t * instance, const char *name);
  94. void clish_shell_insert_view(clish_shell_t * instance, clish_view_t * view);
  95. clish_pargv_status_t clish_shell_parse(clish_shell_t * instance,
  96. const char *line, const clish_command_t ** cmd, clish_pargv_t ** pargv);
  97. clish_pargv_status_t clish_shell_parse_pargv(clish_pargv_t *pargv,
  98. const clish_command_t *cmd,
  99. void *context,
  100. clish_paramv_t *paramv,
  101. const lub_argv_t *argv,
  102. unsigned *idx, clish_pargv_t *last, unsigned need_index);
  103. char *clish_shell_word_generator(clish_shell_t * instance,
  104. const char *line, unsigned offset, unsigned state);
  105. const clish_command_t *clish_shell_resolve_command(const clish_shell_t *
  106. instance, const char *line);
  107. const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t *
  108. instance, const char *line);
  109. void clish_shell_insert_ptype(clish_shell_t * instance, clish_ptype_t * ptype);
  110. void clish_shell_tinyrl_history(clish_shell_t * instance, unsigned int *limit);
  111. tinyrl_t *clish_shell_tinyrl_new(FILE * instream,
  112. FILE * outstream, unsigned stifle);
  113. void clish_shell_tinyrl_delete(tinyrl_t * instance);
  114. void clish_shell_param_generator(clish_shell_t * instance, lub_argv_t *matches,
  115. const clish_command_t * cmd, const char *line, unsigned offset);
  116. char **clish_shell_tinyrl_completion(tinyrl_t * tinyrl,
  117. const char *line, unsigned start, unsigned end);
  118. void clish_shell__expand_viewid(const char *viewid, lub_bintree_t *tree,
  119. clish_context_t *context);
  120. void clish_shell__init_pwd(clish_shell_pwd_t *pwd);
  121. void clish_shell__fini_pwd(clish_shell_pwd_t *pwd);
  122. int clish_shell_timeout_fn(tinyrl_t *tinyrl);
  123. int clish_shell_keypress_fn(tinyrl_t *tinyrl, int key);
  124. /* Internal plugin symbols */
  125. CLISH_PLUGIN_SYM(clish_dryrun);
  126. CLISH_PLUGIN_SYM(clish_script);