annotate lib-src/cvtmail.c @ 18:d95e72db5c07 r19-15b92

Import from CVS: tag r19-15b92
author cvs
date Mon, 13 Aug 2007 08:49:43 +0200
parents 376386a54a3c
children 972bbb6d6ca2
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 /* Copyright (C) 1985, 1993, 1994 Free Software Foundation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 the Free the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 Boston, MA 02111-1307, USA. */
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 /* cvtmail:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 * Program to convert oldstyle goslings emacs mail directories into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 * gnu-rmail format. Program expects a directory called Messages to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * exist in your home directory, containing individual mail messages in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * separate files in the standard gosling emacs mail reader format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 * Program takes one argument: an output file. THis file will contain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 * all the messages in Messages directory, in berkeley mail format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * If no output file is mentioned, messages are put in ~/OMAIL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 * In order to get rmail to read the messages, the resulting file must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 * be mv'ed to ~/mbox, and then have rmail invoked on them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 * Author: Larry Kolodney, 1985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include <../src/config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #if __STDC__ || defined(STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 # include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 char *malloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 char *getenv ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 static void *xmalloc (unsigned int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 static void *xrealloc (char *ptr, unsigned int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 static void skip_to_lf (FILE *stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 static void fatal (CONST char *s1, CONST char *s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 static void error (CONST char *s1, CONST char *s2);
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 main (argc, argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 int argc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 char *argv[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 char *hd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 char *md;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 char *mdd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 char *mfile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 char *cf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 int cflen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 FILE *mddf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 FILE *mfilef;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 FILE *cff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 char pre[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 char name[14];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 hd = (char *) getenv ("HOME");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 md = (char *) xmalloc (strlen (hd) + 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 strcpy (md, hd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 strcat (md, "/Messages");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 mdd = (char *) xmalloc (strlen (md) + 11);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 strcpy (mdd, md);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 strcat (mdd, "/Directory");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 cflen = 100;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 cf = (char *) xmalloc (cflen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 mddf = fopen (mdd, "r");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 if (argc > 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 mfilef = fopen (argv[1], "w");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 mfile = (char *) xmalloc (strlen (hd) + 7);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 strcpy (mfile, hd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 strcat (mfile, "/OMAIL");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 mfilef = fopen (mfile, "w");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 skip_to_lf (mddf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 int comp_len = strlen (md) + strlen (name) + 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 if (cflen < comp_len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 cflen = strlen (md) + strlen (name) + 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 cf = (char *) xrealloc (cf, cflen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 strcpy (cf, md);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 strcat (cf,"/");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 strcat (cf, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 cff = fopen (cf, "r");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 while ((c = getc(cff)) != EOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 putc (c, mfilef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 putc ('\n', mfilef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 skip_to_lf (mddf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 fclose (cff);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 fclose (mddf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 fclose (mfilef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 skip_to_lf (stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 FILE *stream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 register int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 while ((c = getc(stream)) != '\n')
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 xmalloc (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 unsigned size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 char *result = (char *) malloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 if (!result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 fatal ("virtual memory exhausted", 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 xrealloc (ptr, size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 unsigned size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 char *result = (char *) realloc (ptr, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 if (!result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 fatal ("virtual memory exhausted", 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 /* Print error message and exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 fatal (CONST char *s1, CONST char *s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 error (s1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 error (CONST char *s1, CONST char *s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 fprintf (stderr, "cvtmail: ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 fprintf (stderr, s1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 fprintf (stderr, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 }