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