annotate lib-src/b2m.c @ 8204:f5c8a4e8c4a5

(mouse-choose-completion): Use mouse-face properties to find string to use.
author Richard M. Stallman <rms@gnu.org>
date Mon, 11 Jul 1994 21:25:52 +0000
parents 9b2c273b91af
children 4dffbc5d5dc7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /*
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 * b2m - a filter for Babyl -> Unix mail files
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 * usage: b2m < babyl > mailbox
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 * I find this useful whenever I have to use a
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 * system which - shock horror! - doesn't run
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 * Gnu emacs. At least now I can read all my
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 * Gnumacs Babyl format mail files!
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 * it's not much but it's free!
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 * Ed Wilkinson
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 * E.Wilkinson@massey.ac.nz
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 * Mon Nov 7 15:54:06 PDT 1988
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 */
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
18 /* Serious bug: This program uses `gets', which is intrinsically
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
19 unreliable--long lines will cause crashes.
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
20 Someone should fix this program not to use `gets'. */
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 #include <stdio.h>
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include <time.h>
4008
b43e59cb1d54 * b2m.c: #include <sys/types.h>.
Jim Blandy <jimb@redhat.com>
parents: 2101
diff changeset
23 #include <sys/types.h>
5448
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
24 #ifdef MSDOS
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
25 #include <fcntl.h>
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
26 #endif
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
27
6214
512963eb02fe (main): Change delimiter from "^L" to "^_^L".
Richard M. Stallman <rms@gnu.org>
parents: 6173
diff changeset
28 #include <../src/config.h>
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
29
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 /* BSD's strings.h does not declare the type of strtok. */
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 extern char *strtok ();
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
4572
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
33 #ifndef TRUE
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 #define TRUE (1)
4572
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
35 #endif
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
36 #ifndef FALSE
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #define FALSE (0)
4572
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
38 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 int header = FALSE, printing;
4008
b43e59cb1d54 * b2m.c: #include <sys/types.h>.
Jim Blandy <jimb@redhat.com>
parents: 2101
diff changeset
41 time_t ltoday;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 char from[256], labels[256], data[256], *p, *today;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
44 main (argc, argv)
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
45 int argc;
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
46 char **argv;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 {
5448
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
48 #ifdef MSDOS
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
49 _fmode = O_BINARY; /* all of files are treated as binary files */
5448
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
50 (stdout)->_flag &= ~_IOTEXT;
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
51 (stdin)->_flag &= ~_IOTEXT;
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
52 #endif
7528
9b2c273b91af (main): Avoid crash if argc is 1.
Richard M. Stallman <rms@gnu.org>
parents: 7158
diff changeset
53 if (argc >= 2 && strcmp (argv[1], "--help") == 0)
6173
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
54 {
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
55 fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", argv[0]);
6173
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
56 exit (0);
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
57 }
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
58 ltoday = time (0);
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
59 today = ctime (&ltoday);
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
61 /* BUG! Must not use gets in a reliable program! */
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
62 if (gets (data))
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
63 {
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
64 if (strncmp (data, "BABYL OPTIONS:", 14))
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
65 {
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
66 fprintf (stderr, "%s: not a Babyl mailfile!\n", argv[0]);
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
67 exit (-1);
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
68 }
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
69 else
6173
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
70 printing = FALSE;
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
71 }
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 else
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
73 exit (-1);
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 if (printing)
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
75 puts (data);
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
77 while (gets (data))
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
78 {
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
79
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
80 #if 0
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
81 /* What was this for? Does somebody have something against blank
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
82 lines? */
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
83 if (!strcmp (data, ""))
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
84 exit (0);
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
85 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
87 if (!strcmp (data, "*** EOOH ***") && !printing)
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
88 {
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
89 printing = header = TRUE;
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
90 printf ("From %s %s", argv[0], today);
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
91 continue;
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
92 }
6173
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
93
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
94 if (!strcmp (data, "\037\f"))
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
95 {
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
96 /* save labels */
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
97 gets (data);
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
98 p = strtok (data, " ,\r\n\t");
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
99 strcpy (labels, "X-Babyl-Labels: ");
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
101 while (p = strtok (NULL, " ,\r\n\t"))
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
102 {
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
103 strcat (labels, p);
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
104 strcat (labels, ", ");
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
105 }
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
107 labels[strlen (labels) - 2] = '\0';
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
108 printing = header = FALSE;
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
109 continue;
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
110 }
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
112 if (!strlen (data) && header)
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
113 {
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
114 header = FALSE;
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
115 if (strcmp (labels, "X-Babyl-Labels"))
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
116 puts (labels);
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
117 }
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
118
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
119 if (printing)
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
120 puts (data);
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 }