private.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * shell.h - private interface to the shell class
  3. */
  4. #include "lub/bintree.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. /*-------------------------------------
  11. * PRIVATE TYPES
  12. *------------------------------------- */
  13. /*-------------------------------------------------------- */
  14. /*
  15. * iterate around commands
  16. */
  17. typedef struct {
  18. const char *last_cmd;
  19. clish_nspace_visibility_t field;
  20. } clish_shell_iterator_t;
  21. /* this is used to maintain a stack of file handles */
  22. typedef struct clish_shell_file_s clish_shell_file_t;
  23. struct clish_shell_file_s {
  24. clish_shell_file_t *next;
  25. FILE *file;
  26. bool_t stop_on_error; /* stop on error for file input */
  27. };
  28. typedef struct {
  29. char *line;
  30. clish_view_t *view;
  31. char *viewid;
  32. } clish_shell_pwd_t;
  33. struct clish_shell_s {
  34. lub_bintree_t view_tree; /* Maintain a tree of views */
  35. lub_bintree_t ptype_tree; /* Maintain a tree of ptypes */
  36. lub_bintree_t var_tree; /* Maintain a tree of global variables */
  37. const clish_shell_hooks_t *client_hooks; /* Client callback hooks */
  38. void *client_cookie; /* Client callback cookie */
  39. clish_view_t *global; /* Reference to the global view. */
  40. clish_view_t *view; /* Reference to the current view. */
  41. clish_command_t *startup; /* This is the startup command */
  42. clish_shell_state_t state; /* The current state */
  43. char *overview; /* Overview text for this shell. */
  44. char *viewid; /* The current view ID string */
  45. tinyrl_t *tinyrl; /* Tiny readline instance */
  46. clish_shell_file_t *current_file; /* file currently in use for input */
  47. clish_shell_pwd_t **cfg_pwdv; /* Levels for the config file structure */
  48. unsigned cfg_pwdc;
  49. konf_client_t *client;
  50. char * lockfile;
  51. pthread_t pthread;
  52. char * default_shebang;
  53. char * fifo_name; /* The name of temporary fifo file. */
  54. bool_t interactive; /* Is shell interactive. */
  55. /* Static params for var expanding. The refactoring is needed. */
  56. clish_param_t *param_depth;
  57. clish_param_t *param_pwd;
  58. clish_param_t *param_interactive;
  59. };
  60. /**
  61. * Initialise a command iterator structure
  62. */
  63. void
  64. clish_shell_iterator_init(clish_shell_iterator_t * iter,
  65. clish_nspace_visibility_t field);
  66. /**
  67. * get the next command which is an extension of the specified line
  68. */
  69. const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
  70. instance, const char *line, clish_shell_iterator_t * iter);
  71. /**
  72. * Pop the current file handle from the stack of file handles, shutting
  73. * the file down and freeing any associated memory. The next file handle
  74. * in the stack becomes associated with the input stream for this shell.
  75. *
  76. * \return
  77. * BOOL_TRUE - the current file handle has been replaced.
  78. * BOOL_FALSE - there is only one handle on the stack which cannot be replaced.
  79. */
  80. bool_t clish_shell_pop_file(clish_shell_t * instance);
  81. clish_view_t *clish_shell_find_view(clish_shell_t * instance, const char *name);
  82. void clish_shell_insert_view(clish_shell_t * instance, clish_view_t * view);
  83. clish_pargv_status_t clish_shell_parse(clish_shell_t * instance,
  84. const char *line, const clish_command_t ** cmd, clish_pargv_t ** pargv);
  85. clish_pargv_status_t clish_shell_parse_pargv(clish_pargv_t *pargv,
  86. const clish_command_t *cmd,
  87. void *context,
  88. clish_paramv_t *paramv,
  89. const lub_argv_t *argv,
  90. unsigned *idx, clish_pargv_t *last, unsigned need_index);
  91. char *clish_shell_word_generator(clish_shell_t * instance,
  92. const char *line, unsigned offset, unsigned state);
  93. const clish_command_t *clish_shell_resolve_command(const clish_shell_t *
  94. instance, const char *line);
  95. const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t *
  96. instance, const char *line);
  97. void clish_shell_insert_ptype(clish_shell_t * instance, clish_ptype_t * ptype);
  98. void clish_shell_tinyrl_history(clish_shell_t * instance, unsigned int *limit);
  99. tinyrl_t *clish_shell_tinyrl_new(FILE * instream,
  100. FILE * outstream, unsigned stifle);
  101. void clish_shell_tinyrl_delete(tinyrl_t * instance);
  102. void clish_shell_param_generator(clish_shell_t * instance, lub_argv_t *matches,
  103. const clish_command_t * cmd, const char *line, unsigned offset);
  104. char **clish_shell_tinyrl_completion(tinyrl_t * tinyrl,
  105. const char *line, unsigned start, unsigned end);