From 8f1be588163bc3fc5e58cf59252769fbfb04f095 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 2 Mar 2017 14:50:03 +0100 Subject: column: clean up multi-byte #ifelse Signed-off-by: Karel Zak --- text-utils/column.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'text-utils/column.c') diff --git a/text-utils/column.c b/text-utils/column.c index 9e19fff9c..2aca635ad 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -51,10 +51,7 @@ #include "closestream.h" #include "ttyutils.h" -#ifdef HAVE_WIDECHAR -static wchar_t *mbs_to_wcs(const char *); -#else -#define mbs_to_wcs(s) xstrdup(s) +#ifndef HAVE_WIDECHAR static char *mtsafe_strtok(char *, const char *, char **); #define wcstok mtsafe_strtok #endif @@ -85,43 +82,29 @@ struct column_control { size_t maxlength; /* longest input record (line) */ }; -static int read_input(struct column_control *ctl, FILE *fp); -static void columnate_fillrows(struct column_control *ctl); -static void columnate_fillcols(struct column_control *ctl); -static void simple_print(struct column_control *ctl); - static wchar_t *local_wcstok(wchar_t *p, const wchar_t *separator, int greedy, wchar_t **wcstok_state); static void maketbl(struct column_control *ctl, wchar_t *separator, int greedy, wchar_t *colsep); -#ifdef HAVE_WIDECHAR -/* Don't use wcswidth(), we need to ignore non-printable chars. */ -static int width(const wchar_t *str) +static size_t width(const wchar_t *str) { - int x, width = 0; + size_t width = 0; for (; *str != '\0'; str++) { - x = wcwidth(*str); +#ifdef HAVE_WIDECHAR + int x = wcwidth(*str); /* don't use wcswidth(), need to ignore non-printable */ if (x > 0) width += x; - } - return width; -} #else -static int width(const char *str) -{ - int width = 0; - - for (; *str != '\0'; str++) { if (isprint(*str)) width++; +#endif } return width; } -#endif -#ifdef HAVE_WIDECHAR static wchar_t *mbs_to_wcs(const char *s) { +#ifdef HAVE_WIDECHAR ssize_t n; wchar_t *wcs; @@ -135,8 +118,10 @@ static wchar_t *mbs_to_wcs(const char *s) return NULL; } return wcs; -} +#else + return xstrdup(s) #endif +} static int read_input(struct column_control *ctl, FILE *fp) { -- cgit v1.2.3-55-g7522