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