Fix mismatch in conditionals.
[bpt/emacs.git] / lib-src / cvtmail.c
CommitLineData
00345809 1/* Copyright (C) 1985, 1994 Free Software Foundation
518dd722
JB
2This file is part of GNU Emacs.
3
4GNU Emacs is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
00345809 6the Free Software Foundation; either version 2, or (at your option)
518dd722
JB
7any later version.
8
9GNU Emacs is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with GNU Emacs; see the file COPYING. If not, write to
16the 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
518dd722
JB
32 */
33
34
35#include <stdio.h>
36
00345809
DM
37char *malloc ();
38char *realloc ();
340ff9de
DM
39char *getenv ();
40
00345809
DM
41char *xmalloc ();
42char *xrealloc ();
340ff9de 43void skip_to_lf ();
518dd722 44
340ff9de 45int
518dd722
JB
46main (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;
340ff9de 59 char pre[10];
518dd722
JB
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
340ff9de 109void
518dd722
JB
110skip_to_lf (stream)
111 FILE *stream;
112{
113 register int c;
114 while ((c = getc(stream)) != '\n')
115 ;
116}
117
340ff9de
DM
118
119void
120error (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
130void
131fatal (s1, s2)
132 char *s1, *s2;
133{
134 error (s1, s2);
135 exit (1);
136}
137
00345809 138char *
518dd722 139xmalloc (size)
00345809 140 unsigned size;
518dd722 141{
00345809 142 char *result = malloc (size);
518dd722
JB
143 if (!result)
144 fatal ("virtual memory exhausted", 0);
145 return result;
146}
147
00345809 148char *
518dd722
JB
149xrealloc (ptr, size)
150 char *ptr;
00345809 151 unsigned size;
518dd722 152{
00345809 153 char *result = realloc (ptr, size);
518dd722
JB
154 if (!result)
155 fatal ("virtual memory exhausted");
156 return result;
157}