private.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /*-------------------------------------------------------- */
  13. typedef enum {
  14. SHELL_STATE_INITIALISING,
  15. SHELL_STATE_READY,
  16. SHELL_STATE_HELPING,
  17. SHELL_STATE_SCRIPT_ERROR,
  18. SHELL_STATE_CLOSING
  19. } shell_state_t;
  20. /*
  21. * iterate around commands
  22. */
  23. typedef struct {
  24. const char *last_cmd;
  25. clish_nspace_visibility_t field;
  26. } clish_shell_iterator_t;
  27. /* this is used to maintain a stack of file handles */
  28. typedef struct clish_shell_file_s clish_shell_file_t;
  29. struct clish_shell_file_s {
  30. clish_shell_file_t *next;
  31. FILE *file;
  32. bool_t stop_on_error; /* stop on error for file input */
  33. };
  34. typedef struct {
  35. char *line;
  36. clish_view_t *view;
  37. char *viewid;
  38. } clish_shell_pwd_t;
  39. /*
  40. * The context structure
  41. */
  42. struct clish_context_s {
  43. clish_pargv_t *completion_pargv;
  44. unsigned completion_index;
  45. unsigned completion_pindex;
  46. clish_shell_iterator_t iter; /* used for iterating commands */
  47. };
  48. struct clish_shell_s {
  49. lub_bintree_t view_tree; /* Maintain a tree of views */
  50. lub_bintree_t ptype_tree; /* Maintain a tree of ptypes */
  51. const clish_shell_hooks_t *client_hooks; /* Client callback hooks */
  52. void *client_cookie; /* Client callback cookie */
  53. clish_view_t *global; /* Reference to the global view. */
  54. clish_view_t *view; /* Reference to the current view. */
  55. clish_command_t *startup; /* This is the startup command */
  56. shell_state_t state; /* The current state */
  57. char *overview; /* Overview text for this shell. */
  58. char *viewid; /* The current view ID string */
  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 **cfg_pwdv; /* Levels for the config file structure */
  62. unsigned cfg_pwdc;
  63. konf_client_t *client;
  64. clish_param_t *param_depth;
  65. clish_param_t *param_pwd;
  66. char * lockfile;
  67. pthread_t pthread;
  68. clish_context_t context;
  69. };
  70. /**
  71. * Initialise a command iterator structure
  72. */
  73. void
  74. clish_shell_iterator_init(clish_shell_iterator_t * iter,
  75. clish_nspace_visibility_t field);
  76. /**
  77. * get the next command which is an extension of the specified line
  78. */
  79. const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
  80. instance, const char *line, clish_shell_iterator_t * iter);
  81. /**
  82. * Push the specified file handle on to the stack of file handles
  83. * for this shell. The specified file will become the source of
  84. * commands, until it is exhausted.
  85. *
  86. * \return
  87. * BOOL_TRUE - the file was successfully associated with the shell.
  88. * BOOL_FALSE - there was insufficient resource to associate this file.
  89. */
  90. bool_t
  91. clish_shell_push_file(clish_shell_t * instance,
  92. FILE * file, bool_t stop_on_error);
  93. /**
  94. * Pop the current file handle from the stack of file handles, shutting
  95. * the file down and freeing any associated memory. The next file handle
  96. * in the stack becomes associated with the input stream for this shell.
  97. *
  98. * \return
  99. * BOOL_TRUE - the current file handle has been replaced.
  100. * BOOL_FALSE - there is only one handle on the stack which cannot be replaced.
  101. */
  102. bool_t clish_shell_pop_file(clish_shell_t * instance);
  103. clish_view_t *clish_shell_find_view(clish_shell_t * instance, const char *name);
  104. void clish_shell_insert_view(clish_shell_t * instance, clish_view_t * view);
  105. clish_pargv_status_t
  106. clish_shell_parse(const clish_shell_t * instance,
  107. const char *line,
  108. const clish_command_t ** cmd, clish_pargv_t ** pargv);
  109. char *clish_shell_word_generator(clish_shell_t * instance,
  110. const char *line,
  111. unsigned offset, unsigned state);
  112. const clish_command_t *clish_shell_resolve_command(const clish_shell_t *
  113. instance, const char *line);
  114. const clish_command_t *clish_shell_resolve_prefix(const clish_shell_t *
  115. instance, const char *line);
  116. const clish_command_t *clish_shell_getfirst_command(clish_shell_t * instance,
  117. const char *line,
  118. clish_nspace_visibility_t
  119. field);
  120. const clish_command_t *clish_shell_getnext_command(clish_shell_t * instance,
  121. const char *line);
  122. void clish_shell_insert_ptype(clish_shell_t * instance, clish_ptype_t * ptype);
  123. void clish_shell_tinyrl_history(clish_shell_t * instance, unsigned int *limit);
  124. tinyrl_t *clish_shell_tinyrl_new(FILE * instream,
  125. FILE * outstream, unsigned stifle);
  126. void clish_shell_tinyrl_delete(tinyrl_t * instance);