annotate lib-src/b2m.c @ 6064:bdfff039f6e3

(Fget_char_property): Fix docstring.
author Karl Heuer <kwzh@gnu.org>
date Thu, 24 Feb 1994 19:24:37 +0000
parents 18de002e47dd
children cbf3383981cb
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
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 #include <stdio.h>
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
24
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4572
diff changeset
25 #include <../src/config.h>
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
26
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
27 #ifdef USG
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
28 #include <string.h>
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
29 #else
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #include <strings.h>
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
31 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 /* BSD's strings.h does not declare the type of strtok. */
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 extern char *strtok ();
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
4572
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
36 #ifndef TRUE
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #define TRUE (1)
4572
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
38 #endif
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
39 #ifndef FALSE
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 #define FALSE (0)
4572
beb5acbcd482 (TRUE, FALSE): Don't define if already defined.
Richard M. Stallman <rms@gnu.org>
parents: 4008
diff changeset
41 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 int header = FALSE, printing;
4008
b43e59cb1d54 * b2m.c: #include <sys/types.h>.
Jim Blandy <jimb@redhat.com>
parents: 2101
diff changeset
44 time_t ltoday;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 char from[256], labels[256], data[256], *p, *today;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
47 main (argc, argv)
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
48 int argc;
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
49 char **argv;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 {
5448
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
51 #ifdef MSDOS
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
52 _fmode = O_BINARY; /* all of files are treated as binary files */
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
53 (stdout)->_flag &= ~_IOTEXT;
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
54 (stdin)->_flag &= ~_IOTEXT;
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
55 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 ltoday = time(0);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 today = ctime(&ltoday);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 if (gets(data))
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 if (strcmp(data, "BABYL OPTIONS:")) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 fprintf(stderr, "b2m: not a Babyl mailfile!\n");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 exit(-1);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 } else
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 printing = FALSE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 else
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 exit(-1);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 if (printing)
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 puts(data);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 while (gets(data)) {
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
71
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
72 #if 0
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
73 /* What was this for? Does somebody have something against blank
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
74 lines? */
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 if (!strcmp(data, ""))
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 exit(0);
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
77 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 if (!strcmp(data, "*** EOOH ***") && !printing) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 printing = header = TRUE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 printf("From b2m %s", today);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 continue;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 if (!strcmp(data, " ")) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 /* save labels */
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 gets(data);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 p = strtok(data, " ,\r\n\t");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 strcpy(labels, "X-Babyl-Labels: ");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 while (p = strtok(NULL, " ,\r\n\t")) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 strcat(labels, p);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 strcat(labels, ", ");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 labels[strlen(labels) - 2] = '\0';
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 printing = header = FALSE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 continue;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 if (!strlen(data) && header) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 header = FALSE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 if (strcmp(labels, "X-Babyl-Labels"))
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 puts(labels);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 if (printing)
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 puts(data);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 }