pcg@aber-cs.UUCP (Piercarlo Grandi) (01/06/90)
Rs is a columnator, that reshapes its input into different types of output tables etc... It was in a trio with jot and lam in the 4BSD contribs, or the 2BSd ones. The patches correct a (serious) bug, which manifests itself when (*(char *) 0 != '\0'), and some bugs related to the choice of shapes. The behaviour is slightly changed by the latter modification, but I think it is more logical. It is *very* improbably that this change in behaviour has any practical consequence. =================================================================== RCS file: rs.c,v retrieving revision 1.1 diff -c -r1.1 rs.c *** /tmp/,RCSt1a28234 Tue Dec 26 18:48:06 1989 --- rs.c Thu Dec 21 02:09:01 1989 *************** *** 2,8 **** #ifndef lint static char sccsid[] = "@(#)rs.c 4.1 (Berkeley) 7/8/83"; ! #endif not lint /* * rs - reshape a data array --- 2,8 ---- #ifndef lint static char sccsid[] = "@(#)rs.c 4.1 (Berkeley) 7/8/83"; ! #endif /* not lint */ /* * rs - reshape a data array *************** *** 135,142 **** --- 135,144 ---- register char **ep; register int i; register int j; + register char **last = elem+nelem; ep = elem; + if (flags & TRANSPOSE) for (i = 0; i < orows; i++) { for (j = i; j < nelem; j += orows) *************** *** 145,151 **** } else for (i = 0; i < orows; i++) { ! for (j = 0; j < ocols; j++) prints(*ep++, j); putchar('\n'); } --- 147,153 ---- } else for (i = 0; i < orows; i++) { ! for (j = 0; j < ocols && ep < last; j++) prints(*ep++, j); putchar('\n'); } *************** *** 185,190 **** --- 187,194 ---- register char **ep; register int i; register int j; + register char **last = elem+nelem; + char **lp; int colw; int max = 0; *************** *** 208,213 **** --- 212,221 ---- orows = nelem / ocols + (nelem % ocols ? 1 : 0); else if (ocols == 0) /* decide on cols */ ocols = nelem / orows + (nelem % orows ? 1 : 0); + + if (orows > ocols || (orows == ocols && irows > icols)) + flags ^= TRANSPOSE; + lp = elem + orows * ocols; while (lp > endelem) { getptrs(elem + nelem); *************** *** 222,242 **** error("malloc: No gutter space", ""); if (flags & SQUEEZE) { if (flags & TRANSPOSE) ! for (ep = elem, i = 0; i < ocols; i++) { ! for (j = 0; j < orows; j++) ! if ((n = strlen(*ep++)) > max) max = n; colwidths[i] = max + gutter; } else ! for (i = 0; i < ocols; i++) { ! for (j = i; j < nelem; j += ocols) ! if ((n = strlen(ep[j])) > max) max = n; colwidths[i] = max + gutter; } } ! /* for (i = 0; i < orows; i++) { for (j = i; j < nelem; j += orows) prints(ep[j], (j - i) / orows); putchar('\n'); --- 230,251 ---- error("malloc: No gutter space", ""); if (flags & SQUEEZE) { if (flags & TRANSPOSE) ! for (i = 0; i < ocols; i++) { ! for (j = i; j < nelem; j += ocols) ! if ((n = strlen(ep[j])) > max) max = n; colwidths[i] = max + gutter; } else ! for (ep = elem, i = 0; i < ocols; i++) { ! for (j = 0; j < orows && ep < last; j++) ! if ((n = strlen(*ep++)) > max) max = n; colwidths[i] = max + gutter; } } ! #ifdef undef ! for (i = 0; i < orows; i++) { for (j = i; j < nelem; j += orows) prints(ep[j], (j - i) / orows); putchar('\n'); *************** *** 243,252 **** } else for (i = 0; i < orows; i++) { ! for (j = 0; j < ocols; j++) prints(*ep++, j); putchar('\n'); ! }*/ else for (i = 0; i < ocols; i++) colwidths[i] = colw; --- 252,262 ---- } else for (i = 0; i < orows; i++) { ! for (j = 0; j < ocols && ep < last; j++) prints(*ep++, j); putchar('\n'); ! } ! #endif else for (i = 0; i < ocols; i++) colwidths[i] = colw; *************** *** 259,267 **** n = orows * ocols; if (n > nelem && (flags & RECYCLE)) nelem = n; ! /*for (i = 0; i < ocols; i++) fprintf(stderr, "%d ",colwidths[i]); ! fprintf(stderr, "is colwidths, nelem %d\n", nelem);*/ } #define BSIZE 2048 --- 269,279 ---- n = orows * ocols; if (n > nelem && (flags & RECYCLE)) nelem = n; ! #ifdef undef ! for (i = 0; i < ocols; i++) fprintf(stderr, "%d ",colwidths[i]); ! fprintf(stderr, "is colwidths, nelem %d\n", nelem); ! #endif } #define BSIZE 2048 *************** *** 334,342 **** register char *p; char *getnum(), *getlist(); ! if (ac == 1) { ! flags |= ONEPERLINE | TRANSPOSE; ! } while (--ac && **++av == '-') for (p = *av+1; *p; p++) switch (*p) { --- 346,358 ---- register char *p; char *getnum(), *getlist(); ! /* ! If no arguments, just transpose ! */ ! ! if (ac == 1) ! flags |= TRANSPOSE; ! while (--ac && **++av == '-') for (p = *av+1; *p; p++) switch (*p) { *************** *** 424,440 **** } /*if (!osep) osep = isep;*/ switch (ac) { ! /*case 3: ! opages = atoi(av[2]);*/ ! case 2: ! ocols = atoi(av[1]); ! case 1: ! orows = atoi(av[0]); ! case 0: ! break; ! default: ! error("Too many arguments. What do you mean by `%s'?", av[3]); } } --- 440,454 ---- } /*if (!osep) osep = isep;*/ + switch (ac) { ! #ifdef undef ! case 3: opages = atoi(av[2]); ! #endif ! case 2: ocols = atoi(av[1]); ! case 1: orows = atoi(av[0]); ! case 0: break; ! default: error("Too many arguments. What's `%s'?", av[2]); } } -- Piercarlo "Peter" Grandi | ARPA: pcg%cs.aber.ac.uk@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcvax!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk