annotate lib-src/b2m.c @ 129:e292c9648bb9 xemacs-20-1p3

Import from CVS: tag xemacs-20-1p3
author cvs
date Mon, 13 Aug 2007 09:28:38 +0200
parents 376386a54a3c
children 2af401a6ecca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 * b2m - a filter for Babyl -> Unix mail files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 * usage: b2m < babyl > mailbox
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 * I find this useful whenever I have to use a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 * system which - shock horror! - doesn't run
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 * Gnu emacs. At least now I can read all my
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 * Gnumacs Babyl format mail files!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 * it's not much but it's free!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 * Ed Wilkinson
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 * E.Wilkinson@massey.ac.nz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 * Mon Nov 7 15:54:06 PDT 1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 /* Synched up with: FSF 19.28. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Serious bug: This program uses `gets', which is intrinsically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 unreliable--long lines will cause crashes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 Someone should fix this program not to use `gets'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include <time.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include <../src/config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #if __STDC__ || defined(STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 # include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 # include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #else /* ! (__STDC__ || defined(STDC_HEADERS)) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 # ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 # include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 # include <strings.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 /* BSD's strings.h does not declare the type of strtok. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 extern char *strtok ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #endif /* ! (__STDC__ || defined(STDC_HEADERS)) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #ifndef TRUE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #define TRUE (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #ifndef FALSE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #define FALSE (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 int header = FALSE, printing;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 time_t ltoday;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 char from[256], labels[256], data[256], *p, *today;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 main (int argc, char **argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 _fmode = O_BINARY; /* all of files are treated as binary files */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (stdout)->_flag &= ~_IOTEXT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (stdin)->_flag &= ~_IOTEXT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 if ((argc >= 2) && strcmp (argv[1], "--help") == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 fprintf (stderr, "%s - a filter for Babyl -> Unix mail files\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 fprintf (stderr, "Usage: %s < babylmailbox > unixmailbox\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ltoday = time (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 today = ctime (&ltoday);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 /* BUG! Must not use gets in a reliable program! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 if (gets (data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 if (strncmp (data, "BABYL OPTIONS:", 14))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 fprintf (stderr, "%s: not a Babyl mailfile!\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 exit (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 printing = FALSE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 exit (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 if (printing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 puts (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 while (gets (data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 /* What was this for? Does somebody have something against blank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 lines? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 if (!strcmp (data, ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 if (!strcmp (data, "*** EOOH ***") && !printing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 printing = header = TRUE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 printf ("From %s %s", argv[0], today);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 if (!strcmp (data, "\037\f"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 /* save labels */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 gets (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 p = strtok (data, " ,\r\n\t");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 strcpy (labels, "X-Babyl-Labels: ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 while ((p = strtok (NULL, " ,\r\n\t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 strcat (labels, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 strcat (labels, ", ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 labels[strlen (labels) - 2] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 printing = header = FALSE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 if (!strlen (data) && header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 header = FALSE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if (strcmp (labels, "X-Babyl-Labels"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 puts (labels);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 if (printing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 puts (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 }