(x-invocation-args): Add defvar.
[emacs.git] / lib-src / cvtmail.c
blob1f3b8ff9f9e7c9bc56945b42cd07915d2520bb8c
1 /* Copyright (C) 1985 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 1, 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
33 * RMS, 2 Sept 85: Removed fix maximums on file name sizes.
37 #include <stdio.h>
40 main (argc, argv)
41 int argc;
42 char *argv[];
44 char *hd;
45 char *md;
46 char *mdd;
47 char *mfile;
48 char *cf;
49 int cflen;
50 FILE *mddf;
51 FILE *mfilef;
52 FILE *cff;
53 char pre[10], post[100];
54 char name[14];
55 int c;
57 hd = (char *) getenv ("HOME");
59 md = (char *) xmalloc (strlen (hd) + 10);
60 strcpy (md, hd);
61 strcat (md, "/Messages");
63 mdd = (char *) xmalloc (strlen (md) + 11);
64 strcpy (mdd, md);
65 strcat (mdd, "/Directory");
67 cflen = 100;
68 cf = (char *) xmalloc (cflen);
70 mddf = fopen (mdd, "r");
71 if (argc > 1)
72 mfilef = fopen (argv[1], "w");
73 else
75 mfile = (char *) xmalloc (strlen (hd) + 7);
76 strcpy (mfile, hd);
77 strcat (mfile, "/OMAIL");
78 mfilef = fopen (mfile, "w");
80 skip_to_lf (mddf);
81 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF)
83 if (cflen < strlen (md) + strlen (name) + 2)
85 cflen = strlen (md) + strlen (name) + 2;
86 cf = (char *) xrealloc (cf, cflen);
88 strcpy (cf, md);
89 strcat (cf,"/");
90 strcat (cf, name);
91 cff = fopen (cf, "r");
92 while ((c = getc(cff)) != EOF)
93 putc (c, mfilef);
94 putc ('\n', mfilef);
95 skip_to_lf (mddf);
96 fclose (cff);
98 fclose (mddf);
99 fclose (mfilef);
100 return 0;
103 skip_to_lf (stream)
104 FILE *stream;
106 register int c;
107 while ((c = getc(stream)) != '\n')
112 xmalloc (size)
113 int size;
115 int result = malloc (size);
116 if (!result)
117 fatal ("virtual memory exhausted", 0);
118 return result;
122 xrealloc (ptr, size)
123 char *ptr;
124 int size;
126 int result = realloc (ptr, size);
127 if (!result)
128 fatal ("virtual memory exhausted");
129 return result;
132 /* Print error message and exit. */
134 fatal (s1, s2)
135 char *s1, *s2;
137 error (s1, s2);
138 exit (1);
141 error (s1, s2)
142 char *s1, *s2;
144 printf ("cvtmail: ");
145 printf (s1, s2);
146 printf ("\n");