comparison lib-src/fakemail.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents fbbf69b4e8a7
children 6719134a07c2
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
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 is not used in BSD, so just avoid loader complaints. */ 27 /* This program isnot used in BSD, so just avoid loader complaints. */
28 int 28 int
29 main (int argc, char *argv[]) 29 main ()
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 (int argc, char *argv[]) 37 main ()
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 (int argc, char *argv[]) 51 main ()
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)(FILE *); 107 int (*action)();
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_t size) 194 xmalloc (size)
195 size_t size;
195 { 196 {
196 char *result = malloc (((unsigned) size)); 197 char *result = malloc (((unsigned) size));
197 if (result == ((char *) NULL)) 198 if (result == ((char *) NULL))
198 fatal ("virtual memory exhausted", (char *) 0); 199 fatal ("virtual memory exhausted", (char *) 0);
199 return result; 200 return result;
200 } 201 }
201 202
202 static char * 203 static char *
203 xrealloc (char *ptr, size_t size) 204 xrealloc (ptr, size)
205 char *ptr;
206 size_t size;
204 { 207 {
205 char *result = realloc (ptr, ((unsigned) size)); 208 char *result = realloc (ptr, ((unsigned) size));
206 if (result == ((char *) NULL)) 209 if (result == ((char *) NULL))
207 fatal ("virtual memory exhausted", (char *) 0); 210 fatal ("virtual memory exhausted", (char *) 0);
208 return result; 211 return result;
216 linebuffer->size = INITIAL_LINE_SIZE; 219 linebuffer->size = INITIAL_LINE_SIZE;
217 linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); 220 linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE));
218 } 221 }
219 222
220 /* Read a line of text from `stream' into `linebuffer'. 223 /* Read a line of text from `stream' into `linebuffer'.
221 * Return the length of the line. 224 * Return the length of the line.
222 */ 225 */
223 226
224 static long 227 static long
225 readline (struct linebuffer *linebuffer, FILE *stream) 228 readline (struct linebuffer *linebuffer, FILE *stream)
226 { 229 {
258 register char *ptr; 261 register char *ptr;
259 register char c; 262 register char c;
260 263
261 ptr = &keyword[0]; 264 ptr = &keyword[0];
262 c = *field++; 265 c = *field++;
263 if ((isspace ((int) (unsigned char) c)) || (c == ':')) 266 if ((isspace (c)) || (c == ':'))
264 return (char *) NULL; 267 return ((char *) NULL);
265 *ptr++ = ((islower ((int) (unsigned char) c)) ? 268 *ptr++ = ((islower (c)) ? (toupper (c)) : c);
266 (toupper ((int) (unsigned char) c)) : c); 269 while (((c = *field++) != ':') && (!(isspace (c))))
267 while (((c = *field++) != ':') && 270 *ptr++ = ((islower (c)) ? (toupper (c)) : c);
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 ((int) (unsigned char) c)) c = *field++; 272 while (isspace (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)(FILE *)) 374 add_a_stream (FILE *the_stream, int (*closing_action)())
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 (int argc, char *argv[]) 627 main (argc, argv)
628 int argc;
629 char **argv;
628 { 630 {
629 char *command_line; 631 char *command_line;
630 header the_header; 632 header the_header;
631 long name_length; 633 long name_length;
632 char *mail_program_name; 634 char *mail_program_name;
651 the_header = read_header (); 653 the_header = read_header ();
652 command_line = alloc_string ((size_t) (name_length + 654 command_line = alloc_string ((size_t) (name_length +
653 args_size (the_header))); 655 args_size (the_header)));
654 strcpy (command_line, mail_program_name); 656 strcpy (command_line, mail_program_name);
655 parse_header (the_header, &command_line[name_length]); 657 parse_header (the_header, &command_line[name_length]);
656 658
657 the_pipe = popen (command_line, "w"); 659 the_pipe = popen (command_line, "w");
658 if (the_pipe == ((FILE *) NULL)) 660 if (the_pipe == ((FILE *) NULL))
659 fatal ("cannot open pipe to real mailer", (char *) 0); 661 fatal ("cannot open pipe to real mailer", (char *) 0);
660 662
661 add_a_stream (the_pipe, pclose); 663 add_a_stream (the_pipe, pclose);