Commit 1ee79592 1ee79592697f4c931a758d53c2a08a755d32a1a7 by Sergey Poznyakoff

(mail_command_entry): Rewritten

(mail_escape_entry,struct mail_command): New data type
(mail_command_table,mail_escape_table): Variables removed
(util_find_entry): Change prototype
(util_help,util_command_list)
(mail_find_command,mail_find_escape,mail_command_help)
(mail_escape_help,mail_command_list): New functions
(util_help): Removed
(alias_iterate_first,alias_iterate_next,alias_iterate_end)
(var_iterate_first,var_iterate_next,var_iterate_end): New functions
(file_compl,no_compl,msglist_compl,msglist_file_compl,dir_compl
(command_compl,alias_compl,var_compl): New functions for readline
completion support
1 parent d8081b10
Showing 1 changed file with 76 additions and 14 deletions
...@@ -109,30 +109,52 @@ typedef struct compose_env ...@@ -109,30 +109,52 @@ typedef struct compose_env
109 int nfiles; /* Number of output files */ 109 int nfiles; /* Number of output files */
110 } compose_env_t; 110 } compose_env_t;
111 111
112 struct mail_command_entry { 112 #define MAIL_COMMAND_COMMON_MEMBERS \
113 const char *shortname;\
114 const char *longname;\
115 const char *synopsis
116
117 struct mail_command
118 {
119 MAIL_COMMAND_COMMON_MEMBERS;
120 };
121
122 struct mail_command_entry
123 {
124 MAIL_COMMAND_COMMON_MEMBERS;
125 int flags;
126 int (*func) __PMT ((int, char **));
127 char **(*command_completion) __PMT((int argc, char **argv, int ws));
128 };
129
130 struct mail_escape_entry
131 {
113 const char *shortname; 132 const char *shortname;
114 const char *longname; 133 const char *longname;
115 const char *synopsis; 134 const char *synopsis;
116 int flags; 135 int (*escfunc) __PMT ((int, char **, compose_env_t *));
117 int (*func) __P ((int, char **));
118 int (*escfunc) __P ((int, char **, compose_env_t *));
119 }; 136 };
120 137
121 typedef enum { 138 typedef enum
139 {
122 Mail_env_whatever, 140 Mail_env_whatever,
123 Mail_env_number, 141 Mail_env_number,
124 Mail_env_string, 142 Mail_env_string,
125 Mail_env_boolean 143 Mail_env_boolean
126 } mail_env_data_t; 144 }
145 mail_env_data_t;
127 146
128 struct mail_env_entry { 147 struct mail_env_entry
129 char *var; 148 {
149 const char *var;
130 mail_env_data_t type; 150 mail_env_data_t type;
131 int set; 151 int set;
132 union { 152 union
153 {
133 char *string; 154 char *string;
134 int number; 155 int number;
135 } value; 156 }
157 value;
136 }; 158 };
137 159
138 #define mail_env_entry_is_set(ep) ((ep) && (ep)->set) 160 #define mail_env_entry_is_set(ep) ((ep) && (ep)->set)
...@@ -155,8 +177,6 @@ extern unsigned int cursor; ...@@ -155,8 +177,6 @@ extern unsigned int cursor;
155 extern size_t total; 177 extern size_t total;
156 extern FILE *ofile; 178 extern FILE *ofile;
157 extern int interactive; 179 extern int interactive;
158 extern const struct mail_command_entry mail_command_table[];
159 extern const struct mail_command_entry mail_escape_table[];
160 180
161 /* Functions */ 181 /* Functions */
162 extern int mail_alias __P ((int argc, char **argv)); 182 extern int mail_alias __P ((int argc, char **argv));
...@@ -289,7 +309,19 @@ extern size_t util_range_msg __P((size_t low, size_t high, int flags, ...@@ -289,7 +309,19 @@ extern size_t util_range_msg __P((size_t low, size_t high, int flags,
289 309
290 extern function_t* util_command_get __P ((const char *cmd)); 310 extern function_t* util_command_get __P ((const char *cmd));
291 extern char *util_stripwhite __P ((char *string)); 311 extern char *util_stripwhite __P ((char *string));
292 extern struct mail_command_entry util_find_entry __P ((const struct mail_command_entry *table, const char *cmd)); 312
313 extern void *util_find_entry __P((void *table, size_t nmemb, size_t size,
314 const char *cmd));
315 extern int util_help __P((void *table, size_t nmemb, size_t size, const char *word));
316 extern int util_command_list __P((void *table, size_t nmemb, size_t size));
317
318 extern const struct mail_command_entry *mail_find_command __P((const char *cmd));
319 extern const struct mail_escape_entry *mail_find_escape __P((const char *cmd));
320 extern int mail_command_help __P((const char *command));
321 extern int mail_escape_help __P((const char *command));
322 extern void mail_command_list __P((void));
323 extern const struct mail_command *mail_command_name __P((int i));
324
293 extern int util_getcols __P ((void)); 325 extern int util_getcols __P ((void));
294 extern int util_getlines __P ((void)); 326 extern int util_getlines __P ((void));
295 extern int util_screen_lines __P ((void)); 327 extern int util_screen_lines __P ((void));
...@@ -323,7 +355,6 @@ extern void util_save_outgoing __P ((message_t msg, char *savefile)); ...@@ -323,7 +355,6 @@ extern void util_save_outgoing __P ((message_t msg, char *savefile));
323 extern void util_error __P ((const char *format, ...)); 355 extern void util_error __P ((const char *format, ...));
324 extern int util_error_range __P ((size_t msgno)); 356 extern int util_error_range __P ((size_t msgno));
325 extern void util_noapp __P ((void)); 357 extern void util_noapp __P ((void));
326 extern int util_help __P ((const struct mail_command_entry *table, char *word));
327 extern int util_tempfile __P ((char **namep)); 358 extern int util_tempfile __P ((char **namep));
328 extern void util_msgset_iterate __P ((msgset_t *msgset, int (*fun) __P ((message_t, msgset_t *, void *)), void *closure)); 359 extern void util_msgset_iterate __P ((msgset_t *msgset, int (*fun) __P ((message_t, msgset_t *, void *)), void *closure));
329 extern int util_get_content_type __P ((header_t hdr, char **value)); 360 extern int util_get_content_type __P ((header_t hdr, char **value));
...@@ -349,10 +380,21 @@ extern char *ml_readline_with_intr __P((char *prompt)); ...@@ -349,10 +380,21 @@ extern char *ml_readline_with_intr __P((char *prompt));
349 extern char *alias_expand __P ((char *name)); 380 extern char *alias_expand __P ((char *name));
350 extern void alias_destroy __P ((char *name)); 381 extern void alias_destroy __P ((char *name));
351 382
383 typedef struct alias_iterator *alias_iterator_t;
384 extern char *alias_find_first __P ((const char *prefix, alias_iterator_t *itr));
385 extern const char *alias_iterate_next __P ((alias_iterator_t itr));
386 extern const char *alias_iterate_first __P ((const char *p, alias_iterator_t *itr));
387 extern void alias_iterate_end __P ((alias_iterator_t *itr));
388
352 extern int mail_sender __P ((int argc, char **argv)); 389 extern int mail_sender __P ((int argc, char **argv));
353 extern int mail_nosender __P ((int argc, char **argv)); 390 extern int mail_nosender __P ((int argc, char **argv));
354 extern address_t get_sender_address __P((message_t msg)); 391 extern address_t get_sender_address __P((message_t msg));
355 392
393 typedef struct var_iterator *var_iterator_t;
394 extern const char *var_iterate_next __P ((var_iterator_t itr));
395 extern const char *var_iterate_first __P ((const char *prefix, var_iterator_t *pitr));
396 extern void var_iterate_end __P ((var_iterator_t *itr));
397
356 #define COMPOSE_APPEND 0 398 #define COMPOSE_APPEND 0
357 #define COMPOSE_REPLACE 1 399 #define COMPOSE_REPLACE 1
358 #define COMPOSE_SINGLE_LINE 2 400 #define COMPOSE_SINGLE_LINE 2
...@@ -384,6 +426,26 @@ extern char *readline __P ((char *prompt)); ...@@ -384,6 +426,26 @@ extern char *readline __P ((char *prompt));
384 #define MAIL_ATTRIBUTE_TAGGED 0x0004 426 #define MAIL_ATTRIBUTE_TAGGED 0x0004
385 #define MAIL_ATTRIBUTE_SHOWN 0x0008 427 #define MAIL_ATTRIBUTE_SHOWN 0x0008
386 428
429 #ifdef WITH_READLINE
430 extern char **file_compl (int argc, char **argv, int ws);
431 extern char **no_compl (int argc, char **argv, int ws);
432 extern char **msglist_compl (int argc, char **argv, int ws);
433 extern char **msglist_file_compl (int argc, char **argv, int ws);
434 extern char **dir_compl (int argc, char **argv, int ws);
435 extern char **command_compl (int argc, char **argv, int ws);
436 extern char **alias_compl (int argc, char **argv, int ws);
437 extern char **var_compl (int argc, char **argv, int ws);
438 #else
439 # define file_compl NULL
440 # define no_compl NULL
441 # define msglist_compl NULL
442 # define msglist_file_compl NULL
443 # define dir_compl NULL
444 # define command_compl NULL
445 # define alias_compl NULL
446 # define var_compl NULL
447 #endif
448
387 #ifdef __cplusplus 449 #ifdef __cplusplus
388 } 450 }
389 #endif 451 #endif
......