static void lattr_st(struct lattr_db *db, ptrdiff_t line, HIGHLIGHT_STATE *state) { HIGHLIGHT_STATE *st = lattr_gt(db, line); *st = *state; }
HIGHLIGHT_STATE lattr_get(struct lattr_db *db, struct high_syntax *y, P *p, ptrdiff_t line) { /* Past end of file? */ if (line > p->b->eof->line) { HIGHLIGHT_STATE x; clear_state(&x); return x; } /* Check if we need to expand */ if (line >= lattr_size(db)) { /* Expand by this amount */ ptrdiff_t amnt = line - lattr_size(db) + 1; /* Set position to end */ lattr_hole(db, lattr_size(db)); lattr_check(db, amnt); db->ehole -= amnt; /* Set invalid window to cover new space */ if (db->invalid_window == -1) { db->first_invalid = lattr_size(db) - amnt; db->invalid_window = amnt; } else { db->invalid_window = lattr_size(db) - db->first_invalid; } } /* Check if we need to shrink */ /* if (p->b->eof->line + 1 < lattr_size(db)) { lattr_hole(db, p->b->eof->line + 1); db->ehole = db->end; if (db->first_invalid > lattr_size(db)) { db->first_invalid = lattr_size(db); db->invalid_window = -1; } if (db->invalid_window != -1 && db->first_invalid + db->invalid_window > lattr_size(db)) { db->invalid_window = lattr_size(db) - db->first_invalid; } } */ /* Check if we are pointing to a valid record */ if (line >= db->first_invalid) { ptrdiff_t ln; P *tmp = 0; HIGHLIGHT_STATE state; tmp = pdup(p, "lattr_get"); ln = db->first_invalid; /* First line with known good state */ state = lattr_lvalue(db, ln - 1); /* Known good state */ /* Compute up to requested line */ pline(tmp, ln - 1); /* Recompute everything in invalid window */ while (ln < db->first_invalid + db->invalid_window) { state = parse(y, tmp, state, p->b->o.charmap); lattr_st(db, ln, &state); ++ln; } /* Update invalid window: hopefully we did the whole window */ db->invalid_window -= ln - db->first_invalid; db->first_invalid = ln; /* Recompute until match found. If match is found, we can assume rest is valid */ while (ln < lattr_size(db)) { HIGHLIGHT_STATE *prev; state = parse(y, tmp, state, p->b->o.charmap); prev = lattr_gt(db, ln); if (!eq_state(prev, &state)) lattr_st(db, ln, &state); else { db->first_invalid = lattr_size(db); db->invalid_window = -1; ++ln; break; } ++ln; } /* Update invalid pointer */ if (ln > db->first_invalid) { db->first_invalid = ln; db->invalid_window = 0; } if (ln == lattr_size(db)) { db->first_invalid = ln; db->invalid_window = -1; } prm(tmp); } /* Check it */ #ifdef junk { HIGHLIGHT_STATE st; P *tmp =pdup(p, "lattr_get"); pline(tmp, 0); clear_state(&st); for (z = 0; z != db->first_invalid; ++z) { HIGHLIGHT_STATE *prev; prev = lattr_gt(db, z); if (prev->state != st.state) { printf("** Mismatch!! %d %d %d %d **\n",z,tmp->line,prev->state,st.state); abort(); } st = parse(y, tmp, st, p->b->o.charmap); } prm(tmp); } #endif /* Return with attribute */ return lattr_lvalue(db, line); }
void lattr_st(struct lattr_db *db, long line, HIGHLIGHT_STATE *state) { HIGHLIGHT_STATE *st = lattr_gt(db, line); *st = *state; }