X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=interactive.h;h=0af2ef40c27e38950654044ceb0770951ff328ef;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hb=6cb789ba07d3830f1d7fbff9daa059eb1c99c166;hpb=408458ad84180244b6a2ac327d13685bfb2b0867;ds=sidebyside diff --git a/interactive.h b/interactive.h index e69de29b..0af2ef40 100644 --- a/interactive.h +++ b/interactive.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2011-2012 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + +/** \file interactive.h Public API for interactive sessions. */ + +/* Interactive is hard to spell, lets' write i9e. */ + +/** Structure passed as input to the completers. */ +struct i9e_completion_info { + char *buffer; /**< The full line. */ + char *word; /**< The word the cursor is in. */ + int point; /**< Cursor position. */ + char **argv; /**< Vector of words in \a buffer. */ + int argc; /**< Number of elements(words) in argv. */ + int word_num; /**< The cursor is on this word. */ +}; + +/** Completion information returned by the completers. */ +struct i9e_completion_result { + /** NULL-terminated array of possible completions. */ + char **matches; + /** Whether standard filename completion should be performed. */ + bool filename_completion_desired; + /** Suppress adding a space character after the completed word. */ + bool dont_append_space; +}; + +/** + * Define a completer which does nothing. + * + * \param name Determines the name of the function to be defined. + */ +#define I9E_DUMMY_COMPLETER(name) void name ## _completer( \ + __a_unused struct i9e_completion_info *ciname, \ + struct i9e_completion_result *result) {result->matches = NULL;} + +/** + * A completer is simply a function pointer and name of the command for which + * it performs completion. + */ +struct i9e_completer { + /** The command for which this completer provides completion. */ + const char *name; + /** The completer returns all possible completions via the second parameter. */ + void (*completer)(struct i9e_completion_info *, struct i9e_completion_result *); +}; + +/** + * The i9e configuration settings of the client. + * + * A structure of this type must be allocated and filled in by the client + * before it is passed to the i9e subsystem via \ref i9e_open(). + */ +struct i9e_client_info { + /** Threshold for i9e_log(). */ + int loglevel; + /** Complete input lines are passed to this callback function. */ + int (*line_handler)(char *line); + /** File descriptors to use for input/output/log. */ + int fds[3]; + /** Text of the current prompt. */ + char *prompt; + /** Where to store the readline history. */ + char *history_file; + /** + * The array of completers, one per command. This is used for + * completing the first word (the command) and for calling the right + * completer if the cursor is not on the first word. + */ + struct i9e_completer *completers; + /** + * If non-NULL, this node is attached immediately to the stdout btr + * node of the i9e subsystem. + */ + struct btr_node *producer; +}; + +int i9e_open(struct i9e_client_info *ici, struct sched *s); +void i9e_attach_to_stdout(struct btr_node *producer); +void i9e_close(void); +void i9e_signal_dispatch(int sig_num); +__printf_2_3 void i9e_log(int ll, const char* fmt,...); +int i9e_select(int n, fd_set *readfds, fd_set *writefds, + struct timeval *timeout_tv); +int i9e_extract_completions(const char *word, char **string_list, + char ***result); +char **i9e_complete_commands(const char *word, struct i9e_completer *completers); +void i9e_complete_option(char **opts, struct i9e_completion_info *ci, + struct i9e_completion_result *cr); +int i9e_print_completions(struct i9e_completer *completers); +int i9e_get_error(void);