X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lib-src%2Ffakemail.c;h=13976ba1e74b474aaf7c0d7d5f0fd1545643c78c;hb=09ea9552234731fb1cd73d93e1805d7fc5b7ccf8;hp=22cb1ab13f63a4c7a3461462d843e780d7771c40;hpb=6883ee56ec887c2c48abe5b06b5e66aa74031910;p=chise%2Fxemacs-chise.git.1 diff --git a/lib-src/fakemail.c b/lib-src/fakemail.c index 22cb1ab..13976ba 100644 --- a/lib-src/fakemail.c +++ b/lib-src/fakemail.c @@ -21,12 +21,12 @@ Boston, MA 02111-1307, USA. */ /* Synched up with: FSF 19.28. */ #define NO_SHORTNAMES -#include <../src/config.h> +#include #if defined (BSD) && !defined (BSD4_1) && !defined (USE_FAKEMAIL) -/* This program isnot used in BSD, so just avoid loader complaints. */ +/* This program is not used in BSD, so just avoid loader complaints. */ int -main () +main (int argc, char *argv[]) { return 0; } @@ -34,7 +34,7 @@ main () #include #include int -main () +main (int argc, char *argv[]) { /* Linux /bin/mail, if it exists, is NOT the Unix v7 mail that fakemail depends on! This causes garbled mail. Better to @@ -46,14 +46,6 @@ main () return 1; } #else /* not BSD 4.2 (or newer) */ -#ifdef MSDOS -int -main () -{ - return 0; -} -#else /* not MSDOS */ -/* This conditional contains all the rest of the file. */ /* These are defined in config in some versions. */ @@ -100,11 +92,11 @@ struct header_record struct header_record *previous; }; typedef struct header_record *header; - + struct stream_record { FILE *handle; - int (*action)(); + int (*action)(FILE *); struct stream_record *rest_streams; }; typedef struct stream_record *stream_list; @@ -116,7 +108,7 @@ typedef struct stream_record *stream_list; struct linebuffer { - long size; + size_t size; char *buffer; }; @@ -144,7 +136,7 @@ struct linebuffer lb; #define MAIL_PROGRAM_NAME "/bin/mail" #endif -static CONST char *my_name; +static const char *my_name; static char *the_date; static char *the_user; static line_list file_preface; @@ -157,12 +149,20 @@ extern int fclose (), pclose (); extern char *malloc (), *realloc (); #endif +#if defined(__FreeBSD_version) && __FreeBSD_version >= 400000 +#define CURRENT_USER +#endif + #ifdef CURRENT_USER extern struct passwd *getpwuid (); +#if defined(__FreeBSD_version) && __FreeBSD_version >= 400000 +extern uid_t geteuid (); +#else extern unsigned short geteuid (); +#endif static struct passwd *my_entry; #define cuserid(s) \ -(my_entry = getpwuid (((int) geteuid ())), \ +(my_entry = getpwuid ((int) geteuid ()), \ my_entry->pw_name) #endif @@ -171,7 +171,7 @@ static struct passwd *my_entry; /* Print error message. `s1' is printf control string, `s2' is arg for it. */ static void -error (CONST char *s1, CONST char *s2) +error (const char *s1, const char *s2) { printf ("%s: ", my_name); printf (s1, s2); @@ -182,7 +182,7 @@ error (CONST char *s1, CONST char *s2) /* Print error message and exit. */ static void -fatal (CONST char *s1, CONST char *s2) +fatal (const char *s1, const char *s2) { error (s1, s2); exit (1); @@ -190,23 +190,20 @@ fatal (CONST char *s1, CONST char *s2) /* Like malloc but get fatal error if memory is exhausted. */ -static char * -xmalloc (size) - size_t size; +static void * +xmalloc (size_t size) { - char *result = malloc (((unsigned) size)); - if (result == ((char *) NULL)) + void *result = malloc (size); + if (result == NULL) fatal ("virtual memory exhausted", (char *) 0); return result; } -static char * -xrealloc (ptr, size) - char *ptr; - size_t size; +static void * +xrealloc (void *ptr, size_t size) { - char *result = realloc (ptr, ((unsigned) size)); - if (result == ((char *) NULL)) + void *result = realloc (ptr, size); + if (result == NULL) fatal ("virtual memory exhausted", (char *) 0); return result; } @@ -217,11 +214,11 @@ static void init_linebuffer (struct linebuffer *linebuffer) { linebuffer->size = INITIAL_LINE_SIZE; - linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); + linebuffer->buffer = (char *) xmalloc (INITIAL_LINE_SIZE); } /* Read a line of text from `stream' into `linebuffer'. - * Return the length of the line. + * Return the length of the line. */ static long @@ -237,8 +234,7 @@ readline (struct linebuffer *linebuffer, FILE *stream) if (p == end) { linebuffer->size *= 2; - buffer = ((char *) xrealloc ((char *) buffer, - (size_t) (linebuffer->size))); + buffer = (char *) xrealloc (buffer, linebuffer->size); p = buffer + (p - linebuffer->buffer); end = buffer + linebuffer->size; linebuffer->buffer = buffer; @@ -263,14 +259,17 @@ get_keyword (register char *field, char **rest) ptr = &keyword[0]; c = *field++; - if ((isspace (c)) || (c == ':')) - return ((char *) NULL); - *ptr++ = ((islower (c)) ? (toupper (c)) : c); - while (((c = *field++) != ':') && (!(isspace (c)))) - *ptr++ = ((islower (c)) ? (toupper (c)) : c); + if ((isspace ((int) (unsigned char) c)) || (c == ':')) + return (char *) NULL; + *ptr++ = ((islower ((int) (unsigned char) c)) ? + (toupper ((int) (unsigned char) c)) : c); + while (((c = *field++) != ':') && + (!(isspace ((int) (unsigned char) c)))) + *ptr++ = ((islower ((int) (unsigned char) c)) ? + (toupper ((int) (unsigned char) c)) : c); *ptr++ = '\0'; - while (isspace (c)) c = *field++; - if (c != ':') return ((char *) NULL); + while (isspace ((int) (unsigned char) c)) c = *field++; + if (c != ':') return (char *) NULL; *rest = field; return &keyword[0]; } @@ -279,7 +278,7 @@ static boolean has_keyword (char *field) { char *ignored; - return (get_keyword (field, &ignored) != ((char *) NULL)); + return (get_keyword (field, &ignored) != (char *) NULL); } static char * @@ -311,7 +310,7 @@ static line_list make_file_preface (void) { char *the_string, *temp; - long idiotic_interface; + time_t idiotic_interface; long prefix_length; long user_length; long date_length; @@ -322,8 +321,13 @@ make_file_preface (void) the_date = ctime (&idiotic_interface); /* the_date has an unwanted newline at the end */ date_length = strlen (the_date) - 1; - the_date[date_length] = '\0'; + if (the_date[date_length] == '\n') + the_date[date_length] = '\0'; +#ifdef WIN32_NATIVE + temp = "(null)"; +#else temp = cuserid ((char *) NULL); +#endif user_length = strlen (temp); the_user = alloc_string ((size_t) (user_length + 1)); strcpy (the_user, temp); @@ -371,7 +375,7 @@ close_the_streams (void) } static void -add_a_stream (FILE *the_stream, int (*closing_action)()) +add_a_stream (FILE *the_stream, int (*closing_action)(FILE *)) { stream_list old = the_streams; the_streams = new_stream (); @@ -396,7 +400,7 @@ open_a_file (char *name) if (the_stream != ((FILE *) NULL)) { add_a_stream (the_stream, my_fclose); - if (the_user == ((char *) NULL)) + if (the_user == (char *) NULL) file_preface = make_file_preface (); write_line_list (file_preface, the_stream); return true; @@ -416,20 +420,20 @@ put_string (char *s) } static void -put_line (CONST char *string) +put_line (const char *string) { register stream_list rem; for (rem = the_streams; rem != ((stream_list) NULL); rem = rem->rest_streams) { - CONST char *s = string; + const char *s = string; int column = 0; /* Divide STRING into lines. */ while (*s != 0) { - CONST char *breakpos; + const char *breakpos; /* Find the last char that fits. */ for (breakpos = s; *breakpos && column < 78; ++breakpos) @@ -553,7 +557,7 @@ parse_header (header the_header, register char *where) *where = '\0'; return; } - + static header read_header (void) { @@ -624,9 +628,7 @@ write_header (header the_header) } int -main (argc, argv) - int argc; - char **argv; +main (int argc, char *argv[]) { char *command_line; header the_header; @@ -636,10 +638,6 @@ main (argc, argv) register int size; FILE *the_pipe; -#if !(__STDC__ || defined(STDC_HEADERS)) - extern char *getenv (); -#endif - mail_program_name = getenv ("FAKEMAILER"); if (!(mail_program_name && *mail_program_name)) mail_program_name = (char *) MAIL_PROGRAM_NAME; @@ -647,18 +645,18 @@ main (argc, argv) my_name = MY_NAME; the_streams = ((stream_list) NULL); - the_date = ((char *) NULL); - the_user = ((char *) NULL); + the_date = (char *) NULL; + the_user = (char *) NULL; the_header = read_header (); command_line = alloc_string ((size_t) (name_length + args_size (the_header))); strcpy (command_line, mail_program_name); parse_header (the_header, &command_line[name_length]); - + the_pipe = popen (command_line, "w"); if (the_pipe == ((FILE *) NULL)) - fatal ("cannot open pipe to real mailer", (char *) 0); + fatal ("cannot open pipe to real mailer", (char *) NULL); add_a_stream (the_pipe, pclose); @@ -676,5 +674,4 @@ main (argc, argv) return close_the_streams (); } -#endif /* not MSDOS */ #endif /* not BSD 4.2 (or newer) */