| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
#ifdef HAVE_CONFIG_H |
|---|
| 38 |
#include <config.h> |
|---|
| 39 |
#endif |
|---|
| 40 |
|
|---|
| 41 |
#include <stdio.h> |
|---|
| 42 |
|
|---|
| 43 |
#ifndef HAVE_STDLIB_H |
|---|
| 44 |
char *getenv (); |
|---|
| 45 |
#endif |
|---|
| 46 |
|
|---|
| 47 |
char *xmalloc __P ((unsigned)); |
|---|
| 48 |
char *xrealloc __P ((char *, unsigned)); |
|---|
| 49 |
void skip_to_lf __P ((FILE *)); |
|---|
| 50 |
void sysfail __P ((char *)); |
|---|
| 51 |
|
|---|
| 52 |
int |
|---|
| 53 |
main (argc, argv) |
|---|
| 54 |
int argc; |
|---|
| 55 |
char *argv[]; |
|---|
| 56 |
{ |
|---|
| 57 |
char *hd; |
|---|
| 58 |
char *md; |
|---|
| 59 |
char *mdd; |
|---|
| 60 |
char *mfile; |
|---|
| 61 |
char *cf; |
|---|
| 62 |
int cflen; |
|---|
| 63 |
FILE *mddf; |
|---|
| 64 |
FILE *mfilef; |
|---|
| 65 |
FILE *cff; |
|---|
| 66 |
char pre[10]; |
|---|
| 67 |
char name[14]; |
|---|
| 68 |
int c; |
|---|
| 69 |
|
|---|
| 70 |
hd = (char *) getenv ("HOME"); |
|---|
| 71 |
|
|---|
| 72 |
md = (char *) xmalloc (strlen (hd) + 10); |
|---|
| 73 |
strcpy (md, hd); |
|---|
| 74 |
strcat (md, "/Messages"); |
|---|
| 75 |
|
|---|
| 76 |
mdd = (char *) xmalloc (strlen (md) + 11); |
|---|
| 77 |
strcpy (mdd, md); |
|---|
| 78 |
strcat (mdd, "/Directory"); |
|---|
| 79 |
|
|---|
| 80 |
cflen = 100; |
|---|
| 81 |
cf = (char *) xmalloc (cflen); |
|---|
| 82 |
|
|---|
| 83 |
mddf = fopen (mdd, "r"); |
|---|
| 84 |
if (!mddf) |
|---|
| 85 |
sysfail (mdd); |
|---|
| 86 |
if (argc > 1) |
|---|
| 87 |
mfile = argv[1]; |
|---|
| 88 |
else |
|---|
| 89 |
{ |
|---|
| 90 |
mfile = (char *) xmalloc (strlen (hd) + 7); |
|---|
| 91 |
strcpy (mfile, hd); |
|---|
| 92 |
strcat (mfile, "/OMAIL"); |
|---|
| 93 |
} |
|---|
| 94 |
mfilef = fopen (mfile, "w"); |
|---|
| 95 |
if (!mfilef) |
|---|
| 96 |
sysfail (mfile); |
|---|
| 97 |
|
|---|
| 98 |
skip_to_lf (mddf); |
|---|
| 99 |
while (fscanf (mddf, "%4c%14[0123456789]", pre, name) != EOF) |
|---|
| 100 |
{ |
|---|
| 101 |
if (cflen < strlen (md) + strlen (name) + 2) |
|---|
| 102 |
{ |
|---|
| 103 |
cflen = strlen (md) + strlen (name) + 2; |
|---|
| 104 |
cf = (char *) xrealloc (cf, cflen); |
|---|
| 105 |
} |
|---|
| 106 |
strcpy (cf, md); |
|---|
| 107 |
strcat (cf,"/"); |
|---|
| 108 |
strcat (cf, name); |
|---|
| 109 |
cff = fopen (cf, "r"); |
|---|
| 110 |
if (!cff) |
|---|
| 111 |
perror (cf); |
|---|
| 112 |
else |
|---|
| 113 |
{ |
|---|
| 114 |
while ((c = getc(cff)) != EOF) |
|---|
| 115 |
putc (c, mfilef); |
|---|
| 116 |
putc ('\n', mfilef); |
|---|
| 117 |
skip_to_lf (mddf); |
|---|
| 118 |
fclose (cff); |
|---|
| 119 |
} |
|---|
| 120 |
} |
|---|
| 121 |
fclose (mddf); |
|---|
| 122 |
fclose (mfilef); |
|---|
| 123 |
return EXIT_SUCCESS; |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
void |
|---|
| 127 |
skip_to_lf (stream) |
|---|
| 128 |
FILE *stream; |
|---|
| 129 |
{ |
|---|
| 130 |
register int c; |
|---|
| 131 |
while ((c = getc(stream)) != EOF && c != '\n') |
|---|
| 132 |
; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
void |
|---|
| 137 |
error (s1, s2) |
|---|
| 138 |
char *s1, *s2; |
|---|
| 139 |
{ |
|---|
| 140 |
fprintf (stderr, "cvtmail: "); |
|---|
| 141 |
fprintf (stderr, s1, s2); |
|---|
| 142 |
fprintf (stderr, "\n"); |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
void |
|---|
| 148 |
fatal (s1, s2) |
|---|
| 149 |
char *s1, *s2; |
|---|
| 150 |
{ |
|---|
| 151 |
error (s1, s2); |
|---|
| 152 |
exit (EXIT_FAILURE); |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
void |
|---|
| 156 |
sysfail (s) |
|---|
| 157 |
char *s; |
|---|
| 158 |
{ |
|---|
| 159 |
fprintf (stderr, "cvtmail: "); |
|---|
| 160 |
perror (s); |
|---|
| 161 |
exit (EXIT_FAILURE); |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
char * |
|---|
| 165 |
xmalloc (size) |
|---|
| 166 |
unsigned size; |
|---|
| 167 |
{ |
|---|
| 168 |
char *result = (char *) malloc (size); |
|---|
| 169 |
if (!result) |
|---|
| 170 |
fatal ("virtual memory exhausted", 0); |
|---|
| 171 |
return result; |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
char * |
|---|
| 175 |
xrealloc (ptr, size) |
|---|
| 176 |
char *ptr; |
|---|
| 177 |
unsigned size; |
|---|
| 178 |
{ |
|---|
| 179 |
char *result = (char *) realloc (ptr, size); |
|---|
| 180 |
if (!result) |
|---|
| 181 |
fatal ("virtual memory exhausted", 0); |
|---|
| 182 |
return result; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|