diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-03-03 10:50:25 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-03-03 10:50:25 +0000 |
commit | 7faf960dd525f08fc885cf2111566b31ee6802b5 (patch) | |
tree | 987482808667e48055c0ef6e5d6fcca00dc06f7e /frm | |
parent | 1f978a4835fba109988f50ab323f2820bcd363dd (diff) | |
download | mailutils-7faf960dd525f08fc885cf2111566b31ee6802b5.tar.gz mailutils-7faf960dd525f08fc885cf2111566b31ee6802b5.tar.bz2 |
Moved to common.c the part of code to be shared between `frm' and `from'
Diffstat (limited to 'frm')
-rw-r--r-- | frm/frm.c | 644 |
1 files changed, 29 insertions, 615 deletions
@@ -16,75 +16,19 @@ | |||
16 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
18 | 18 | ||
19 | #ifdef HAVE_CONFIG_H | 19 | #include <frm.h> |
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | #include <unistd.h> | ||
27 | #include <fcntl.h> | ||
28 | #include <sys/types.h> | ||
29 | #ifdef HAVE_TERMIOS_H | ||
30 | # include <termios.h> | ||
31 | #endif | ||
32 | #include <sys/ioctl.h> | ||
33 | #include <sys/stat.h> | ||
34 | |||
35 | #ifdef HAVE_ICONV_H | ||
36 | # include <iconv.h> | ||
37 | #endif | ||
38 | #ifndef MB_LEN_MAX | ||
39 | # define MB_LEN_MAX 4 | ||
40 | #endif | ||
41 | |||
42 | #include <mbswidth.h> | ||
43 | #include <xalloc.h> | ||
44 | 20 | ||
45 | #ifdef HAVE_FRIBIDI_FRIBIDI_H | ||
46 | # include <fribidi/fribidi.h> | ||
47 | #endif | ||
48 | |||
49 | #include <mailutils/address.h> | ||
50 | #include <mailutils/argp.h> | ||
51 | #include <mailutils/attribute.h> | ||
52 | #include <mailutils/debug.h> | ||
53 | #include <mailutils/errno.h> | ||
54 | #include <mailutils/header.h> | ||
55 | #include <mailutils/list.h> | ||
56 | #include <mailutils/mailbox.h> | ||
57 | #include <mailutils/message.h> | ||
58 | #include <mailutils/observer.h> | ||
59 | #include <mailutils/registrar.h> | ||
60 | #include <mailutils/stream.h> | ||
61 | #include <mailutils/url.h> | ||
62 | #include <mailutils/nls.h> | ||
63 | #include <mailutils/tls.h> | ||
64 | #include <mailutils/error.h> | ||
65 | #include <mailutils/mutil.h> | ||
66 | #include <mailutils/mime.h> | ||
67 | |||
68 | static char *show_field; /* Show this header field instead of the default | ||
69 | `From: Subject:' pair. -f option */ | ||
70 | static int show_to; /* Additionally display To: field. -l option */ | ||
71 | static int show_number; /* Prefix each line with the message number. -n */ | ||
72 | static int show_summary; /* Summarize the number of messages by message | 21 | static int show_summary; /* Summarize the number of messages by message |
73 | status in each mailbox. -S option */ | 22 | status in each mailbox. -S option */ |
74 | static int be_quiet; /* Quiet mode. -q option. */ | 23 | static int be_quiet; /* Quiet mode. -q option. */ |
75 | static int show_query; /* Additional flag toggled by -q to display | 24 | static int show_query; /* Additional flag toggled by -q to display |
76 | a one-line summary for each mailbox */ | 25 | a one-line summary for each mailbox */ |
77 | static int align = 0; /* Tidy mode. -t option. */ | 26 | static int align = 0; /* Tidy mode. -t option. */ |
78 | static int dbug; /* Debug level. -d option.*/ | ||
79 | 27 | ||
80 | #define IS_READ 0x001 | 28 | #define IS_READ 0x001 |
81 | #define IS_OLD 0x010 | 29 | #define IS_OLD 0x010 |
82 | #define IS_NEW 0x100 | 30 | #define IS_NEW 0x100 |
83 | static int select_attribute; | 31 | static int select_attribute; |
84 | static int selected; | ||
85 | |||
86 | static int action (observer_t, size_t); | ||
87 | void init_output (size_t s); | ||
88 | 32 | ||
89 | const char *program_version = "frm (" PACKAGE_STRING ")"; | 33 | const char *program_version = "frm (" PACKAGE_STRING ")"; |
90 | static char doc[] = N_("GNU frm -- display From: lines"); | 34 | static char doc[] = N_("GNU frm -- display From: lines"); |
@@ -187,36 +131,6 @@ decode_attr (char *arg) | |||
187 | 131 | ||
188 | 132 | ||
189 | 133 | ||
190 | /* Get the number of columns on the screen | ||
191 | First try an ioctl() call, not all shells set the COLUMNS environ. | ||
192 | If ioctl does not succeed on stdout, try it on /dev/tty, as we | ||
193 | may work via a pipe. | ||
194 | |||
195 | This function was taken from mail/util.c. It should probably reside | ||
196 | in the library */ | ||
197 | int | ||
198 | util_getcols (void) | ||
199 | { | ||
200 | struct winsize ws; | ||
201 | |||
202 | ws.ws_col = ws.ws_row = 0; | ||
203 | if (ioctl (1, TIOCGWINSZ, (char *) &ws) < 0) | ||
204 | { | ||
205 | int fd = open ("/dev/tty", O_RDWR); | ||
206 | ioctl (fd, TIOCGWINSZ, (char *) &ws); | ||
207 | close (fd); | ||
208 | } | ||
209 | if (ws.ws_row == 0) | ||
210 | { | ||
211 | const char *columns = getenv ("COLUMNS"); | ||
212 | if (columns) | ||
213 | ws.ws_col = strtol (columns, NULL, 10); | ||
214 | } | ||
215 | return ws.ws_col; | ||
216 | } | ||
217 | |||
218 | |||
219 | |||
220 | static struct argp_option options[] = { | 134 | static struct argp_option options[] = { |
221 | {"debug", 'd', NULL, 0, N_("Enable debugging output"), 0}, | 135 | {"debug", 'd', NULL, 0, N_("Enable debugging output"), 0}, |
222 | {"field", 'f', N_("NAME"), 0, N_("Header field to display"), 0}, | 136 | {"field", 'f', N_("NAME"), 0, N_("Header field to display"), 0}, |
@@ -236,7 +150,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
236 | switch (key) | 150 | switch (key) |
237 | { | 151 | { |
238 | case 'd': | 152 | case 'd': |
239 | dbug++; | 153 | frm_debug++; |
240 | break; | 154 | break; |
241 | 155 | ||
242 | case 'f': | 156 | case 'f': |
@@ -309,487 +223,45 @@ static const char *frm_argp_capa[] = { | |||
309 | NULL | 223 | NULL |
310 | }; | 224 | }; |
311 | 225 | ||
312 | |||
313 | /* Charset magic */ | ||
314 | static char *output_charset = NULL; | ||
315 | |||
316 | const char * | ||
317 | get_charset () | ||
318 | { | ||
319 | char *tmp; | ||
320 | |||
321 | if (!output_charset) | ||
322 | { | ||
323 | char locale[32]; | ||
324 | |||
325 | memset (locale, 0, sizeof (locale)); | ||
326 | |||
327 | /* Try to deduce the charset from LC_ALL or LANG variables */ | ||
328 | |||
329 | tmp = getenv ("LC_ALL"); | ||
330 | if (!tmp) | ||
331 | tmp = getenv ("LANG"); | ||
332 | |||
333 | if (tmp) | ||
334 | { | ||
335 | char *sp = NULL; | ||
336 | char *lang; | ||
337 | char *terr; | ||
338 | |||
339 | strncpy (locale, tmp, sizeof (locale) - 1); | ||
340 | |||
341 | lang = strtok_r (locale, "_", &sp); | ||
342 | terr = strtok_r (NULL, ".", &sp); | ||
343 | output_charset = strtok_r (NULL, "@", &sp); | ||
344 | |||
345 | if (output_charset) | ||
346 | output_charset = xstrdup (output_charset); | ||
347 | else | ||
348 | output_charset = mu_charset_lookup (lang, terr); | ||
349 | |||
350 | if (!output_charset) | ||
351 | output_charset = "ASCII"; | ||
352 | } | ||
353 | } | ||
354 | return output_charset; | ||
355 | } | ||
356 | |||
357 | |||
358 | /* BIDI support (will be moved to lib when it's ready) */ | ||
359 | #ifdef HAVE_LIBFRIBIDI | ||
360 | |||
361 | static int fb_charset_num = -1; | ||
362 | FriBidiChar *logical; | ||
363 | char *outstring; | ||
364 | size_t logical_size; | ||
365 | |||
366 | void | ||
367 | alloc_logical (size_t size) | ||
368 | { | ||
369 | logical = xmalloc (size * sizeof (logical[0])); | ||
370 | logical_size = size; | ||
371 | outstring = xmalloc (size); | ||
372 | } | ||
373 | |||
374 | void | ||
375 | puts_bidi (char *string) | ||
376 | { | ||
377 | if (fb_charset_num == -1) | ||
378 | { | ||
379 | fb_charset_num = fribidi_parse_charset (get_charset ()); | ||
380 | if (fb_charset_num && dbug) | ||
381 | mu_error (_("fribidi failed to recognize charset `%s'"), | ||
382 | get_charset ()); | ||
383 | } | ||
384 | |||
385 | if (fb_charset_num == 0) | ||
386 | puts (string); | ||
387 | else | ||
388 | { | ||
389 | FriBidiStrIndex len; | ||
390 | FriBidiCharType base = FRIBIDI_TYPE_ON; | ||
391 | fribidi_boolean log2vis; | ||
392 | |||
393 | static FriBidiChar *visual; | ||
394 | static size_t visual_size; | ||
395 | |||
396 | |||
397 | len = fribidi_charset_to_unicode (fb_charset_num, | ||
398 | string, strlen (string), | ||
399 | logical); | ||
400 | |||
401 | if (len + 1 > visual_size) | ||
402 | { | ||
403 | visual_size = len + 1; | ||
404 | visual = xrealloc (visual, visual_size * sizeof *visual); | ||
405 | } | ||
406 | |||
407 | /* Create a bidi string. */ | ||
408 | log2vis = fribidi_log2vis (logical, len, &base, | ||
409 | /* output */ | ||
410 | visual, NULL, NULL, NULL); | ||
411 | |||
412 | if (log2vis) | ||
413 | { | ||
414 | FriBidiStrIndex idx, st; | ||
415 | <