=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rs/rs.c,v retrieving revision 1.27 retrieving revision 1.28 diff -c -r1.27 -r1.28 *** src/usr.bin/rs/rs.c 2015/10/09 01:37:08 1.27 --- src/usr.bin/rs/rs.c 2015/11/10 14:42:41 1.28 *************** *** 1,4 **** ! /* $OpenBSD: rs.c,v 1.27 2015/10/09 01:37:08 deraadt Exp $ */ /*- * Copyright (c) 1993 --- 1,4 ---- ! /* $OpenBSD: rs.c,v 1.28 2015/11/10 14:42:41 schwarze Exp $ */ /*- * Copyright (c) 1993 *************** *** 67,76 **** char **endelem; char *curline; int allocsize = BUFSIZ; ! int curlen; int irows, icols; int orows, ocols; ! int maxlen; int skip; int propgutter; char isep = ' ', osep = ' '; --- 67,76 ---- char **endelem; char *curline; int allocsize = BUFSIZ; ! ssize_t curlen; int irows, icols; int orows, ocols; ! ssize_t maxlen; int skip; int propgutter; char isep = ' ', osep = ' '; *************** *** 118,128 **** char **padto; while (skip--) { ! get_line(); if (flags & SKIPPRINT) puts(curline); } ! get_line(); if (flags & NOARGS && curlen < owidth) flags |= ONEPERLINE; if (flags & ONEPERLINE) --- 118,130 ---- char **padto; while (skip--) { ! if (get_line() == EOF) ! return; if (flags & SKIPPRINT) puts(curline); } ! if (get_line() == EOF) ! return; if (flags & NOARGS && curlen < owidth) flags |= ONEPERLINE; if (flags & ONEPERLINE) *************** *** 303,339 **** nelem = n; } - #define BSIZE 2048 - char ibuf[BSIZE]; /* two screenfuls should do */ - int get_line(void) /* get line; maintain curline, curlen; manage storage */ { ! static int putlength; ! static char *endblock = ibuf + BSIZE; ! char *p; ! int c, i; ! if (!irows) { ! curline = ibuf; ! putlength = flags & DETAILSHAPE; } ! else if (skip <= 0) { /* don't waste storage */ ! curline += curlen + 1; ! if (putlength) /* print length, recycle storage */ ! printf(" %d line %d\n", curlen, irows); ! } ! if (!putlength && endblock - curline < BUFSIZ) { /* need storage */ ! if (!(curline = malloc(BSIZE))) ! errx(1, "File too large"); ! endblock = curline + BSIZE; ! } ! 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 ** --- 305,333 ---- nelem = n; } int get_line(void) /* get line; maintain curline, curlen; manage storage */ { ! static char *ibuf = NULL; ! static size_t ibufsz = 0; ! if (irows > 0 && flags & DETAILSHAPE) ! printf(" %zd line %d\n", curlen, irows); ! ! if ((curlen = getline(&ibuf, &ibufsz, stdin)) == EOF) { ! if (ferror(stdin)) ! err(1, NULL); ! return EOF; } ! if (curlen > 0 && ibuf[curlen - 1] == '\n') ! ibuf[--curlen] = '\0'; ! ! if (skip >= 0 || flags & SHAPEONLY) ! curline = ibuf; ! else if ((curline = strdup(ibuf)) == NULL) ! err(1, NULL); ! ! return 0; } char **