size_t selectlist(LinkList l, size_t start) { size_t longest = 1, fct, fw = 0, colsz, t0, t1, ct; char **arr, **ap; zleentry(ZLE_CMD_TRASH); arr = hlinklist2array(l, 0); for (ap = arr; *ap; ap++) if (strlen(*ap) > longest) longest = strlen(*ap); t0 = ct = ap - arr; longest++; while (t0) t0 /= 10, longest++; /* to compensate for added ')' */ fct = (zterm_columns - 1) / (longest + 3); if (fct == 0) fct = 1; else fw = (zterm_columns - 1) / fct; colsz = (ct + fct - 1) / fct; for (t1 = start; t1 != colsz && t1 - start < zterm_lines - 2; t1++) { ap = arr + t1; do { size_t t2 = strlen(*ap) + 2; int t3; fprintf(stderr, "%d) %s", t3 = ap - arr + 1, *ap); while (t3) t2++, t3 /= 10; for (; t2 < fw; t2++) fputc(' ', stderr); for (t0 = colsz; t0 && *ap; t0--, ap++); } while (*ap); fputc('\n', stderr); } /* Below is a simple attempt at doing it the Korn Way.. ap = arr; t0 = 0; do { t0++; fprintf(stderr,"%d) %s\n",t0,*ap); ap++; } while (*ap);*/ fflush(stderr); return t1 < colsz ? t1 : 0; }
static void cond_subst(char **strp, int glob_ok) { if (glob_ok && checkglobqual(*strp, strlen(*strp), 1, NULL)) { LinkList args = newlinklist(); addlinknode(args, *strp); prefork(args, 0, NULL); while (!errflag && args && nonempty(args) && has_token((char *)peekfirst(args))) zglob(args, firstnode(args), 0); *strp = sepjoin(hlinklist2array(args, 0), NULL, 1); } else singsub(strp); }