From 045101c0a79f43fe566422622f154d5cc0141d8a Mon Sep 17 00:00:00 2001 From: Joel Reicher Date: Sun, 4 Nov 2007 08:52:17 +0000 Subject: [PATCH] Refactor cts pointer and free()ing on abnormal exit of associated list into mhfree.c, eliminating duplication. --- uip/mhfree.c | 18 ++++++++++++++++++ uip/mhlist.c | 22 +++------------------- uip/mhn.c | 22 +++------------------- uip/mhshow.c | 22 +++------------------- uip/mhstore.c | 22 +++------------------- uip/mhtest.c | 22 +++------------------- 6 files changed, 33 insertions(+), 95 deletions(-) diff --git a/uip/mhfree.c b/uip/mhfree.c index abaeb2b..418e5c9 100644 --- a/uip/mhfree.c +++ b/uip/mhfree.c @@ -15,6 +15,9 @@ #include #include +/* The list of top-level contents to display */ +CT *cts = NULL; + /* * prototypes */ @@ -22,6 +25,7 @@ void free_content (CT); void free_header (CT); void free_ctinfo (CT); void free_encoding (CT, int); +int freects_done (int); /* * static prototypes @@ -281,3 +285,17 @@ free_encoding (CT ct, int toplevel) ct->c_ceopenfnx = NULL; } } + + +int +freects_done (int status) +{ + CT *ctp; + + if ((ctp = cts)) + for (; *ctp; ctp++) + free_content (*ctp); + + exit (status); + return 1; /* dead code to satisfy the compiler */ +} diff --git a/uip/mhlist.c b/uip/mhlist.c index bcc4dd2..112c098 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -93,9 +93,6 @@ pid_t xpid = 0; int debugsw = 0; int verbosw = 0; -/* The list of top-level contents to display */ -CT *cts = NULL; - #define quitser pipeser /* mhparse.c */ @@ -112,12 +109,13 @@ void list_all_messages (CT *, int, int, int, int); /* mhfree.c */ void free_content (CT); +extern CT *cts; +int freects_done (int); /* * static prototypes */ static RETSIGTYPE pipeser (int); -static int freectp_done (int); int @@ -132,7 +130,7 @@ main (int argc, char **argv) struct msgs *mp = NULL; CT ct, *ctp; - done=freectp_done; + done=freects_done; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -392,17 +390,3 @@ pipeser (int i) done (1); /* NOTREACHED */ } - - -static int -freectp_done (int status) -{ - CT *ctp; - - if ((ctp = cts)) - for (; *ctp; ctp++) - free_content (*ctp); - - exit (status); - return 1; /* dead code to satisfy the compiler */ -} diff --git a/uip/mhn.c b/uip/mhn.c index 3f2d262..41eb33a 100644 --- a/uip/mhn.c +++ b/uip/mhn.c @@ -157,9 +157,6 @@ extern int userrs; int debugsw = 0; int verbosw = 0; -/* The list of top-level contents to display */ -CT *cts = NULL; - /* * variables for mhbuild (mhn -build) */ @@ -200,12 +197,13 @@ void cache_all_messages (CT *); /* mhfree.c */ void free_content (CT); +extern CT *cts; +int freects_done (int); /* * static prototypes */ static RETSIGTYPE pipeser (int); -static int freectp_done (int); int @@ -221,7 +219,7 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; - done=freectp_done; + done=freects_done; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -705,17 +703,3 @@ pipeser (int i) done (1); /* NOTREACHED */ } - - -static int -freectp_done (int status) -{ - CT *ctp; - - if ((ctp = cts)) - for (; *ctp; ctp++) - free_content (*ctp); - - exit (status); - return 1; /* dead code to satisfy the compiler */ -} diff --git a/uip/mhshow.c b/uip/mhshow.c index 4755171..b7a097c 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -109,9 +109,6 @@ extern int userrs; int debugsw = 0; int verbosw = 0; -/* The list of top-level contents to display */ -CT *cts = NULL; - #define quitser pipeser /* mhparse.c */ @@ -128,12 +125,13 @@ void show_all_messages (CT *); /* mhfree.c */ void free_content (CT); +extern CT *cts; +int freects_done (int); /* * static prototypes */ static RETSIGTYPE pipeser (int); -static int freectp_done (int); int @@ -148,7 +146,7 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; - done=freectp_done; + done=freects_done; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -472,17 +470,3 @@ pipeser (int i) done (1); /* NOTREACHED */ } - - -static int -freectp_done (int status) -{ - CT *ctp; - - if ((ctp = cts)) - for (; *ctp; ctp++) - free_content (*ctp); - - exit (status); - return 1; /* dead code to satisfy the compiler */ -} diff --git a/uip/mhstore.c b/uip/mhstore.c index b1f57fe..4d1ebe0 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -87,9 +87,6 @@ extern int userrs; int debugsw = 0; int verbosw = 0; -/* The list of top-level contents to display */ -CT *cts = NULL; - #define quitser pipeser /* mhparse.c */ @@ -106,12 +103,13 @@ void store_all_messages (CT *); /* mhfree.c */ void free_content (CT); +extern CT *cts; +int freects_done (int); /* * static prototypes */ static RETSIGTYPE pipeser (int); -static int freectp_done (int); int @@ -126,7 +124,7 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; - done=freectp_done; + done=freects_done; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -404,17 +402,3 @@ pipeser (int i) done (1); /* NOTREACHED */ } - - -static int -freectp_done (int status) -{ - CT *ctp; - - if ((ctp = cts)) - for (; *ctp; ctp++) - free_content (*ctp); - - exit (status); - return 1; /* dead code to satisfy the compiler */ -} diff --git a/uip/mhtest.c b/uip/mhtest.c index 985147c..6771bdb 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -89,9 +89,6 @@ pid_t xpid = 0; int debugsw = 0; int verbosw = 0; -/* The list of top-level contents to display */ -CT *cts = NULL; - #define quitser pipeser /* mhparse.c */ @@ -108,13 +105,14 @@ void flush_errors (void); /* mhfree.c */ void free_content (CT); +extern CT *cts; +int freects_done (int); /* * static prototypes */ static int write_content (CT *, char *); static RETSIGTYPE pipeser (int); -static int freectp_done (int); int @@ -128,7 +126,7 @@ main (int argc, char **argv) struct msgs *mp = NULL; CT ct, *ctp; - done=freectp_done; + done=freects_done; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -398,17 +396,3 @@ pipeser (int i) done (1); /* NOTREACHED */ } - - -static int -freectp_done (int status) -{ - CT *ctp; - - if ((ctp = cts)) - for (; *ctp; ctp++) - free_content (*ctp); - - exit (status); - return 1; /* dead code to satisfy the compiler */ -} -- 1.7.10.4