comparison lib-src/fakemail.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
19 Boston, MA 02111-1307, USA. */ 19 Boston, MA 02111-1307, USA. */
20 20
21 /* Synched up with: FSF 19.28. */ 21 /* Synched up with: FSF 19.28. */
22 22
23 #define NO_SHORTNAMES 23 #define NO_SHORTNAMES
24 #include <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 is not used in BSD, so just avoid loader complaints. */
28 int 28 int
29 main (int argc, char *argv[]) 29 main (int argc, char *argv[])
44 fprintf (stderr, "set the Lisp variable `sendmail-program' to point\n"); 44 fprintf (stderr, "set the Lisp variable `sendmail-program' to point\n");
45 fprintf (stderr, "to the path of the sendmail binary.\n"); 45 fprintf (stderr, "to the path of the sendmail binary.\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
50 int
51 main (int argc, char *argv[])
52 {
53 return 0;
54 }
55 #else /* not MSDOS */
56 /* This conditional contains all the rest of the file. */
49 57
50 /* These are defined in config in some versions. */ 58 /* These are defined in config in some versions. */
51 59
52 #ifdef static 60 #ifdef static
53 #undef static 61 #undef static
106 * and works regardless of the length of the line. 114 * and works regardless of the length of the line.
107 */ 115 */
108 116
109 struct linebuffer 117 struct linebuffer
110 { 118 {
111 size_t size; 119 long size;
112 char *buffer; 120 char *buffer;
113 }; 121 };
114 122
115 struct linebuffer lb; 123 struct linebuffer lb;
116 124
134 142
135 #ifndef MAIL_PROGRAM_NAME 143 #ifndef MAIL_PROGRAM_NAME
136 #define MAIL_PROGRAM_NAME "/bin/mail" 144 #define MAIL_PROGRAM_NAME "/bin/mail"
137 #endif 145 #endif
138 146
139 static const char *my_name; 147 static CONST char *my_name;
140 static char *the_date; 148 static char *the_date;
141 static char *the_user; 149 static char *the_user;
142 static line_list file_preface; 150 static line_list file_preface;
143 static stream_list the_streams; 151 static stream_list the_streams;
144 static boolean no_problems = true; 152 static boolean no_problems = true;
152 #ifdef CURRENT_USER 160 #ifdef CURRENT_USER
153 extern struct passwd *getpwuid (); 161 extern struct passwd *getpwuid ();
154 extern unsigned short geteuid (); 162 extern unsigned short geteuid ();
155 static struct passwd *my_entry; 163 static struct passwd *my_entry;
156 #define cuserid(s) \ 164 #define cuserid(s) \
157 (my_entry = getpwuid ((int) geteuid ()), \ 165 (my_entry = getpwuid (((int) geteuid ())), \
158 my_entry->pw_name) 166 my_entry->pw_name)
159 #endif 167 #endif
160 168
161 /* Utilities */ 169 /* Utilities */
162 170
163 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ 171 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
164 172
165 static void 173 static void
166 error (const char *s1, const char *s2) 174 error (CONST char *s1, CONST char *s2)
167 { 175 {
168 printf ("%s: ", my_name); 176 printf ("%s: ", my_name);
169 printf (s1, s2); 177 printf (s1, s2);
170 printf ("\n"); 178 printf ("\n");
171 no_problems = false; 179 no_problems = false;
172 } 180 }
173 181
174 /* Print error message and exit. */ 182 /* Print error message and exit. */
175 183
176 static void 184 static void
177 fatal (const char *s1, const char *s2) 185 fatal (CONST char *s1, CONST char *s2)
178 { 186 {
179 error (s1, s2); 187 error (s1, s2);
180 exit (1); 188 exit (1);
181 } 189 }
182 190
183 /* Like malloc but get fatal error if memory is exhausted. */ 191 /* Like malloc but get fatal error if memory is exhausted. */
184 192
185 static void * 193 static char *
186 xmalloc (size_t size) 194 xmalloc (size_t size)
187 { 195 {
188 void *result = malloc (size); 196 char *result = malloc (((unsigned) size));
189 if (result == NULL) 197 if (result == ((char *) NULL))
190 fatal ("virtual memory exhausted", (char *) 0); 198 fatal ("virtual memory exhausted", (char *) 0);
191 return result; 199 return result;
192 } 200 }
193 201
194 static void * 202 static char *
195 xrealloc (void *ptr, size_t size) 203 xrealloc (char *ptr, size_t size)
196 { 204 {
197 void *result = realloc (ptr, size); 205 char *result = realloc (ptr, ((unsigned) size));
198 if (result == NULL) 206 if (result == ((char *) NULL))
199 fatal ("virtual memory exhausted", (char *) 0); 207 fatal ("virtual memory exhausted", (char *) 0);
200 return result; 208 return result;
201 } 209 }
202 210
203 /* Initialize a linebuffer for use */ 211 /* Initialize a linebuffer for use */
204 212
205 static void 213 static void
206 init_linebuffer (struct linebuffer *linebuffer) 214 init_linebuffer (struct linebuffer *linebuffer)
207 { 215 {
208 linebuffer->size = INITIAL_LINE_SIZE; 216 linebuffer->size = INITIAL_LINE_SIZE;
209 linebuffer->buffer = (char *) xmalloc (INITIAL_LINE_SIZE); 217 linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE));
210 } 218 }
211 219
212 /* Read a line of text from `stream' into `linebuffer'. 220 /* Read a line of text from `stream' into `linebuffer'.
213 * Return the length of the line. 221 * Return the length of the line.
214 */ 222 */
224 { 232 {
225 int c = getc (stream); 233 int c = getc (stream);
226 if (p == end) 234 if (p == end)
227 { 235 {
228 linebuffer->size *= 2; 236 linebuffer->size *= 2;
229 buffer = (char *) xrealloc (buffer, linebuffer->size); 237 buffer = ((char *) xrealloc ((char *) buffer,
238 (size_t) (linebuffer->size)));
230 p = buffer + (p - linebuffer->buffer); 239 p = buffer + (p - linebuffer->buffer);
231 end = buffer + linebuffer->size; 240 end = buffer + linebuffer->size;
232 linebuffer->buffer = buffer; 241 linebuffer->buffer = buffer;
233 } 242 }
234 if (c < 0 || c == '\n') 243 if (c < 0 || c == '\n')
268 277
269 static boolean 278 static boolean
270 has_keyword (char *field) 279 has_keyword (char *field)
271 { 280 {
272 char *ignored; 281 char *ignored;
273 return (get_keyword (field, &ignored) != (char *) NULL); 282 return (get_keyword (field, &ignored) != ((char *) NULL));
274 } 283 }
275 284
276 static char * 285 static char *
277 add_field (line_list the_list, register char *field, register char *where) 286 add_field (line_list the_list, register char *field, register char *where)
278 { 287 {
312 time (&idiotic_interface); 321 time (&idiotic_interface);
313 the_date = ctime (&idiotic_interface); 322 the_date = ctime (&idiotic_interface);
314 /* the_date has an unwanted newline at the end */ 323 /* the_date has an unwanted newline at the end */
315 date_length = strlen (the_date) - 1; 324 date_length = strlen (the_date) - 1;
316 the_date[date_length] = '\0'; 325 the_date[date_length] = '\0';
317 #ifdef WIN32_NATIVE 326 #ifdef WINDOWSNT
318 temp = "(null)"; 327 temp = "(null)";
319 #else 328 #else
320 temp = cuserid ((char *) NULL); 329 temp = cuserid ((char *) NULL);
321 #endif 330 #endif
322 user_length = strlen (temp); 331 user_length = strlen (temp);
389 { 398 {
390 FILE *the_stream = fopen (name, "a"); 399 FILE *the_stream = fopen (name, "a");
391 if (the_stream != ((FILE *) NULL)) 400 if (the_stream != ((FILE *) NULL))
392 { 401 {
393 add_a_stream (the_stream, my_fclose); 402 add_a_stream (the_stream, my_fclose);
394 if (the_user == (char *) NULL) 403 if (the_user == ((char *) NULL))
395 file_preface = make_file_preface (); 404 file_preface = make_file_preface ();
396 write_line_list (file_preface, the_stream); 405 write_line_list (file_preface, the_stream);
397 return true; 406 return true;
398 } 407 }
399 return false; 408 return false;
409 fputs (s, rem->handle); 418 fputs (s, rem->handle);
410 return; 419 return;
411 } 420 }
412 421
413 static void 422 static void
414 put_line (const char *string) 423 put_line (CONST char *string)
415 { 424 {
416 register stream_list rem; 425 register stream_list rem;
417 for (rem = the_streams; 426 for (rem = the_streams;
418 rem != ((stream_list) NULL); 427 rem != ((stream_list) NULL);
419 rem = rem->rest_streams) 428 rem = rem->rest_streams)
420 { 429 {
421 const char *s = string; 430 CONST char *s = string;
422 int column = 0; 431 int column = 0;
423 432
424 /* Divide STRING into lines. */ 433 /* Divide STRING into lines. */
425 while (*s != 0) 434 while (*s != 0)
426 { 435 {
427 const char *breakpos; 436 CONST char *breakpos;
428 437
429 /* Find the last char that fits. */ 438 /* Find the last char that fits. */
430 for (breakpos = s; *breakpos && column < 78; ++breakpos) 439 for (breakpos = s; *breakpos && column < 78; ++breakpos)
431 { 440 {
432 if (*breakpos == '\t') 441 if (*breakpos == '\t')
627 char *mail_program_name; 636 char *mail_program_name;
628 char buf[BUFLEN + 1]; 637 char buf[BUFLEN + 1];
629 register int size; 638 register int size;
630 FILE *the_pipe; 639 FILE *the_pipe;
631 640
641 #if !(__STDC__ || defined(STDC_HEADERS))
642 extern char *getenv ();
643 #endif
644
632 mail_program_name = getenv ("FAKEMAILER"); 645 mail_program_name = getenv ("FAKEMAILER");
633 if (!(mail_program_name && *mail_program_name)) 646 if (!(mail_program_name && *mail_program_name))
634 mail_program_name = (char *) MAIL_PROGRAM_NAME; 647 mail_program_name = (char *) MAIL_PROGRAM_NAME;
635 name_length = strlen (mail_program_name); 648 name_length = strlen (mail_program_name);
636 649
637 my_name = MY_NAME; 650 my_name = MY_NAME;
638 the_streams = ((stream_list) NULL); 651 the_streams = ((stream_list) NULL);
639 the_date = (char *) NULL; 652 the_date = ((char *) NULL);
640 the_user = (char *) NULL; 653 the_user = ((char *) NULL);
641 654
642 the_header = read_header (); 655 the_header = read_header ();
643 command_line = alloc_string ((size_t) (name_length + 656 command_line = alloc_string ((size_t) (name_length +
644 args_size (the_header))); 657 args_size (the_header)));
645 strcpy (command_line, mail_program_name); 658 strcpy (command_line, mail_program_name);
646 parse_header (the_header, &command_line[name_length]); 659 parse_header (the_header, &command_line[name_length]);
647 660
648 the_pipe = popen (command_line, "w"); 661 the_pipe = popen (command_line, "w");
649 if (the_pipe == ((FILE *) NULL)) 662 if (the_pipe == ((FILE *) NULL))
650 fatal ("cannot open pipe to real mailer", (char *) NULL); 663 fatal ("cannot open pipe to real mailer", (char *) 0);
651 664
652 add_a_stream (the_pipe, pclose); 665 add_a_stream (the_pipe, pclose);
653 666
654 write_header (the_header); 667 write_header (the_header);
655 668
663 } 676 }
664 677
665 return close_the_streams (); 678 return close_the_streams ();
666 } 679 }
667 680
681 #endif /* not MSDOS */
668 #endif /* not BSD 4.2 (or newer) */ 682 #endif /* not BSD 4.2 (or newer) */