(defvar_display): Don't staticpro; these objects are now protected through
[emacs.git] / lib-src / cvtmail.c
blobb6e0c58ceb3ff332ebed41dd77d3e77cb491830c
1 /* Copyright (C) 1985, 1994 Free Software Foundation
2 This file is part of GNU Emacs.
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.
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.
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. */
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.
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.
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.
31 * Author: Larry Kolodney, 1985
35 #include <stdio.h>
37 char *malloc ();
38 char *realloc ();
39 char *getenv ();
41 char *xmalloc ();
42 char *xrealloc ();
43 void skip_to_lf ();
45 int
46 main (argc, argv)
47 int argc;
48 char *argv[];
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;
63 hd = (char *) getenv ("HOME");
65 md = (char *) xmalloc (strlen (hd) + 10);
66 strcpy (md, hd);
67 strcat (md, "/Messages");
69 mdd = (char *) xmalloc (strlen (md) + 11);
70 strcpy (mdd, md);
71 strcat (mdd, "/Directory");
73 cflen = 100;
74 cf = (char *) xmalloc (cflen);
76 mddf = fopen (mdd, "r");
77 if (argc > 1)
78 mfilef = fopen (argv[1], "w");
79 else
81 mfile = (char *) xmalloc (strlen (hd) + 7);
82 strcpy (mfile, hd);
83 strcat (mfile, "/OMAIL");
84 mfilef = fopen (mfile, "w");
86 skip_to_lf (mddf);
87 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF)
89 if (cflen < strlen (md) + strlen (name) + 2)
91 cflen = strlen (md) + strlen (name) + 2;
92 cf = (char *) xrealloc (cf, cflen);
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);
104 fclose (mddf);
105 fclose (mfilef);
106 return 0;
109 void
110 skip_to_lf (stream)
111 FILE *stream;
113 register int c;
114 while ((c = getc(stream)) != '\n')
119 void
120 error (s1, s2)
121 char *s1, *s2;
123 fprintf (stderr, "cvtmail: ");
124 fprintf (stderr, s1, s2);
125 fprintf (stderr, "\n");
128 /* Print error message and exit. */
130 void
131 fatal (s1, s2)
132 char *s1, *s2;
134 error (s1, s2);
135 exit (1);
138 char *
139 xmalloc (size)
140 unsigned size;
142 char *result = malloc (size);
143 if (!result)
144 fatal ("virtual memory exhausted", 0);
145 return result;
148 char *
149 xrealloc (ptr, size)
150 char *ptr;
151 unsigned size;
153 char *result = realloc (ptr, size);
154 if (!result)
155 fatal ("virtual memory exhausted");
156 return result;