home *** CD-ROM | disk | FTP | other *** search
- /*
- ** stom.c --
- ** Convert a .sends formatted message into a Unix mailbox
- ** format.
- **
- ** Written by: Keith Gabryelski (ag@elgar.UUCP)
- **
- ** Released into public domain June 14, 1988.
- ** Please keep this header.
- */
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <pwd.h>
- #include <errno.h>
-
- extern errno;
-
- extern FILE *fopen();
- extern struct passwd *getpwuid(), *getpwnam();
- extern char *sys_errlist[], *malloc(), *realloc();
- extern int sys_nerr;
-
- #undef TRUE
- #undef FALSE
- #define TRUE 1
- #define FALSE 0
-
- #define SENDS_FILENAME "/.sends" /* must have the '/' */
- #define MESSAGE_SEPARATOR 0x1F
-
- char *puterr(), *mymalloc(), *myrealloc();
- char *progname;
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- FILE *fp;
-
- progname = *argv++; --argc;
-
- if (argc < 1)
- convert(stdin);
- else
- while (argc--)
- {
- if ((fp = fopen(*argv, "r")) == NULL)
- fprintf(stderr, "%s: can't access file %s (%s).\n", progname,
- *argv, puterr(errno));
- else
- convert(fp);
-
- *++argv;
- }
-
- exit(0);
- }
-
- convert(stream)
- FILE *stream;
- {
- char text[20], user_name[10], date[28];
- char *dp;
- int c;
-
- while (fscanf(stream, "[%s from %s ", text, user_name) == 2)
- {
- /*
- ** ignore tty.
- */
- while ((c = getc(stream)) != ')')
- ;
-
- /*
- ** get date.
- */
-
- dp = date;
-
- while ((c = getc(stream)) != ']')
- *dp++ = c;
-
- *dp = '\0';
-
- printf("From %s%s\nSubject: A %s\n", user_name, date, text);
-
- /*
- ** And the message itself.
- */
- while ((c = getc(stream)) != MESSAGE_SEPARATOR)
- putchar(c);
- }
- }
-
- char *
- puterr(error)
- int error;
- {
- static char qwerty[42];
-
- (void) sprintf(qwerty, "Unknown error %d", error);
-
- return ((unsigned)error >= sys_nerr) ? qwerty : sys_errlist[error];
- }
-