From 56a805299de35d8924969138aef4d0f1580daa6d Mon Sep 17 00:00:00 2001 From: Joel Reicher Date: Sun, 4 Nov 2007 04:47:17 +0000 Subject: [PATCH] Change link-time overriding of done() to run-time reassigning of equivalent (*done)(). This should make changing the return type of done and the rationalisation of exit code easier. --- h/mh.h | 2 ++ h/prototypes.h | 2 +- sbr/done.c | 4 +++- uip/inc.c | 8 +++++--- uip/mhbuild.c | 7 +++++-- uip/mhlist.c | 7 +++++-- uip/mhn.c | 7 +++++-- uip/mhshow.c | 7 +++++-- uip/mhstore.c | 7 +++++-- uip/mhtest.c | 7 +++++-- uip/packf.c | 8 ++++++-- uip/pick.c | 7 +++++-- uip/rcvdist.c | 8 +++++--- uip/rcvstore.c | 7 +++++-- uip/sendsbr.c | 14 ++++++-------- 15 files changed, 68 insertions(+), 34 deletions(-) diff --git a/h/mh.h b/h/mh.h index 130bfde..bcfe6ae 100644 --- a/h/mh.h +++ b/h/mh.h @@ -336,5 +336,7 @@ extern char *vmhproc; extern char *whatnowproc; extern char *whomproc; +extern int (*done) (int); + #include diff --git a/h/prototypes.h b/h/prototypes.h index a91418e..0f05025 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -47,7 +47,7 @@ void cpydata (int, int, char *, char *); void cpydgst (int, int, char *, char *); int decode_rfc2047 (char *, char *, size_t); void discard (FILE *); -int done (int); +int default_done (int); int ext_hook(char *, char *, char *); int fdcompare (int, int); int folder_addmsg (struct msgs **, char *, int, int, int, int, char *); diff --git a/sbr/done.c b/sbr/done.c index cf2e308..bcc258c 100644 --- a/sbr/done.c +++ b/sbr/done.c @@ -11,8 +11,10 @@ #include +int (*done) (int) = default_done; + int -done (int status) +default_done (int status) { exit (status); return 1; /* dead code to satisfy the compiler */ diff --git a/uip/inc.c b/uip/inc.c index 45036f5..f2d2e77 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -223,8 +223,8 @@ static FILE *in; */ char *map_name(char *); +static int inc_done(int); #ifdef POP -int done(int); static int pop_action(char *); static int pop_pack(char *); static int map_count(void); @@ -263,6 +263,8 @@ main (int argc, char **argv) struct hes_postoffice *po; #endif + done=inc_done; + /* absolutely the first thing we do is save our privileges, * and drop them if we can. */ @@ -987,8 +989,8 @@ cpymsg (FILE *in, FILE *out) #endif /* if 0 */ -int -done (int status) +static int +inc_done (int status) { #ifdef POP if (packfile && pd != NOTOK) diff --git a/uip/mhbuild.c b/uip/mhbuild.c index cfe776f..15132ee 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -100,6 +100,7 @@ static int unlink_infile = 0; static char outfile[BUFSIZ]; static int unlink_outfile = 0; +static int unlink_done (int); /* mhbuildsbr.c */ CT build_mime (char *); @@ -126,6 +127,8 @@ main (int argc, char **argv) CT ct, cts[2]; FILE *fp; + done=unlink_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -382,8 +385,8 @@ main (int argc, char **argv) } -int -done (int status) +static int +unlink_done (int status) { /* * Check if we need to remove stray diff --git a/uip/mhlist.c b/uip/mhlist.c index 1de53e3..bcc4dd2 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -117,6 +117,7 @@ void free_content (CT); * static prototypes */ static RETSIGTYPE pipeser (int); +static int freectp_done (int); int @@ -131,6 +132,8 @@ main (int argc, char **argv) struct msgs *mp = NULL; CT ct, *ctp; + done=freectp_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -391,8 +394,8 @@ pipeser (int i) } -int -done (int status) +static int +freectp_done (int status) { CT *ctp; diff --git a/uip/mhn.c b/uip/mhn.c index 809568c..3f2d262 100644 --- a/uip/mhn.c +++ b/uip/mhn.c @@ -205,6 +205,7 @@ void free_content (CT); * static prototypes */ static RETSIGTYPE pipeser (int); +static int freectp_done (int); int @@ -220,6 +221,8 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; + done=freectp_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -704,8 +707,8 @@ pipeser (int i) } -int -done (int status) +static int +freectp_done (int status) { CT *ctp; diff --git a/uip/mhshow.c b/uip/mhshow.c index 3e7e3a5..4755171 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -133,6 +133,7 @@ void free_content (CT); * static prototypes */ static RETSIGTYPE pipeser (int); +static int freectp_done (int); int @@ -147,6 +148,8 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; + done=freectp_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -471,8 +474,8 @@ pipeser (int i) } -int -done (int status) +static int +freectp_done (int status) { CT *ctp; diff --git a/uip/mhstore.c b/uip/mhstore.c index dc62724..b1f57fe 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -111,6 +111,7 @@ void free_content (CT); * static prototypes */ static RETSIGTYPE pipeser (int); +static int freectp_done (int); int @@ -125,6 +126,8 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; + done=freectp_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -403,8 +406,8 @@ pipeser (int i) } -int -done (int status) +static int +freectp_done (int status) { CT *ctp; diff --git a/uip/mhtest.c b/uip/mhtest.c index 5e6494a..985147c 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -114,6 +114,7 @@ void free_content (CT); */ static int write_content (CT *, char *); static RETSIGTYPE pipeser (int); +static int freectp_done (int); int @@ -127,6 +128,8 @@ main (int argc, char **argv) struct msgs *mp = NULL; CT ct, *ctp; + done=freectp_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -397,8 +400,8 @@ pipeser (int i) } -int -done (int status) +static int +freectp_done (int status) { CT *ctp; diff --git a/uip/packf.c b/uip/packf.c index 9f95466..0183da6 100644 --- a/uip/packf.c +++ b/uip/packf.c @@ -33,6 +33,8 @@ static int md = NOTOK; static int mbx_style = MBOX_FORMAT; static int mapping = 0; +static int mbxclose_done(int); + char *file = NULL; @@ -46,6 +48,8 @@ main (int argc, char **argv) struct msgs *mp; struct stat st; + done=mbxclose_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -178,8 +182,8 @@ main (int argc, char **argv) return done (0); } -int -done (int status) +static int +mbxclose_done (int status) { mbx_close (file, md); exit (status); diff --git a/uip/pick.c b/uip/pick.c index dff628a..afbcf88 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -68,6 +68,7 @@ static struct swit switches[] = { static int listsw = -1; +static int putzero_done (int); int main (int argc, char **argv) @@ -81,6 +82,8 @@ main (int argc, char **argv) struct msgs *mp; register FILE *fp; + done=putzero_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -287,8 +290,8 @@ main (int argc, char **argv) } -int -done (int status) +static int +putzero_done (int status) { if (listsw && status && !isatty (fileno (stdout))) printf ("0\n"); diff --git a/uip/rcvdist.c b/uip/rcvdist.c index e881565..1667232 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -34,7 +34,7 @@ static char tmpfil[BUFSIZ] = ""; * prototypes */ static void rcvdistout (FILE *, char *, char *); -int done (int); +static int unlink_done (int); int @@ -46,6 +46,8 @@ main (int argc, char **argv) char **argp, **arguments, *vec[MAXARGS]; register FILE *fp; + done=unlink_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -268,8 +270,8 @@ finished: ; } -int -done (int status) +static int +unlink_done (int status) { if (backup[0]) unlink (backup); diff --git a/uip/rcvstore.c b/uip/rcvstore.c index 4e14afb..3e0961e 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -48,6 +48,7 @@ static struct swit switches[] = { */ static char *tmpfilenam = NULL; +static int unlink_done(int); int main (int argc, char **argv) @@ -60,6 +61,8 @@ main (int argc, char **argv) struct msgs *mp; struct stat st; + done=unlink_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -228,8 +231,8 @@ main (int argc, char **argv) /* * Clean up and exit */ -int -done(int status) +static int +unlink_done(int status) { if (tmpfilenam && *tmpfilenam) unlink (tmpfilenam); diff --git a/uip/sendsbr.c b/uip/sendsbr.c index aeba011..cb6bb3f 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -41,7 +41,6 @@ char *altmsg = NULL; /* .. */ char *annotext = NULL; char *distfile = NULL; -static int armed = 0; static jmp_buf env; static char body_file_name[MAXPATHLEN + 1]; /* name of temporary file for body content */ @@ -56,12 +55,12 @@ static FILE *composition_file; /* composition file pointer */ * external prototypes */ int sendsbr (char **, int, char *, struct stat *, int, char *, int); -int done (int); char *getusername (void); /* * static prototypes */ +static int armed_done (int); static void alert (char *, int); static int tmp_fd (void); static void anno (int, struct stat *); @@ -118,7 +117,7 @@ sendsbr (char **vec, int vecp, char *drft, struct stat *st, int rename_drft, cha } } - armed++; + done=armed_done; switch (setjmp (env)) { case OK: /* @@ -154,7 +153,7 @@ sendsbr (char **vec, int vecp, char *drft, struct stat *st, int rename_drft, cha break; } - armed = 0; + done=default_done; if (distfile) unlink (distfile); @@ -1075,11 +1074,10 @@ oops: } -int -done (int status) +static int +armed_done (int status) { - if (armed) - longjmp (env, status ? status : NOTOK); + longjmp (env, status ? status : NOTOK); exit (status); return 1; /* dead code to satisfy the compiler */ -- 1.7.10.4