X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/e19bdc1471737b32c839b81daf1916556e13986c..5cb4031d8f4101d80e936a9a13839ea1820db938:/lib-src/b2m.c diff --git a/lib-src/b2m.c b/lib-src/b2m.c index 416db6385f..05caa1424e 100644 --- a/lib-src/b2m.c +++ b/lib-src/b2m.c @@ -1,12 +1,13 @@ /* * b2m - a filter for Babyl -> Unix mail files + * The copyright on this file has been disclaimed. * * usage: b2m < babyl > mailbox * * I find this useful whenever I have to use a * system which - shock horror! - doesn't run - * Gnu emacs. At least now I can read all my - * Gnumacs Babyl format mail files! + * GNU Emacs. At least now I can read all my + * GNU Emacs Babyl format mail files! * * it's not much but it's free! * @@ -18,13 +19,6 @@ /* Made conformant to the GNU coding standards January, 1995 by Francesco Potorti` . */ -#include -#include -#include -#ifdef MSDOS -#include -#endif - #ifdef HAVE_CONFIG_H #include /* On some systems, Emacs defines static as nothing for the sake @@ -32,6 +26,14 @@ #undef static #endif +#include +#include +#include +#include +#ifdef MSDOS +#include +#endif + #undef TRUE #define TRUE 1 #undef FALSE @@ -64,7 +66,7 @@ struct linebuffer extern char *strtok(); -char *xmalloc (), *xrealloc (); +long *xmalloc (), *xrealloc (); char *concat (); long readline (); void fatal (); @@ -78,6 +80,16 @@ void fatal (); char *progname; +struct option longopts[] = +{ + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, + { 0 } +}; + +extern int optind; + +int main (argc, argv) int argc; char **argv; @@ -89,16 +101,44 @@ main (argc, argv) #ifdef MSDOS _fmode = O_BINARY; /* all of files are treated as binary files */ +#if __DJGPP__ > 1 + if (!isatty (fileno (stdout))) + setmode (fileno (stdout), O_BINARY); + if (!isatty (fileno (stdin))) + setmode (fileno (stdin), O_BINARY); +#else /* not __DJGPP__ > 1 */ (stdout)->_flag &= ~_IOTEXT; (stdin)->_flag &= ~_IOTEXT; +#endif /* not __DJGPP__ > 1 */ #endif - if (argc != 1) + progname = argv[0]; + + while (1) + { + int opt = getopt_long (argc, argv, "hV", longopts, 0); + if (opt == EOF) + break; + + switch (opt) + { + case 'V': + printf ("%s (GNU Emacs %s)\n", "b2m", VERSION); + puts ("b2m is in the public domain."); + exit (GOOD); + + case 'h': + fprintf (stderr, "Usage: %s unixmailbox\n", progname); + exit (GOOD); + } + } + + if (optind != argc) { fprintf (stderr, "Usage: %s unixmailbox\n", progname); exit (GOOD); } + labels_saved = printing = header = FALSE; - progname = argv[0]; ltoday = time (0); today = ctime (<oday); data.size = 200; @@ -113,7 +153,7 @@ main (argc, argv) if (streq (data.buffer, "*** EOOH ***") && !printing) { printing = header = TRUE; - printf ("From Babyl to mail by %s %s", progname, today); + printf ("From \"Babyl to mail by %s\" %s", progname, today); continue; } @@ -128,10 +168,12 @@ main (argc, argv) p = strtok (data.buffer, " ,\r\n\t"); labels = "X-Babyl-Labels: "; - while (p = strtok (NULL, " ,\r\n\t")) + while ((p = strtok (NULL, " ,\r\n\t"))) labels = concat (labels, p, ", "); - labels[strlen (labels) - 2] = '\0'; + p = &labels[strlen (labels) - 2]; + if (*p == ',') + *p = '\0'; printing = header = FALSE; labels_saved = TRUE; continue; @@ -148,6 +190,8 @@ main (argc, argv) if (printing) puts (data.buffer); } + + return 0; } @@ -201,12 +245,13 @@ readline (linebuffer, stream) } if (c == EOF) { + *p = '\0'; chars_deleted = 0; break; } if (c == '\n') { - if (p[-1] == '\r' && p > buffer) + if (p > buffer && p[-1] == '\r') { *--p = '\0'; chars_deleted = 2; @@ -227,22 +272,22 @@ readline (linebuffer, stream) /* * Like malloc but get fatal error if memory is exhausted. */ -char * +long * xmalloc (size) unsigned int size; { - char *result = (char *) malloc (size); + long *result = (long *) malloc (size); if (result == NULL) fatal ("virtual memory exhausted"); return result; } -char * +long * xrealloc (ptr, size) char *ptr; unsigned int size; { - char *result = (char *) realloc (ptr, size); + long *result = (long *) realloc (ptr, size); if (result == NULL) fatal ("virtual memory exhausted"); return result; @@ -250,6 +295,7 @@ xrealloc (ptr, size) void fatal (message) + char *message; { fprintf (stderr, "%s: %s\n", progname, message); exit (BAD);