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