Mercurial > hg > xemacs-beta
comparison lib-src/fakemail.c @ 337:fbbf69b4e8a7 r21-0-66
Import from CVS: tag r21-0-66
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:51:02 +0200 |
parents | 1f0dabaa0855 |
children | cc15677e0335 |
comparison
equal
deleted
inserted
replaced
336:fe0a93612022 | 337:fbbf69b4e8a7 |
---|---|
22 | 22 |
23 #define NO_SHORTNAMES | 23 #define NO_SHORTNAMES |
24 #include <../src/config.h> | 24 #include <../src/config.h> |
25 | 25 |
26 #if defined (BSD) && !defined (BSD4_1) && !defined (USE_FAKEMAIL) | 26 #if defined (BSD) && !defined (BSD4_1) && !defined (USE_FAKEMAIL) |
27 /* This program isnot used in BSD, so just avoid loader complaints. */ | 27 /* This program is not used in BSD, so just avoid loader complaints. */ |
28 int | 28 int |
29 main () | 29 main (int argc, char *argv[]) |
30 { | 30 { |
31 return 0; | 31 return 0; |
32 } | 32 } |
33 #elif defined (LINUX) | 33 #elif defined (LINUX) |
34 #include <stdio.h> | 34 #include <stdio.h> |
35 #include <stdlib.h> | 35 #include <stdlib.h> |
36 int | 36 int |
37 main () | 37 main (int argc, char *argv[]) |
38 { | 38 { |
39 /* Linux /bin/mail, if it exists, is NOT the Unix v7 mail that | 39 /* Linux /bin/mail, if it exists, is NOT the Unix v7 mail that |
40 fakemail depends on! This causes garbled mail. Better to | 40 fakemail depends on! This causes garbled mail. Better to |
41 output an error message. */ | 41 output an error message. */ |
42 fprintf (stderr, "Sorry, fakemail does not work on Linux.\n"); | 42 fprintf (stderr, "Sorry, fakemail does not work on Linux.\n"); |
46 return 1; | 46 return 1; |
47 } | 47 } |
48 #else /* not BSD 4.2 (or newer) */ | 48 #else /* not BSD 4.2 (or newer) */ |
49 #ifdef MSDOS | 49 #ifdef MSDOS |
50 int | 50 int |
51 main () | 51 main (int argc, char *argv[]) |
52 { | 52 { |
53 return 0; | 53 return 0; |
54 } | 54 } |
55 #else /* not MSDOS */ | 55 #else /* not MSDOS */ |
56 /* This conditional contains all the rest of the file. */ | 56 /* This conditional contains all the rest of the file. */ |
98 line_list text; | 98 line_list text; |
99 struct header_record *next; | 99 struct header_record *next; |
100 struct header_record *previous; | 100 struct header_record *previous; |
101 }; | 101 }; |
102 typedef struct header_record *header; | 102 typedef struct header_record *header; |
103 | 103 |
104 struct stream_record | 104 struct stream_record |
105 { | 105 { |
106 FILE *handle; | 106 FILE *handle; |
107 int (*action)(); | 107 int (*action)(FILE *); |
108 struct stream_record *rest_streams; | 108 struct stream_record *rest_streams; |
109 }; | 109 }; |
110 typedef struct stream_record *stream_list; | 110 typedef struct stream_record *stream_list; |
111 | 111 |
112 /* A `struct linebuffer' is a structure which holds a line of text. | 112 /* A `struct linebuffer' is a structure which holds a line of text. |
189 } | 189 } |
190 | 190 |
191 /* Like malloc but get fatal error if memory is exhausted. */ | 191 /* Like malloc but get fatal error if memory is exhausted. */ |
192 | 192 |
193 static char * | 193 static char * |
194 xmalloc (size) | 194 xmalloc (size_t size) |
195 size_t size; | |
196 { | 195 { |
197 char *result = malloc (((unsigned) size)); | 196 char *result = malloc (((unsigned) size)); |
198 if (result == ((char *) NULL)) | 197 if (result == ((char *) NULL)) |
199 fatal ("virtual memory exhausted", (char *) 0); | 198 fatal ("virtual memory exhausted", (char *) 0); |
200 return result; | 199 return result; |
201 } | 200 } |
202 | 201 |
203 static char * | 202 static char * |
204 xrealloc (ptr, size) | 203 xrealloc (char *ptr, size_t size) |
205 char *ptr; | |
206 size_t size; | |
207 { | 204 { |
208 char *result = realloc (ptr, ((unsigned) size)); | 205 char *result = realloc (ptr, ((unsigned) size)); |
209 if (result == ((char *) NULL)) | 206 if (result == ((char *) NULL)) |
210 fatal ("virtual memory exhausted", (char *) 0); | 207 fatal ("virtual memory exhausted", (char *) 0); |
211 return result; | 208 return result; |
219 linebuffer->size = INITIAL_LINE_SIZE; | 216 linebuffer->size = INITIAL_LINE_SIZE; |
220 linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); | 217 linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); |
221 } | 218 } |
222 | 219 |
223 /* Read a line of text from `stream' into `linebuffer'. | 220 /* Read a line of text from `stream' into `linebuffer'. |
224 * Return the length of the line. | 221 * Return the length of the line. |
225 */ | 222 */ |
226 | 223 |
227 static long | 224 static long |
228 readline (struct linebuffer *linebuffer, FILE *stream) | 225 readline (struct linebuffer *linebuffer, FILE *stream) |
229 { | 226 { |
261 register char *ptr; | 258 register char *ptr; |
262 register char c; | 259 register char c; |
263 | 260 |
264 ptr = &keyword[0]; | 261 ptr = &keyword[0]; |
265 c = *field++; | 262 c = *field++; |
266 if ((isspace (c)) || (c == ':')) | 263 if ((isspace ((int) (unsigned char) c)) || (c == ':')) |
267 return ((char *) NULL); | 264 return (char *) NULL; |
268 *ptr++ = ((islower (c)) ? (toupper (c)) : c); | 265 *ptr++ = ((islower ((int) (unsigned char) c)) ? |
269 while (((c = *field++) != ':') && (!(isspace (c)))) | 266 (toupper ((int) (unsigned char) c)) : c); |
270 *ptr++ = ((islower (c)) ? (toupper (c)) : c); | 267 while (((c = *field++) != ':') && |
268 (!(isspace ((int) (unsigned char) c)))) | |
269 *ptr++ = ((islower ((int) (unsigned char) c)) ? | |
270 (toupper ((int) (unsigned char) c)) : c); | |
271 *ptr++ = '\0'; | 271 *ptr++ = '\0'; |
272 while (isspace (c)) c = *field++; | 272 while (isspace ((int) (unsigned char) c)) c = *field++; |
273 if (c != ':') return ((char *) NULL); | 273 if (c != ':') return (char *) NULL; |
274 *rest = field; | 274 *rest = field; |
275 return &keyword[0]; | 275 return &keyword[0]; |
276 } | 276 } |
277 | 277 |
278 static boolean | 278 static boolean |
369 the_streams = ((stream_list) NULL); | 369 the_streams = ((stream_list) NULL); |
370 return (no_problems ? 0 : 1); | 370 return (no_problems ? 0 : 1); |
371 } | 371 } |
372 | 372 |
373 static void | 373 static void |
374 add_a_stream (FILE *the_stream, int (*closing_action)()) | 374 add_a_stream (FILE *the_stream, int (*closing_action)(FILE *)) |
375 { | 375 { |
376 stream_list old = the_streams; | 376 stream_list old = the_streams; |
377 the_streams = new_stream (); | 377 the_streams = new_stream (); |
378 the_streams->handle = the_stream; | 378 the_streams->handle = the_stream; |
379 the_streams->action = closing_action; | 379 the_streams->action = closing_action; |
551 the_header = the_header->next; | 551 the_header = the_header->next; |
552 } while (the_header != old); | 552 } while (the_header != old); |
553 *where = '\0'; | 553 *where = '\0'; |
554 return; | 554 return; |
555 } | 555 } |
556 | 556 |
557 static header | 557 static header |
558 read_header (void) | 558 read_header (void) |
559 { | 559 { |
560 register header the_header = ((header) NULL); | 560 register header the_header = ((header) NULL); |
561 register line_list *next_line = ((line_list *) NULL); | 561 register line_list *next_line = ((line_list *) NULL); |
622 put_line (""); | 622 put_line (""); |
623 return; | 623 return; |
624 } | 624 } |
625 | 625 |
626 int | 626 int |
627 main (argc, argv) | 627 main (int argc, char *argv[]) |
628 int argc; | |
629 char **argv; | |
630 { | 628 { |
631 char *command_line; | 629 char *command_line; |
632 header the_header; | 630 header the_header; |
633 long name_length; | 631 long name_length; |
634 char *mail_program_name; | 632 char *mail_program_name; |
653 the_header = read_header (); | 651 the_header = read_header (); |
654 command_line = alloc_string ((size_t) (name_length + | 652 command_line = alloc_string ((size_t) (name_length + |
655 args_size (the_header))); | 653 args_size (the_header))); |
656 strcpy (command_line, mail_program_name); | 654 strcpy (command_line, mail_program_name); |
657 parse_header (the_header, &command_line[name_length]); | 655 parse_header (the_header, &command_line[name_length]); |
658 | 656 |
659 the_pipe = popen (command_line, "w"); | 657 the_pipe = popen (command_line, "w"); |
660 if (the_pipe == ((FILE *) NULL)) | 658 if (the_pipe == ((FILE *) NULL)) |
661 fatal ("cannot open pipe to real mailer", (char *) 0); | 659 fatal ("cannot open pipe to real mailer", (char *) 0); |
662 | 660 |
663 add_a_stream (the_pipe, pclose); | 661 add_a_stream (the_pipe, pclose); |