diff options
| author | Karl Heuer | 1995-04-13 17:24:35 +0000 |
|---|---|---|
| committer | Karl Heuer | 1995-04-13 17:24:35 +0000 |
| commit | 231c740a450fc16fce7b69193e7beb10d0d4cfac (patch) | |
| tree | 98eef666a9b1c0d07487c48c32802de94696a894 /lib-src | |
| parent | 8902ae9e18aac6274e2822ea2c4b65de9b103c4a (diff) | |
| download | emacs-231c740a450fc16fce7b69193e7beb10d0d4cfac.tar.gz emacs-231c740a450fc16fce7b69193e7beb10d0d4cfac.zip | |
(main, skip_to_lf): Improve error handling.
(sysfail): New function.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/cvtmail.c | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/lib-src/cvtmail.c b/lib-src/cvtmail.c index b6e0c58ceb3..d2123291d18 100644 --- a/lib-src/cvtmail.c +++ b/lib-src/cvtmail.c | |||
| @@ -21,7 +21,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |||
| 21 | * exist in your home directory, containing individual mail messages in | 21 | * exist in your home directory, containing individual mail messages in |
| 22 | * separate files in the standard gosling emacs mail reader format. | 22 | * separate files in the standard gosling emacs mail reader format. |
| 23 | * | 23 | * |
| 24 | * Program takes one argument: an output file. THis file will contain | 24 | * Program takes one argument: an output file. This file will contain |
| 25 | * all the messages in Messages directory, in berkeley mail format. | 25 | * all the messages in Messages directory, in berkeley mail format. |
| 26 | * If no output file is mentioned, messages are put in ~/OMAIL. | 26 | * If no output file is mentioned, messages are put in ~/OMAIL. |
| 27 | * | 27 | * |
| @@ -41,6 +41,7 @@ char *getenv (); | |||
| 41 | char *xmalloc (); | 41 | char *xmalloc (); |
| 42 | char *xrealloc (); | 42 | char *xrealloc (); |
| 43 | void skip_to_lf (); | 43 | void skip_to_lf (); |
| 44 | void sysfail (); | ||
| 44 | 45 | ||
| 45 | int | 46 | int |
| 46 | main (argc, argv) | 47 | main (argc, argv) |
| @@ -74,15 +75,20 @@ main (argc, argv) | |||
| 74 | cf = (char *) xmalloc (cflen); | 75 | cf = (char *) xmalloc (cflen); |
| 75 | 76 | ||
| 76 | mddf = fopen (mdd, "r"); | 77 | mddf = fopen (mdd, "r"); |
| 78 | if (!mddf) | ||
| 79 | sysfail (mdd); | ||
| 77 | if (argc > 1) | 80 | if (argc > 1) |
| 78 | mfilef = fopen (argv[1], "w"); | 81 | mfile = argv[1]; |
| 79 | else | 82 | else |
| 80 | { | 83 | { |
| 81 | mfile = (char *) xmalloc (strlen (hd) + 7); | 84 | mfile = (char *) xmalloc (strlen (hd) + 7); |
| 82 | strcpy (mfile, hd); | 85 | strcpy (mfile, hd); |
| 83 | strcat (mfile, "/OMAIL"); | 86 | strcat (mfile, "/OMAIL"); |
| 84 | mfilef = fopen (mfile, "w"); | ||
| 85 | } | 87 | } |
| 88 | mfilef = fopen (mfile, "w"); | ||
| 89 | if (!mfilef) | ||
| 90 | sysfail (mfile); | ||
| 91 | |||
| 86 | skip_to_lf (mddf); | 92 | skip_to_lf (mddf); |
| 87 | while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF) | 93 | while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF) |
| 88 | { | 94 | { |
| @@ -95,11 +101,16 @@ main (argc, argv) | |||
| 95 | strcat (cf,"/"); | 101 | strcat (cf,"/"); |
| 96 | strcat (cf, name); | 102 | strcat (cf, name); |
| 97 | cff = fopen (cf, "r"); | 103 | cff = fopen (cf, "r"); |
| 98 | while ((c = getc(cff)) != EOF) | 104 | if (!cff) |
| 99 | putc (c, mfilef); | 105 | perror (cf); |
| 100 | putc ('\n', mfilef); | 106 | else |
| 101 | skip_to_lf (mddf); | 107 | { |
| 102 | fclose (cff); | 108 | while ((c = getc(cff)) != EOF) |
| 109 | putc (c, mfilef); | ||
| 110 | putc ('\n', mfilef); | ||
| 111 | skip_to_lf (mddf); | ||
| 112 | fclose (cff); | ||
| 113 | } | ||
| 103 | } | 114 | } |
| 104 | fclose (mddf); | 115 | fclose (mddf); |
| 105 | fclose (mfilef); | 116 | fclose (mfilef); |
| @@ -111,7 +122,7 @@ skip_to_lf (stream) | |||
| 111 | FILE *stream; | 122 | FILE *stream; |
| 112 | { | 123 | { |
| 113 | register int c; | 124 | register int c; |
| 114 | while ((c = getc(stream)) != '\n') | 125 | while ((c = getc(stream)) != EOF && c != '\n') |
| 115 | ; | 126 | ; |
| 116 | } | 127 | } |
| 117 | 128 | ||
| @@ -135,6 +146,15 @@ fatal (s1, s2) | |||
| 135 | exit (1); | 146 | exit (1); |
| 136 | } | 147 | } |
| 137 | 148 | ||
| 149 | void | ||
| 150 | sysfail (s) | ||
| 151 | char *s; | ||
| 152 | { | ||
| 153 | fprintf (stderr, "cvtmail: "); | ||
| 154 | perror (s); | ||
| 155 | exit (1); | ||
| 156 | } | ||
| 157 | |||
| 138 | char * | 158 | char * |
| 139 | xmalloc (size) | 159 | xmalloc (size) |
| 140 | unsigned size; | 160 | unsigned size; |