1 /*--- command.h ----------------------------------------------------------------
2 Copyright (C) 2004, 2005 Sylvain Fourmanoit <syfou@users.sourceforge.net>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to
6 deal in the Software without restriction, including without limitation the
7 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 sell copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies of the Software and its documentation and acknowledgment shall be
13 given in the documentation and software packages that this Software was
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ------------------------------------------------------------------------------*/
23 /* Command interpreter related header
26 /*----------------------------------------------------------------------------*/
27 #ifndef HAVE_COMMAND_H
28 #define HAVE_COMMAND_H
31 #error Autogenerated config.h should be used.
34 /*----------------------------------------------------------------------------*/
35 #include "config.h" /* Autoconf header */
38 #include <stdio.h> /* Standard IO routines */
42 #ifdef HAVE_STDARG_H /* Variadic functions */
46 #include <readline/readline.h> /* GNU readline: greatly simplify
49 #ifdef HAVE_READLINE_HISTORY_H /* GNU history support */
50 #include <readline/history.h>
53 #ifdef HAVE_SYS_TIME_H /* timeval struct, fd_set typedef */
57 #ifdef HAVE_SYS_TYPES_H /* select() and associated functions */
58 #include <sys/types.h>
65 #ifdef HAVE_ICONV_H /* charset conversion */
69 #ifndef X_DISPLAY_MISSING /* mask defines */
73 #include "types.h" /* Various typedef */
74 #include "error.h" /* Error wrapper */
75 #include "vector.h" /* Vector API */
77 #include "event.h" /* Used by command_replayer() */
79 /*----------------------------------------------------------------------------*/
80 typedef struct s_command
{
81 int interactive
; /* Interactive input flag */
82 int recording
; /* Recording input flag */
83 int replay_pos
; /* Current replay position */
84 int replay_stop
; /* Stop replay position */
85 int replay_abort
; /* Specifically abord replaying */
86 int replay_abort_on_events
;/* How to react to events */
87 struct timeval replay_time
; /* Start time for replay */
88 int rank
; /* Command rank */
89 int ready
; /* Command is ready to be processed */
90 int message_out
; /* Message have been delivered */
91 char * line
; /* Dynamic line */
92 char * message
; /* Dynamic message */
94 char * from_page
; /* From codepage name */
95 iconv_t cd
; /* Conversion descriptor */
99 typedef struct s_COMMAND
{
100 char * name
; /* User printable name of the function. */
102 * generator
; /* Generator function */
103 char *doc
; /* Documentation for this function. */
106 #ifndef X_DISPLAY_MISSING
107 typedef struct s_XWINDOW_EVENT
{
108 char *name
; /* User printable name of the event */
109 long mask
; /* Associated mask */
113 /* Note: this typedef has to be in sync AT ALL TIMES with the
114 contents of variable COMMANDS: this is why we use
115 automatic generation performed by lister.sh */
116 typedef enum e_command
{
117 #include "command_enum.h"
120 /*----------------------------------------------------------------------------*/
121 extern const COMMAND COMMANDS
[];
122 extern const char * DIRECTIONS
[];
123 extern const char * OPERATIONS
[];
124 extern const char * LOAD_ERRORS
[];
125 extern const char * RGBA_TABLES
[];
126 extern const char * WINDOW_MANAGER
[];
128 #ifndef X_DISPLAY_MISSING
129 extern const X_WINDOW_EVENT X_WINDOW_EVENTS
[];
132 extern t_command command
;
134 /*----------------------------------------------------------------------------*/
135 /* History convenience function: it exists in GNU readline >= 5.0,
136 but it is a backport for older libraries */
137 #ifdef HAVE_READLINE_HISTORY_H
138 #ifndef HAVE_FREE_HISTORY_ENTRY
139 histdata_t
free_history_entry (HIST_ENTRY
*);
143 /*----------------------------------------------------------------------------*/
144 /* Command output formatting functions */
145 void command_ok(char *, ...);
146 void command_error(char *, ...);
147 int command_printf(const char *, ...);
149 /*----------------------------------------------------------------------------*/
150 /* String duplicator. Returns duplicated string or NULL
152 char * dupstr(const char *);
154 /*----------------------------------------------------------------------------*/
155 /* String duplicator up to n characters: result always zero terminated
156 with n>0. Returns duplicated string or NULL
158 char * dupnstr(const char *, int);
160 /*----------------------------------------------------------------------------*/
161 /* String duplicator that also take care of conversion to utf8 if applicable */
162 char * dupstr_utf8(const char *);
164 /*----------------------------------------------------------------------------*/
165 /* Return actual size of history list*/
166 #ifdef HAVE_READLINE_HISTORY_H
167 int history_size(void);
170 /*----------------------------------------------------------------------------*/
171 /* Returns 1 if a string is blank, 0 otherwise.
173 int blank_line(const char *);
175 /*----------------------------------------------------------------------------*/
176 /* Send the number of second passed since the beginning of current replay
178 double command_gate_chronometer(void);
180 /*----------------------------------------------------------------------------*/
181 /* Initialisation routine of the command interpreter.
182 Return 1 in case of success, 0 otherwise.
184 int command_interpreter_reset(void);
186 /*----------------------------------------------------------------------------*/
187 /* Command replayer function, indirect mode counterpart of 'command_interpreter'
188 Fills the same structures than the latter.
190 int command_replayer();
192 /*----------------------------------------------------------------------------*/
193 /* Command Interpreter function. If there is at least one character, pooling
194 will continue until the input buffer is flushed.
195 Return 1 if an error occured, 0 otherwise.
197 int command_interpreter(void);
199 /*----------------------------------------------------------------------------*/
200 /* Command arguments separator function. Identify the command and return
201 pointer to beginning of nth character, if found.
203 char * command_subsplitter(char *, int);
205 /*----------------------------------------------------------------------------*/
206 /* Command arguments separator function. Identify the command and split
207 its parameters into individual fields, sent back into a vector.
209 vector
* command_splitter(const char *, command_enum
*);
211 /*----------------------------------------------------------------------------*/
212 /* A generic generator function, to be reused with many textual generator
214 char * generic_generator(const char *, int, char **, int);
216 /*----------------------------------------------------------------------------*/
217 /* A generic index generator function, to be reused with many textual generator
219 char * generic_index_generator(const char *, int, int);
221 /*----------------------------------------------------------------------------*/
222 /* A generic index generator function, to be reused with many textual generator,
225 char * generic_index_generator_with_null(const char *, int, int);
227 /*----------------------------------------------------------------------------*/