summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mail/table.c342
1 files changed, 232 insertions, 110 deletions
diff --git a/mail/table.c b/mail/table.c
index ab8c5a728..e97df6cfe 100644
--- a/mail/table.c
+++ b/mail/table.c
@@ -1,5 +1,5 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2005 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,116 +18,238 @@
#include "mail.h"
-const struct mail_command_entry mail_command_table[] = {
- { "a", "alias", "a[lias] [alias [address...]]", 0, mail_alias, 0 },
- { "alt", "alternates", "alt[ernates] name...", 0, mail_alt, 0 },
- { "C", "Copy", "C[opy] [msglist]", 0, mail_copy, 0 },
- { "cd", "cd", "cd [directory]", 0, mail_cd, 0 },
- { "ch", "chdir", "ch[dir] directory", 0, mail_cd, 0 },
- { "c", "copy", "c[opy] [[msglist] file]", 0, mail_copy, 0 },
- { "dec", "decode", "dec[ode] [msglist]", 0, mail_decode, 0 },
- { "d", "delete", "d[elete] [msglist]", 0, mail_delete, 0 },
- { "di", "discard", "di[scard] [header-field...]", 0, mail_discard, 0 },
- { "dp", "dp", "dp [msglist]", 0, mail_dp, 0 },
- { "dt", "dt", "dt [msglist]", 0, mail_dp, 0 },
- { "ec", "echo", "ec[ho] string ...", 0, mail_echo, 0 },
- { "e", "edit", "e[dit] [msglist]", 0, mail_edit, 0 },
- { "el", "else", "el[se]", EF_FLOW, mail_else, 0 },
- { "en", "endif", "en[dif]", EF_FLOW, mail_endif, 0 },
- { "ex", "exit", "ex[it]", 0, mail_exit, 0 },
- { "F", "Followup", "F[ollowup] [msglist]", EF_SEND, mail_followup, 0 },
- { "fi", "file", "fi[le] [file]", 0, mail_file, 0 },
- { "fold", "folder", "fold[er] [file]", 0, mail_file, 0 },
- { "folders", "folders", "folders", 0, mail_folders, 0 },
- { "fo", "followup", "fo[llowup] [msglist]", EF_SEND, mail_followup, 0 },
- { "f", "from", "f[rom] [msglist]", 0, mail_from, 0 },
- { "g", "group", "g[roup] [alias [address...]]", 0, mail_alias, 0 },
- { "h", "headers", "h[eaders] [msglist]", 0, mail_headers, 0 },
- { "hel", "help", "hel[p] [command...]", 0, mail_help, 0 },
- { "ho", "hold", "ho[ld] [msglist]", 0, mail_hold, 0 },
- { "i", "if", "i[f] s|r|t", EF_FLOW, mail_if, 0 },
- { "ig", "ignore", "ig[nore] [header-field...]", 0, mail_discard, 0 },
- { "inc", "incorporate", "inc[orporate]", 0, mail_inc, 0 },
- { "l", "list", "l[ist]", 0, mail_list, 0 },
- { "m", "mail", "m[ail] [address...]", EF_SEND, mail_send, 0 },
- { "mb", "mbox", "mb[ox] [msglist]", 0, mail_mbox, 0 },
- { "n", "next", "n[ext] [message]", 0, mail_next, 0 },
- { "nosender", "nos", "nos[ender] [header-field...]", 0, mail_nosender, 0 },
- { "nou", "nounfold", "nou[nfold] [header-field]", 0, mail_nounfold, 0 },
- { "P", "Print", "P[rint] [msglist]", 0, mail_print, 0 },
- { "pi", "pipe", "pi[pe] [[msglist] command]", 0, mail_pipe, 0 },
- { "pre", "preserve", "pre[serve] [msglist]", 0, mail_hold, 0 },
- { "prev", "previous", "prev[ious] [message]", 0, mail_previous, 0 },
- { "p", "print", "p[rint] [msglist]", 0, mail_print, 0 },
- { "q", "quit", "q[uit]", 0, mail_quit, 0 },
- { "R", "Reply", "R[eply] [msglist]", EF_SEND, mail_reply, 0 },
- { "R", "Respond", "R[espond] [msglist]", EF_SEND, mail_reply, 0 },
- { "r", "reply", "r[eply] [msglist]", EF_SEND, mail_reply, 0 },
- { "r", "respond", "r[espond] [msglist]", EF_SEND, mail_reply, 0 },
- { "ret", "retain", "ret[ain] [header-field]", 0, mail_retain, 0 },
- { "S", "Save", "S[ave] [msglist]", 0, mail_save, 0 },
- { "s", "save", "s[ave] [[msglist] file]", 0, mail_save, 0 },
+#define FIND_IN_TABLE(f,t,c)\
+ f ((void*)(t), sizeof ((t)) / sizeof ((t)[0]), sizeof ((t)[0]), c)
+
+static const struct mail_command_entry mail_command_table[] = {
+ { "a", "alias", "a[lias] [alias [address...]]", 0,
+ mail_alias, alias_compl },
+ { "alt", "alternates", "alt[ernates] name...", 0,
+ mail_alt, NULL },
+ { "C", "Copy", "C[opy] [msglist]", 0,
+ mail_copy, msglist_compl },
+ { "cd", "cd", "cd [directory]", 0,
+ mail_cd, dir_compl },
+ { "ch", "chdir", "ch[dir] directory", 0,
+ mail_cd, NULL },
+ { "c", "copy", "c[opy] [[msglist] file]", 0,
+ mail_copy, msglist_file_compl },
+ { "dec", "decode", "dec[ode] [msglist]", 0,
+ mail_decode, msglist_compl },
+ { "d", "delete", "d[elete] [msglist]", 0,
+ mail_delete, msglist_compl },
+ { "di", "discard", "di[scard] [header-field...]", 0,
+ mail_discard, no_compl },
+ { "dp", "dp", "dp [msglist]", 0,
+ mail_dp, msglist_compl },
+ { "dt", "dt", "dt [msglist]", 0,
+ mail_dp, msglist_compl },
+ { "ec", "echo", "ec[ho] string ...", 0,
+ mail_echo, no_compl },
+ { "e", "edit", "e[dit] [msglist]", 0,
+ mail_edit, msglist_compl },
+ { "el", "else", "el[se]", EF_FLOW,
+ mail_else, no_compl },
+ { "en", "endif", "en[dif]", EF_FLOW,
+ mail_endif, no_compl },
+ { "ex", "exit", "ex[it]", 0,
+ mail_exit, no_compl },
+ { "F", "Followup", "F[ollowup] [msglist]", EF_SEND,
+ mail_followup, msglist_compl },
+ { "fi", "file", "fi[le] [file]", 0,
+ mail_file, file_compl },
+ { "fold", "folder", "fold[er] [file]", 0,
+ mail_file, file_compl },
+ { "folders", "folders", "folders", 0,
+ mail_folders, no_compl },
+ { "fo", "followup", "fo[llowup] [msglist]", EF_SEND,
+ mail_followup, msglist_compl },
+ { "f", "from", "f[rom] [msglist]", 0,
+ mail_from, msglist_compl },
+ { "g", "group", "g[roup] [alias [address...]]", 0,
+ mail_alias, alias_compl },
+ { "h", "headers", "h[eaders] [msglist]", 0,
+ mail_headers, msglist_compl },
+ { "hel", "help", "hel[p] [command...]", 0,
+ mail_help, command_compl },
+ { "ho", "hold", "ho[ld] [msglist]", 0,
+ mail_hold, msglist_compl },
+ { "i", "if", "i[f] s|r|t", EF_FLOW,
+ mail_if, no_compl },
+ { "ig", "ignore", "ig[nore] [header-field...]", 0,
+ mail_discard, no_compl },
+ { "inc", "incorporate", "inc[orporate]", 0,
+ mail_inc, no_compl },
+ { "l", "list", "l[ist]", 0,
+ mail_list, no_compl },
+ { "m", "mail", "m[ail] [address...]", EF_SEND,
+ mail_send, alias_compl },
+ { "mb", "mbox", "mb[ox] [msglist]", 0,
+ mail_mbox, msglist_compl },
+ { "n", "next", "n[ext] [message]", 0,
+ mail_next, no_compl },
+ { "nosender", "nos", "nos[ender] [header-field...]", 0,
+ mail_nosender, no_compl },
+ { "nou", "nounfold", "nou[nfold] [header-field]", 0,
+ mail_nounfold, no_compl },
+ { "P", "Print", "P[rint] [msglist]", 0,
+ mail_print, msglist_compl },
+ { "pi", "pipe", "pi[pe] [[msglist] command]", 0,
+ mail_pipe, no_compl }, /* FIXME: exec_compl */
+ { "pre", "preserve", "pre[serve] [msglist]", 0,
+ mail_hold, msglist_compl },
+ { "prev", "previous", "prev[ious] [message]", 0,
+ mail_previous, no_compl },
+ { "p", "print", "p[rint] [msglist]", 0,
+ mail_print, msglist_compl },
+ { "q", "quit", "q[uit]", 0,
+ mail_quit, no_compl },
+ { "R", "Reply", "R[eply] [msglist]", EF_SEND,
+ mail_reply, msglist_compl },
+ { "R", "Respond", "R[espond] [msglist]", EF_SEND,
+ mail_reply, msglist_compl },
+ { "r", "reply", "r[eply] [msglist]", EF_SEND,
+ mail_reply, msglist_compl },
+ { "r", "respond", "r[espond] [msglist]", EF_SEND,
+ mail_reply, msglist_compl },
+ { "ret", "retain", "ret[ain] [header-field]", 0,
+ mail_retain, no_compl },
+ { "S", "Save", "S[ave] [msglist]", 0,
+ mail_save, msglist_compl },
+ { "s", "save", "s[ave] [[msglist] file]", 0,
+ mail_save, msglist_file_compl },
{ "sen", "sendheader", "sen[dheader] [[header][: value]]", EF_SEND,
- mail_sendheader },
- { "se", "set", "se[t] [name[=[string]]...] [name=number...] [noname...]",
- 0, mail_set, 0 },
- { "sender", "sen", "sen[der] [header-field...]", 0, mail_sender, 0 },
- { "sete", "setenv", "sete[nv] [name[=value]]", 0, mail_setenv, 0 },
- { "sh", "shell", "sh[ell] [command]", 0, mail_shell, 0 },
- { "si", "size", "si[ze] [msglist]", 0, mail_size, 0 },
- { "so", "source", "so[urce] file", 0, mail_source, 0 },
- { "su", "summary", "su[mmary]", 0, mail_summary, 0 },
- { "T", "Type", "T[ype] [msglist]", 0, mail_print, 0 },
- { "ta", "tag", "ta[g] [msglist]", 0, mail_tag, 0 },
- { "to", "top", "to[p] [msglist]", 0, mail_top, 0 },
- { "tou", "touch", "tou[ch] [msglist]", 0, mail_touch, 0 },
- { "t", "type", "t[ype] [msglist]", 0, mail_print, 0 },
- { "una", "unalias", "una[lias] [alias]...", 0, mail_unalias, 0 },
- { "u", "undelete", "u[ndelete] [msglist]", 0, mail_undelete, 0 },
- { "unf", "unfold", "unf[old] [header-field]", 0, mail_unfold, 0 },
- { "uns", "unset", "uns[et] name...", 0, mail_unset, 0 },
- { "unt", "untag", "unt[ag] [msglist]", 0, mail_tag, 0 },
- { "ve", "version", "ve[rsion]", 0, mail_version, 0 },
- { "v", "visual", "v[isual] [msglist]", 0, mail_visual, 0 },
- { "wa", "warranty", "wa[rranty]", 0, mail_warranty, 0 },
- { "W", "Write", "W[rite] [msglist]", 0, mail_write, 0 },
- { "w", "write", "w[rite] [[msglist] file]", 0, mail_write, 0 },
- { "x", "xit", "x[it]", 0, mail_exit, 0 },
- { "z", "", "z[+|-|. [count]]", 0, mail_z, 0 },
- { "?", "?", "? [command...]", 0, mail_help, 0 },
- { "!", "", "![command]", 0, mail_shell, 0 },
- { "=", "=", "=", 0, mail_eq, 0 },
- { "#", "#", "# comment", 0, NULL, 0 },
- { "*", "*", "*", 0, mail_list, 0 },
- { "+", "+", "+ [message]", 0, mail_next, 0 },
- { "|", "|", "| [[msglist] command]", 0, mail_pipe, 0 },
- { "-", "-", "- [message]", 0, mail_previous, 0 },
- { 0, 0, 0, 0, 0, 0}
+ mail_sendheader, no_compl },
+ { "se", "set", "se[t] [name[=[string]]...] [name=number...] [noname...]", 0,
+ mail_set, no_compl },
+ { "sender", "sen", "sen[der] [header-field...]", 0,
+ mail_sender, no_compl },
+ { "sete", "setenv", "sete[nv] [name[=value]]", 0,
+ mail_setenv, no_compl },
+ { "sh", "shell", "sh[ell] [command]", 0,
+ mail_shell, no_compl }, /* FIXME: exec_compl */
+ { "si", "size", "si[ze] [msglist]", 0,
+ mail_size, msglist_compl },
+ { "so", "source", "so[urce] file", 0,
+ mail_source, NULL },
+ { "su", "summary", "su[mmary]", 0,
+ mail_summary, no_compl },
+ { "T", "Type", "T[ype] [msglist]", 0,
+ mail_print, msglist_compl },
+ { "ta", "tag", "ta[g] [msglist]", 0,
+ mail_tag, msglist_compl },
+ { "to", "top", "to[p] [msglist]", 0,
+ mail_top, msglist_compl },
+ { "tou", "touch", "tou[ch] [msglist]", 0,
+ mail_touch, msglist_compl },
+ { "t", "type", "t[ype] [msglist]", 0,
+ mail_print, msglist_compl },
+ { "una", "unalias", "una[lias] [alias]...", 0,
+ mail_unalias, NULL },
+ { "u", "undelete", "u[ndelete] [msglist]", 0,
+ mail_undelete, msglist_compl },
+ { "unf", "unfold", "unf[old] [header-field]", 0,
+ mail_unfold, no_compl },
+ { "uns", "unset", "uns[et] name...", 0,
+ mail_unset, var_compl },
+ { "unt", "untag", "unt[ag] [msglist]", 0,
+ mail_tag, msglist_compl },
+ { "ve", "version", "ve[rsion]", 0,
+ mail_version, no_compl },
+ { "v", "visual", "v[isual] [msglist]", 0,
+ mail_visual, msglist_compl },
+ { "wa", "warranty", "wa[rranty]", 0,
+ mail_warranty, no_compl },
+ { "W", "Write", "W[rite] [msglist]", 0,
+ mail_write, msglist_compl },
+ { "w", "write", "w[rite] [[msglist] file]", 0,
+ mail_write, msglist_file_compl },
+ { "x", "xit", "x[it]", 0,
+ mail_exit, no_compl },
+ { "z", "", "z[+|-|. [count]]", 0,
+ mail_z, no_compl },
+ { "?", "?", "? [command...]", 0,
+ mail_help, command_compl },
+ { "!", "", "![command]", 0,
+ mail_shell, NULL }, /* FIXME: exec_compl */
+ { "=", "=", "=", 0,
+ mail_eq, no_compl },
+ { "#", "#", "# comment", 0,
+ NULL, no_compl },
+ { "*", "*", "*", 0,
+ mail_list, no_compl },
+ { "+", "+", "+ [message]", 0,
+ mail_next, msglist_compl },
+ { "|", "|", "| [[msglist] command]", 0,
+ mail_pipe, msglist_compl }, /* FIXME: msglist_exec_compl */
+ { "-", "-", "- [message]", 0,
+ mail_previous, msglist_compl },
};
-const struct mail_command_entry mail_escape_table[] = {
- {"!", "!", "![shell-command]", 0, 0, var_shell },
- {":", ":", ":[mail-command]", 0, 0, var_command },
- {"-", "-", "-[mail-command]", 0, 0, var_command },
- {"?", "?", "?", 0, 0, var_help },
- {"A", "A", "A", 0, 0, var_sign },
- {"a", "a", "a", 0, 0, var_sign },
- {"b", "b", "b[bcc-list]", 0, 0, var_bcc },
- {"c", "c", "c[cc-list]", 0, 0, var_cc },
- {"d", "d", "d", 0, 0, var_deadletter },
- {"e", "e", "e", 0, 0, var_editor },
- {"f", "f", "f[mesg-list]", 0, 0, var_print },
- {"F", "F", "F[mesg-list]", 0, 0, var_print },
- {"h", "h", "h", 0, 0, var_headers },
- {"i", "i", "i[var-name]", 0, 0, var_insert },
- {"m", "m", "m[mesg-list]", 0, 0, var_quote },
- {"M", "M", "M[mesg-list]", 0, 0, var_quote },
- {"p", "p", "p", 0, 0, var_type_input },
- {"r", "<", "r[filename]", 0, 0, var_read },
- {"s", "s", "s[string]", 0, 0, var_subj },
- {"t", "t", "t[name-list]", 0, 0, var_to },
- {"v", "v", "v", 0, 0, var_visual },
- {"w", "w", "w[filename]", 0, 0, var_write },
- {"|", "|", "|[shell-command]", 0, 0, var_pipe },
- {0, 0, 0, 0, 0, 0}
+
+const struct mail_command_entry *
+mail_find_command (const char *cmd)
+{
+ return FIND_IN_TABLE (util_find_entry, mail_command_table, cmd);
+}
+
+int
+mail_command_help (const char *cmd)
+{
+ return FIND_IN_TABLE (util_help, mail_command_table, cmd);
+}
+
+void
+mail_command_list ()
+{
+ util_command_list ((void*)mail_command_table,
+ sizeof (mail_command_table) / sizeof (mail_command_table[0]),
+ sizeof (mail_command_table[0]));
+}
+
+const struct mail_command *
+mail_command_name (int i)
+{
+ if (i < 0 || i >= sizeof (mail_command_table) / sizeof (mail_command_table[0]))
+ return NULL;
+ return (struct mail_command*) &mail_command_table[i];
+}
+
+static const struct mail_escape_entry mail_escape_table[] = {
+ {"!", "!", "![shell-command]", var_shell },
+ {":", ":", ":[mail-command]", var_command },
+ {"-", "-", "-[mail-command]", var_command },
+ {"?", "?", "?", var_help },
+ {"A", "A", "A", var_sign },
+ {"a", "a", "a", var_sign },
+ {"b", "b", "b[bcc-list]", var_bcc },
+ {"c", "c", "c[cc-list]", var_cc },
+ {"d", "d", "d", var_deadletter },
+ {"e", "e", "e", var_editor },
+ {"f", "f", "f[mesg-list]", var_print },
+ {"F", "F", "F[mesg-list]", var_print },
+ {"h", "h", "h", var_headers },
+ {"i", "i", "i[var-name]", var_insert },
+ {"m", "m", "m[mesg-list]", var_quote },
+ {"M", "M", "M[mesg-list]", var_quote },
+ {"p", "p", "p", var_type_input },
+ {"r", "<", "r[filename]", var_read },
+ {"s", "s", "s[string]", var_subj },
+ {"t", "t", "t[name-list]", var_to },
+ {"v", "v", "v", var_visual },
+ {"w", "w", "w[filename]", var_write },
+ {"|", "|", "|[shell-command]", var_pipe },
};
+
+const struct mail_escape_entry *
+mail_find_escape (const char *cmd)
+{
+ return FIND_IN_TABLE (util_find_entry, mail_escape_table, cmd);
+}
+
+int
+mail_escape_help (const char *cmd)
+{
+ return FIND_IN_TABLE (util_help, mail_escape_table, cmd);
+}
+

Return to:

Send suggestions and report system problems to the System administrator.