summaryrefslogtreecommitdiff
path: root/frm
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2004-01-13 15:16:33 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2004-01-13 15:16:33 +0000
commit2fbac4d8dd83b0badc8d06388de4847563e29c5f (patch)
tree033331b78ad9bdd7c0ce9d342e911bba2235ac25 /frm
parentbf42e7a2697bde04aee7df19764345feba275ce6 (diff)
downloadmailutils-2fbac4d8dd83b0badc8d06388de4847563e29c5f.tar.gz
mailutils-2fbac4d8dd83b0badc8d06388de4847563e29c5f.tar.bz2
Improved handling of --select option
Diffstat (limited to 'frm')
-rw-r--r--frm/frm.c122
1 files changed, 104 insertions, 18 deletions
diff --git a/frm/frm.c b/frm/frm.c
index cc4c1d7aa..d5cb6adfe 100644
--- a/frm/frm.c
+++ b/frm/frm.c
@@ -41,6 +41,8 @@
41#include <mailutils/url.h> 41#include <mailutils/url.h>
42#include <mailutils/nls.h> 42#include <mailutils/nls.h>
43#include <mailutils/tls.h> 43#include <mailutils/tls.h>
44#include <mailutils/error.h>
45#include <mailutils/mutil.h>
44 46
45static char* show_field; 47static char* show_field;
46static int show_to; 48static int show_to;
@@ -65,6 +67,104 @@ static int action (observer_t, size_t);
65const char *program_version = "frm (" PACKAGE_STRING ")"; 67const char *program_version = "frm (" PACKAGE_STRING ")";
66static char doc[] = N_("GNU frm -- display From: lines"); 68static char doc[] = N_("GNU frm -- display From: lines");
67 69
70static struct attr_tab {
71 char *name; /* Attribute name */
72 int code; /* Corresponding IS_.* flag */
73 size_t len; /* Minimum abbreviation length */
74} attr_tab[] = {
75 /* TRANSLATORS: See comment marked [frm status] below */
76 { N_("new"), IS_NEW, 0 },
77 /* TRANSLATORS: See comment marked [frm status] below */
78 { N_("old"), IS_OLD, 0 },
79 /* TRANSLATORS: See comment marked [frm status] below */
80 { N_("unread"), IS_OLD, 0 },
81 /* TRANSLATORS: See comment marked [frm status] below */
82 { N_("read"), IS_READ, 0 },
83 { NULL }
84};
85
86static char attr_help[] =
87/* TRANSLATORS: [frm status]
88
89 1) Please make sure the words "new", "unread", "old" and
90 "read" are translated exactly as in four preceeding messages.
91
92 2) If possible, select such translations for these words, that
93 differ by the first letter.
94*/
95N_("Select messages with the specific attribute. STATUS is one \
96of the following: new, unread, old (same as unread) or read. Any unambiguous \
97abbreviation of those is also accepted.");
98
99
100/* Attribute table handling */
101
102/* Prepares the table for use: computes minimum abbreviation lengths */
103static void
104prepare_attrs (void)
105{
106 struct attr_tab *p, *q;
107
108 for (p = attr_tab; p->name; p++)
109 {
110 const char *name = gettext (p->name);
111 size_t len = strlen (name);
112 size_t n = 1;
113
114 for (q = attr_tab; q->name; q++)
115 {
116 if (p != q)
117 {
118 const char *str = gettext (q->name);
119 size_t slen = strlen (str);
120
121 if (memcmp (name, str, n) == 0)
122 {
123 for (n++;
124 memcmp (name, str, n) == 0
125 && n < len
126 && n < slen; n++)
127 ;
128
129 q->len = n < slen ? n : slen;
130 }
131 }
132 }
133 p->len = n < len ? n : len;
134 }
135}
136
137/* Translates the textual status representation to the corresponding
138 IS_.* flag */
139static int
140decode_attr (char *arg)
141{
142 struct attr_tab *p;
143 int len = strlen (arg);
144 int pretendents = 0;
145
146 for (p = attr_tab; p->name; p++)
147 {
148 const char *str = gettext (p->name);
149 if (str[0] == arg[0])
150 {
151 if (len < p->len)
152 pretendents++;
153 else if (len > strlen (str))
154 continue;
155 if (memcmp (str, arg, p->len) == 0)
156 return p->code;
157 }
158 }
159 if (pretendents)
160 mu_error (_("%s: ambiguous abbreviation"), arg);
161 else
162 mu_error (_("%s: unknown attribute"), arg);
163 return 0;
164}
165
166
167
68static struct argp_option options[] = { 168static struct argp_option options[] = {
69 {"debug", 'd', NULL, 0, N_("Enable debugging output"), 0}, 169 {"debug", 'd', NULL, 0, N_("Enable debugging output"), 0},
70 {"field", 'f', N_("NAME"), 0, N_("Header field to display"), 0}, 170 {"field", 'f', N_("NAME"), 0, N_("Header field to display"), 0},
@@ -73,8 +173,7 @@ static struct argp_option options[] = {
73 {"Quiet", 'Q', NULL, 0, N_("Very quiet"), 0}, 173 {"Quiet", 'Q', NULL, 0, N_("Very quiet"), 0},
74 {"query", 'q', NULL, 0, N_("Print a message if unread mail"), 0}, 174 {"query", 'q', NULL, 0, N_("Print a message if unread mail"), 0},
75 {"summary",'S', NULL, 0, N_("Print a summary of messages"), 0}, 175 {"summary",'S', NULL, 0, N_("Print a summary of messages"), 0},
76 {"status", 's', "[nor]",0, 176 {"status", 's', N_("STATUS"), 0, attr_help, 0},
77 N_("Select message with the specific attribute: [n]ew, [r]ead, [u]nread."), 0 },
78 {"align", 't', NULL, 0, N_("Try to align"), 0}, 177 {"align", 't', NULL, 0, N_("Try to align"), 0},
79 {0, 0, 0, 0} 178 {0, 0, 0, 0}
80}; 179};
@@ -123,22 +222,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
123 break; 222 break;
124 223
125 case 's': 224 case 's':
126 if (optarg) 225 select_attribute = decode_attr (optarg);
127 switch (*optarg)
128 {
129 case 'r':
130 select_attribute |= IS_READ;
131 break;
132
133 case 'o':
134 select_attribute |= IS_OLD;
135 break;
136
137 case 'n':
138 select_attribute |= IS_NEW;
139 break;
140
141 }
142 break; 226 break;
143 227
144 case 't': 228 case 't':
@@ -366,6 +450,8 @@ main (int argc, char **argv)
366 /* Native Language Support */ 450 /* Native Language Support */
367 mu_init_nls (); 451 mu_init_nls ();
368 452
453 prepare_attrs ();
454
369 mu_argp_init (program_version, NULL); 455 mu_argp_init (program_version, NULL);
370#ifdef WITH_TLS 456#ifdef WITH_TLS
371 mu_tls_init_client_argp (); 457 mu_tls_init_client_argp ();

Return to:

Send suggestions and report system problems to the System administrator.