lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev [PATCH 2.8.4dev.16] Fixes for TRST


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.4dev.16] Fixes for TRST
Date: Tue, 23 Jan 2001 01:05:53 -0500
User-agent: Mutt/1.2.5i

The TRST changes I sent before had one misprint, one misconception,
and triggered one bug in the  older code.  This patches fixes them all.

Enjoy,
Ilya

P.S.  To answer Nelson's questions: if your screen is too narrow, the
code performs the same way the older code did: it ignores <table>
tags.  And if javascript sites annoy you, this means that you forgot
to switch off javascript in netscape.  ;-)

--- ./src/GridText.c-after-table-table  Mon Jan 22 00:24:50 2001
+++ ./src/GridText.c    Mon Jan 22 18:50:04 2001
@@ -4888,7 +4888,7 @@ PUBLIC void HText_cancelStbl ARGS1(
     stbl = me->stbl;
     while (stbl) {
        STable_info *enclosing = Stbl_get_enclosing(stbl);
-       Stbl_free(me->stbl);
+       Stbl_free(stbl);
        stbl = enclosing;
     }
     me->stbl = NULL;
--- ./src/TRSTable.c-after-table-table  Sun Jan 21 23:51:10 2001
+++ ./src/TRSTable.c    Mon Jan 22 20:39:38 2001
@@ -1297,6 +1297,7 @@ PRIVATE int get_remaining_colspan ARGS5(
     return colspan;
 }
 
+/* Returns -1 on failure, 1 if faking was performed, 0 if not needed. */
 PRIVATE int Stbl_fakeFinishCellInTable ARGS4(
     STable_info *,     me,
     STable_rowinfo *,  lastrow,
@@ -1347,15 +1348,22 @@ PRIVATE int Stbl_fakeFinishCellInTable A
        CTRACE((tfp, "TRST:Stbl_fakeFinishCellInTable(lineno=%d, finishing=%d) 
START FAKING\n",
                lineno, finishing));
 
+       /* Although here we use pos=0, this may commit the previous
+          cell which had <BR> as a last element.  This may overflow
+          the screen width, so the additional checks performed in
+          Stbl_finishCellInTable (comparing to Stbl_finishCellInRow)
+          are needed. */
        if (finishing)
            /* Fake </TD> at BOL */
-           Stbl_finishCellInRow(lastrow, s, end_td, lineno, 0);
-
+           if (Stbl_finishCellInTable(me, end_td, lineno, 0) < 0)
+               return -1;
+       
        /* Fake </TR> at BOL */
        /* Stbl_finishCellInTable(lineno, 0, 0);*/ /* Needed? */
 
        /* Fake <TR> at BOL */
-       Stbl_addRowToTable(me, al, lineno);
+       if (Stbl_addRowToTable(me, al, lineno) < 0)
+           return -1;
        lastrow = me->rows + (me->nrows - 1);
        for (i = 0; i < lastrow->allocated; i++)
            if (lastrow->cells[i].alignment == RESERVEDCELL) {
@@ -1380,7 +1388,7 @@ PRIVATE int Stbl_fakeFinishCellInTable A
            int need_cells = prev_reserved_last + 1;
 
            if (!rows)
-               return 1; /* ignore silently, no free memory, may be 
recoverable */
+               return -1; /* ignore silently, no free memory, may be 
recoverable */
 
            CTRACE((tfp, "TRST:Stbl_fakeFinishCellInTable REALLOC ROWSPAN\n"));
            me->rows = rows;
@@ -1399,7 +1407,7 @@ PRIVATE int Stbl_fakeFinishCellInTable A
                lastrow->cells = typecallocn(STable_cellinfo, need_cells);
                /* ignore silently, no free memory, may be recoverable */
                if (!lastrow->cells)
-                   return 1;
+                   return -1;
                lastrow->allocated = need_cells;
                memcpy(lastrow->cells, prev_row->cells, 
                       lastrow->allocated * sizeof(STable_cellinfo));
@@ -1422,10 +1430,14 @@ PRIVATE int Stbl_fakeFinishCellInTable A
        i = 0;
        while (++i <= ncells) {
            /* XXXX A lot of args may be wrong... */
-           Stbl_addCellToTable(me, (i==ncells ? cs : 1), rs, al, ih,
-                               lineno, 0);
+           if (Stbl_addCellToTable(me, (i==ncells ? cs : 1), rs, al,
+                                   ih, lineno, 0) < 0)
+               return -1;
+           /* We cannot run out of width here, so it is safe to not
+              call Stbl_finishCellInTable(), but Stbl_finishCellInRow. */
            if (!finishing || (i != ncells))
-               Stbl_finishCellInRow(lastrow, s, end_td, lineno, 0);
+               if (Stbl_finishCellInRow(lastrow, s, end_td, lineno, 0) < 0)
+                   return -1;
        }
        CTRACE((tfp, "TRST:Stbl_fakeFinishCellInTable(lineno=%d) FINISH 
FAKING\n",
                lineno));
@@ -1467,7 +1479,11 @@ PUBLIC int Stbl_addCellToTable ARGS7(
        appropriate amount of cells */
     if (!NO_AGRESSIVE_NEWROW && pos == 0 && lastrow->ncells > 0
        && lastrow->cells[lastrow->ncells-1].cLine != lineno) {
-       if (Stbl_fakeFinishCellInTable(me, lastrow, lineno, 0))
+       int rc = Stbl_fakeFinishCellInTable(me, lastrow, lineno, 0);
+
+       if (rc < 0)
+           return -1;
+       if (rc)
            lastrow = me->rows + (me->nrows - 1);
     }
     if (colspan == 0) {
@@ -1591,8 +1607,13 @@ PUBLIC int Stbl_finishCellInTable ARGS4(
     if (s->x_td == -1)
        return end_td ? -1 : 0;
 
+    /* This check for pos saves us from infinite recursion... */
     if (!NO_AGRESSIVE_NEWROW && pos) {
-       if (Stbl_fakeFinishCellInTable(me, lastrow, lineno, 1)) {
+       int rc = Stbl_fakeFinishCellInTable(me, lastrow, lineno, 1);
+
+       if (rc) {
+           if (rc < 0)
+               return -1;
            lastrow = me->rows + (me->nrows - 1);
            icell = lastrow->ncells - 1;
        }
@@ -1689,8 +1710,10 @@ PUBLIC int Stbl_finishCellInTable ARGS4(
     }
 #endif
 
+#if 0  /* maxlen may already include contribution of a cell in this column */
     if (me->maxlen + (xlen - len) > MAX_STBL_POS)
        return -1;
+#endif
     if (me->maxpos > /* @@@ max. line length we can accept */ MAX_STBL_POS)
        return -1;
 
@@ -1935,7 +1958,21 @@ PUBLIC void Stbl_update_enclosing ARGS3(
            max_width, me->startline, last_lineno));
     for (l = me->startline; l <= last_lineno; l++)
        /* Fake <BR> in appropriate positions */
-       Stbl_finishCellInTable(me->enclosing, 0, l, max_width);
+       if (Stbl_finishCellInTable(me->enclosing, 0, l, max_width) < 0) {
+           /* It is not handy to let the caller delete me->enclosing,
+              and it does not buy us anything.  Do it directly. */
+           STable_info *stbl = me->enclosing;
+
+           CTRACE((tfp, "TRST:Stbl_update_enclosing: width too large, aborting 
enclosing\n"));
+           me->enclosing = 0;
+           while (stbl) {
+               STable_info *enclosing = stbl->enclosing;
+               Stbl_free(stbl);
+               stbl = enclosing;
+           }
+           return;
+       }
+    return;
 }
 
 PUBLIC void Stbl_set_enclosing ARGS3(

; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]