Mercurial > emacs
annotate lib-src/cvtmail.c @ 6653:14a0a3fe93fd
(Fx_popup_dialog): If POSITION is t, use selected frame.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 03 Apr 1994 19:03:23 +0000 |
parents | 8cc2a5d2e728 |
children | dd3b83e4ceb0 |
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 |
37 | 2 This file is part of GNU Emacs. |
3 | |
4 GNU Emacs is free software; you can redistribute it and/or modify | |
5 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
|
6 the Free Software Foundation; either version 2, or (at your option) |
37 | 7 any later version. |
8 | |
9 GNU Emacs is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with GNU Emacs; see the file COPYING. If not, write to | |
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
17 | |
18 /* cvtmail: | |
19 * Program to convert oldstyle goslings emacs mail directories into | |
20 * gnu-rmail format. Program expects a directory called Messages to | |
21 * exist in your home directory, containing individual mail messages in | |
22 * separate files in the standard gosling emacs mail reader format. | |
23 * | |
24 * Program takes one argument: an output file. THis file will contain | |
25 * all the messages in Messages directory, in berkeley mail format. | |
26 * If no output file is mentioned, messages are put in ~/OMAIL. | |
27 * | |
28 * In order to get rmail to read the messages, the resulting file must | |
29 * be mv'ed to ~/mbox, and then have rmail invoked on them. | |
30 * | |
31 * Author: Larry Kolodney, 1985 | |
32 */ | |
33 | |
34 | |
35 #include <stdio.h> | |
36 | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
37 char *malloc (); |
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
38 char *realloc (); |
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
39 char *xmalloc (); |
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
40 char *xrealloc (); |
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
41 char *getenv (); |
37 | 42 |
43 main (argc, argv) | |
44 int argc; | |
45 char *argv[]; | |
46 { | |
47 char *hd; | |
48 char *md; | |
49 char *mdd; | |
50 char *mfile; | |
51 char *cf; | |
52 int cflen; | |
53 FILE *mddf; | |
54 FILE *mfilef; | |
55 FILE *cff; | |
56 char pre[10], post[100]; | |
57 char name[14]; | |
58 int c; | |
59 | |
60 hd = (char *) getenv ("HOME"); | |
61 | |
62 md = (char *) xmalloc (strlen (hd) + 10); | |
63 strcpy (md, hd); | |
64 strcat (md, "/Messages"); | |
65 | |
66 mdd = (char *) xmalloc (strlen (md) + 11); | |
67 strcpy (mdd, md); | |
68 strcat (mdd, "/Directory"); | |
69 | |
70 cflen = 100; | |
71 cf = (char *) xmalloc (cflen); | |
72 | |
73 mddf = fopen (mdd, "r"); | |
74 if (argc > 1) | |
75 mfilef = fopen (argv[1], "w"); | |
76 else | |
77 { | |
78 mfile = (char *) xmalloc (strlen (hd) + 7); | |
79 strcpy (mfile, hd); | |
80 strcat (mfile, "/OMAIL"); | |
81 mfilef = fopen (mfile, "w"); | |
82 } | |
83 skip_to_lf (mddf); | |
84 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF) | |
85 { | |
86 if (cflen < strlen (md) + strlen (name) + 2) | |
87 { | |
88 cflen = strlen (md) + strlen (name) + 2; | |
89 cf = (char *) xrealloc (cf, cflen); | |
90 } | |
91 strcpy (cf, md); | |
92 strcat (cf,"/"); | |
93 strcat (cf, name); | |
94 cff = fopen (cf, "r"); | |
95 while ((c = getc(cff)) != EOF) | |
96 putc (c, mfilef); | |
97 putc ('\n', mfilef); | |
98 skip_to_lf (mddf); | |
99 fclose (cff); | |
100 } | |
101 fclose (mddf); | |
102 fclose (mfilef); | |
103 return 0; | |
104 } | |
105 | |
106 skip_to_lf (stream) | |
107 FILE *stream; | |
108 { | |
109 register int c; | |
110 while ((c = getc(stream)) != '\n') | |
111 ; | |
112 } | |
113 | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
114 char * |
37 | 115 xmalloc (size) |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
116 unsigned size; |
37 | 117 { |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
118 char *result = malloc (size); |
37 | 119 if (!result) |
120 fatal ("virtual memory exhausted", 0); | |
121 return result; | |
122 } | |
123 | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
124 char * |
37 | 125 xrealloc (ptr, size) |
126 char *ptr; | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
127 unsigned size; |
37 | 128 { |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
129 char *result = realloc (ptr, size); |
37 | 130 if (!result) |
131 fatal ("virtual memory exhausted"); | |
132 return result; | |
133 } | |
134 | |
135 /* Print error message and exit. */ | |
136 | |
137 fatal (s1, s2) | |
138 char *s1, *s2; | |
139 { | |
140 error (s1, s2); | |
141 exit (1); | |
142 } | |
143 | |
144 error (s1, s2) | |
145 char *s1, *s2; | |
146 { | |
6107
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
147 fprintf (stderr, "cvtmail: "); |
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
148 fprintf (stderr, s1, s2); |
8cc2a5d2e728
* cvtmail.c: Declare malloc, realloc, xmalloc, xrealloc.
David J. MacKenzie <djm@gnu.org>
parents:
37
diff
changeset
|
149 fprintf (stderr, "\n"); |
37 | 150 } |