version 1.13, 2007/05/01 01:26:23 |
version 1.14, 2007/08/01 13:30:21 |
|
|
|
|
void c_columnate(void); |
void c_columnate(void); |
void *emalloc(size_t); |
void *emalloc(size_t); |
|
void *erealloc(void *, size_t); |
void input(FILE *); |
void input(FILE *); |
void maketbl(void); |
void maketbl(void); |
void print(void); |
void print(void); |
|
|
TBL *t; |
TBL *t; |
int coloff, cnt; |
int coloff, cnt; |
char *p, **lp; |
char *p, **lp; |
int *lens, *lens2, maxcols; |
int *lens, maxcols; |
TBL *tbl; |
TBL *tbl; |
char **cols, **cols2; |
char **cols; |
|
|
t = tbl = emalloc(entries * sizeof(TBL)); |
t = tbl = emalloc(entries * sizeof(TBL)); |
cols = emalloc((maxcols = DEFCOLS) * sizeof(char *)); |
cols = emalloc((maxcols = DEFCOLS) * sizeof(char *)); |
|
|
for (coloff = 0, p = *lp; (cols[coloff] = strtok(p, separator)); |
for (coloff = 0, p = *lp; (cols[coloff] = strtok(p, separator)); |
p = NULL) |
p = NULL) |
if (++coloff == maxcols) { |
if (++coloff == maxcols) { |
if (!(cols2 = realloc(cols, (u_int)maxcols + |
|
DEFCOLS * sizeof(char *))) || |
|
!(lens2 = realloc(lens, |
|
(u_int)maxcols + DEFCOLS * sizeof(int)))) |
|
err(1, NULL); |
|
cols = cols2; |
|
lens = lens2; |
|
memset(lens + maxcols, 0, |
|
DEFCOLS * sizeof(int)); |
|
maxcols += DEFCOLS; |
maxcols += DEFCOLS; |
|
cols = erealloc(cols, maxcols * sizeof(char *)); |
|
lens = erealloc(lens, maxcols * sizeof(int)); |
|
memset(lens + coloff, 0, DEFCOLS * sizeof(int)); |
} |
} |
|
if (coloff == 0) |
|
continue; |
t->list = emalloc(coloff * sizeof(char *)); |
t->list = emalloc(coloff * sizeof(char *)); |
t->len = emalloc(coloff * sizeof(int)); |
t->len = emalloc(coloff * sizeof(int)); |
for (t->cols = coloff; --coloff >= 0;) { |
for (t->cols = coloff; --coloff >= 0;) { |
|
|
} |
} |
} |
} |
for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) { |
for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) { |
for (coloff = 0; coloff < t->cols - 1; ++coloff) |
if (t->cols > 0) { |
(void)printf("%s%*s", t->list[coloff], |
for (coloff = 0; coloff < t->cols - 1; ++coloff) |
lens[coloff] - t->len[coloff] + 2, " "); |
(void)printf("%s%*s", t->list[coloff], |
(void)printf("%s\n", t->list[coloff]); |
lens[coloff] - t->len[coloff] + 2, " "); |
|
(void)printf("%s\n", t->list[coloff]); |
|
} |
} |
} |
} |
} |
|
|
|
|
if (maxlength < len) |
if (maxlength < len) |
maxlength = len; |
maxlength = len; |
if (entries == maxentry) { |
if (entries == maxentry) { |
char **nlist; |
maxentry += DEFNUM; |
size_t nsize = maxentry + DEFNUM; |
list = erealloc(list, maxentry * sizeof(char *)); |
|
|
if (!(nlist = realloc(list, nsize * sizeof(char *)))) |
|
err(1, NULL); |
|
list = nlist; |
|
maxentry = nsize; |
|
} |
} |
if (!(list[entries++] = strdup(buf))) |
if (!(list[entries++] = strdup(buf))) |
err(1, NULL); |
err(1, NULL); |
|
|
if (!(p = malloc(size))) |
if (!(p = malloc(size))) |
err(1, NULL); |
err(1, NULL); |
memset(p, 0, size); |
memset(p, 0, size); |
|
return (p); |
|
} |
|
|
|
void * |
|
erealloc(void *oldp, size_t size) |
|
{ |
|
void *p; |
|
|
|
if (!(p = realloc(oldp, size))) |
|
err(1, NULL); |
return (p); |
return (p); |
} |
} |
|
|