From 162c6411b3a8313b83e6c032111d8667aada14ba Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 29 Jul 2024 11:08:30 -0600 Subject: [PATCH] mm(1): remove terminate macro --- src/mm.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/src/mm.c b/src/mm.c index d148446..a9c45b3 100644 --- a/src/mm.c +++ b/src/mm.c @@ -88,25 +88,6 @@ oserr(char *s, char *r) { return EX_OSERR; } -/* Hijacks i and j from main and destructs the files[2] struct used by main by - * closing its files and freeing its files and names arrays, returning retval - * from main. */ -#define terminate \ - for (i = 0; i < 2; ++i) { \ - for (j = 0; j < files[i].s; ++j) { \ - if ( \ - files[i].files[j] != stdin \ - && files[i].files[j] != stdout \ - && files[i].files[j] != stderr \ - ) { \ - fclose(files[i].files[j]); \ - } \ - } \ - free(files[i].files); \ - free(files[i].names); \ - } \ - return retval - static int usage(char *argv0) { (void)fprintf( @@ -163,8 +144,7 @@ int main(int argc, char *argv[]) { break; } - retval = oserr(program_name, "-e"); - terminate; + return oserr(program_name, "-e"); case 'i': if ( (strcmp(optarg, "-") == 0 @@ -172,8 +152,7 @@ int main(int argc, char *argv[]) { || Files_open(&files[0], optarg) != NULL ) { break; } - retval = oserr(program_name, optarg); - terminate; + return oserr(program_name, optarg); case 'o': if ( (strcmp(optarg, "-") == 0 @@ -190,27 +169,21 @@ int main(int argc, char *argv[]) { } } - retval = oserr(program_name, optarg); - terminate; + return oserr(program_name, optarg); case 'n': if (signal(SIGINT, SIG_IGN) != SIG_ERR) { break; } - retval = oserr(program_name, "-n"); - terminate; + return oserr(program_name, "-n"); case 'u': k = 1; break; default: - retval = usage(program_name); - terminate; + return usage(program_name); } } } - if (optind != argc) { - retval = usage(program_name); - terminate; - } + if (optind != argc) { return usage(program_name); } files[0].s += files[0].s == 0; files[1].s += files[1].s == 0; @@ -258,11 +231,11 @@ int main(int argc, char *argv[]) { files[1].names[k] = files[1].names[k+1]; } - if(--files[1].s == 0) { terminate; } + if(--files[1].s == 0) { return retval; } } } } } - terminate; + return retval; }