txtview.c 19 KB
Newer Older
1 2 3
/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

ellson's avatar
ellson committed
4 5 6 7 8 9 10 11 12
/*************************************************************************
 * Copyright (c) 2011 AT&T Intellectual Property 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: See CVS logs. Details at http://www.graphviz.org/
 *************************************************************************/
13

14
/* Lefteris Koutsofios - AT&T Labs Research */
15 16 17 18 19 20 21 22 23 24 25

#include "common.h"
#include "g.h"
#include "mem.h"
#include "code.h"
#include "tbl.h"
#include "parse.h"
#include "exec.h"
#include "str.h"
#include "txtview.h"

26 27 28 29
#define TXT_SEEN     0
#define TXT_ABSTRACT 1
#define TXT_FULL     2

30
typedef struct txtnode_t {
31 32
    int mode;
    int ttype;
33 34 35 36
    Tobj ko, vo;
    long time;
    char *path;
    union {
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        struct {
            struct txtnode_t *txtnode;
            Tobj ko;
            char *text;
            int wi;
        } s;
        struct {
            char *text;
            int wi;
        } a;
        union {
            struct {
                char *text;
                int wi;
            } s;
            struct {
                char *ftext, *ltext;
                int fwi, mwi, lwi;
                struct txtnode_t *list;
                int n;
            } t;
        } f;
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    } u;
} txtnode_t;
static txtnode_t *txtroot;
static txtnode_t defnode;

static txtnode_t **seenp;
static long seeni, seenn;
#define SEENINCR 100
#define SEENSIZE sizeof (txtnode_t)

static Tobj txtvo2toggle = NULL;

static Gwattr_t arraydata[2], buttondata[5];

static int txton, txtx, txty, txtwidth, txtheight;
static int txtwi, queryws[G_QWMODES + 1], listwi, scrollwi, arraywi, cmdwi;

static Psrc_t src;

78
#define __max(a, b) (((a) >= (b)) ? (a) : (b))
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
static void viewon (void);
static void viewoff (void);
static void update (txtnode_t *, long);
static void buildlist (txtnode_t *);
static void rebuildlist (txtnode_t *);
static void fillnode (txtnode_t *, txtnode_t *);
static void unfillnode (txtnode_t *);
static int cmp (const void *, const void *);
static txtnode_t *findseen (txtnode_t *);
static void add2seen (txtnode_t *);
static void orderfunc (void *, Gawdata_t *);
static void coordsfunc (int, Gawdata_t *);
static void coords2func (int, Gawdata_t *);

void TXTinit (Grect_t r) {
95 96 97 98 99 100 101 102 103
    Gwattr_t data[1];
    int i;

    txton = TRUE;
    txtwi = -1;
    txtx = r.o.x, txty = r.o.y;
    txtwidth = r.c.x - r.o.x + 1, txtheight = r.c.y - r.o.y + 1;

    buttondata[0].id = G_ATTRBUTTONCB;
104
    buttondata[0].u.func = TXTtoggle;
105 106 107 108 109 110 111 112
    buttondata[1].id = G_ATTRSIZE;
    buttondata[1].u.s.x = buttondata[1].u.s.y = 0;
    buttondata[2].id = G_ATTRBORDERWIDTH;
    buttondata[2].u.i = 0;
    buttondata[3].id = G_ATTRTEXT;
    buttondata[4].id = G_ATTRUSERDATA;

    arraydata[0].id = G_ATTRRESIZECB;
113
    arraydata[0].u.func = coordsfunc;
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    arraydata[1].id = G_ATTRSIZE;
    arraydata[1].u.s.x = arraydata[1].u.s.y = 0;

    defnode.mode = TXT_ABSTRACT;
    defnode.ttype = T_TABLE;
    defnode.ko = defnode.vo = NULL;
    defnode.time = -1;
    defnode.path = NULL;
    defnode.u.s.txtnode = NULL;
    defnode.u.s.ko = NULL;
    defnode.u.s.text = NULL;
    defnode.u.s.wi = 0;
    defnode.u.a.text = NULL;
    defnode.u.a.wi = 0;
    defnode.u.f.s.text = NULL;
    defnode.u.f.s.wi = 0;
    defnode.u.f.t.ftext = defnode.u.f.t.ltext = NULL;
    defnode.u.f.t.fwi = 0;
    defnode.u.f.t.mwi = 0;
    defnode.u.f.t.lwi = 0;
    defnode.u.f.t.list = NULL;
    defnode.u.f.t.n = 0;

    for (i = 1; i <= G_QWMODES; i++) {
138 139 140 141 142 143 144 145 146 147 148 149 150
        data[0].id = G_ATTRMODE;
        switch (i) {
        case G_QWSTRING:
            data[0].u.t = "string";
            break;
        case G_QWFILE:
            data[0].u.t = "file";
            break;
        case G_QWCHOICE:
            data[0].u.t = "choice";
            break;
        }
        queryws[i] = Gcreatewidget (-1, G_QUERYWIDGET, 1, &data[0]);
151 152 153 154 155
    }

    src.flag = CHARSRC, src.fp = NULL, src.tok = -1, src.lnum = 1;
}

156
void TXTterm (void) {
157 158 159
    int i;

    for (i = 1; i <= G_QWMODES; i++)
160
        Gdestroywidget (queryws[i]);
161
    if (txton)
162
        viewoff (), txton = FALSE;
163 164 165
}

/* LEFTY builtin */
166
int TXTmode (int argc, lvar_t *argv) {
167 168
    char *s;

169 170 171 172 173 174 175 176 177 178 179
    if (!argv[0].o || Tgettype (argv[0].o) != T_STRING)
        return L_FAILURE;
    s = Tgetstring (argv[0].o);
    if (strcmp (s, "on") == 0) {
        if (txtwi == -1)
            viewon ();
    } else if (strcmp (s, "off") == 0) {
        if (txtwi != -1)
            viewoff ();
        else
            txton = FALSE;
180 181 182 183
    }
    return L_SUCCESS;
}

184
static void viewon (void) {
185 186 187 188 189 190 191 192
    Gwattr_t data[5];

    data[0].id = G_ATTRNAME;
    data[0].u.t = "LEFTY text view";
    data[1].id = G_ATTRORIGIN;
    data[1].u.p.x = txtx, data[1].u.p.y = txty;
    data[2].id = G_ATTRSIZE;
    data[2].u.s.x = txtwidth, data[2].u.s.y = txtheight;
193
    txtwi = Gcreatewidget (-1, G_VIEWWIDGET, 3, &data[0]);
194 195 196 197 198 199

    data[0].id = G_ATTRSIZE;
    data[0].u.s.x = txtwidth, data[0].u.s.y = txtheight;
    data[1].id = G_ATTRBORDERWIDTH;
    data[1].u.i = 1;
    data[2].id = G_ATTRRESIZECB;
200 201 202
    data[2].u.func = coords2func;
    listwi = Gcreatewidget (txtwi, G_ARRAYWIDGET, 3, &data[0]);
    Gawsetmode (&Gwidgets[listwi], TRUE);
203 204 205 206 207 208 209 210

    data[0].id = G_ATTRSIZE;
    data[0].u.s.x = txtwidth, data[0].u.s.y = txtheight / 3;
    data[1].id = G_ATTRBORDERWIDTH;
    data[1].u.i = 0;
    data[2].id = G_ATTRTEXT;
    data[2].u.t = NULL;
    data[3].id = G_ATTRNEWLINECB;
211
    data[3].u.func = TXTprocess;
212 213
    data[4].id = G_ATTRMODE;
    data[4].u.t = "oneline";
214
    cmdwi = Gcreatewidget (listwi, G_TEXTWIDGET, 5, &data[0]);
215 216 217 218 219

    data[0].id = G_ATTRSIZE;
    data[0].u.s.x = txtwidth, data[0].u.s.y = txtheight * 2 / 3;
    data[1].id = G_ATTRMODE;
    data[1].u.t = "forcebars";
220
    scrollwi = Gcreatewidget (listwi, G_SCROLLWIDGET, 2, &data[0]);
221 222

    data[0].id = G_ATTRRESIZECB;
223
    data[0].u.func = coordsfunc;
224 225 226 227
    data[1].id = G_ATTRSIZE;
    data[1].u.s.x = txtwidth, data[1].u.s.y = txtheight;
    data[2].id = G_ATTRBORDERWIDTH;
    data[2].u.i = 0;
228
    arraywi = Gcreatewidget (scrollwi, G_ARRAYWIDGET, 3, &data[0]);
229

230
    Gawsetmode (&Gwidgets[listwi], FALSE);
231

232
    if (!(txtroot = malloc (sizeof (txtnode_t))))
233
        panic1 (POS, "TXTinit", "txtroot malloc failed");
234 235 236 237 238 239
    *txtroot = defnode;
    txtroot->mode = TXT_FULL;
    txtroot->vo = root;
    txtroot->path = NULL;
    txtroot->u.f.t.mwi = arraywi;

240
    seenp = Marrayalloc ((long) SEENINCR * SEENSIZE);
241 242 243 244 245
    seeni = 0;
    seenn = SEENINCR;
    txton = TRUE;
}

246 247
static void viewoff (void) {
    Marrayfree (seenp);
248
    seeni = seenn = 0;
249 250 251 252 253 254 255
    unfillnode (txtroot);
    free (txtroot);
    Gdestroywidget (arraywi);
    Gdestroywidget (scrollwi);
    Gdestroywidget (cmdwi);
    Gdestroywidget (listwi);
    Gdestroywidget (txtwi);
256 257 258 259 260
    txton = FALSE;
    txtwi = -1;
}

/* LEFTY builtin */
261
int TXTask (int argc, lvar_t *argv) {
262 263 264
    Tobj so, ao;
    char buf[1200];
    char *sp, *ap;
265
    int mode;
266

267 268
    mode = 0;
    ap = NULL;
269
    if (argc < 2)
270
        mode = G_QWSTRING;
271
    else {
272 273 274 275 276 277 278 279 280 281 282
        so = argv[1].o;
        if (T_ISSTRING (so)) {
            sp = Tgetstring (so);
            if (strcmp (sp, "string") == 0)
                mode = G_QWSTRING;
            else if (strcmp (sp, "file") == 0)
                mode = G_QWFILE;
            else if (strcmp (sp, "choice") == 0)
                mode = G_QWCHOICE;
            else mode = 0;
        }
283 284
    }
    if (argc < 3)
285
        ap = NULL;
286
    else {
287 288 289
        ao = argv[2].o;
        if (T_ISSTRING (ao))
            ap = Tgetstring (ao);
290
    }
291 292
    if (Gqueryask (queryws[mode], Tgetstring (argv[0].o), ap, buf, 1200) == 0)
        rtno = Tstring (buf);
293
    else
294
        rtno = NULL;
295 296
#ifndef NOQUERYFIX
    if (mode == G_QWCHOICE) {
297
        Gwattr_t data[1];
298

299 300 301 302
        data[0].id = G_ATTRMODE;
        data[0].u.t = "choice";
        Gdestroywidget (queryws[mode]);
        queryws[mode] = Gcreatewidget (-1, G_QUERYWIDGET, 1, &data[0]);
303 304 305 306 307
    }
#endif
    return L_SUCCESS;
}

308
void TXTprocess (int wi, char *sp) {
309 310 311
    Tobj co;

    src.s = sp;
312 313
    if ((co = Punit (&src)))
        Eoktorun = TRUE, Eunit (co);
314 315
}

316
void TXTupdate (void) {
317
    if (!txton)
318
        return;
319
    if (txtwi == -1)
320
        viewon ();
321
    seeni = 0;
322
    update (txtroot, txtroot->time);
323 324 325 326
    txtroot->time = Ttime;
    Ttime++;
}

327
void TXTtoggle (int wi, void *data) {
328
    txtvo2toggle = data;
329
    TXTupdate ();
330 331 332 333
    txtvo2toggle = NULL;
}

/* update is called only for TXT_FULL tables */
334
static void update (txtnode_t *pnode, long ptim) {
335 336 337 338
    txtnode_t *cnode, *seennode;
    long ctim;
    int i;

339
    Gawsetmode (&Gwidgets[pnode->u.f.t.mwi], TRUE);
340
    if (!pnode->u.f.t.list)
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
        buildlist (pnode);
    else if (ptim < Tgettime (pnode->vo))
        rebuildlist (pnode);
    for (
        i = 0, cnode = &pnode->u.f.t.list[0]; i < pnode->u.f.t.n;
        i++, cnode++
    ) {
        ctim = cnode->time;
        if (txtvo2toggle == cnode->vo) {
            switch (cnode->mode) {
            case TXT_SEEN:
                break;
            case TXT_ABSTRACT:
                unfillnode (cnode);
                cnode->mode = TXT_FULL;
                fillnode (pnode, cnode);
                break;
            case TXT_FULL:
                unfillnode (cnode);
                cnode->mode = TXT_ABSTRACT;
                fillnode (pnode, cnode);
                break;
            }
        }
        if (!(seennode = findseen (cnode)))
            add2seen (cnode);
        if (
            seennode && cnode->mode == TXT_SEEN && seennode->ko != cnode->u.s.ko
        ) {
            unfillnode (cnode);
            cnode->u.s.txtnode = seennode;
            cnode->u.s.ko = seennode->ko;
            fillnode (pnode, cnode);
        } else if (seennode && cnode->mode != TXT_SEEN) {
            unfillnode (cnode);
            cnode->mode = TXT_SEEN;
            cnode->u.s.txtnode = seennode;
            cnode->u.s.ko = seennode->ko;
            fillnode (pnode, cnode);
        } else if (!seennode && cnode->mode == TXT_SEEN) {
            unfillnode (cnode);
            cnode->mode = TXT_ABSTRACT;
            fillnode (pnode, cnode);
        } else if (cnode->time == -1) {
            unfillnode (cnode);
            if (seennode)
                cnode->u.s.txtnode = seennode;
            fillnode (pnode, cnode);
        }
        if (cnode->ttype == T_TABLE && cnode->mode == TXT_FULL)
            update (cnode, ctim);
392
    }
393 394
    Gaworder (&Gwidgets[pnode->u.f.t.mwi], pnode, orderfunc);
    Gawsetmode (&Gwidgets[pnode->u.f.t.mwi], FALSE);
395 396
}

397
static void buildlist (txtnode_t *pnode) {
398 399
    Tkvindex_t tkvi;
    Tobj ko, vo;
400
    int vtype;
401 402 403
    txtnode_t *cnode;

    pnode->u.f.t.n = ((Ttable_t *) pnode->vo)->n;
404
    if (!(pnode->u.f.t.list = malloc (
405
        __max (pnode->u.f.t.n, 1) * sizeof (txtnode_t)
406
    )))
407
        panic1 (POS, "buildlist", "list malloc failed");
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425

    for (
        cnode = &pnode->u.f.t.list[0], Tgetfirst (pnode->vo, &tkvi);
        tkvi.kvp; Tgetnext (&tkvi)
    ) {
        ko = tkvi.kvp->ko, vo = tkvi.kvp->vo;
        vtype = Tgettype (vo);
        if (vtype == T_CODE && TCgettype (vo, TCgetnext (
            vo, TCgetnext (vo, TCgetnext (vo, TCgetfp (vo, 0)))
        )) == C_INTERNAL) {
            pnode->u.f.t.n--;
            continue;
        }
        *cnode = defnode;
        cnode->vo = vo;
        cnode->ko = ko;
        cnode->ttype = vtype;
        cnode++;
426
    }
427 428 429
    qsort (
        (char *) pnode->u.f.t.list, pnode->u.f.t.n, sizeof (txtnode_t), cmp
    );
430 431
}

432
static void rebuildlist (txtnode_t *pnode) {
433 434
    Tkvindex_t tkvi;
    Tobj ko, vo;
435
    int vtype;
436 437 438
    txtnode_t *cnode;
    txtnode_t *olist, *nlist;
    txtnode_t tmpnode;
439
    int on, nn, i, j, cmpval;
440

ellson's avatar
ellson committed
441
    cmpval = 0;
442 443 444
    olist = pnode->u.f.t.list;
    on = pnode->u.f.t.n;
    pnode->u.f.t.n = ((Ttable_t *) pnode->vo)->n;
445
    if (!(pnode->u.f.t.list = malloc (
446
        __max (pnode->u.f.t.n, 1) * sizeof (txtnode_t)
447
    )))
448
        panic1 (POS, "rebuildlist", "list malloc failed");
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466

    for (
        cnode = &pnode->u.f.t.list[0], Tgetfirst (pnode->vo, &tkvi);
        tkvi.kvp; Tgetnext (&tkvi)
    ) {
        ko = tkvi.kvp->ko, vo = tkvi.kvp->vo;
        vtype = Tgettype (vo);
        if (vtype == T_CODE && TCgettype (vo, TCgetnext (
            vo, TCgetnext (vo, TCgetnext (vo, TCgetfp (vo, 0)))
        )) == C_INTERNAL) {
            pnode->u.f.t.n--;
            continue;
        }
        *cnode = defnode;
        cnode->vo = vo;
        cnode->ko = ko;
        cnode->ttype = vtype;
        cnode++;
467
    }
468
    qsort ((char *) pnode->u.f.t.list, pnode->u.f.t.n, sizeof (txtnode_t), cmp);
469 470 471
    nlist = pnode->u.f.t.list;
    nn = pnode->u.f.t.n;
    for (i = 0, j = 0; i < nn; i++) {
472 473 474 475
        while (j < on && (cmpval = cmp (&olist[j], &nlist[i])) < 0)
            j++;
        if (j < on && cmpval == 0 && nlist[i].vo == olist[j].vo)
            tmpnode = olist[j], olist[j] = nlist[i], nlist[i] = tmpnode, j++;
476 477
    }
    for (j = 0; j < on; j++)
478 479
        unfillnode (&olist[j]);
    free (olist);
480 481
}

482
static void fillnode (txtnode_t *pnode, txtnode_t *cnode) {
483
    cnode->time = Ttime;
484
    cnode->path = Spath (pnode->path, cnode->ko);
485 486
    switch (cnode->mode) {
    case TXT_SEEN:
487 488 489 490 491 492 493
        cnode->u.s.text = Sseen (cnode->ko, cnode->u.s.txtnode->path);
        buttondata[3].u.t = cnode->u.s.text;
        buttondata[4].u.u = (unsigned long) cnode->vo;
        cnode->u.s.wi = Gcreatewidget (
            pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
        );
        break;
494
    case TXT_ABSTRACT:
495 496 497 498 499 500 501
        cnode->u.a.text = Sabstract (cnode->ko, cnode->vo);
        buttondata[3].u.t = cnode->u.a.text;
        buttondata[4].u.u = (unsigned long) cnode->vo;
        cnode->u.a.wi = Gcreatewidget (
            pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
        );
        break;
502
    case TXT_FULL:
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
        if (cnode->ttype == T_TABLE) {
            cnode->u.f.t.ftext = Stfull (cnode->ko);
            cnode->u.f.t.ltext = "];";
            buttondata[3].u.t = cnode->u.f.t.ftext;
            buttondata[4].u.u = (unsigned long) cnode->vo;
            cnode->u.f.t.fwi = Gcreatewidget (
                pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
            );
            cnode->u.f.t.mwi = Gcreatewidget (
                pnode->u.f.t.mwi, G_ARRAYWIDGET, 2, &arraydata[0]
            );
            buttondata[3].u.t = cnode->u.f.t.ltext;
            buttondata[4].u.u = (unsigned long) cnode->vo;
            cnode->u.f.t.lwi = Gcreatewidget (
                pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
            );
        } else {
            cnode->u.f.s.text = Ssfull (cnode->ko, cnode->vo);
            buttondata[3].u.t = cnode->u.f.s.text;
            buttondata[4].u.u = (unsigned long) cnode->vo;
            cnode->u.f.s.wi = Gcreatewidget (
                pnode->u.f.t.mwi, G_BUTTONWIDGET, 5, &buttondata[0]
            );
        }
        break;
528 529 530
    }
}

531
static void unfillnode (txtnode_t *cnode) {
532 533 534
    int i;

    if (cnode->path)
535
        free (cnode->path), cnode->path = NULL;
536 537
    switch (cnode->mode) {
    case TXT_SEEN:
538 539 540 541 542
        if (cnode->u.s.text)
            free (cnode->u.s.text);
        if (cnode->u.s.wi)
            Gdestroywidget (cnode->u.s.wi);
        break;
543
    case TXT_ABSTRACT:
544 545 546 547 548
        if (cnode->u.a.text)
            free (cnode->u.a.text);
        if (cnode->u.a.wi)
            Gdestroywidget (cnode->u.a.wi);
        break;
549
    case TXT_FULL:
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
        if (cnode->ttype == T_TABLE) {
            for (i = 0; i < cnode->u.f.t.n; i++)
                unfillnode (&cnode->u.f.t.list[i]);
            if (cnode->u.f.t.list)
                free (cnode->u.f.t.list);
            if (cnode->u.f.t.ftext)
                free (cnode->u.f.t.ftext);
            if (cnode->u.f.t.fwi) {
                Gdestroywidget (cnode->u.f.t.fwi);
                Gdestroywidget (cnode->u.f.t.mwi);
                Gdestroywidget (cnode->u.f.t.lwi);
            }
        } else {
            if (cnode->u.f.s.text)
                free (cnode->u.f.s.text);
            if (cnode->u.f.s.wi)
                Gdestroywidget (cnode->u.f.s.wi);
        }
        break;
569 570 571 572 573 574 575 576 577 578 579 580 581 582
    }
    cnode->u.s.text = NULL;
    cnode->u.s.wi = 0;
    cnode->u.a.text = NULL;
    cnode->u.a.wi = 0;
    cnode->u.f.t.list = NULL;
    cnode->u.f.t.ftext = NULL;
    cnode->u.f.t.fwi = 0;
    cnode->u.f.t.mwi = 0;
    cnode->u.f.t.lwi = 0;
    cnode->u.f.s.text = NULL;
    cnode->u.f.s.wi = 0;
}

583 584
static int cmp (const void *a, const void *b) {
    int atype, btype;
585
    txtnode_t *anode, *bnode;
586
    double d1, d2;
587

588
    d1 = 0.0, d2 = 0.0;
589
    anode = (txtnode_t *) a, bnode = (txtnode_t *) b;
590
    atype = Tgettype (anode->ko), btype = Tgettype (bnode->ko);
591
    if (atype != btype)
592
        return (atype - btype);
593
    if (atype == T_STRING)
594
        return strcmp (Tgetstring (anode->ko), Tgetstring (bnode->ko));
595
    if (atype == T_INTEGER)
596
        d1 = Tgetinteger (anode->ko), d2 = Tgetinteger (bnode->ko);
597
    else if (atype == T_REAL)
598
        d1 = Tgetreal (anode->ko), d2 = Tgetreal (bnode->ko);
599
    if (d1 < d2)
600
        return -1;
601
    else if (d1 > d2)
602
        return 1;
603
    else
604
        return 0; /* but this should never happen since keys are unique */
605 606
}

607
static txtnode_t *findseen (txtnode_t *cnode) {
608 609 610
    int i;

    for (i = 0; i < seeni; i++)
611 612
        if (seenp[i]->vo == cnode->vo)
            return seenp[i];
613 614 615
    return NULL;
}

616
static void add2seen (txtnode_t *cnode) {
617
    if (seeni >= seenn) {
618 619
        seenp = Marraygrow (seenp, (long) (seenn + SEENINCR) * SEENSIZE);
        seenn += SEENINCR;
620 621 622 623
    }
    seenp[seeni++] = cnode;
}

624
static void orderfunc (void *data, Gawdata_t *dp) {
625 626 627 628 629
    txtnode_t *pnode, *cnode;
    int i;

    pnode = data;
    dp->cj = 0;
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    for (i = 0, cnode = &pnode->u.f.t.list[0]; i < pnode->u.f.t.n; i++, cnode++)
        switch (cnode->mode) {
        case TXT_SEEN:
            dp->carray[dp->cj++].w = Gwidgets[cnode->u.s.wi].w;
            break;
        case TXT_ABSTRACT:
            dp->carray[dp->cj++].w = Gwidgets[cnode->u.a.wi].w;
            break;
        case TXT_FULL:
            if (cnode->ttype == T_TABLE) {
                dp->carray[dp->cj++].w = Gwidgets[cnode->u.f.t.fwi].w;
                dp->carray[dp->cj++].w = Gwidgets[cnode->u.f.t.mwi].w;
                dp->carray[dp->cj++].w = Gwidgets[cnode->u.f.t.lwi].w;
            } else
                dp->carray[dp->cj++].w = Gwidgets[cnode->u.f.s.wi].w;
            break;
        }
647 648
}

649
static void coordsfunc (int wi, Gawdata_t *dp) {
650 651 652 653 654 655
    Gawcarray_t *cp;
    int cox, coy;
    int ci;

    cox = coy = 0;
    for (ci = 0; ci < dp->cj; ci++) {
656 657 658 659 660 661
        cp = &dp->carray[ci];
        if (!cp->flag)
            continue;
        cp->ox = cox, cp->oy = coy;
        cp->sx = dp->sx - 2 * cp->bs;
        coy += cp->sy + 2 * cp->bs;
662 663 664 665
    }
    dp->sy = coy;
}

666
static void coords2func (int wi, Gawdata_t *dp) {
667 668 669 670 671 672
    Gawcarray_t *cp;
    int cox, coy;
    int ci, cj;

    cox = coy = 0;
    for (ci = 0, cj = 0; ci < dp->cj; ci++) {
673 674 675 676 677 678 679 680 681
        cp = &dp->carray[ci];
        if (!cp->flag)
            continue;
        cp->ox = cox, cp->oy = coy;
        cj++;
        cp->sx = dp->sx - 2 * cp->bs;
        if (cj == 2)
            cp->sy = dp->sy - coy - 2 * cp->bs;
        coy += cp->sy + 2 * cp->bs;
682 683
    }
}