annotate lib-src/b2m.c @ 4124:a91cdccf5458

* Makefile.in (src/Makefile): Propagate C_SWITCH_SYSTEM to the src directory's makefile. This allows the invocation of CPP which builds xmakefile to receive these switches. The SunSoft C preprocessor inserts spaces between tokens if it doesn't get the -Xs flag requested in src/s/sol2.h.
author Jim Blandy <jimb@redhat.com>
date Sun, 18 Jul 1993 06:10:46 +0000
parents b43e59cb1d54
children beb5acbcd482
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>
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
21
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
22 #include "../src/config.h"
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
23
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
24 #ifdef USG
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
25 #include <string.h>
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
26 #else
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 #include <strings.h>
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 440
diff changeset
28 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
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
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 #define TRUE (1)
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 #define FALSE (0)
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 int header = FALSE, printing;
4008
b43e59cb1d54 * b2m.c: #include <sys/types.h>.
Jim Blandy <jimb@redhat.com>
parents: 2101
diff changeset
37 time_t ltoday;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 char from[256], labels[256], data[256], *p, *today;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
40 main (argc, argv)
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
41 int argc;
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
42 char **argv;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ltoday = time(0);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 today = ctime(&ltoday);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 if (gets(data))
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 if (strcmp(data, "BABYL OPTIONS:")) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 fprintf(stderr, "b2m: not a Babyl mailfile!\n");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 exit(-1);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 } else
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 printing = FALSE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 else
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 exit(-1);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 if (printing)
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 puts(data);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 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
59
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
60 #if 0
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
61 /* 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
62 lines? */
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 if (!strcmp(data, ""))
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 exit(0);
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
65 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 if (!strcmp(data, "*** EOOH ***") && !printing) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 printing = header = TRUE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 printf("From b2m %s", today);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 continue;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 if (!strcmp(data, " ")) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 /* save labels */
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 gets(data);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 p = strtok(data, " ,\r\n\t");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 strcpy(labels, "X-Babyl-Labels: ");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 while (p = strtok(NULL, " ,\r\n\t")) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 strcat(labels, p);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 strcat(labels, ", ");
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 labels[strlen(labels) - 2] = '\0';
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 printing = header = FALSE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 continue;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 if (!strlen(data) && header) {
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 header = FALSE;
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 if (strcmp(labels, "X-Babyl-Labels"))
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 puts(labels);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 if (printing)
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 puts(data);
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 }
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 }