$NetBSD: patch-ai,v 1.4 2015/11/08 20:51:59 dholland Exp $ - clean up junk decls that exist in headers, and include the right headers - use fgets instead of gets - fix printf to always have format - when executing a child metamail, propagate the parents options as much as possible - use termios instead of termio/sgtty --- metamail/metamail.c.orig 1994-02-17 01:57:19.000000000 +0000 +++ metamail/metamail.c @@ -46,12 +46,8 @@ extern char *mktemp(char *); #include #ifndef AMIGA -#ifdef SYSV -#include +#include #include -#else /* SYSV */ -#include -#endif /* SYSV */ #endif /* AMIGA */ #endif /* MICROSOFT */ #endif /* BORLAND */ @@ -83,7 +79,7 @@ extern char *MkRmScript(); #define MAX_FILE_NAME_SIZE 256 #define WRITE_BINARY "w" #else /* AMIGA */ -extern char **environ, *gets(); +extern char **environ; #define CATCOMMAND "cat" #define CATTEMPLATE "cat %s" #define METAMAIL "metamail" @@ -100,15 +96,14 @@ extern char **environ, *gets(); #define CMDSIZE 1200 /* Maximum size of command to execute */ #define LINE_BUF_SIZE 2000 -#ifndef MICROSOFT -extern char *malloc(); -extern char *realloc(); -#endif -extern char *getenv(); -extern char *index(); -extern char *rindex(); +#include +#include + char fileToDelete[MAX_FILE_NAME_SIZE]; +void PauseForUser(void); +void maybephead(char *); + char *FindParam(); extern FILE *popen(); static char *nomem = "Out of memory!"; @@ -151,6 +146,32 @@ int MightAskBeforeExecuting = 1, JustWriteFiles = 0, ProcessingErrors = 0; +static const char * +makeoptions(void) +{ + static char buf[1024]; + buf[0] = 0; + if (!MightAskBeforeExecuting) + strlcat(buf, " -d", sizeof(buf)); + if (DefinitelyNotTty && MustNotBeTty) + strlcat(buf, " -x", sizeof(buf)); + if (MaybePageOutput) + strlcat(buf, MustPageOutput ? " -P" : " -p", sizeof(buf)); + if (EatLeadingNewlines) + strlcat(buf, " -e", sizeof(buf)); + if (!PrintSomeHeaders && Quiet) + strlcat(buf, " -q", sizeof(buf)); + if (DoInBackground) + strlcat(buf, " -B", sizeof(buf)); + if (!Is822Format) + strlcat(buf, " -b", sizeof(buf)); + if (PrintingMode) + strlcat(buf, " -h", sizeof(buf)); + if (JustWriteFiles) + strlcat(buf, " -w", sizeof(buf)); + return buf; +} + char *ContentType = NULL, *ContentEncoding = NULL, *MailerName = "unknown", @@ -497,8 +518,9 @@ int nestingdepth; if (IsAlternative) { if (WroteSquirrelFile) { int retcode; - char Cmd[TMPFILE_NAME_SIZE + 15]; - sprintf(Cmd, "%s %s", METAMAIL, NewSquirrelFile); + char Cmd[TMPFILE_NAME_SIZE + 15 + 1024]; + snprintf(Cmd, sizeof(Cmd), "%s %s %s", METAMAIL, makeoptions(), + NewSquirrelFile); fflush(stdout); fflush(stderr); retcode = system(Cmd); #ifdef MSDOS @@ -579,7 +601,7 @@ int nestingdepth; int overwriteans = -1; do { printf("File %s exists. Do you want to overwrite it (y/n) ?\n", Fname); - s = gets(AnsBuf); + s = fgets(AnsBuf, sizeof(AnsBuf), stdin); if (!s) { overwriteans = 0; } else { @@ -1202,9 +1224,9 @@ char *SquirrelFile; fprintf(outfp, "Content-type: %s", ContentType); for (j=0; j