From 8afa7f29c93a2a478437c28e8e0ff1a2e9050b37 Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 19 Apr 2008 03:29:49 +0000 Subject: - add priority to vcol git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4201 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/visio.h | 6 +++++- mbbsd/visio.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/include/visio.h b/include/visio.h index 37aa9cce..676aad9a 100644 --- a/include/visio.h +++ b/include/visio.h @@ -37,6 +37,7 @@ // CONSTANT DEFINITION ------------------------------------------------- #define VCOL_MAXW (INT16_MAX) +#define VCOL_MAXPRI (INT16_MAX) #define VFILL_DEFAULT (0x00) // #define VFILL_NO_ANSI VFILL_DEFAULT @@ -58,10 +59,13 @@ typedef void * VREFSCR; typedef long VREFCUR; typedef short VCOLW; -typedef struct { +typedef short VCOLPRI; + +typedef struct VCOL { char *attr; // default attribute VCOLW minw; // minimal width VCOLW maxw; // max width + VCOLPRI pri; // priority (higher expands first) struct { char has_ansi; // field data have ANSI escapes diff --git a/mbbsd/visio.c b/mbbsd/visio.c index 27b6cbf9..ea6701e4 100644 --- a/mbbsd/visio.c +++ b/mbbsd/visio.c @@ -638,7 +638,8 @@ vs_footer(const char *caption, const char *msg) void vs_cols_layout(const VCOL *cols, VCOLW *ws, int n) { - int i, tw, d = 0; + int i, tw; + VCOLPRI pri1 = cols[0].pri; memset(ws, 0, sizeof(VCOLW) * n); // first run, calculate minimal size @@ -651,22 +652,49 @@ vs_cols_layout(const VCOL *cols, VCOLW *ws, int n) tw += ws[i]; } + if (tw < MAX_COL) { + // calculate highest priorities + // (pri1 already set to col[0].pri) + for (i = 1; i < n; i++) + { + if (cols[i].pri > pri1) + pri1 = cols[i].pri; + } + } + // try to iterate through all. while (tw < MAX_COL) { - // TODO process priority? char run = 0; - d++; + + // also update pri2 here for next run. + VCOLPRI pri2 = cols[0].pri; + for (i = 0; i < n; i++) { - // increase fields if still ok. - if (cols[i].maxw - cols[i].minw < d) + // if reach max, skip. + if (ws[i] >= cols[i].maxw) continue; + + // lower priority, update pri2 and skip. + if (cols[i].pri < pri1) + { + if (cols[i].pri > pri2) + pri2 = cols[i].pri; + continue; + } + + // now increase fields ws[i] ++; if (++tw >= MAX_COL) break; run ++; } + // if no more fields... - if (!run) break; + if (!run) { + if (pri1 <= pri2) // no more priorities + break; + pri1 = pri2; // try lower priority. + } } } -- cgit v1.2.3