(compile-mouse-goto-error): New command.
[bpt/emacs.git] / lib-src / b2m.c
CommitLineData
cc9940c7
JB
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
e3515d10
RS
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'. */
cc9940c7
JB
21#include <stdio.h>
22#include <time.h>
312752df 23#include <sys/types.h>
c6880c90
RS
24#ifdef MSDOS
25#include <fcntl.h>
26#endif
fbfed6f0 27
902a54b2 28#include <../src/config.h>
fbfed6f0
JB
29
30#ifdef USG
31#include <string.h>
32#else
cc9940c7 33#include <strings.h>
fbfed6f0 34#endif
cc9940c7
JB
35
36/* BSD's strings.h does not declare the type of strtok. */
37extern char *strtok ();
38
cbc61077 39#ifndef TRUE
cc9940c7 40#define TRUE (1)
cbc61077
RS
41#endif
42#ifndef FALSE
cc9940c7 43#define FALSE (0)
cbc61077 44#endif
cc9940c7
JB
45
46int header = FALSE, printing;
312752df 47time_t ltoday;
cc9940c7
JB
48char from[256], labels[256], data[256], *p, *today;
49
5d13f393
JB
50main (argc, argv)
51 int argc;
52 char **argv;
cc9940c7 53{
c6880c90 54#ifdef MSDOS
e3515d10 55 _fmode = O_BINARY; /* all of files are treated as binary files */
c6880c90
RS
56 (stdout)->_flag &= ~_IOTEXT;
57 (stdin)->_flag &= ~_IOTEXT;
58#endif
e3515d10 59 if (strcmp (argv[1], "--help") == 0)
88d00c7e 60 {
e3515d10 61 fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", argv[0]);
88d00c7e
KH
62 exit (0);
63 }
e3515d10
RS
64 ltoday = time (0);
65 today = ctime (&ltoday);
cc9940c7 66
e3515d10
RS
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
88d00c7e 76 printing = FALSE;
e3515d10 77 }
cc9940c7 78 else
e3515d10 79 exit (-1);
cc9940c7 80 if (printing)
e3515d10 81 puts (data);
cc9940c7 82
e3515d10
RS
83 while (gets (data))
84 {
5d13f393
JB
85
86#if 0
e3515d10
RS
87 /* What was this for? Does somebody have something against blank
88 lines? */
89 if (!strcmp (data, ""))
90 exit (0);
5d13f393 91#endif
cc9940c7 92
e3515d10
RS
93 if (!strcmp (data, "*** EOOH ***") && !printing)
94 {
95 printing = header = TRUE;
96 printf ("From %s %s", argv[0], today);
97 continue;
98 }
88d00c7e 99
e3515d10
RS
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: ");
cc9940c7 106
e3515d10
RS
107 while (p = strtok (NULL, " ,\r\n\t"))
108 {
109 strcat (labels, p);
110 strcat (labels, ", ");
111 }
cc9940c7 112
e3515d10
RS
113 labels[strlen (labels) - 2] = '\0';
114 printing = header = FALSE;
115 continue;
116 }
cc9940c7 117
e3515d10
RS
118 if (!strlen (data) && header)
119 {
120 header = FALSE;
121 if (strcmp (labels, "X-Babyl-Labels"))
122 puts (labels);
123 }
cc9940c7 124
e3515d10
RS
125 if (printing)
126 puts (data);
127 }
cc9940c7 128}