X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftabs.c;fp=progs%2Ftabs.c;h=07790f831d9df89d2361103d5aed75e473fa6d48;hp=88bbf2edb92cfc964de86c9c7cb44e43562682b9;hb=91fa4688e82518794fcf0c32a36f3fcca5e4c2d5;hpb=6b4de0a4ef55b9505f6d46f0d9886ab0ca30cffe diff --git a/progs/tabs.c b/progs/tabs.c index 88bbf2ed..07790f83 100644 --- a/progs/tabs.c +++ b/progs/tabs.c @@ -37,12 +37,19 @@ #define USE_LIBTINFO #include -MODULE_ID("$Id: tabs.c,v 1.23 2012/02/22 23:57:44 tom Exp $") +MODULE_ID("$Id: tabs.c,v 1.24 2012/10/27 19:53:53 tom Exp $") static void usage(void) GCC_NORETURN; static int max_cols; +static void +failed(const char *s) +{ + perror(s); + ExitProgram(EXIT_FAILURE); +} + static int putch(int c) { @@ -83,49 +90,49 @@ decode_tabs(const char *tab_list) int prior = 0; int ch; - if (result != 0) { - while ((ch = *tab_list++) != '\0') { - if (isdigit(UChar(ch))) { - value *= 10; - value += (ch - '0'); - } else if (ch == ',') { - result[n] = value + prior; - if (n > 0 && result[n] <= result[n - 1]) { - fprintf(stderr, - "tab-stops are not in increasing order: %d %d\n", - value, result[n - 1]); - free(result); - result = 0; - break; - } - ++n; - value = 0; - prior = 0; - } else if (ch == '+') { - if (n) - prior = result[n - 1]; + if (result == 0) + failed("decode_tabs"); + + while ((ch = *tab_list++) != '\0') { + if (isdigit(UChar(ch))) { + value *= 10; + value += (ch - '0'); + } else if (ch == ',') { + result[n] = value + prior; + if (n > 0 && result[n] <= result[n - 1]) { + fprintf(stderr, + "tab-stops are not in increasing order: %d %d\n", + value, result[n - 1]); + free(result); + result = 0; + break; } + ++n; + value = 0; + prior = 0; + } else if (ch == '+') { + if (n) + prior = result[n - 1]; } } - if (result != 0) { - /* - * If there is only one value, then it is an option such as "-8". - */ - if ((n == 0) && (value > 0)) { - int step = value; - while (n < max_cols - 1) { - result[n++] = value; - value += step; - } + /* + * If there is only one value, then it is an option such as "-8". + */ + if ((n == 0) && (value > 0)) { + int step = value; + while (n < max_cols - 1) { + result[n++] = value; + value += step; } - - /* - * Add the last value, if any. - */ - result[n++] = value + prior; - result[n] = 0; } + + /* + * Add the last value, if any. + */ + result[n++] = value + prior; + result[n] = 0; + return result; } @@ -264,15 +271,16 @@ add_to_tab_list(char **append, const char *value) need += strlen(*append); result = malloc(need); - if (result != 0) { - *result = '\0'; - if (*append != 0) { - _nc_STRCPY(result, *append, need); - free(*append); - } - _nc_STRCAT(result, comma, need); - _nc_STRCAT(result, copied, need); + if (result == 0) + failed("add_to_tab_list"); + + *result = '\0'; + if (*append != 0) { + _nc_STRCPY(result, *append, need); + free(*append); } + _nc_STRCAT(result, comma, need); + _nc_STRCAT(result, copied, need); *append = result; }