private.h 4.2 KB

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