From 2c308875a7fa1aaa44892c368f6b37bcfcb8879a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 16 Apr 2019 15:14:13 +0200 Subject: misc: consolidate version printing and close_stdout() Signed-off-by: Karel Zak --- text-utils/col.c | 6 +++--- text-utils/colcrt.c | 6 +++--- text-utils/colrm.c | 3 +-- text-utils/column.c | 13 ++++++------- text-utils/hexdump.c | 7 +++---- text-utils/line.c | 5 ++--- text-utils/more.c | 10 ++++------ text-utils/pg.c | 8 ++++---- text-utils/rev.c | 5 ++--- text-utils/ul.c | 6 +++--- 10 files changed, 31 insertions(+), 38 deletions(-) (limited to 'text-utils') diff --git a/text-utils/col.c b/text-utils/col.c index 1ba195e24..5ad38bc97 100644 --- a/text-utils/col.c +++ b/text-utils/col.c @@ -190,7 +190,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); max_bufd_lines = 128 * 2; compress_spaces = 1; /* compress spaces into tabs */ @@ -220,9 +220,9 @@ int main(int argc, char **argv) case 'x': /* do not compress spaces into tabs */ compress_spaces = 0; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'H': usage(); default: diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c index 6113880e4..798f5bd7b 100644 --- a/text-utils/colcrt.c +++ b/text-utils/colcrt.c @@ -239,7 +239,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); /* Take care of lonely hyphen option. */ for (opt = 0; opt < argc; opt++) { @@ -260,9 +260,9 @@ int main(int argc, char **argv) case '2': ctl.half_lines = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/colrm.c b/text-utils/colrm.c index 8bb0ee9cc..d0ef2eb66 100644 --- a/text-utils/colrm.c +++ b/text-utils/colrm.c @@ -173,8 +173,7 @@ int main(int argc, char **argv) NULL)) != -1) switch (opt) { case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/column.c b/text-utils/column.c index 8961bd38b..78eeddb8e 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -706,7 +706,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); ctl.output_separator = " "; ctl.input_separator = mbs_to_wcs("\t "); @@ -731,9 +731,6 @@ int main(int argc, char **argv) case 'H': ctl.tab_colhide = optarg; break; - case 'h': - usage(); - break; case 'i': ctl.tree_id = optarg; break; @@ -776,15 +773,17 @@ int main(int argc, char **argv) case 't': ctl.mode = COLUMN_MODE_TABLE; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'W': ctl.tab_colwrap = optarg; break; case 'x': ctl.mode = COLUMN_MODE_FILLROWS; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c index 94c53b8e5..cbd593e5f 100644 --- a/text-utils/hexdump.c +++ b/text-utils/hexdump.c @@ -130,12 +130,11 @@ parse_args(int argc, char **argv, struct hexdump *hex) add_fmt(hex_offt, hex); add_fmt("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"", hex); break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - break; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } @@ -193,7 +192,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); argv += parse_args(argc, argv, hex); diff --git a/text-utils/line.c b/text-utils/line.c index 63c001261..e89407618 100644 --- a/text-utils/line.c +++ b/text-utils/line.c @@ -54,13 +54,12 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((opt = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch (opt) { case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/more.c b/text-utils/more.c index 8d394bc30..6e1ca569c 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -275,7 +275,7 @@ static void arg_parser(struct more_control *ctl, char *s) case '\t': break; case 'V': - printf(UTIL_LINUX_VERSION); + print_version(EXIT_SUCCESS); exit(EXIT_SUCCESS); break; default: @@ -1920,16 +1920,14 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc > 1) { /* first arg may be one of our standard longopts */ if (!strcmp(argv[1], "--help")) usage(); - if (!strcmp(argv[1], "--version")) { - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - } + if (!strcmp(argv[1], "--version")) + print_version(EXIT_SUCCESS); } ctl.num_files = argc; diff --git a/text-utils/pg.c b/text-utils/pg.c index f441c04f0..7eef9b88b 100644 --- a/text-utils/pg.c +++ b/text-utils/pg.c @@ -1544,7 +1544,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (tcgetattr(STDOUT_FILENO, &otio) == 0) { ontty = 1; @@ -1570,7 +1570,7 @@ int main(int argc, char **argv) } if (!strcmp(argv[arg], "--version")) { - printf(UTIL_LINUX_VERSION); + print_version(EXIT_SUCCESS); return EXIT_SUCCESS; } @@ -1621,11 +1621,11 @@ int main(int argc, char **argv) case 's': sflag = 1; break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: invopt(&argv[arg][i]); } diff --git a/text-utils/rev.c b/text-utils/rev.c index 13a41f633..57624e6fb 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -121,8 +121,7 @@ int main(int argc, char *argv[]) while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch(ch) { case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/ul.c b/text-utils/ul.c index b5ce4db84..3a9e31bc7 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -172,7 +172,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -191,9 +191,9 @@ int main(int argc, char **argv) case 'i': iflag = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: -- cgit v1.2.3-55-g7522