summaryrefslogtreecommitdiff
path: root/Src/Zle/compresult.c
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-27 12:56:57 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-27 12:56:57 +0000
commit4da5c1b2e0ae1dce9c75c8c883c4eb0ae8528c53 (patch)
treedfc53fd59bc2bc7ee174ebf97d91f107b642bb87 /Src/Zle/compresult.c
parent08225106263417d4d6124c1ce619b8c8ae447bdb (diff)
downloadzsh-4da5c1b2e0ae1dce9c75c8c883c4eb0ae8528c53.tar.gz
zsh-4da5c1b2e0ae1dce9c75c8c883c4eb0ae8528c53.zip
(15509)
Diffstat (limited to 'Src/Zle/compresult.c')
-rw-r--r--Src/Zle/compresult.c318
1 files changed, 123 insertions, 195 deletions
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 6b5d7df38..14fa3adca 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -1588,214 +1588,142 @@ calclist(int showall)
ylens[i] = ztrlen(*pp) + add;
if (g->flags & CGF_ROWS) {
- int count, tcol, first, maxlines = 0, llines;
- int beg = columns / g->shortest, end = g->cols;
-
- while (1) {
- tcols = (beg + end) >> 1;
-
- for (nth = first = maxlen = width = maxlines =
- llines = tcol = 0,
- count = g->dcount;
- count > 0; count--) {
- if (ylens[nth] > maxlen)
- maxlen = ylens[nth];
- nth += tcols;
- tlines++;
- if (nth >= g->dcount) {
- if ((width += maxlen) >= columns)
- break;
- ws[tcol++] = maxlen;
- maxlen = 0;
- nth = ++first;
- if (llines > maxlines)
- maxlines = llines;
- llines = 0;
- }
- }
- if (nth < yl) {
- ws[tcol++] = maxlen;
- width += maxlen;
- }
- if (!count && width <= columns &&
- (tcols <= 0 || beg == end))
- break;
-
- if (beg == end) {
- beg--;
- end--;
- } else if (width < columns) {
- if ((end = tcols) == beg - 1)
- end++;
- } else {
- if ((beg = tcols) - 1 == end)
- end++;
- }
- }
- if (tcols > g->cols)
- tlines = maxlines;
+ int nth, tcol, len;
+
+ for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ tcols--) {
+
+ memset(ws, 0, tcols * sizeof(int));
+
+ for (width = nth = tcol = 0, tlines = 1;
+ width < columns && nth < g->dcount;
+ nth++, tcol++) {
+
+ m = *p;
+
+ if (tcol == tcols) {
+ tcol = 0;
+ tlines++;
+ }
+ len = ylens[nth];
+
+ if (len > ws[tcol]) {
+ width += len - ws[tcol];
+ ws[tcol] = len;
+ }
+ }
+ if (width < columns)
+ break;
+ }
} else {
- int beg = ((g->totl + columns) / columns);
- int end = g->lins;
-
- while (1) {
- tlines = (beg + end) >> 1;
-
- for (pp = g->ylist, nth = tline = width =
- maxlen = tcols = 0;
- *pp; pp++) {
- if (ylens[nth] > maxlen)
- maxlen = ylens[nth];
- if (++tline == tlines) {
- if ((width += maxlen) >= columns)
- break;
- ws[tcols++] = maxlen;
- maxlen = tline = 0;
- }
- nth++;
- }
- if (tline) {
- ws[tcols++] = maxlen;
- width += maxlen;
- }
- if (nth == yl && width <= columns &&
- (beg == end || tlines >= g->lins))
- break;
-
- if (beg == end) {
- beg++;
- end++;
- } else if (width < columns) {
- if ((end = tlines) == beg + 1)
- end--;
- } else {
- if ((beg = tlines) + 1 == end)
- end--;
- }
- }
- if (tlines > g->lins)
- tlines = g->lins;
+ int nth, tcol, tline, len;
+
+ for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ tcols--) {
+
+ if ((tlines = (g->dcount + tcols - 1) / tcols) <= 0)
+ tlines = 1;
+
+ memset(ws, 0, tcols * sizeof(int));
+
+ for (width = nth = tcol = tline = 0;
+ width < columns && nth < g->dcount;
+ nth++, tline++) {
+
+ m = *p;
+
+ if (tline == tlines) {
+ tcol++;
+ tline = 0;
+ }
+ if (tcol == tcols) {
+ tcol = 0;
+ tlines++;
+ }
+ len = ylens[nth];
+
+ if (len > ws[tcol]) {
+ width += len - ws[tcol];
+ ws[tcol] = len;
+ }
+ }
+ if (width < columns)
+ break;
+ }
}
}
} else if (g->width) {
if (g->flags & CGF_ROWS) {
- int addlen, count, tcol, maxlines = 0, llines, i;
- int beg = columns / g->shortest, end = g->cols, fe = 1;
- Cmatch *first;
-
- while (1) {
- tcols = (beg + end) >> 1;
-
- p = first = skipnolist(g->matches, showall);
- for (maxlen = width = maxlines = llines = tcol = 0,
- count = g->dcount;
- count > 0; count--) {
- m = *p;
- addlen = (mlens[m->gnum] +
- (tcol == tcols - 1 ? 0 : add));
- if (addlen > maxlen)
- maxlen = addlen;
- for (i = tcols; i && *p; i--)
- p = skipnolist(p + 1, showall);
-
- llines++;
- if (!*p) {
- if (llines > maxlines)
- maxlines = llines;
- llines = 0;
-
- if ((width += maxlen) >= columns)
- break;
- ws[tcol++] = maxlen;
- maxlen = 0;
-
- p = first = skipnolist(first + 1, showall);
- }
- }
- if (tlines) {
- ws[tcol++] = maxlen;
- width += maxlen;
- }
- if (!count && width <= columns &&
- (tcols <= 0 || beg == end))
- break;
+ int nth, tcol, len;
+
+ for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ tcols--) {
+
+ memset(ws, 0, tcols * sizeof(int));
- if (beg == end) {
- if (fe) {
- beg += 2;
- end += 2;
- fe = 0;
- } else {
- beg--;
- end--;
+ for (width = nth = tcol = 0, tlines = 1,
+ p = skipnolist(g->matches, showall);
+ *p && width < columns && nth < g->dcount;
+ nth++, p = skipnolist(p + 1, showall), tcol++) {
+
+ m = *p;
+
+ if (tcol == tcols) {
+ tcol = 0;
+ tlines++;
+ }
+ len = (mlens[m->gnum] +
+ (tcol == tcols - 1 ? 0 : add));
+
+ if (len > ws[tcol]) {
+ width += len - ws[tcol];
+ ws[tcol] = len;
}
- } else if (width < columns) {
- if ((end = tcols) == beg - 1)
- end++;
- } else {
- if ((beg = tcols) - 1 == end)
- end++;
}
- }
- if (tcols > g->cols)
- tlines = maxlines;
+ if (width < columns)
+ break;
+ }
} else {
- int addlen;
- int smask = ((showall ? 0 : (CMF_NOLIST | CMF_MULT)) |
- CMF_HIDE);
- int beg = ((g->totl + columns) / columns);
- int end = g->lins, fe = 1;
-
- while (1) {
- tlines = (beg + end) >> 1;
-
- for (p = g->matches, nth = tline = width =
- maxlen = tcols = 0;
- (m = *p); p++) {
- if (!(m->flags &
- (m->disp ? (CMF_DISPLINE | CMF_HIDE) :
- smask))) {
- addlen = mlens[m->gnum] + add;
- if (addlen > maxlen)
- maxlen = addlen;
- if (++tline == tlines) {
- if ((width += maxlen) >= columns)
- break;
- ws[tcols++] = maxlen;
- maxlen = tline = 0;
- }
- nth++;
- }
- }
- if (tline) {
- ws[tcols++] = maxlen;
- width += maxlen;
- }
- if (nth == g->dcount && width <= columns &&
- (beg == end || tlines >= g->lins))
- break;
+ int nth, tcol, tline, len;
+
+ for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ tcols--) {
+
+ if ((tlines = (g->dcount + tcols - 1) / tcols) <= 0)
+ tlines = 1;
+
+ memset(ws, 0, tcols * sizeof(int));
- if (beg == end) {
- if (fe) {
- beg -= 2;
- end -= 2;
- fe = 0;
- } else {
- beg++;
- end++;
+ for (width = nth = tcol = tline = 0,
+ p = skipnolist(g->matches, showall);
+ *p && width < columns && nth < g->dcount;
+ nth++, p = skipnolist(p + 1, showall), tline++) {
+
+ m = *p;
+
+ if (tline == tlines) {
+ tcol++;
+ tline = 0;
}
- } else if (width < columns) {
- if ((end = tlines) == beg + 1)
- end--;
- } else {
- if ((beg = tlines) + 1 == end)
- end--;
- }
- }
- if (tlines > g->lins)
- tlines = g->lins;
+ if (tcol == tcols) {
+ tcol = 0;
+ tlines++;
+ }
+ len = (mlens[m->gnum] +
+ (tcol == tcols - 1 ? 0 : add));
+
+ if (len > ws[tcol]) {
+ width += len - ws[tcol];
+ ws[tcol] = len;
+ }
+ }
+ if (width < columns)
+ break;
+ }
}
}
+ if (tcols <= g->cols)
+ tlines = g->lins;
if (tlines == g->lins) {
zfree(ws, columns * sizeof(int));
g->widths = NULL;