Clean up indentation and whitespace.
[bpt/emacs.git] / lib-src / b2m.c
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 /* Serious bug: This program uses `gets', which is intrinsically
19 unreliable--long lines will cause crashes.
20 Someone should fix this program not to use `gets'. */
21 #include <stdio.h>
22 #include <time.h>
23 #include <sys/types.h>
24 #ifdef MSDOS
25 #include <fcntl.h>
26 #endif
27
28 #include <../src/config.h>
29
30 #ifdef USG
31 #include <string.h>
32 #else
33 #include <strings.h>
34 #endif
35
36 /* BSD's strings.h does not declare the type of strtok. */
37 extern char *strtok ();
38
39 #ifndef TRUE
40 #define TRUE (1)
41 #endif
42 #ifndef FALSE
43 #define FALSE (0)
44 #endif
45
46 int header = FALSE, printing;
47 time_t ltoday;
48 char from[256], labels[256], data[256], *p, *today;
49
50 main (argc, argv)
51 int argc;
52 char **argv;
53 {
54 #ifdef MSDOS
55 _fmode = O_BINARY; /* all of files are treated as binary files */
56 (stdout)->_flag &= ~_IOTEXT;
57 (stdin)->_flag &= ~_IOTEXT;
58 #endif
59 if (strcmp (argv[1], "--help") == 0)
60 {
61 fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", argv[0]);
62 exit (0);
63 }
64 ltoday = time (0);
65 today = ctime (&ltoday);
66
67 /* BUG! Must not use gets in a reliable program! */
68 if (gets (data))
69 {
70 if (strncmp (data, "BABYL OPTIONS:", 14))
71 {
72 fprintf (stderr, "%s: not a Babyl mailfile!\n", argv[0]);
73 exit (-1);
74 }
75 else
76 printing = FALSE;
77 }
78 else
79 exit (-1);
80 if (printing)
81 puts (data);
82
83 while (gets (data))
84 {
85
86 #if 0
87 /* What was this for? Does somebody have something against blank
88 lines? */
89 if (!strcmp (data, ""))
90 exit (0);
91 #endif
92
93 if (!strcmp (data, "*** EOOH ***") && !printing)
94 {
95 printing = header = TRUE;
96 printf ("From %s %s", argv[0], today);
97 continue;
98 }
99
100 if (!strcmp (data, "\037\f"))
101 {
102 /* save labels */
103 gets (data);
104 p = strtok (data, " ,\r\n\t");
105 strcpy (labels, "X-Babyl-Labels: ");
106
107 while (p = strtok (NULL, " ,\r\n\t"))
108 {
109 strcat (labels, p);
110 strcat (labels, ", ");
111 }
112
113 labels[strlen (labels) - 2] = '\0';
114 printing = header = FALSE;
115 continue;
116 }
117
118 if (!strlen (data) && header)
119 {
120 header = FALSE;
121 if (strcmp (labels, "X-Babyl-Labels"))
122 puts (labels);
123 }
124
125 if (printing)
126 puts (data);
127 }
128 }