Moved (define-key menu-bar-ediff-menu ...) to ediff-hook.el:
[emacs.git] / lib-src / cvtmail.c
blobd2123291d1826605560ae31a198fe6afb6109774
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 ();
44 void sysfail ();
46 int
47 main (argc, argv)
48 int argc;
49 char *argv[];
51 char *hd;
52 char *md;
53 char *mdd;
54 char *mfile;
55 char *cf;
56 int cflen;
57 FILE *mddf;
58 FILE *mfilef;
59 FILE *cff;
60 char pre[10];
61 char name[14];
62 int c;
64 hd = (char *) getenv ("HOME");
66 md = (char *) xmalloc (strlen (hd) + 10);
67 strcpy (md, hd);
68 strcat (md, "/Messages");
70 mdd = (char *) xmalloc (strlen (md) + 11);
71 strcpy (mdd, md);
72 strcat (mdd, "/Directory");
74 cflen = 100;
75 cf = (char *) xmalloc (cflen);
77 mddf = fopen (mdd, "r");
78 if (!mddf)
79 sysfail (mdd);
80 if (argc > 1)
81 mfile = argv[1];
82 else
84 mfile = (char *) xmalloc (strlen (hd) + 7);
85 strcpy (mfile, hd);
86 strcat (mfile, "/OMAIL");
88 mfilef = fopen (mfile, "w");
89 if (!mfilef)
90 sysfail (mfile);
92 skip_to_lf (mddf);
93 while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF)
95 if (cflen < strlen (md) + strlen (name) + 2)
97 cflen = strlen (md) + strlen (name) + 2;
98 cf = (char *) xrealloc (cf, cflen);
100 strcpy (cf, md);
101 strcat (cf,"/");
102 strcat (cf, name);
103 cff = fopen (cf, "r");
104 if (!cff)
105 perror (cf);
106 else
108 while ((c = getc(cff)) != EOF)
109 putc (c, mfilef);
110 putc ('\n', mfilef);
111 skip_to_lf (mddf);
112 fclose (cff);
115 fclose (mddf);
116 fclose (mfilef);
117 return 0;
120 void
121 skip_to_lf (stream)
122 FILE *stream;
124 register int c;
125 while ((c = getc(stream)) != EOF && c != '\n')
130 void
131 error (s1, s2)
132 char *s1, *s2;
134 fprintf (stderr, "cvtmail: ");
135 fprintf (stderr, s1, s2);
136 fprintf (stderr, "\n");
139 /* Print error message and exit. */
141 void
142 fatal (s1, s2)
143 char *s1, *s2;
145 error (s1, s2);
146 exit (1);
149 void
150 sysfail (s)
151 char *s;
153 fprintf (stderr, "cvtmail: ");
154 perror (s);
155 exit (1);
158 char *
159 xmalloc (size)
160 unsigned size;
162 char *result = malloc (size);
163 if (!result)
164 fatal ("virtual memory exhausted", 0);
165 return result;
168 char *
169 xrealloc (ptr, size)
170 char *ptr;
171 unsigned size;
173 char *result = realloc (ptr, size);
174 if (!result)
175 fatal ("virtual memory exhausted");
176 return result;