X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2Flibhtml%2Fbuild.c;h=b0484c261597fbf77ae998beed7712334a1457ce;hb=47c188c0c6c2a013aded790bcaa5c9640955e38b;hp=7855d8bdeb4961ce1813e4e4f4716b6a50efb829;hpb=a9060cc06bee66e12fe16644511f181a4b0cdbd3;p=plan9front.git diff --git a/sys/src/libhtml/build.c b/sys/src/libhtml/build.c index 7855d8bde..b0484c261 100644 --- a/sys/src/libhtml/build.c +++ b/sys/src/libhtml/build.c @@ -7,7 +7,7 @@ // A stack for holding integer values enum { - Nestmax = 40 // max nesting level of lists, font styles, etc. + Nestmax = 256 // max nesting level of lists, font styles, etc. }; struct Stack { @@ -54,6 +54,7 @@ struct ItemSource int ntables; int nanchors; int nframes; + Formfield* curfield; Form* curform; Map* curmap; Table* tabstk; @@ -274,7 +275,7 @@ static Anchor* newanchor(int index, Rune* name, Rune* href, int target, Anchor* static Area* newarea(int shape, Rune* href, int target, Area* link); static DestAnchor* newdestanchor(int index, Rune* name, Item* item, DestAnchor* link); static Docinfo* newdocinfo(void); -static Genattr* newgenattr(Rune* id, Rune* class, Rune* style, Rune* title, Attr* events); +static Genattr* newgenattr(Rune* id, Rune* class, Rune* style, Rune* title, SEvent* events); static Form* newform(int formid, Rune* name, Rune* action, int target, int method, Form* link); static Formfield* newformfield(int ftype, int fieldid, Form* form, Rune* name, @@ -358,6 +359,7 @@ newitemsource(Docinfo* di) is->ntables = 0; is->nanchors = 0; is->nframes = 0; + is->curfield = nil; is->curform = nil; is->curmap = nil; is->tabstk = nil; @@ -365,6 +367,62 @@ newitemsource(Docinfo* di) return is; } +static void +linkitems(Docinfo *di, Item *it) +{ + Formfield *ff; + Tablecell *c; + Table *tt; + + while(it != nil){ + switch(it->tag) { + case Iimagetag: + /* link image to docinfo */ + ((Iimage*)it)->nextimage = di->images; + di->images = (Iimage*)it; + break; + case Iformfieldtag: + /* link formfield to form */ + ff = ((Iformfield*)it)->formfield; + if(ff != nil && ff->form != nil){ + for(ff = ff->form->fields; ff != nil; ff = ff->next){ + if(ff == ((Iformfield*)it)->formfield) + goto Next; + if(ff->next == nil) + break; + } + ((Iformfield*)it)->formfield->next = nil; + if(ff != nil){ + ff->next = ((Iformfield*)it)->formfield; + ff = ff->next; + } else { + ff = ((Iformfield*)it)->formfield; + ff->form->fields = ff; + } + linkitems(di, ff->image); + } + break; + case Itabletag: + /* link table to docinfo */ + tt = ((Itable*)it)->table; + if(tt == nil) + break; + tt->tabletok = nil; + tt->next = di->tables; + di->tables = tt; + linkitems(di, tt->caption); + for(c = tt->cells; c != nil; c = c->next) + linkitems(di, c->content); + break; + case Ifloattag: + linkitems(di, ((Ifloat*)it)->item); + break; + } + Next: + it = it->next; + } +} + static Item *getitems(ItemSource* is, uchar* data, int datalen); // Parse an html document and create a list of layout items. @@ -453,7 +511,6 @@ getitems(ItemSource* is, uchar* data, int datalen) Rune* script; Map* map; Form* frm; - Iimage* ii; Kidinfo* kd; Kidinfo* ks; Kidinfo* pks; @@ -694,12 +751,8 @@ getitems(ItemSource* is, uchar* data, int datalen) bgurl = aurlval(tok, Abackground, nil, di->base); if(bgurl != nil) { if(di->backgrounditem != nil) - freeitem((Item*)di->backgrounditem); - // really should remove old item from di->images list, - // but there should only be one BODY element ... + freeitem(di->backgrounditem); di->backgrounditem = (Iimage*)newiimage(bgurl, nil, ALnone, 0, 0, 0, 0, 0, 0, nil); - di->backgrounditem->nextimage = di->images; - di->images = di->backgrounditem; } ps->curbg = bg; di->background = bg; @@ -747,8 +800,11 @@ getitems(ItemSource* is, uchar* data, int datalen) fprint(2, "warning: unexpected \n"); continue; } + if(curtab->caption != nil) + freeitems(curtab->caption); curtab->caption = ps->items->next; - free(ps); + ps->items->next = nil; + freepstate(ps); ps = nextps; break; @@ -893,8 +949,6 @@ getitems(ItemSource* is, uchar* data, int datalen) fprint(2, "warning: unexpected \n"); continue; } - // put fields back in input order - is->curform->fields = (Formfield*)_revlist((List*)is->curform->fields); is->curform = nil; break; @@ -1083,10 +1137,6 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->skipwhite = 0; additem(ps, img, tok); } - if(!ps->skipping) { - ((Iimage*)img)->nextimage = di->images; - di->images = (Iimage*)img; - } ps->curanchor = oldcuranchor; break; @@ -1098,7 +1148,7 @@ getitems(ItemSource* is, uchar* data, int datalen) fprint(2, " not inside