]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - text-utils/ul.c
docs: update year in libs docs
[thirdparty/util-linux.git] / text-utils / ul.c
index 178d5cb7fbb5ffe64c397a2679fee7eb9837ee1e..e8137edbd88278b04b4c5ac480a2636c719abe68 100644 (file)
 #include <stdio.h>
 #include <unistd.h>            /* for getopt(), isatty() */
 #include <string.h>            /* for memset(), strcpy() */
-#include <term.h>              /* for setupterm() */
 #include <stdlib.h>            /* for getenv() */
 #include <limits.h>            /* for INT_MAX */
 #include <signal.h>            /* for signal() */
 #include <errno.h>
 #include <getopt.h>
 
+#if defined(HAVE_NCURSESW_TERM_H)
+# include <ncursesw/term.h>
+#elif defined(HAVE_NCURSES_TERM_H)
+# include <ncurses/term.h>
+#elif defined(HAVE_TERM_H)
+# include <term.h>
+#endif
+
 #include "nls.h"
 #include "xalloc.h"
 #include "widechar.h"
@@ -128,9 +135,9 @@ static int  halfpos;
 static int     upln;
 static int     iflag;
 
-static void __attribute__((__noreturn__))
-usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] [<file> ...]\n"), program_invocation_short_name);
 
@@ -141,12 +148,11 @@ usage(FILE *out)
        fputs(_(" -t, -T, --terminal TERMINAL  override the TERM environment variable\n"), out);
        fputs(_(" -i, --indicated              underlining is indicated via a separate line\n"), out);
        fputs(USAGE_SEPARATOR, out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
+       printf(USAGE_HELP_OPTIONS(30));
 
-       fprintf(out, USAGE_MAN_TAIL("ul(1)"));
+       printf(USAGE_MAN_TAIL("ul(1)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -166,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);
@@ -185,11 +191,11 @@ 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(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -201,7 +207,7 @@ int main(int argc, char **argv)
 
        default:
                warnx(_("trouble reading terminfo"));
-               /* fall through to ... */
+               /* fallthrough */
 
        case 0:
                if (tflag)
@@ -310,7 +316,7 @@ static void filter(FILE *f)
                        }
                        obuf[col].c_char = '_';
                        obuf[col].c_width = 1;
-                       /* fall through */
+                       /* fallthrough */
                case ' ':
                        setcol(col + 1);
                        continue;
@@ -401,7 +407,7 @@ static void flushln(void)
 static void overstrike(void)
 {
        register int i;
-       register wchar_t *lbuf = xmalloc((maxcol + 1) * sizeof(wchar_t));
+       register wchar_t *lbuf = xcalloc(maxcol + 1, sizeof(wchar_t));
        register wchar_t *cp = lbuf;
        int hadbold=0;
 
@@ -440,7 +446,7 @@ static void overstrike(void)
 static void iattr(void)
 {
        register int i;
-       register wchar_t *lbuf = xmalloc((maxcol + 1) * sizeof(wchar_t));
+       register wchar_t *lbuf = xcalloc(maxcol + 1, sizeof(wchar_t));
        register wchar_t *cp = lbuf;
 
        for (i = 0; i < maxcol; i++)