diff options
author | Sami Kerola | 2011-05-01 19:16:29 +0200 |
---|---|---|
committer | Sami Kerola | 2011-05-19 21:09:23 +0200 |
commit | 4eaeb0ef25ea00be23457a452f497307ea8291f4 (patch) | |
tree | c94fa8193fcb11cae626e5818b47672e32718c90 /text-utils | |
parent | column.c: coding style fixes (diff) | |
download | kernel-qcow2-util-linux-4eaeb0ef25ea00be23457a452f497307ea8291f4.tar.gz kernel-qcow2-util-linux-4eaeb0ef25ea00be23457a452f497307ea8291f4.tar.xz kernel-qcow2-util-linux-4eaeb0ef25ea00be23457a452f497307ea8291f4.zip |
column.c: make table function clarification
Readability enchancement, and few variable type changes to be
more proper.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'text-utils')
-rw-r--r-- | text-utils/column.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/text-utils/column.c b/text-utils/column.c index 77dabd2d5..984b0ef5b 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -267,29 +267,31 @@ static void print() static void maketbl() { TBL *t; - int coloff, cnt, i; + int cnt, i; wchar_t *p, **lp; - int *lens, maxcols = DEFCOLS; + ssize_t *lens; + ssize_t maxcols = DEFCOLS, coloff; TBL *tbl; wchar_t **cols; wchar_t *wcstok_state; t = tbl = xcalloc(entries, sizeof(TBL)); cols = xcalloc(maxcols, sizeof(wchar_t *)); - lens = xcalloc(maxcols, sizeof(int)); - for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) { - for (coloff = 0, p = *lp; - (cols[coloff] = wcstok(p, separator, &wcstok_state)) != NULL; - p = NULL) { + lens = xcalloc(maxcols, sizeof(ssize_t)); + + for (lp = list, cnt = 0; cnt < entries; ++cnt, ++lp, ++t) { + coloff = 0; + p = *lp; + while ((cols[coloff] = wcstok(p, separator, &wcstok_state)) != NULL) { if (++coloff == maxcols) { - cols = xrealloc(cols, ((u_int)maxcols + DEFCOLS) - * sizeof(wchar_t *)); - lens = xrealloc(lens, ((u_int)maxcols + DEFCOLS) - * sizeof(int)); - memset((char *)lens + maxcols * sizeof(int), - 0, DEFCOLS * sizeof(int)); maxcols += DEFCOLS; + cols = xrealloc(cols, maxcols * sizeof(wchar_t *)); + lens = xrealloc(lens, maxcols * sizeof(ssize_t)); + /* zero fill only new memory */ + memset(lens + ((maxcols - DEFCOLS) * sizeof(ssize_t)), 0, + DEFCOLS * sizeof(int)); } + p = NULL; } t->list = xcalloc(coloff, sizeof(wchar_t *)); t->len = xcalloc(coloff, sizeof(int)); @@ -300,7 +302,8 @@ static void maketbl() lens[coloff] = t->len[coloff]; } } - for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) { + + for (t = tbl, cnt = 0; cnt < entries; ++cnt, ++t) { for (coloff = 0; coloff < t->cols - 1; ++coloff) { fputws(t->list[coloff], stdout); for (i = lens[coloff] - t->len[coloff] + 2; i > 0; i--) |