version 1.27, 2015/10/09 01:37:08 |
version 1.28, 2015/11/10 14:42:41 |
|
|
char **endelem; |
char **endelem; |
char *curline; |
char *curline; |
int allocsize = BUFSIZ; |
int allocsize = BUFSIZ; |
int curlen; |
ssize_t curlen; |
int irows, icols; |
int irows, icols; |
int orows, ocols; |
int orows, ocols; |
int maxlen; |
ssize_t maxlen; |
int skip; |
int skip; |
int propgutter; |
int propgutter; |
char isep = ' ', osep = ' '; |
char isep = ' ', osep = ' '; |
|
|
char **padto; |
char **padto; |
|
|
while (skip--) { |
while (skip--) { |
get_line(); |
if (get_line() == EOF) |
|
return; |
if (flags & SKIPPRINT) |
if (flags & SKIPPRINT) |
puts(curline); |
puts(curline); |
} |
} |
get_line(); |
if (get_line() == EOF) |
|
return; |
if (flags & NOARGS && curlen < owidth) |
if (flags & NOARGS && curlen < owidth) |
flags |= ONEPERLINE; |
flags |= ONEPERLINE; |
if (flags & ONEPERLINE) |
if (flags & ONEPERLINE) |
|
|
nelem = n; |
nelem = n; |
} |
} |
|
|
#define BSIZE 2048 |
|
char ibuf[BSIZE]; /* two screenfuls should do */ |
|
|
|
int |
int |
get_line(void) /* get line; maintain curline, curlen; manage storage */ |
get_line(void) /* get line; maintain curline, curlen; manage storage */ |
{ |
{ |
static int putlength; |
static char *ibuf = NULL; |
static char *endblock = ibuf + BSIZE; |
static size_t ibufsz = 0; |
char *p; |
|
int c, i; |
|
|
|
if (!irows) { |
if (irows > 0 && flags & DETAILSHAPE) |
curline = ibuf; |
printf(" %zd line %d\n", curlen, irows); |
putlength = flags & DETAILSHAPE; |
|
|
if ((curlen = getline(&ibuf, &ibufsz, stdin)) == EOF) { |
|
if (ferror(stdin)) |
|
err(1, NULL); |
|
return EOF; |
} |
} |
else if (skip <= 0) { /* don't waste storage */ |
if (curlen > 0 && ibuf[curlen - 1] == '\n') |
curline += curlen + 1; |
ibuf[--curlen] = '\0'; |
if (putlength) /* print length, recycle storage */ |
|
printf(" %d line %d\n", curlen, irows); |
if (skip >= 0 || flags & SHAPEONLY) |
} |
curline = ibuf; |
if (!putlength && endblock - curline < BUFSIZ) { /* need storage */ |
else if ((curline = strdup(ibuf)) == NULL) |
if (!(curline = malloc(BSIZE))) |
err(1, NULL); |
errx(1, "File too large"); |
|
endblock = curline + BSIZE; |
return 0; |
} |
|
for (p = curline, i = 1; i < BUFSIZ; *p++ = c, i++) |
|
if ((c = getchar()) == EOF || c == '\n') |
|
break; |
|
*p = '\0'; |
|
curlen = i - 1; |
|
return(c); |
|
} |
} |
|
|
char ** |
char ** |