(outline-end-of-subtree): Stop before final newline.
[emacs.git] / lib-src / b2m.c
blob77cfa9a622bde38024ea9ca0050d0dd901a4492f
1 /*
2 * b2m - a filter for Babyl -> Unix mail files
4 * usage: b2m < babyl > mailbox
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!
11 * it's not much but it's free!
13 * Ed Wilkinson
14 * E.Wilkinson@massey.ac.nz
15 * Mon Nov 7 15:54:06 PDT 1988
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
28 #include <../src/config.h>
30 #ifdef USG
31 #include <string.h>
32 #else
33 #include <strings.h>
34 #endif
36 /* BSD's strings.h does not declare the type of strtok. */
37 extern char *strtok ();
39 #ifndef TRUE
40 #define TRUE (1)
41 #endif
42 #ifndef FALSE
43 #define FALSE (0)
44 #endif
46 int header = FALSE, printing;
47 time_t ltoday;
48 char from[256], labels[256], data[256], *p, *today;
50 main (argc, argv)
51 int argc;
52 char **argv;
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)
61 fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", argv[0]);
62 exit (0);
64 ltoday = time (0);
65 today = ctime (&ltoday);
67 /* BUG! Must not use gets in a reliable program! */
68 if (gets (data))
70 if (strncmp (data, "BABYL OPTIONS:", 14))
72 fprintf (stderr, "%s: not a Babyl mailfile!\n", argv[0]);
73 exit (-1);
75 else
76 printing = FALSE;
78 else
79 exit (-1);
80 if (printing)
81 puts (data);
83 while (gets (data))
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
93 if (!strcmp (data, "*** EOOH ***") && !printing)
95 printing = header = TRUE;
96 printf ("From %s %s", argv[0], today);
97 continue;
100 if (!strcmp (data, "\037\f"))
102 /* save labels */
103 gets (data);
104 p = strtok (data, " ,\r\n\t");
105 strcpy (labels, "X-Babyl-Labels: ");
107 while (p = strtok (NULL, " ,\r\n\t"))
109 strcat (labels, p);
110 strcat (labels, ", ");
113 labels[strlen (labels) - 2] = '\0';
114 printing = header = FALSE;
115 continue;
118 if (!strlen (data) && header)
120 header = FALSE;
121 if (strcmp (labels, "X-Babyl-Labels"))
122 puts (labels);
125 if (printing)
126 puts (data);