[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev [PATCH 2.8.4dev.10] Trace/document TRST code
From: |
Ilya Zakharevich |
Subject: |
lynx-dev [PATCH 2.8.4dev.10] Trace/document TRST code |
Date: |
Sun, 21 Jan 2001 01:45:41 -0500 |
User-agent: |
Mutt/1.2.5i |
The only functionality change by this giant patch is addition of more
tracing. All the rest is just more comments and more sensible names
for variables. I still do not understand most of the logic, though, sigh...
Enjoy,
Ilya
--- ./src/TRSTable.c.orig Mon Feb 14 23:07:38 2000
+++ ./src/TRSTable.c Sun Jan 21 01:29:46 2001
@@ -29,33 +29,56 @@
#define EOCOLG (-2) /* sumcols' Line field isn't used for line info, this
special value means end of COLGROUP */
typedef enum {
- CS_invalid = -1,
- CS_new = 0,
- CS__0, /* new, at BOL */
+ CS_invalid = -1, /* cell "before the first",
+ or empty lines after [ce]bc,
+ or TRST aborted */
+ CS__0new = 0, /* starts at BOL, new */
+ CS__new, /* new */
CS__0eb, /* starts at BOL, empty, break */
CS__eb, /* empty, break */
CS__0cb, /* starts at BOL, content, break */
CS__cb, /* content, break */
- CS__0f, /* starts at BOL, finished */
+ CS__0ef, /* starts at BOL, empty, finished */
CS__ef, /* empty, finished */
CS__0cf, /* starts at BOL, content, finished */
CS__cf, /* content, finished */
- CS__ebc, /* empty, break, more content */
- CS__cbc /* content, break, more content */
+ CS__ebc, /* empty, break, more content (maybe @BOL) */
+ CS__cbc /* content, break, more content (maybe @BOL) */
} cellstate_t;
+const char * const cellstate_s[] = { /* Should be indexed by cellstate+1 */
+ "CS_invalid",
+ "CS__new",
+ "CS__0new",
+ "CS__0eb",
+ "CS__eb",
+ "CS__0cb",
+ "CS__cb",
+ "CS__0ef",
+ "CS__ef",
+ "CS__0cf",
+ "CS__cf",
+ "CS__ebc",
+ "CS__cbc"
+};
+
typedef struct _STable_states {
- cellstate_t prev_state;
- cellstate_t state;
- int lineno; /* last line no. looked at */
- int icell_core; /* first/best 'core' cell in row so far
*/
- int x_td; /* x pos of currently open cell or -1 */
- int pending_len; /* if state is CS__0?[ec]b (??) */
+ cellstate_t prev_state; /* Contents type of the previous cell */
+ cellstate_t state; /* Contents type of the worked-on cell
*/
+ int lineno; /* Start line of the current cell */
+ int icell_core; /* -1 or the 1st cell with <BR></TD> on
row */
+ int x_td; /* x start pos of the current cell or
-1 */
+ int pending_len; /* For multiline cells, the length of
+ the part on the first line (if
+ state is CS__0?[ec]b) (??), or 0 */
} STable_states;
typedef struct _STable_cellinfo {
- int Line; /* lineno in doc (zero-based) */
+ int cLine; /* lineno in doc (zero-based): -1 for
+ contentless cells (and cells we do
+ not want to measure and count?),
+ line-of-the-start otherwise. */
int pos; /* column where cell starts */
int len; /* number of character positions */
int colspan; /* number of columns to span */
@@ -64,9 +87,33 @@ typedef struct _STable_cellinfo {
} STable_cellinfo;
typedef struct _STable_rowinfo {
+ /* Each row may be displayed on many display lines, but we fix up
+ positions of cells on this display line only: */
int Line; /* lineno in doc (zero-based) */
int ncells; /* number of table cells */
-/* int pending_skip;*/ /* skip this many after finishing open cell */
+
+ /* What is the meaning of this?! It is set if:
+ [search for def of fixed_line below]
+
+ a1) a non-last cell is not at BOL,
+ a2) a non-last cell has something on the first line,
+ b) a >=3-lines-cell not at BOL, the first row non-empty, the 2nd empty;
+ c) a multiline cell not at BOL, the first row non-empty, the rest empty;
+ d) a multiline cell not at BOL, the first row non-empty;
+ e) a singleline non-empty cell not at BOL;
+
+ Summary: have seen a cell which is one of:
+ (Notation: B: at BOL; L: last; E: the first row is
non-empty)
+
+ bcde: !B && !E
+ a1: !L && !B
+ a2: !L && !E
+
+ Or: has at least two of !B, !L, !E, or: has at most one of B,L,E.
+
+ REMARK: If this variable is not set, but icell_core is, Line is
+ reset to the line of icell_core.
+ */
BOOL fixed_line; /* if we have a 'core' line of cells */
int allocated; /* number of table cells allocated */
STable_cellinfo * cells;
@@ -143,7 +190,7 @@ struct _STable_info {
PRIVATE int Stbl_finishCellInRow PARAMS((
STable_rowinfo * me,
STable_states * s,
- BOOL certain,
+ BOOL end_td,
int lineno,
int pos));
PRIVATE int Stbl_finishRowInTable PARAMS((
@@ -154,6 +201,8 @@ PUBLIC struct _STable_info * Stbl_startT
short, alignment)
{
STable_info *me = typecalloc(STable_info);
+
+ CTRACE((tfp, "TRST:Stbl_startTABLE(align=%d)\n", (int)alignment));
if (me) {
me->alignment = alignment;
me->rowgroup_align = HT_ALIGN_NONE;
@@ -175,6 +224,7 @@ PRIVATE void free_rowinfo ARGS1(
PUBLIC void Stbl_free ARGS1(
STable_info *, me)
{
+ CTRACE((tfp, "TRST:Stbl_free()\n"));
if (me && me->allocated_rows && me->rows) {
int i;
for (i = 0; i < me->allocated_rows; i++)
@@ -206,18 +256,24 @@ PRIVATE int Stbl_addCellToRow ARGS9(
int last_colspan = me->ncells ?
me->cells[me->ncells - 1].colspan : 1;
cellstate_t newstate;
+ int ret;
+ CTRACE((tfp, "TRST:Stbl_addCellToRow, line=%d, pos=%d, colspan=%d\n",
+ lineno, *ppos, colspan));
+ CTRACE((tfp, " ncells=%d, stateLine=%d, pending_len=%d, pstate=%s,
state=%s\n",
+ me->ncells, s->lineno, s->pending_len,
+ cellstate_s[s->prev_state+1], cellstate_s[s->state+1]));
if (me->ncells == 0)
s->prev_state = CS_invalid;
else if (s->prev_state == CS_invalid ||
- (/*s->state != CS_new && */ s->state != CS__0 &&
- s->state != CS__ef && s->state != CS__0f))
+ (/*s->state != CS__new && */ s->state != CS__0new &&
+ s->state != CS__ef && s->state != CS__0ef))
s->prev_state = s->state;
if (me->ncells == 0 || *ppos == 0)
- newstate = CS__0;
+ newstate = CS__0new;
else
- newstate = CS_new;
+ newstate = CS__new;
if (me->ncells > 0 && s->pending_len > 0) {
if (s->prev_state != CS__cbc)
@@ -231,21 +287,21 @@ PRIVATE int Stbl_addCellToRow ARGS9(
if (me->ncells == 0 || *ppos == 0) {
switch (s->prev_state) {
case CS_invalid:
- case CS__0:
+ case CS__0new:
case CS__0eb:
case CS__0cb:
- case CS__0f:
+ case CS__0ef:
case CS__0cf:
if (me->ncells > 0)
for (i = me->ncells + last_colspan - 2;
i >= me->ncells - 1; i--) {
me->cells[i].pos = *ppos;
- me->cells[i].Line = lineno;
+ me->cells[i].cLine = lineno;
}
me->Line = lineno;
/* s->lineno = lineno; */
break;
- case CS_new:
+ case CS__new:
case CS__eb:
case CS__ef:
case CS__cf:
@@ -255,31 +311,32 @@ PRIVATE int Stbl_addCellToRow ARGS9(
*ppos = me->cells[me->ncells - 1].pos +
me->cells[me->ncells - 1].len;
}
- } else {
+ } else { /* last cell multiline, ncells != 0, pos != 0 */
switch (s->prev_state) {
- case CS__0:
+ case CS__0new:
case CS__0eb:
- case CS__0f:
+ case CS__0ef:
+ /* Do not fail, but do not set fixed_line either */
break;
case CS__cb:
- return -1;
+ goto trace_and_fail;
case CS__cf:
/* HTAlert("foo woo!!"); */
- return -1;
+ goto trace_and_fail;
case CS__0cb:
case CS__0cf:
if (*ppos > me->cells[0].pos)
me->Line = lineno;
- me->fixed_line = YES;
+ me->fixed_line = YES; /* type=a def of fixed_line i */
break;
- case CS_new:
+ case CS__new:
case CS__eb:
case CS__ef:
default:
- me->fixed_line = YES;
+ me->fixed_line = YES; /* type=e def of fixed_line ii */
break;
case CS__cbc:
- return -1;
+ goto trace_and_fail;
}
}
}
@@ -288,7 +345,7 @@ PRIVATE int Stbl_addCellToRow ARGS9(
case CS__cb:
case CS__cf:
if (*ppos > 0)
- return -1;
+ goto trace_and_fail;
else
*ppos = me->cells[me->ncells - 1].pos /* == 0 */ +
me->cells[me->ncells - 1].len;
@@ -299,12 +356,12 @@ PRIVATE int Stbl_addCellToRow ARGS9(
*ppos = me->cells[me->ncells - 1].pos /* == 0 */ +
me->cells[me->ncells - 1].len;
break;
- case CS__0:
- case CS__0f:
+ case CS__0new:
+ case CS__0ef:
case CS__0eb:
/* me->Line = lineno; */
break;
- case CS_new:
+ case CS__new:
case CS__eb:
case CS__ef:
default:
@@ -323,10 +380,10 @@ PRIVATE int Stbl_addCellToRow ARGS9(
} else { /* lineno == s->lineno: */
switch (s->prev_state) {
case CS_invalid:
- case CS__0:
+ case CS__0new:
case CS__0eb: /* cannot happen */
case CS__0cb: /* cannot happen */
- case CS__0f:
+ case CS__0ef:
case CS__0cf: /* ##302?? set icell_core? or only in finish? */
break;
case CS__eb: /* cannot happen */
@@ -336,10 +393,10 @@ PRIVATE int Stbl_addCellToRow ARGS9(
case CS__ebc: /* should have done smth in finish */
case CS__cbc: /* should have done smth in finish */
break;
- case CS_new:
+ case CS__new:
case CS__cf:
if (me->fixed_line && me->Line != lineno) {
- return -1;
+ goto trace_and_fail;
} else {
me->fixed_line = YES;
me->Line = lineno;
@@ -356,10 +413,10 @@ PRIVATE int Stbl_addCellToRow ARGS9(
for (i = me->ncells + last_colspan - 2;
i >= 0; i--) {
me->cells[i].pos = *ppos;
- me->cells[i].Line = lineno;
+ me->cells[i].cLine = lineno;
}
me->Line = lineno;
- s->state = CS__0;
+ s->state = CS__0new;
}
if (*ppos > 0 && me->ncells > 0 &&
(me->cells[me->ncells - 1].pos > 0 ||
@@ -371,7 +428,7 @@ PRIVATE int Stbl_addCellToRow ARGS9(
if (me->fixed_line && lineno != me->Line) {
if (me->cells[me->ncells - 1].pos > 0 &&
me->cells[me->ncells - 1].len > 0) {
- return -1;
+ goto trace_and_fail;
} else if (me->cells[me->ncells - 1].pos == 0 &&
me->cells[me->ncells - 1].len > 0) {
if (*ppos > 0 && *ppos > me->cells[0].pos)
@@ -387,16 +444,16 @@ PRIVATE int Stbl_addCellToRow ARGS9(
}
#if 0
for (i = 0; i < me->ncells; i++) {
- if (me->cells[i].Line == lineno) {
+ if (me->cells[i].cLine == lineno) {
break;
} else if (me->cells[i].len <= 0) {
- me->cells[i].Line = lineno;
+ me->cells[i].cLine = lineno;
/* @@@ reset its pos too ?? */
} else {
break;
}
}
- if (i < me->ncells && me->cells[i].Line != lineno)
+ if (i < me->ncells && me->cells[i].cLine != lineno)
return -1;
me->Line = lineno;
#endif
@@ -430,12 +487,12 @@ PRIVATE int Stbl_addCellToRow ARGS9(
me->allocated += growby;
me->cells = cells;
} else {
- return -1;
+ goto trace_and_fail;
}
}
}
- me->cells[me->ncells].Line = lineno;
+ me->cells[me->ncells].cLine = lineno;
me->cells[me->ncells].pos = *ppos;
me->cells[me->ncells].len = -1;
me->cells[me->ncells].colspan = colspan;
@@ -453,7 +510,7 @@ PRIVATE int Stbl_addCellToRow ARGS9(
me->cells[me->ncells].alignment = isheader ? HT_CENTER : HT_LEFT;
}
for (i = me->ncells + 1; i < me->ncells + colspan; i++) {
- me->cells[i].Line = lineno;
+ me->cells[i].cLine = lineno;
me->cells[i].pos = *ppos;
me->cells[i].len = -1;
me->cells[i].colspan = 0;
@@ -461,7 +518,16 @@ PRIVATE int Stbl_addCellToRow ARGS9(
}
me->cells[me->ncells + colspan].pos = -1; /* not yet used */
me->ncells++;
- return (me->ncells - 1);
+
+ ret = me->ncells - 1;
+ trace_and_return:
+ CTRACE((tfp, " => prev_state=%s, state=%s, ret=%d\n",
+ cellstate_s[s->prev_state+1], cellstate_s[s->state+1], ret));
+ return (ret);
+
+ trace_and_fail:
+ ret = -1;
+ goto trace_and_return;
}
/* returns -1 on error, 0 otherwise */
@@ -474,6 +540,9 @@ PRIVATE int Stbl_reserveCellsInRow ARGS3
STable_cellinfo *cells;
int i;
int growby = icell + colspan - me->allocated;
+
+ CTRACE((tfp, "TRST:Stbl_reserveCellsInRow(icell=%d, colspan=%d\n",
+ icell, colspan));
if (growby > 0) {
cells = realloc(me->cells,
(me->allocated + growby)
@@ -489,7 +558,7 @@ PRIVATE int Stbl_reserveCellsInRow ARGS3
}
}
for (i = icell; i < icell + colspan; i++) {
- me->cells[i].Line = -1;
+ me->cells[i].cLine = -1;
me->cells[i].pos = -1;
me->cells[i].len = -1;
me->cells[i].colspan = 0;
@@ -499,29 +568,39 @@ PRIVATE int Stbl_reserveCellsInRow ARGS3
return 0;
}
+/* Returns -1 on failure. */
PRIVATE int Stbl_finishCellInRow ARGS5(
STable_rowinfo *, me,
STable_states *, s,
- BOOL, certain,
+ BOOL, end_td,
int, lineno,
int, pos)
{
STable_cellinfo *lastcell;
cellstate_t newstate = CS_invalid;
- BOOL broken = NO, empty;
+ BOOL multiline = NO, empty;
+ int ret;
+
+ CTRACE((tfp, "TRST:Stbl_finishCellInRow line=%d pos=%d end_td=%d ncells=%d
pnd_len=%d\n",
+ lineno, pos, (int)end_td, me->ncells, s->pending_len));
if (me->ncells <= 0)
return -1;
lastcell = me->cells + (me->ncells - 1);
- broken = (lineno != lastcell->Line || lineno != s->lineno);
- empty = broken ? (pos == 0) : (pos <= s->x_td);
- if (broken) {
- if (!certain) {
+ multiline = (lineno != lastcell->cLine || lineno != s->lineno);
+ empty = multiline ? (pos == 0) : (pos <= s->x_td);
+
+ CTRACE((tfp, " [lines: lastCell=%d state=%d multi=%d] empty=%d
(prev)state=(%s) %s\n",
+ lastcell->cLine, s->lineno, multiline, empty,
+ cellstate_s[s->prev_state+1], cellstate_s[s->state+1]));
+
+ if (multiline) {
+ if (!end_td) { /* processing line-break */
switch (s->state) {
case CS_invalid:
newstate = empty ? CS_invalid : CS__cbc;
break;
- case CS__0:
+ case CS__0new:
newstate = empty ? CS__0eb : CS__0cb;
break;
case CS__0eb:
@@ -529,38 +608,39 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
s->state = newstate;
if (me->fixed_line) {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : -1;
+ ret = (lastcell->len <= 0 ? 0 : -1);
} else {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : 0;
+ ret = (lastcell->len <= 0 ? 0 : 0);
}
+ goto trace_and_return;
case CS__0cb:
if (!me->fixed_line) {
if (empty) { /* ##462_return_0 */
/* if (s->icell_core == -1)
- s->icell_core = lastcell->Line; */ /* we don't know
yet */
- /* lastcell->Line = lineno; */
+ s->icell_core = lastcell->cLine; */ /* we don't
know yet */
+ /* lastcell->cLine = lineno; */
} else { /* !empty */
if (s->icell_core == -1)
me->Line = -1;
}
}
- if (s->pending_len && empty) { /* ##470_why_that?? */
- if ((me->fixed_line && me->Line == lastcell->Line) ||
+ if (s->pending_len && empty) { /* First line non-empty */
+ if ((me->fixed_line && me->Line == lastcell->cLine) ||
s->icell_core == me->ncells - 1)
lastcell->len = s->pending_len;
s->pending_len = 0;
} /* @@@ for empty do smth. about ->Line / ->icell_core !! */
newstate = empty ? CS__0cb : CS__cbc; /* ##474_needs_len!=-1? */
break;
- case CS__0f:
+ case CS__0ef:
case CS__0cf:
break;
- case CS_new:
+ case CS__new:
newstate = empty ? CS__eb : CS__cb;
break;
case CS__eb: /* ##484_set_pending_ret_0_if_empty? */
@@ -568,42 +648,46 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
s->state = newstate;
if (me->fixed_line) {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : -1;
+ ret = (lastcell->len <= 0 ? 0 : -1);
} else {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : -1;
+ ret = (lastcell->len <= 0 ? 0 : -1);
}
+ goto trace_and_return;
case CS__cb:
if (s->pending_len && empty) { /* ##496: */
lastcell->len = s->pending_len;
s->pending_len = 0;
} /* @@@ for empty do smth. about ->Line / ->icell_core !! */
+ ret = -1;
if (empty) {
if (!me->fixed_line) {
- me->fixed_line = YES;
- me->Line = lastcell->Line; /* should've happened in
break */
+ me->fixed_line = YES; /* type=b def of fixed_line i */
+ me->Line = lastcell->cLine; /* should've happened in
break */
} else {
- if (me->Line != lastcell->Line)
- return -1;
+ if (me->Line != lastcell->cLine)
+ goto trace_and_return;
}
} else {
if (!me->fixed_line) {
- me->fixed_line = YES;
- me->Line = lastcell->Line; /* should've happened in
break */
+ me->fixed_line = YES; /* type=b def of fixed_line ii */
+ me->Line = lastcell->cLine; /* should've happened in
break */
}
s->state = CS__cbc;
- return -1;
+ goto trace_and_return;
}
newstate = empty ? CS__cb : CS__cbc;
break;
case CS__ef:
- return 0;
+ ret = 0;
+ goto trace_and_return;
case CS__cf:
- return lastcell->len; /* ##523_change_state? */
+ ret = lastcell->len; /* ##523_change_state? */
+ goto trace_and_return;
case CS__cbc:
if (!me->fixed_line) {
if (empty) {
@@ -621,7 +705,7 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
default:
break;
}
- } else { /* broken, certain: */
+ } else { /* multiline cell, processing </TD>: */
s->x_td = -1;
switch (s->state) {
case CS_invalid:
@@ -629,29 +713,31 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
if (!empty && lastcell->len > 0) {
newstate = CS__0cf;
s->state = newstate;
- return -1;
+ ret = -1;
+ goto trace_and_return;
}
/* ##541_set_len_0_Line_-1_sometimes: */
lastcell->len = 0;
- lastcell->Line = -1;
+ lastcell->cLine = -1;
/* fall thru ##546 really fall thru??: */
newstate = empty ? CS_invalid : CS__cbc; break;
- case CS__0:
- newstate = empty ? CS__0f : CS__0cf; break;
+ case CS__0new:
+ newstate = empty ? CS__0ef : CS__0cf; break;
case CS__0eb:
- newstate = empty ? CS__0f : CS__0cf; /* ebc?? */
+ newstate = empty ? CS__0ef : CS__0cf; /* ebc?? */
s->state = newstate;
if (me->fixed_line) {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : -1;
+ ret = (lastcell->len <= 0 ? 0 : -1);
} else {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : 0;
+ ret = (lastcell->len <= 0 ? 0 : 0);
}
+ goto trace_and_return;
case CS__0cb:
if (s->pending_len) {
if (empty)
@@ -663,8 +749,9 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
if (!me->fixed_line) {
if (empty) {
if (s->icell_core == -1)
+ /* first cell before <BR></TD> => the core cell */
s->icell_core = me->ncells - 1;
- /* lastcell->Line = lineno; */
+ /* lastcell->cLine = lineno; */
} else { /* !empty */
if (s->icell_core == -1)
me->Line = -1;
@@ -675,42 +762,44 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
s->pending_len = 0;
} /* @@@ for empty do smth. about ->Line / ->icell_core !! */
newstate = empty ? CS__0cf : CS__cbc; break;
- case CS__0f:
- newstate = CS__0f;
+ case CS__0ef:
+ newstate = CS__0ef;
/* FALLTHRU */
case CS__0cf:
break;
- case CS_new:
+ case CS__new:
newstate = empty ? CS__ef : CS__cf; break;
case CS__eb:
newstate = empty ? CS__ef : CS__ef; /* ##579??? !!!!! */
s->state = newstate;
if (me->fixed_line) {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : -1;
+ ret = (lastcell->len <= 0 ? 0 : -1);
} else {
if (empty)
- return lastcell->len <= 0 ? 0 : lastcell->len;
+ ret = (lastcell->len <= 0 ? 0 : lastcell->len);
else
- return lastcell->len <= 0 ? 0 : -1;
+ ret = (lastcell->len <= 0 ? 0 : -1);
}
+ goto trace_and_return;
case CS__cb:
if (s->pending_len && empty) {
lastcell->len = s->pending_len;
s->pending_len = 0;
}
+ ret = -1;
if (empty) {
if (!me->fixed_line) {
- me->fixed_line = YES;
- me->Line = lastcell->Line; /* should've happened in
break */
+ me->fixed_line = YES; /* type=c def of fixed_line */
+ me->Line = lastcell->cLine; /* should've happened in
break */
} else {
- if (me->Line != lastcell->Line)
- return -1;
+ if (me->Line != lastcell->cLine)
+ goto trace_and_return;
}
} else {
- return -1;
+ goto trace_and_return;
}
newstate = empty ? CS__cf : CS__cbc; break;
case CS__ef: /* ignored error */
@@ -721,15 +810,16 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
if (!me->fixed_line) {
if (!empty) {
if (s->icell_core == -1)
- lastcell->Line = -1;
+ lastcell->cLine = -1;
}
}
s->pending_len = 0;
newstate = empty ? CS_invalid : CS__cbc; break;
case CS__cbc: /* ##586 */
lastcell->len = 0; /* ##613 */
- if (me->fixed_line && me->Line == lastcell->Line)
- return -1;
+ ret = -1;
+ if (me->fixed_line && me->Line == lastcell->cLine)
+ goto trace_and_return;
if (!me->fixed_line) {
if (empty) {
if (s->icell_core == -1)
@@ -746,93 +836,102 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
newstate = empty ? CS_invalid : CS__cbc; break;
}
}
- } else { /* (!broken) */
- if (!certain) {
+ } else { /* (!multiline) */
+ if (!end_td) { /* processing line-break */
switch (s->state) {
case CS_invalid:
- case CS__0:
+ case CS__0new:
s->pending_len = empty ? 0 : pos - lastcell->pos;
newstate = empty ? CS__0eb : CS__0cb;
s->state = newstate;
- return 0; /* or 0 for xlen to s->pending_len?? */
+ ret = 0; /* or 0 for xlen to s->pending_len?? */
+ goto trace_and_return;
case CS__0eb: /* cannot happen */
newstate = CS__eb;
break;
case CS__0cb: /* cannot happen */
newstate = CS__cb;
break;
- case CS__0f:
+ case CS__0ef:
case CS__0cf:
break;
- case CS_new:
+ case CS__new:
+ ret = -1;
if (!empty && s->prev_state == CS__cbc) /* ##609: */
- return -1;
+ goto trace_and_return;
if (!empty) {
if (!me->fixed_line) {
- me->fixed_line = YES;
+ me->fixed_line = YES; /* type=d def of fixed_line */
me->Line = lineno;
} else {
if (me->Line != lineno)
- return -1;
+ goto trace_and_return;
}
}
newstate = empty ? CS__eb : CS__cb;
s->state = newstate;
if (!me->fixed_line) {
s->pending_len = empty ? 0 : pos - lastcell->pos;
- return 0;
+ ret = 0;
+ goto trace_and_return;
} else {
s->pending_len = 0;
lastcell->len = empty ? 0 : pos - lastcell->pos;
- return lastcell->len;
+ ret = lastcell->len;
+ goto trace_and_return;
}
case CS__eb: /* cannot happen */
newstate = empty ? CS__eb : CS__ebc; break;
case CS__cb: /* cannot happen */
newstate = empty ? CS__cb : CS__cbc; break;
case CS__ef:
- return 0;
+ ret = 0;
+ goto trace_and_return;
case CS__cf:
- return lastcell->len;
+ ret = lastcell->len;
+ goto trace_and_return;
case CS__cbc: /* ??? */
break;
default:
break;
}
- } else { /* !broken, certain: */
+ } else { /* !multiline, processing </TD>: */
s->x_td = -1;
switch (s->state) {
case CS_invalid: /* ##691_no_lastcell_len_for_invalid: */
- if (!(me->fixed_line && me->Line == lastcell->Line))
+ if (!(me->fixed_line && me->Line == lastcell->cLine))
lastcell->len = 0;
/* FALLTHRU */
- case CS__0:
- newstate = empty ? CS__0f : CS__0cf; break; /* ##630 */
+ case CS__0new:
+ newstate = empty ? CS__0ef : CS__0cf; break; /* ##630 */
case CS__0eb:
- newstate = empty ? CS__0f : CS__0f; break; /* ??? */
+ newstate = empty ? CS__0ef : CS__0ef; break; /* ??? */
case CS__0cb:
newstate = empty ? CS__0cf : CS__cbc; break; /* ??? */
- case CS__0f:
- newstate = CS__0f; break; /* ??? */
+ case CS__0ef:
+ newstate = CS__0ef; break; /* ??? */
case CS__0cf:
break; /* ??? */
- case CS_new:
+ case CS__new:
+ ret = -1;
if (!empty && s->prev_state == CS__cbc)
- return -1;
+ goto trace_and_return;
if (!empty) { /* ##642_set_fixed!: */
if (!me->fixed_line) {
- me->fixed_line = YES;
+ me->fixed_line = YES; /* type=e def of fixed_line */
me->Line = lineno;
} else {
if (me->Line != lineno)
- return -1;
+ goto trace_and_return;
}
}
if (lastcell->len < 0)
lastcell->len = empty ? 0 : pos - lastcell->pos;
newstate = empty ? CS__ef : CS__cf;
s->state = newstate;
- return (me->fixed_line && lineno != me->Line) ? -1 :
lastcell->len;
+ ret = ((me->fixed_line && lineno != me->Line)
+ ? -1 : lastcell->len);
+ goto trace_and_return;
case CS__eb:
newstate = empty ? CS__ef : CS__cf; break; /* ??? */
case CS__cb:
@@ -843,11 +942,11 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
break;
}
lastcell->len = pos - lastcell->pos;
- } /* if (!certain) ... else */
- } /* if (broken) ... else */
+ } /* if (!end_td) ... else */
+ } /* if (multiline) ... else */
#if 0 /* MEGA_COMMENTOUT */
- if (lineno != me->cells[0].Line) {
+ if (lineno != me->cells[0].cLine) {
#if 0
int i;
for (i = ncells - 1; i >= 0; i--) {
@@ -855,7 +954,7 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
break;
}
#endif
- if (lineno >= lastcell->Line) {
+ if (lineno >= lastcell->cLine) {
if (me->fixed_line) {
if (pos == 0) {
if (lastcell->len <= 0) {
@@ -864,7 +963,7 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
return lastcell->len;
}
} else { /* pos != 0 */
- if (lastcell->len <= 0 && lineno > lastcell->Line &&
lastcell->Line <= me->Line) {
+ if (lastcell->len <= 0 && lineno > lastcell->cLine &&
lastcell->cLine <= me->Line) {
return 0;
} else {
return -1;
@@ -892,8 +991,13 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
}
#endif /* MEGA_COMMENTOUT */
s->state = newstate;
+ ret = lastcell->len;
+
/* lastcell->len = pos - lastcell->pos; */
- return (lastcell->len);
+ trace_and_return:
+ CTRACE((tfp, " => prev_state=%s, state=%s, return=%d\n",
+ cellstate_s[s->prev_state+1], cellstate_s[s->state+1], ret));
+ return ret;
}
/*
@@ -914,6 +1018,8 @@ PRIVATE int Stbl_reserveCellsInTable ARG
if (me->nrows <= 0)
return -1; /* must already have at least one row */
+ CTRACE((tfp, "TRST:Stbl_reserveCellsInTable(icell=%d, colspan=%d,
rowspan=%d)\n",
+ icell, colspan, rowspan));
if (rowspan == 0) {
if (!me->rowspans2eog.cells) {
me->rowspans2eog.cells = typecallocn(STable_cellinfo, icell +
colspan);
@@ -974,6 +1080,7 @@ PRIVATE void Stbl_cancelRowSpans ARGS1(
STable_info *, me)
{
int i;
+ CTRACE((tfp, "TRST:Stbl_cancelRowSpans()"));
for (i = me->nrows; i < me->allocated_rows; i++) {
if (!me->rows[i].ncells) { /* should always be the case */
FREE(me->rows[i].cells);
@@ -994,12 +1101,15 @@ PUBLIC int Stbl_addRowToTable ARGS3(
{
STable_rowinfo *rows, *row;
STable_states * s = &me->s;
+
+ CTRACE((tfp, "TRST:Stbl_addRowToTable(alignment=%d, lineno=%d)\n",
+ alignment, lineno));
if (me->nrows > 0 && me->rows[me->nrows-1].ncells > 0) {
if (s->pending_len > 0)
me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].len =
s->pending_len;
s->pending_len = 0;
/* if (me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].len
>= 0 &&
- me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].Line
== lineno)
+ me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].cLine
== lineno)
Stbl_finishCellInTable(me, YES,
lineno,
me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells -
1].pos +
@@ -1086,6 +1196,8 @@ PRIVATE int Stbl_finishRowInTable ARGS1(
STable_rowinfo *lastrow;
STable_states * s = &me->s;
int ncells;
+
+ CTRACE((tfp, "TRST:Stbl_finishRowInTable()\n"));
if (!me->rows || !me->nrows)
return -1; /* no row started! */
lastrow = me->rows + (me->nrows - 1);
@@ -1102,8 +1214,8 @@ PRIVATE int Stbl_finishRowInTable ARGS1(
if (lastrow->Line == -1 && s->icell_core >= 0)
#endif
if (s->icell_core >= 0 && !lastrow->fixed_line &&
- lastrow->cells[s->icell_core].Line >= 0)
- lastrow->Line = lastrow->cells[s->icell_core].Line;
+ lastrow->cells[s->icell_core].cLine >= 0)
+ lastrow->Line = lastrow->cells[s->icell_core].cLine;
s->icell_core = -1;
return (me->nrows);
}
@@ -1169,7 +1281,7 @@ PRIVATE int get_remaining_colspan ARGS5(
ncols_sofar - (me->ncells + last_colspan - 1));
} else {
for (i = me->ncells + last_colspan - 1; i < ncolinfo - 1; i++)
- if (colinfo[i].Line == EOCOLG)
+ if (colinfo[i].cLine == EOCOLG)
break;
colspan = i - (me->ncells + last_colspan - 2);
}
@@ -1196,6 +1308,8 @@ PUBLIC int Stbl_addCellToTable ARGS7(
int prevsumpos, advance;
#endif
+ CTRACE((tfp, "TRST:Stbl_addCellToTable(lineno=%d, pos=%d, isheader=%d,
cs=%d, rs=%d, al=%d)\n",
+ lineno, pos, (int)isheader, colspan,rowspan,alignment));
if (!me->rows || !me->nrows)
return -1; /* no row started! */
/* ##850_fail_if_fail?? */
@@ -1237,7 +1351,7 @@ PUBLIC int Stbl_addCellToTable ARGS7(
sumcol->pos = sumcols[me->allocated_sumcols-1].pos;
sumcol->len = 0;
sumcol->colspan = 0;
- sumcol->Line = 0;
+ sumcol->cLine = 0;
sumcol->alignment = HT_ALIGN_NONE;
}
}
@@ -1303,7 +1417,7 @@ PUBLIC int Stbl_addCellToTable ARGS7(
*/
PUBLIC int Stbl_finishCellInTable ARGS4(
STable_info *, me,
- BOOL, certain,
+ BOOL, end_td,
int, lineno,
int, pos)
{
@@ -1311,6 +1425,9 @@ PUBLIC int Stbl_finishCellInTable ARGS4(
STable_rowinfo *lastrow;
int len, xlen, icell;
int i;
+
+ CTRACE((tfp, "TRST:Stbl_finishCellInTable(lineno=%d, pos=%d, end_td=%d)\n",
+ lineno, pos, (int)end_td));
if (me->nrows == 0)
return -1;
lastrow = me->rows + (me->nrows - 1);
@@ -1318,8 +1435,8 @@ PUBLIC int Stbl_finishCellInTable ARGS4(
if (icell < 0)
return icell;
if (s->x_td == -1)
- return certain ? -1 : 0;
- len = Stbl_finishCellInRow(lastrow, s, certain, lineno, pos);
+ return end_td ? -1 : 0;
+ len = Stbl_finishCellInRow(lastrow, s, end_td, lineno, pos);
if (len == -1)
return len;
xlen = (len > 0) ? len : s->pending_len; /* ##890 use xlen if fixed_line?:
*/
@@ -1436,12 +1553,14 @@ PUBLIC int Stbl_addColInfo ARGS4(
STable_cellinfo *sumcols, *sumcol;
int i, icolinfo;
+ CTRACE((tfp, "TRST:Stbl_addColInfo(cs=%d, al=%d, isgroup=%d)\n",
+ colspan, alignment, (int)isgroup));
if (isgroup) {
if (me->pending_colgroup_next > me->ncolinfo)
me->ncolinfo = me->pending_colgroup_next;
me->pending_colgroup_next = me->ncolinfo + colspan;
if (me->ncolinfo > 0)
- me->sumcols[me->ncolinfo - 1].Line = EOCOLG;
+ me->sumcols[me->ncolinfo - 1].cLine = EOCOLG;
me->pending_colgroup_align = alignment;
} else {
for (i = me->pending_colgroup_next - 1;
@@ -1469,7 +1588,7 @@ PUBLIC int Stbl_addColInfo ARGS4(
sumcol->pos = sumcols[me->allocated_sumcols-1].pos;
sumcol->len = 0;
sumcol->colspan = 0;
- sumcol->Line = 0;
+ sumcol->cLine = 0;
}
}
if (sumcols) {
@@ -1495,10 +1614,11 @@ PUBLIC int Stbl_addColInfo ARGS4(
PUBLIC int Stbl_finishColGroup ARGS1(
STable_info *, me)
{
+ CTRACE((tfp, "TRST:Stbl_finishColGroup()\n"));
if (me->pending_colgroup_next >= me->ncolinfo) {
me->ncolinfo = me->pending_colgroup_next;
if (me->ncolinfo > 0)
- me->sumcols[me->ncolinfo - 1].Line = EOCOLG;
+ me->sumcols[me->ncolinfo - 1].cLine = EOCOLG;
}
me->pending_colgroup_next = 0;
me->pending_colgroup_align = HT_ALIGN_NONE;
@@ -1509,6 +1629,7 @@ PUBLIC int Stbl_addRowGroup ARGS2(
STable_info *, me,
short, alignment)
{
+ CTRACE((tfp, "TRST:Stbl_addRowGroup()\n"));
Stbl_cancelRowSpans(me);
me->rowgroup_align = alignment;
return 0; /* that's all! */
@@ -1521,6 +1642,7 @@ PUBLIC int Stbl_finishTABLE ARGS1(
int i;
int curpos = 0;
+ CTRACE((tfp, "TRST:Stbl_finishTABLE()\n"));
if (!me || me->nrows <= 0 || me->ncols <= 0) {
return -1;
}
@@ -1530,7 +1652,7 @@ PUBLIC int Stbl_finishTABLE ARGS1(
s->pending_len = 0;
/* if (me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].len
>= 0)
Stbl_finishCellInTable(me, YES,
- me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells -
1].Line,
+ me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells -
1].cLine,
me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells -
1].pos +
me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells -
1].len); */
}
@@ -1575,8 +1697,8 @@ PRIVATE int get_fixup_positions ARGS4(
return -1;
while (i < me->ncells) {
next_i = i + HTMAX(1, me->cells[i].colspan);
- if (me->cells[i].Line != me->Line) {
- if (me->cells[i].Line > me->Line)
+ if (me->cells[i].cLine != me->Line) {
+ if (me->cells[i].cLine > me->Line)
break;
i = next_i;
continue;
; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- lynx-dev [PATCH 2.8.4dev.10] Trace/document TRST code,
Ilya Zakharevich <=