/* Page through a buffer string * buf Buffer to page through */ void rosh_more_buf(char *buf, int buflen, int rows, int cols, char *scrbuf) { char *bufp, *bufeol, *bufeol2; /* Pointer to current and next end-of-line position in buffer */ int bufpos, bufcnt; /* current position, count characters */ int inc; int i, numln; /* Index, Number of lines */ int elpl; /* Extra lines per line read */ (void)cols; bufpos = 0; bufp = buf + bufpos; bufeol = bufp; numln = rows - 1; ROSH_DEBUG("--(%d)\n", buflen); while (bufpos < buflen) { for (i = 0; i < numln; i++) { bufeol2 = strchr(bufeol, '\n'); if (bufeol2 == NULL) { bufeol = buf + buflen; i = numln; } else { elpl = ((bufeol2 - bufeol - 1) / cols); if (elpl < 0) elpl = 0; i += elpl; ROSH_DEBUG2(" %d/%d ", elpl, i+1); /* If this will not push too much, use it */ /* but if it's the first line, use it */ /* //HERE: We should probably snip the line off */ if ((i < numln) || (i == elpl)) bufeol = bufeol2 + 1; } } ROSH_DEBUG2("\n"); bufcnt = bufeol - bufp; printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos); memcpy(scrbuf, bufp, bufcnt); scrbuf[bufcnt] = 0; printf("%s", scrbuf); bufp = bufeol; bufpos += bufcnt; if (bufpos == buflen) break; inc = rosh_getkey(); numln = 1; switch (inc) { case KEY_CTRL('c'): case 'q': case 'Q': bufpos = buflen; break; case ' ': numln = rows - 1; } } } /* rosh_more_buf */
//HERE: minor pagination issue; sometimes prints 1 less than rows void rosh_more_buf(char *buf, int buflen, int rows, int cols) { char *bufp, *bufeol, *bufeol2; /* Pointer to current and next end-of-line position in buffer */ int bufpos, bufcnt; /* current position, count characters */ char scrbuf[ROSH_SBUF_SZ]; int inc; int i, numln; /* Index, Number of lines */ (void)cols; bufpos = 0; bufp = buf + bufpos; bufeol = bufp; numln = rows - 1; ROSH_DEBUG("--(%d)\n", buflen); while (bufpos < buflen) { for (i = 0; i < numln; i++) { bufeol2 = strchr(bufeol, '\n'); if (bufeol2 == NULL) { bufeol = buf + buflen; i = numln; } else { i += ((bufeol2 - bufeol) / cols); bufeol = bufeol2 + 1; } } bufcnt = bufeol - bufp; printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos); memcpy(scrbuf, bufp, bufcnt); scrbuf[bufcnt] = 0; printf("%s", scrbuf); bufp = bufeol; bufpos += bufcnt; if (bufpos == buflen) break; inc = rosh_getkey(); numln = 1; switch (inc) { case KEY_CTRL('c'): case 'q': case 'Q': bufpos = buflen; break; case ' ': numln = rows - 1; } } } /* rosh_more_buf */