private.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * shell.h - private interface to the shell class
  3. */
  4. #include "clish/shell.h"
  5. #include "clish/pargv.h"
  6. #include "clish/variable.h"
  7. #include "lub/bintree.h"
  8. #include "tinyrl/tinyrl.h"
  9. /*-------------------------------------
  10. * PRIVATE TYPES
  11. *------------------------------------- */
  12. typedef enum {
  13. SHELL_STATE_INITIALISING,
  14. SHELL_STATE_READY,
  15. SHELL_STATE_HELPING,
  16. SHELL_STATE_SCRIPT_ERROR,
  17. SHELL_STATE_CLOSING
  18. } shell_state_t;
  19. /*
  20. * iterate around commands
  21. */
  22. typedef struct {
  23. const char *last_cmd;
  24. clish_nspace_visibility_t field;
  25. } clish_shell_iterator_t;
  26. /* this is used to maintain a stack of file handles */
  27. typedef struct clish_shell_file_s clish_shell_file_t;
  28. struct clish_shell_file_s {
  29. clish_shell_file_t *next;
  30. FILE *file;
  31. bool_t stop_on_error; /* stop on error for file input */
  32. };
  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. const clish_shell_hooks_t *client_hooks; /* Client callback hooks */
  37. void *client_cookie; /* Client callback cookie */
  38. clish_view_t *global; /* Reference to the global view. */
  39. clish_view_t *view; /* Reference to the current view. */
  40. clish_command_t *startup; /* This is the startup command */
  41. clish_shell_iterator_t iter; /* used for iterating commands */
  42. 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. char **cfg_pwdv; /* Levels for the config file structure */
  48. unsigned cfg_pwdc;
  49. conf_client_t *client;
  50. clish_pargv_t *completion_pargv;
  51. unsigned completion_index;
  52. unsigned completion_pindex;
  53. };
  54. /**
  55. * Initialise a command iterator structure
  56. */
  57. void
  58. clish_shell_iterator_init(clish_shell_iterator_t * iter,
  59. clish_nspace_visibility_t field);
  60. /**
  61. * get the next command which is an extension of the specified line
  62. */
  63. const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
  64. instance,
  65. const char *line,
  66. clish_shell_iterator_t *
  67. iter);
  68. /**
  69. * Push the specified file handle on to the stack of file handles
  70. * for this shell. The specified file will become the source of
  71. * commands, until it is exhausted.
  72. *
  73. * \return
  74. * BOOL_TRUE - the file was successfully associated with the shell.
  75. * BOOL_FALSE - there was insufficient resource to associate this file.
  76. */
  77. bool_t
  78. clish_shell_push_file(clish_shell_t * instance,
  79. FILE * file, bool_t stop_on_error);
  80. /**
  81. * Pop the current file handle from the stack of file handles, shutting
  82. * the file down and freeing any associated memory. The next file handle
  83. * in the stack becomes associated with the input stream for this shell.
  84. *
  85. * \return
  86. * BOOL_TRUE - the current file handle has been replaced.
  87. * BOOL_FALSE - there is only one handle on the stack which cannot be replaced.
  88. */
  89. bool_t clish_shell_pop_file(clish_shell_t * instance);
  90. clish_view_t *clish_shell_find_view(clish_shell_t * instance, const char *name);
  91. void clish_shell_insert_view(clish_shell_t * instance, clish_view_t * view);
  92. clish_pargv_status_t
  93. clish_shell_parse(const clish_shell_t * instance,
  94. const char *line,
  95. const clish_command_t ** cmd, clish_pargv_t ** pargv);
  96. char *clish_shell_word_generator(clish_shell_t * instance,
  97. const char *line,
  98. unsigned offset, unsigned state);
  99. const clish_command_t *clish_shell_resolve_command(const clish_shell_t *
  100. instance, const char *line);
  101. const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t *
  102. instance, const char *line);
  103. const clish_command_t *clish_shell_getfirst_command(clish_shell_t * instance,
  104. const char *line,
  105. clish_nspace_visibility_t
  106. field);
  107. const clish_command_t *clish_shell_getnext_command(clish_shell_t * instance,
  108. 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);