(Farray_length): Delete this obsolete function.
[bpt/emacs.git] / lib-src / cvtmail.c
1 /* Copyright (C) 1985, 1994 Free Software Foundation
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
6 the Free Software Foundation; either version 2, or (at your option)
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
37 char *malloc ();
38 char *realloc ();
39 char *getenv ();
40
41 char *xmalloc ();
42 char *xrealloc ();
43 void skip_to_lf ();
44
45 int
46 main (argc, argv)
47 int argc;
48 char *argv[];
49 {
50 char *hd;
51 char *md;
52 char *mdd;
53 char *mfile;
54 char *cf;
55 int cflen;
56 FILE *mddf;
57 FILE *mfilef;
58 FILE *cff;
59 char pre[10];
60 char name[14];
61 int c;
62
63 hd = (char *) getenv ("HOME");
64
65 md = (char *) xmalloc (strlen (hd) + 10);
66 strcpy (md, hd);
67 strcat (md, "/Messages");
68
69 mdd = (char *) xmalloc (strlen (md) + 11);
70 strcpy (mdd, md);
71 strcat (mdd, "/Directory");
72
73 cflen = 100;
74 cf = (char *) xmalloc (cflen);
75
76 mddf = fopen (mdd, "r");
77 if (argc > 1)
78 mfilef = fopen (argv[1], "w");
79 else
80 {
81 mfile = (char *) xmalloc (strlen (hd) + 7);
82 strcpy (mfile, hd);
83 strcat (mfile, "/OMAIL");
84 mfilef = fopen (mfile, "w");
85 }
86 skip_to_lf (mddf);
87 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF)
88 {
89 if (cflen < strlen (md) + strlen (name) + 2)
90 {
91 cflen = strlen (md) + strlen (name) + 2;
92 cf = (char *) xrealloc (cf, cflen);
93 }
94 strcpy (cf, md);
95 strcat (cf,"/");
96 strcat (cf, name);
97 cff = fopen (cf, "r");
98 while ((c = getc(cff)) != EOF)
99 putc (c, mfilef);
100 putc ('\n', mfilef);
101 skip_to_lf (mddf);
102 fclose (cff);
103 }
104 fclose (mddf);
105 fclose (mfilef);
106 return 0;
107 }
108
109 void
110 skip_to_lf (stream)
111 FILE *stream;
112 {
113 register int c;
114 while ((c = getc(stream)) != '\n')
115 ;
116 }
117
118
119 void
120 error (s1, s2)
121 char *s1, *s2;
122 {
123 fprintf (stderr, "cvtmail: ");
124 fprintf (stderr, s1, s2);
125 fprintf (stderr, "\n");
126 }
127
128 /* Print error message and exit. */
129
130 void
131 fatal (s1, s2)
132 char *s1, *s2;
133 {
134 error (s1, s2);
135 exit (1);
136 }
137
138 char *
139 xmalloc (size)
140 unsigned size;
141 {
142 char *result = malloc (size);
143 if (!result)
144 fatal ("virtual memory exhausted", 0);
145 return result;
146 }
147
148 char *
149 xrealloc (ptr, size)
150 char *ptr;
151 unsigned size;
152 {
153 char *result = realloc (ptr, size);
154 if (!result)
155 fatal ("virtual memory exhausted");
156 return result;
157 }