Mercurial > emacs
annotate lib-src/cvtmail.c @ 52137:3c3abdef580e
(Buffer File Name): set-visited-file-name renames the buffer too.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 06 Aug 2003 01:12:25 +0000 |
parents | c6c565402859 |
children | 695cf19ef79e |
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 |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
43 char *getenv (); |
42132 | 44 #endif |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
45 |
42132 | 46 char *xmalloc __P ((unsigned)); |
47 char *xrealloc __P ((char *, unsigned)); | |
48 void skip_to_lf __P ((FILE *)); | |
49 void sysfail __P ((char *)); | |
37 | 50 |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
51 int |
37 | 52 main (argc, argv) |
53 int argc; | |
54 char *argv[]; | |
55 { | |
56 char *hd; | |
57 char *md; | |
58 char *mdd; | |
59 char *mfile; | |
60 char *cf; | |
61 int cflen; | |
62 FILE *mddf; | |
63 FILE *mfilef; | |
64 FILE *cff; | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
65 char pre[10]; |
37 | 66 char name[14]; |
67 int c; | |
68 | |
69 hd = (char *) getenv ("HOME"); | |
70 | |
71 md = (char *) xmalloc (strlen (hd) + 10); | |
72 strcpy (md, hd); | |
73 strcat (md, "/Messages"); | |
74 | |
75 mdd = (char *) xmalloc (strlen (md) + 11); | |
76 strcpy (mdd, md); | |
77 strcat (mdd, "/Directory"); | |
78 | |
79 cflen = 100; | |
80 cf = (char *) xmalloc (cflen); | |
81 | |
82 mddf = fopen (mdd, "r"); | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
83 if (!mddf) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
84 sysfail (mdd); |
37 | 85 if (argc > 1) |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
86 mfile = argv[1]; |
37 | 87 else |
88 { | |
89 mfile = (char *) xmalloc (strlen (hd) + 7); | |
90 strcpy (mfile, hd); | |
91 strcat (mfile, "/OMAIL"); | |
92 } | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
93 mfilef = fopen (mfile, "w"); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
94 if (!mfilef) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
95 sysfail (mfile); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
96 |
37 | 97 skip_to_lf (mddf); |
98 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF) | |
99 { | |
100 if (cflen < strlen (md) + strlen (name) + 2) | |
101 { | |
102 cflen = strlen (md) + strlen (name) + 2; | |
103 cf = (char *) xrealloc (cf, cflen); | |
104 } | |
105 strcpy (cf, md); | |
106 strcat (cf,"/"); | |
107 strcat (cf, name); | |
108 cff = fopen (cf, "r"); | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
109 if (!cff) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
110 perror (cf); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
111 else |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
112 { |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
113 while ((c = getc(cff)) != EOF) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
114 putc (c, mfilef); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
115 putc ('\n', mfilef); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
116 skip_to_lf (mddf); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
117 fclose (cff); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
118 } |
37 | 119 } |
120 fclose (mddf); | |
42412 | 121 fclose (mfilef); |
37 | 122 return 0; |
123 } | |
124 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
125 void |
37 | 126 skip_to_lf (stream) |
127 FILE *stream; | |
128 { | |
129 register int c; | |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
130 while ((c = getc(stream)) != EOF && c != '\n') |
37 | 131 ; |
132 } | |
133 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
134 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
135 void |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
136 error (s1, s2) |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
137 char *s1, *s2; |
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 fprintf (stderr, "cvtmail: "); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
140 fprintf (stderr, s1, s2); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
141 fprintf (stderr, "\n"); |
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 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
144 /* Print error message and exit. */ |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
145 |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
146 void |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
147 fatal (s1, s2) |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
148 char *s1, *s2; |
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 error (s1, s2); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
151 exit (1); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
152 } |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
6107
diff
changeset
|
153 |
11425
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
154 void |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
155 sysfail (s) |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
156 char *s; |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
157 { |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
158 fprintf (stderr, "cvtmail: "); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
159 perror (s); |
bcb88697b70b
(main, skip_to_lf): Improve error handling.
Karl Heuer <kwzh@gnu.org>
parents:
9491
diff
changeset
|
160 exit (1); |
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 |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
163 char * |
37 | 164 xmalloc (size) |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
165 unsigned size; |
37 | 166 { |
49803
c6c565402859
Cast result of malloc and realloc.
Richard M. Stallman <rms@gnu.org>
parents:
42412
diff
changeset
|
167 char *result = (char *) malloc (size); |
37 | 168 if (!result) |
169 fatal ("virtual memory exhausted", 0); | |
170 return result; | |
171 } | |
172 | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
173 char * |
37 | 174 xrealloc (ptr, size) |
175 char *ptr; | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
176 unsigned size; |
37 | 177 { |
49803
c6c565402859
Cast result of malloc and realloc.
Richard M. Stallman <rms@gnu.org>
parents:
42412
diff
changeset
|
178 char *result = (char *) realloc (ptr, size); |
37 | 179 if (!result) |
40684
e3eadbc9fda7
(xrealloc): Always pass two args to `fatal'.
Richard M. Stallman <rms@gnu.org>
parents:
15719
diff
changeset
|
180 fatal ("virtual memory exhausted", 0); |
37 | 181 return result; |
182 } |