Commit 8e8f1a17 8e8f1a173abe3c1cd65124007640b1c19186effc by Sergey Poznyakoff

(mail_command_table,mail_escape_table): Changed

data type
(mail_find_command,mail_command_help,mail_command_list)
(mail_command_name,mail_find_escape,mail_escape_help): New
functions
1 parent b6eecab8
Showing 1 changed file with 232 additions and 110 deletions
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or modify 4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -18,116 +18,238 @@ ...@@ -18,116 +18,238 @@
18 18
19 #include "mail.h" 19 #include "mail.h"
20 20
21 const struct mail_command_entry mail_command_table[] = { 21 #define FIND_IN_TABLE(f,t,c)\
22 { "a", "alias", "a[lias] [alias [address...]]", 0, mail_alias, 0 }, 22 f ((void*)(t), sizeof ((t)) / sizeof ((t)[0]), sizeof ((t)[0]), c)
23 { "alt", "alternates", "alt[ernates] name...", 0, mail_alt, 0 }, 23
24 { "C", "Copy", "C[opy] [msglist]", 0, mail_copy, 0 }, 24 static const struct mail_command_entry mail_command_table[] = {
25 { "cd", "cd", "cd [directory]", 0, mail_cd, 0 }, 25 { "a", "alias", "a[lias] [alias [address...]]", 0,
26 { "ch", "chdir", "ch[dir] directory", 0, mail_cd, 0 }, 26 mail_alias, alias_compl },
27 { "c", "copy", "c[opy] [[msglist] file]", 0, mail_copy, 0 }, 27 { "alt", "alternates", "alt[ernates] name...", 0,
28 { "dec", "decode", "dec[ode] [msglist]", 0, mail_decode, 0 }, 28 mail_alt, NULL },
29 { "d", "delete", "d[elete] [msglist]", 0, mail_delete, 0 }, 29 { "C", "Copy", "C[opy] [msglist]", 0,
30 { "di", "discard", "di[scard] [header-field...]", 0, mail_discard, 0 }, 30 mail_copy, msglist_compl },
31 { "dp", "dp", "dp [msglist]", 0, mail_dp, 0 }, 31 { "cd", "cd", "cd [directory]", 0,
32 { "dt", "dt", "dt [msglist]", 0, mail_dp, 0 }, 32 mail_cd, dir_compl },
33 { "ec", "echo", "ec[ho] string ...", 0, mail_echo, 0 }, 33 { "ch", "chdir", "ch[dir] directory", 0,
34 { "e", "edit", "e[dit] [msglist]", 0, mail_edit, 0 }, 34 mail_cd, NULL },
35 { "el", "else", "el[se]", EF_FLOW, mail_else, 0 }, 35 { "c", "copy", "c[opy] [[msglist] file]", 0,
36 { "en", "endif", "en[dif]", EF_FLOW, mail_endif, 0 }, 36 mail_copy, msglist_file_compl },
37 { "ex", "exit", "ex[it]", 0, mail_exit, 0 }, 37 { "dec", "decode", "dec[ode] [msglist]", 0,
38 { "F", "Followup", "F[ollowup] [msglist]", EF_SEND, mail_followup, 0 }, 38 mail_decode, msglist_compl },
39 { "fi", "file", "fi[le] [file]", 0, mail_file, 0 }, 39 { "d", "delete", "d[elete] [msglist]", 0,
40 { "fold", "folder", "fold[er] [file]", 0, mail_file, 0 }, 40 mail_delete, msglist_compl },
41 { "folders", "folders", "folders", 0, mail_folders, 0 }, 41 { "di", "discard", "di[scard] [header-field...]", 0,
42 { "fo", "followup", "fo[llowup] [msglist]", EF_SEND, mail_followup, 0 }, 42 mail_discard, no_compl },
43 { "f", "from", "f[rom] [msglist]", 0, mail_from, 0 }, 43 { "dp", "dp", "dp [msglist]", 0,
44 { "g", "group", "g[roup] [alias [address...]]", 0, mail_alias, 0 }, 44 mail_dp, msglist_compl },
45 { "h", "headers", "h[eaders] [msglist]", 0, mail_headers, 0 }, 45 { "dt", "dt", "dt [msglist]", 0,
46 { "hel", "help", "hel[p] [command...]", 0, mail_help, 0 }, 46 mail_dp, msglist_compl },
47 { "ho", "hold", "ho[ld] [msglist]", 0, mail_hold, 0 }, 47 { "ec", "echo", "ec[ho] string ...", 0,
48 { "i", "if", "i[f] s|r|t", EF_FLOW, mail_if, 0 }, 48 mail_echo, no_compl },
49 { "ig", "ignore", "ig[nore] [header-field...]", 0, mail_discard, 0 }, 49 { "e", "edit", "e[dit] [msglist]", 0,
50 { "inc", "incorporate", "inc[orporate]", 0, mail_inc, 0 }, 50 mail_edit, msglist_compl },
51 { "l", "list", "l[ist]", 0, mail_list, 0 }, 51 { "el", "else", "el[se]", EF_FLOW,
52 { "m", "mail", "m[ail] [address...]", EF_SEND, mail_send, 0 }, 52 mail_else, no_compl },
53 { "mb", "mbox", "mb[ox] [msglist]", 0, mail_mbox, 0 }, 53 { "en", "endif", "en[dif]", EF_FLOW,
54 { "n", "next", "n[ext] [message]", 0, mail_next, 0 }, 54 mail_endif, no_compl },
55 { "nosender", "nos", "nos[ender] [header-field...]", 0, mail_nosender, 0 }, 55 { "ex", "exit", "ex[it]", 0,
56 { "nou", "nounfold", "nou[nfold] [header-field]", 0, mail_nounfold, 0 }, 56 mail_exit, no_compl },
57 { "P", "Print", "P[rint] [msglist]", 0, mail_print, 0 }, 57 { "F", "Followup", "F[ollowup] [msglist]", EF_SEND,
58 { "pi", "pipe", "pi[pe] [[msglist] command]", 0, mail_pipe, 0 }, 58 mail_followup, msglist_compl },
59 { "pre", "preserve", "pre[serve] [msglist]", 0, mail_hold, 0 }, 59 { "fi", "file", "fi[le] [file]", 0,
60 { "prev", "previous", "prev[ious] [message]", 0, mail_previous, 0 }, 60 mail_file, file_compl },
61 { "p", "print", "p[rint] [msglist]", 0, mail_print, 0 }, 61 { "fold", "folder", "fold[er] [file]", 0,
62 { "q", "quit", "q[uit]", 0, mail_quit, 0 }, 62 mail_file, file_compl },
63 { "R", "Reply", "R[eply] [msglist]", EF_SEND, mail_reply, 0 }, 63 { "folders", "folders", "folders", 0,
64 { "R", "Respond", "R[espond] [msglist]", EF_SEND, mail_reply, 0 }, 64 mail_folders, no_compl },
65 { "r", "reply", "r[eply] [msglist]", EF_SEND, mail_reply, 0 }, 65 { "fo", "followup", "fo[llowup] [msglist]", EF_SEND,
66 { "r", "respond", "r[espond] [msglist]", EF_SEND, mail_reply, 0 }, 66 mail_followup, msglist_compl },
67 { "ret", "retain", "ret[ain] [header-field]", 0, mail_retain, 0 }, 67 { "f", "from", "f[rom] [msglist]", 0,
68 { "S", "Save", "S[ave] [msglist]", 0, mail_save, 0 }, 68 mail_from, msglist_compl },
69 { "s", "save", "s[ave] [[msglist] file]", 0, mail_save, 0 }, 69 { "g", "group", "g[roup] [alias [address...]]", 0,
70 mail_alias, alias_compl },
71 { "h", "headers", "h[eaders] [msglist]", 0,
72 mail_headers, msglist_compl },
73 { "hel", "help", "hel[p] [command...]", 0,
74 mail_help, command_compl },
75 { "ho", "hold", "ho[ld] [msglist]", 0,
76 mail_hold, msglist_compl },
77 { "i", "if", "i[f] s|r|t", EF_FLOW,
78 mail_if, no_compl },
79 { "ig", "ignore", "ig[nore] [header-field...]", 0,
80 mail_discard, no_compl },
81 { "inc", "incorporate", "inc[orporate]", 0,
82 mail_inc, no_compl },
83 { "l", "list", "l[ist]", 0,
84 mail_list, no_compl },
85 { "m", "mail", "m[ail] [address...]", EF_SEND,
86 mail_send, alias_compl },
87 { "mb", "mbox", "mb[ox] [msglist]", 0,
88 mail_mbox, msglist_compl },
89 { "n", "next", "n[ext] [message]", 0,
90 mail_next, no_compl },
91 { "nosender", "nos", "nos[ender] [header-field...]", 0,
92 mail_nosender, no_compl },
93 { "nou", "nounfold", "nou[nfold] [header-field]", 0,
94 mail_nounfold, no_compl },
95 { "P", "Print", "P[rint] [msglist]", 0,
96 mail_print, msglist_compl },
97 { "pi", "pipe", "pi[pe] [[msglist] command]", 0,
98 mail_pipe, no_compl }, /* FIXME: exec_compl */
99 { "pre", "preserve", "pre[serve] [msglist]", 0,
100 mail_hold, msglist_compl },
101 { "prev", "previous", "prev[ious] [message]", 0,
102 mail_previous, no_compl },
103 { "p", "print", "p[rint] [msglist]", 0,
104 mail_print, msglist_compl },
105 { "q", "quit", "q[uit]", 0,
106 mail_quit, no_compl },
107 { "R", "Reply", "R[eply] [msglist]", EF_SEND,
108 mail_reply, msglist_compl },
109 { "R", "Respond", "R[espond] [msglist]", EF_SEND,
110 mail_reply, msglist_compl },
111 { "r", "reply", "r[eply] [msglist]", EF_SEND,
112 mail_reply, msglist_compl },
113 { "r", "respond", "r[espond] [msglist]", EF_SEND,
114 mail_reply, msglist_compl },
115 { "ret", "retain", "ret[ain] [header-field]", 0,
116 mail_retain, no_compl },
117 { "S", "Save", "S[ave] [msglist]", 0,
118 mail_save, msglist_compl },
119 { "s", "save", "s[ave] [[msglist] file]", 0,
120 mail_save, msglist_file_compl },
70 { "sen", "sendheader", "sen[dheader] [[header][: value]]", EF_SEND, 121 { "sen", "sendheader", "sen[dheader] [[header][: value]]", EF_SEND,
71 mail_sendheader }, 122 mail_sendheader, no_compl },
72 { "se", "set", "se[t] [name[=[string]]...] [name=number...] [noname...]", 123 { "se", "set", "se[t] [name[=[string]]...] [name=number...] [noname...]", 0,
73 0, mail_set, 0 }, 124 mail_set, no_compl },
74 { "sender", "sen", "sen[der] [header-field...]", 0, mail_sender, 0 }, 125 { "sender", "sen", "sen[der] [header-field...]", 0,
75 { "sete", "setenv", "sete[nv] [name[=value]]", 0, mail_setenv, 0 }, 126 mail_sender, no_compl },
76 { "sh", "shell", "sh[ell] [command]", 0, mail_shell, 0 }, 127 { "sete", "setenv", "sete[nv] [name[=value]]", 0,
77 { "si", "size", "si[ze] [msglist]", 0, mail_size, 0 }, 128 mail_setenv, no_compl },
78 { "so", "source", "so[urce] file", 0, mail_source, 0 }, 129 { "sh", "shell", "sh[ell] [command]", 0,
79 { "su", "summary", "su[mmary]", 0, mail_summary, 0 }, 130 mail_shell, no_compl }, /* FIXME: exec_compl */
80 { "T", "Type", "T[ype] [msglist]", 0, mail_print, 0 }, 131 { "si", "size", "si[ze] [msglist]", 0,
81 { "ta", "tag", "ta[g] [msglist]", 0, mail_tag, 0 }, 132 mail_size, msglist_compl },
82 { "to", "top", "to[p] [msglist]", 0, mail_top, 0 }, 133 { "so", "source", "so[urce] file", 0,
83 { "tou", "touch", "tou[ch] [msglist]", 0, mail_touch, 0 }, 134 mail_source, NULL },
84 { "t", "type", "t[ype] [msglist]", 0, mail_print, 0 }, 135 { "su", "summary", "su[mmary]", 0,
85 { "una", "unalias", "una[lias] [alias]...", 0, mail_unalias, 0 }, 136 mail_summary, no_compl },
86 { "u", "undelete", "u[ndelete] [msglist]", 0, mail_undelete, 0 }, 137 { "T", "Type", "T[ype] [msglist]", 0,
87 { "unf", "unfold", "unf[old] [header-field]", 0, mail_unfold, 0 }, 138 mail_print, msglist_compl },
88 { "uns", "unset", "uns[et] name...", 0, mail_unset, 0 }, 139 { "ta", "tag", "ta[g] [msglist]", 0,
89 { "unt", "untag", "unt[ag] [msglist]", 0, mail_tag, 0 }, 140 mail_tag, msglist_compl },
90 { "ve", "version", "ve[rsion]", 0, mail_version, 0 }, 141 { "to", "top", "to[p] [msglist]", 0,
91 { "v", "visual", "v[isual] [msglist]", 0, mail_visual, 0 }, 142 mail_top, msglist_compl },
92 { "wa", "warranty", "wa[rranty]", 0, mail_warranty, 0 }, 143 { "tou", "touch", "tou[ch] [msglist]", 0,
93 { "W", "Write", "W[rite] [msglist]", 0, mail_write, 0 }, 144 mail_touch, msglist_compl },
94 { "w", "write", "w[rite] [[msglist] file]", 0, mail_write, 0 }, 145 { "t", "type", "t[ype] [msglist]", 0,
95 { "x", "xit", "x[it]", 0, mail_exit, 0 }, 146 mail_print, msglist_compl },
96 { "z", "", "z[+|-|. [count]]", 0, mail_z, 0 }, 147 { "una", "unalias", "una[lias] [alias]...", 0,
97 { "?", "?", "? [command...]", 0, mail_help, 0 }, 148 mail_unalias, NULL },
98 { "!", "", "![command]", 0, mail_shell, 0 }, 149 { "u", "undelete", "u[ndelete] [msglist]", 0,
99 { "=", "=", "=", 0, mail_eq, 0 }, 150 mail_undelete, msglist_compl },
100 { "#", "#", "# comment", 0, NULL, 0 }, 151 { "unf", "unfold", "unf[old] [header-field]", 0,
101 { "*", "*", "*", 0, mail_list, 0 }, 152 mail_unfold, no_compl },
102 { "+", "+", "+ [message]", 0, mail_next, 0 }, 153 { "uns", "unset", "uns[et] name...", 0,
103 { "|", "|", "| [[msglist] command]", 0, mail_pipe, 0 }, 154 mail_unset, var_compl },
104 { "-", "-", "- [message]", 0, mail_previous, 0 }, 155 { "unt", "untag", "unt[ag] [msglist]", 0,
105 { 0, 0, 0, 0, 0, 0} 156 mail_tag, msglist_compl },
157 { "ve", "version", "ve[rsion]", 0,
158 mail_version, no_compl },
159 { "v", "visual", "v[isual] [msglist]", 0,
160 mail_visual, msglist_compl },
161 { "wa", "warranty", "wa[rranty]", 0,
162 mail_warranty, no_compl },
163 { "W", "Write", "W[rite] [msglist]", 0,
164 mail_write, msglist_compl },
165 { "w", "write", "w[rite] [[msglist] file]", 0,
166 mail_write, msglist_file_compl },
167 { "x", "xit", "x[it]", 0,
168 mail_exit, no_compl },
169 { "z", "", "z[+|-|. [count]]", 0,
170 mail_z, no_compl },
171 { "?", "?", "? [command...]", 0,
172 mail_help, command_compl },
173 { "!", "", "![command]", 0,
174 mail_shell, NULL }, /* FIXME: exec_compl */
175 { "=", "=", "=", 0,
176 mail_eq, no_compl },
177 { "#", "#", "# comment", 0,
178 NULL, no_compl },
179 { "*", "*", "*", 0,
180 mail_list, no_compl },
181 { "+", "+", "+ [message]", 0,
182 mail_next, msglist_compl },
183 { "|", "|", "| [[msglist] command]", 0,
184 mail_pipe, msglist_compl }, /* FIXME: msglist_exec_compl */
185 { "-", "-", "- [message]", 0,
186 mail_previous, msglist_compl },
106 }; 187 };
107 188
108 const struct mail_command_entry mail_escape_table[] = { 189
109 {"!", "!", "![shell-command]", 0, 0, var_shell }, 190 const struct mail_command_entry *
110 {":", ":", ":[mail-command]", 0, 0, var_command }, 191 mail_find_command (const char *cmd)
111 {"-", "-", "-[mail-command]", 0, 0, var_command }, 192 {
112 {"?", "?", "?", 0, 0, var_help }, 193 return FIND_IN_TABLE (util_find_entry, mail_command_table, cmd);
113 {"A", "A", "A", 0, 0, var_sign }, 194 }
114 {"a", "a", "a", 0, 0, var_sign }, 195
115 {"b", "b", "b[bcc-list]", 0, 0, var_bcc }, 196 int
116 {"c", "c", "c[cc-list]", 0, 0, var_cc }, 197 mail_command_help (const char *cmd)
117 {"d", "d", "d", 0, 0, var_deadletter }, 198 {
118 {"e", "e", "e", 0, 0, var_editor }, 199 return FIND_IN_TABLE (util_help, mail_command_table, cmd);
119 {"f", "f", "f[mesg-list]", 0, 0, var_print }, 200 }
120 {"F", "F", "F[mesg-list]", 0, 0, var_print }, 201
121 {"h", "h", "h", 0, 0, var_headers }, 202 void
122 {"i", "i", "i[var-name]", 0, 0, var_insert }, 203 mail_command_list ()
123 {"m", "m", "m[mesg-list]", 0, 0, var_quote }, 204 {
124 {"M", "M", "M[mesg-list]", 0, 0, var_quote }, 205 util_command_list ((void*)mail_command_table,
125 {"p", "p", "p", 0, 0, var_type_input }, 206 sizeof (mail_command_table) / sizeof (mail_command_table[0]),
126 {"r", "<", "r[filename]", 0, 0, var_read }, 207 sizeof (mail_command_table[0]));
127 {"s", "s", "s[string]", 0, 0, var_subj }, 208 }
128 {"t", "t", "t[name-list]", 0, 0, var_to }, 209
129 {"v", "v", "v", 0, 0, var_visual }, 210 const struct mail_command *
130 {"w", "w", "w[filename]", 0, 0, var_write }, 211 mail_command_name (int i)
131 {"|", "|", "|[shell-command]", 0, 0, var_pipe }, 212 {
132 {0, 0, 0, 0, 0, 0} 213 if (i < 0 || i >= sizeof (mail_command_table) / sizeof (mail_command_table[0]))
214 return NULL;
215 return (struct mail_command*) &mail_command_table[i];
216 }
217
218 static const struct mail_escape_entry mail_escape_table[] = {
219 {"!", "!", "![shell-command]", var_shell },
220 {":", ":", ":[mail-command]", var_command },
221 {"-", "-", "-[mail-command]", var_command },
222 {"?", "?", "?", var_help },
223 {"A", "A", "A", var_sign },
224 {"a", "a", "a", var_sign },
225 {"b", "b", "b[bcc-list]", var_bcc },
226 {"c", "c", "c[cc-list]", var_cc },
227 {"d", "d", "d", var_deadletter },
228 {"e", "e", "e", var_editor },
229 {"f", "f", "f[mesg-list]", var_print },
230 {"F", "F", "F[mesg-list]", var_print },
231 {"h", "h", "h", var_headers },
232 {"i", "i", "i[var-name]", var_insert },
233 {"m", "m", "m[mesg-list]", var_quote },
234 {"M", "M", "M[mesg-list]", var_quote },
235 {"p", "p", "p", var_type_input },
236 {"r", "<", "r[filename]", var_read },
237 {"s", "s", "s[string]", var_subj },
238 {"t", "t", "t[name-list]", var_to },
239 {"v", "v", "v", var_visual },
240 {"w", "w", "w[filename]", var_write },
241 {"|", "|", "|[shell-command]", var_pipe },
133 }; 242 };
243
244 const struct mail_escape_entry *
245 mail_find_escape (const char *cmd)
246 {
247 return FIND_IN_TABLE (util_find_entry, mail_escape_table, cmd);
248 }
249
250 int
251 mail_escape_help (const char *cmd)
252 {
253 return FIND_IN_TABLE (util_help, mail_escape_table, cmd);
254 }
255
......