Mercurial > emacs
annotate lib-src/cvtmail.c @ 89171:d7ce536898bf
(define_charset_internal): Rename `supprementary'.
author | Dave Love <fx@gnu.org> |
---|---|
date | Sun, 06 Oct 2002 21:15:08 +0000 |
parents | 83c1951257f1 |
children | c6c565402859 d7ddb3e565de |
rev | line source |
---|---|
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
1 /* Copyright (C) 1985, 1994 Free Software Foundation |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
11425
diff
changeset
|
2 |
37 | 3 This file is part of GNU Emacs. |
4 | |
5 GNU Emacs is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
7 the Free Software Foundation; either version 2, or (at your option) |
37 | 8 any later version. |
9 | |
10 GNU Emacs is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
11425
diff
changeset
|
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
11425
diff
changeset
|
18 Boston, MA 02111-1307, USA. */ |
37 | 19 |
20 /* cvtmail: | |
21 * Program to convert oldstyle goslings emacs mail directories into | |
22 * gnu-rmail format. Program expects a directory called Messages to | |
23 * exist in your home directory, containing individual mail messages in | |
24 * separate files in the standard gosling emacs mail reader format. | |
25 * | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
26 * Program takes one argument: an output file. This file will contain |
37 | 27 * all the messages in Messages directory, in berkeley mail format. |
28 * If no output file is mentioned, messages are put in ~/OMAIL. | |
29 * | |
30 * In order to get rmail to read the messages, the resulting file must | |
31 * be mv'ed to ~/mbox, and then have rmail invoked on them. | |
42412 | 32 * |
37 | 33 * Author: Larry Kolodney, 1985 |
34 */ | |
35 | |
42412 | 36 #ifdef HAVE_CONFIG_H |
37 #include <config.h> | |
38 #endif | |
39 | |
37 | 40 #include <stdio.h> |
41 | |
42132 | 42 #ifndef HAVE_STDLIB_H |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
43 char *malloc (); |
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
44 char *realloc (); |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
45 char *getenv (); |
42132 | 46 #else |
47 #include <stdlib.h> | |
48 #endif | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
49 |
42132 | 50 char *xmalloc __P ((unsigned)); |
51 char *xrealloc __P ((char *, unsigned)); | |
52 void skip_to_lf __P ((FILE *)); | |
53 void sysfail __P ((char *)); | |
37 | 54 |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
55 int |
37 | 56 main (argc, argv) |
57 int argc; | |
58 char *argv[]; | |
59 { | |
60 char *hd; | |
61 char *md; | |
62 char *mdd; | |
63 char *mfile; | |
64 char *cf; | |
65 int cflen; | |
66 FILE *mddf; | |
67 FILE *mfilef; | |
68 FILE *cff; | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
69 char pre[10]; |
37 | 70 char name[14]; |
71 int c; | |
72 | |
73 hd = (char *) getenv ("HOME"); | |
74 | |
75 md = (char *) xmalloc (strlen (hd) + 10); | |
76 strcpy (md, hd); | |
77 strcat (md, "/Messages"); | |
78 | |
79 mdd = (char *) xmalloc (strlen (md) + 11); | |
80 strcpy (mdd, md); | |
81 strcat (mdd, "/Directory"); | |
82 | |
83 cflen = 100; | |
84 cf = (char *) xmalloc (cflen); | |
85 | |
86 mddf = fopen (mdd, "r"); | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
87 if (!mddf) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
88 sysfail (mdd); |
37 | 89 if (argc > 1) |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
90 mfile = argv[1]; |
37 | 91 else |
92 { | |
93 mfile = (char *) xmalloc (strlen (hd) + 7); | |
94 strcpy (mfile, hd); | |
95 strcat (mfile, "/OMAIL"); | |
96 } | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
97 mfilef = fopen (mfile, "w"); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
98 if (!mfilef) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
99 sysfail (mfile); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
100 |
37 | 101 skip_to_lf (mddf); |
102 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF) | |
103 { | |
104 if (cflen < strlen (md) + strlen (name) + 2) | |
105 { | |
106 cflen = strlen (md) + strlen (name) + 2; | |
107 cf = (char *) xrealloc (cf, cflen); | |
108 } | |
109 strcpy (cf, md); | |
110 strcat (cf,"/"); | |
111 strcat (cf, name); | |
112 cff = fopen (cf, "r"); | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
113 if (!cff) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
114 perror (cf); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
115 else |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
116 { |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
117 while ((c = getc(cff)) != EOF) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
118 putc (c, mfilef); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
119 putc ('\n', mfilef); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
120 skip_to_lf (mddf); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
121 fclose (cff); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
122 } |
37 | 123 } |
124 fclose (mddf); | |
42412 | 125 fclose (mfilef); |
37 | 126 return 0; |
127 } | |
128 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
129 void |
37 | 130 skip_to_lf (stream) |
131 FILE *stream; | |
132 { | |
133 register int c; | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
134 while ((c = getc(stream)) != EOF && c != '\n') |
37 | 135 ; |
136 } | |
137 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
138 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
139 void |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
140 error (s1, s2) |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
141 char *s1, *s2; |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
142 { |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
143 fprintf (stderr, "cvtmail: "); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
144 fprintf (stderr, s1, s2); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
145 fprintf (stderr, "\n"); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
146 } |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
147 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
148 /* Print error message and exit. */ |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
149 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
150 void |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
151 fatal (s1, s2) |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
152 char *s1, *s2; |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
153 { |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
154 error (s1, s2); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
155 exit (1); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
156 } |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
157 |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
158 void |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
159 sysfail (s) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
160 char *s; |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
161 { |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
162 fprintf (stderr, "cvtmail: "); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
163 perror (s); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
164 exit (1); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
165 } |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
166 |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
167 char * |
37 | 168 xmalloc (size) |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
169 unsigned size; |
37 | 170 { |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
171 char *result = malloc (size); |
37 | 172 if (!result) |
173 fatal ("virtual memory exhausted", 0); | |
174 return result; | |
175 } | |
176 | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
177 char * |
37 | 178 xrealloc (ptr, size) |
179 char *ptr; | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
180 unsigned size; |
37 | 181 { |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
182 char *result = realloc (ptr, size); |
37 | 183 if (!result) |
40684
e3eadbc9fda7
(xrealloc): Always pass two args to `fatal'.
Richard M. Stallman <rms@gnu.org>
parents:
15719
diff
changeset
|
184 fatal ("virtual memory exhausted", 0); |
37 | 185 return result; |
186 } |