#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"
{
if (putwchar(c) == WEOF)
return EOF;
- else
- return c;
+
+ return c;
}
#define putwp(s) tputs(s, STDOUT_FILENO, put1wc)
#else
#define putwp(s) putp(s)
#endif
-static void usage(FILE *out);
static int handle_escape(FILE * f);
static void filter(FILE *f);
static void flushln(void);
#define UNDERL 010 /* Ul */
#define BOLD 020 /* Bold */
-int must_use_uc, must_overstrike;
-char *CURS_UP,
- *CURS_RIGHT,
- *CURS_LEFT,
- *ENTER_STANDOUT,
- *EXIT_STANDOUT,
- *ENTER_UNDERLINE,
- *EXIT_UNDERLINE,
- *ENTER_DIM,
- *ENTER_BOLD,
- *ENTER_REVERSE,
- *UNDER_CHAR,
- *EXIT_ATTRIBUTES;
-
-struct CHAR {
+static int must_use_uc, must_overstrike;
+static char *CURS_UP,
+ *CURS_RIGHT,
+ *CURS_LEFT,
+ *ENTER_STANDOUT,
+ *EXIT_STANDOUT,
+ *ENTER_UNDERLINE,
+ *EXIT_UNDERLINE,
+ *ENTER_DIM,
+ *ENTER_BOLD,
+ *ENTER_REVERSE,
+ *UNDER_CHAR,
+ *EXIT_ATTRIBUTES;
+
+struct CHAR {
char c_mode;
wchar_t c_char;
int c_width;
};
-struct CHAR *obuf;
-int obuflen;
-int col, maxcol;
-int mode;
-int halfpos;
-int upln;
-int iflag;
+static struct CHAR *obuf;
+static int obuflen;
+static int col, maxcol;
+static int mode;
+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);
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)
FILE *f;
static const struct option longopts[] = {
- { "terminal", required_argument, 0, 't' },
- { "indicated", no_argument, 0, 'i' },
- { "version", no_argument, 0, 'V' },
- { "help", no_argument, 0, 'h' },
- { NULL, 0, 0, 0 }
+ { "terminal", required_argument, NULL, 't' },
+ { "indicated", no_argument, NULL, 'i' },
+ { "version", no_argument, NULL, 'V' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL, 0, NULL, 0 }
};
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
case 'i':
iflag = 1;
break;
+
case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
+ print_version(EXIT_SUCCESS);
case 'h':
- usage(stdout);
+ usage();
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
setupterm(termtype, STDOUT_FILENO, &ret);
switch (ret) {
default:
warnx(_("trouble reading terminfo"));
- /* fall through to ... */
+ /* fallthrough */
case 0:
if (tflag)
}
obuf[col].c_char = '_';
obuf[col].c_width = 1;
- /* fall through */
+ /* fallthrough */
case ' ':
setcol(col + 1);
continue;
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;
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++)