diff options
author | rsc <devnull@localhost> | 2006-04-01 19:24:03 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2006-04-01 19:24:03 +0000 |
commit | cbeb0b26e4c7caa8d1b47de791a7418dc20a4567 (patch) | |
tree | e0f7e445de1aa22a42ef873dc4b1118a8105ae93 /src/libhtml | |
parent | 226d80b8213821af0cbf092d1507c52b504fd368 (diff) | |
download | plan9port-cbeb0b26e4c7caa8d1b47de791a7418dc20a4567.tar.gz plan9port-cbeb0b26e4c7caa8d1b47de791a7418dc20a4567.tar.bz2 plan9port-cbeb0b26e4c7caa8d1b47de791a7418dc20a4567.zip |
Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms.
Diffstat (limited to 'src/libhtml')
-rw-r--r-- | src/libhtml/build.c | 656 | ||||
-rw-r--r-- | src/libhtml/impl.h | 34 | ||||
-rw-r--r-- | src/libhtml/lex.c | 226 | ||||
-rw-r--r-- | src/libhtml/runetab.h | 2 | ||||
-rw-r--r-- | src/libhtml/strinttab.c | 16 | ||||
-rw-r--r-- | src/libhtml/utils.c | 116 |
6 files changed, 526 insertions, 524 deletions
diff --git a/src/libhtml/build.c b/src/libhtml/build.c index 7cae15d4..c65918c2 100644 --- a/src/libhtml/build.c +++ b/src/libhtml/build.c @@ -5,45 +5,45 @@ #include <html.h> #include "impl.h" -// A stack for holding integer values +/* A stack for holding integer values */ enum { - Nestmax = 40 // max nesting level of lists, font styles, etc. + Nestmax = 40 /* max nesting level of lists, font styles, etc. */ }; struct Stack { - int n; // next available slot (top of stack is stack[n-1]) - int slots[Nestmax]; // stack entries + int n; /* next available slot (top of stack is stack[n-1]) */ + int slots[Nestmax]; /* stack entries */ }; -// Parsing state +/* Parsing state */ struct Pstate { - Pstate* next; // in stack of Pstates - int skipping; // true when we shouldn't add items - int skipwhite; // true when we should strip leading space - int curfont; // font index for current font - int curfg; // current foreground color - Background curbg; // current background - int curvoff; // current baseline offset - uchar curul; // current underline/strike state - uchar curjust; // current justify state - int curanchor; // current (href) anchor id (if in one), or 0 - int curstate; // current value of item state - int literal; // current literal state - int inpar; // true when in a paragraph-like construct - int adjsize; // current font size adjustment - Item* items; // dummy head of item list we're building - Item* lastit; // tail of item list we're building - Item* prelastit; // item before lastit - Stack fntstylestk; // style stack - Stack fntsizestk; // size stack - Stack fgstk; // text color stack - Stack ulstk; // underline stack - Stack voffstk; // vertical offset stack - Stack listtypestk; // list type stack - Stack listcntstk; // list counter stack - Stack juststk; // justification stack - Stack hangstk; // hanging stack + Pstate* next; /* in stack of Pstates */ + int skipping; /* true when we shouldn't add items */ + int skipwhite; /* true when we should strip leading space */ + int curfont; /* font index for current font */ + int curfg; /* current foreground color */ + Background curbg; /* current background */ + int curvoff; /* current baseline offset */ + uchar curul; /* current underline/strike state */ + uchar curjust; /* current justify state */ + int curanchor; /* current (href) anchor id (if in one), or 0 */ + int curstate; /* current value of item state */ + int literal; /* current literal state */ + int inpar; /* true when in a paragraph-like construct */ + int adjsize; /* current font size adjustment */ + Item* items; /* dummy head of item list we're building */ + Item* lastit; /* tail of item list we're building */ + Item* prelastit; /* item before lastit */ + Stack fntstylestk; /* style stack */ + Stack fntsizestk; /* size stack */ + Stack fgstk; /* text color stack */ + Stack ulstk; /* underline stack */ + Stack voffstk; /* vertical offset stack */ + Stack listtypestk; /* list type stack */ + Stack listcntstk; /* list counter stack */ + Stack juststk; /* justification stack */ + Stack hangstk; /* hanging stack */ }; struct ItemSource @@ -60,23 +60,23 @@ struct ItemSource Kidinfo* kidstk; }; -// Some layout parameters +/* Some layout parameters */ enum { - FRKIDMARGIN = 6, // default margin around kid frames - IMGHSPACE = 0, // default hspace for images (0 matches IE, Netscape) - IMGVSPACE = 0, // default vspace for images - FLTIMGHSPACE = 2, // default hspace for float images - TABSP = 5, // default cellspacing for tables - TABPAD = 1, // default cell padding for tables - LISTTAB = 1, // number of tabs to indent lists - BQTAB = 1, // number of tabs to indent blockquotes - HRSZ = 2, // thickness of horizontal rules - SUBOFF = 4, // vertical offset for subscripts - SUPOFF = 6, // vertical offset for superscripts - NBSP = 160 // non-breaking space character + FRKIDMARGIN = 6, /* default margin around kid frames */ + IMGHSPACE = 0, /* default hspace for images (0 matches IE, Netscape) */ + IMGVSPACE = 0, /* default vspace for images */ + FLTIMGHSPACE = 2, /* default hspace for float images */ + TABSP = 5, /* default cellspacing for tables */ + TABPAD = 1, /* default cell padding for tables */ + LISTTAB = 1, /* number of tabs to indent lists */ + BQTAB = 1, /* number of tabs to indent blockquotes */ + HRSZ = 2, /* thickness of horizontal rules */ + SUBOFF = 4, /* vertical offset for subscripts */ + SUPOFF = 6, /* vertical offset for superscripts */ + NBSP = 160 /* non-breaking space character */ }; -// These tables must be sorted +/* These tables must be sorted */ static StringInt *align_tab; static AsciiInt _align_tab[] = { {"baseline", ALbaseline}, @@ -147,7 +147,7 @@ static char* _roman[15]= { }; #define NROMAN 15 -// List number types +/* List number types */ enum { LTdisc, LTsquare, LTcircle, LT1, LTa, LTA, LTi, LTI }; @@ -159,11 +159,11 @@ enum { BLBA = (BL|SPBefore|SPAfter) }; -// blockbrk[tag] is break info for a block level element, or one -// of a few others that get the same treatment re ending open paragraphs -// and requiring a line break / vertical space before them. -// If we want a line of space before the given element, SPBefore is OR'd in. -// If we want a line of space after the given element, SPAfter is OR'd in. +/* blockbrk[tag] is break info for a block level element, or one */ +/* of a few others that get the same treatment re ending open paragraphs */ +/* and requiring a line break / vertical space before them. */ +/* If we want a line of space before the given element, SPBefore is OR'd in. */ +/* If we want a line of space after the given element, SPAfter is OR'd in. */ static uchar blockbrk[Numtags]= { /*Notfound*/ 0, @@ -268,8 +268,8 @@ enum { AGEN = 1 }; -// attrinfo is information about attributes. -// The AGEN value means that the attribute is generic (applies to almost all elements) +/* attrinfo is information about attributes. */ +/* The AGEN value means that the attribute is generic (applies to almost all elements) */ static uchar attrinfo[Numattrs]= { /*Aabbr*/ 0, /*Aaccept_charset*/ 0, @@ -508,7 +508,7 @@ static uchar scriptev[Numattrs]= { /*Awidth*/ 0, }; -// Color lookup table +/* Color lookup table */ static StringInt *color_tab; static AsciiInt _color_tab[] = { {"aqua", 0x00FFFF}, @@ -691,11 +691,11 @@ newitemsource(Docinfo* di) static Item *getitems(ItemSource* is, uchar* data, int datalen); -// Parse an html document and create a list of layout items. -// Allocate and return document info in *pdi. -// When caller is done with the items, it should call -// freeitems on the returned result, and then -// freedocinfo(*pdi). +/* Parse an html document and create a list of layout items. */ +/* Allocate and return document info in *pdi. */ +/* When caller is done with the items, it should call */ +/* freeitems on the returned result, and then */ +/* freedocinfo(*pdi). */ Item* parsehtml(uchar* data, int datalen, Rune* pagesrc, int mtype, int chset, Docinfo** pdi) { @@ -716,10 +716,10 @@ parsehtml(uchar* data, int datalen, Rune* pagesrc, int mtype, int chset, Docinfo return it; } -// Get a group of tokens for lexer, parse them, and create -// a list of layout items. -// When caller is done with the items, it should call -// freeitems on the returned result. +/* Get a group of tokens for lexer, parse them, and create */ +/* a list of layout items. */ +/* When caller is done with the items, it should call */ +/* freeitems on the returned result. */ static Item* getitems(ItemSource* is, uchar* data, int datalen) { @@ -796,7 +796,7 @@ getitems(ItemSource* is, uchar* data, int datalen) if(!buildinited) buildinit(); - doscripts = 0; // for now + doscripts = 0; /* for now */ ps = is->psstk; curtab = is->tabstk; di = is->doc; @@ -826,15 +826,15 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->inpar = 0; } } - // check common case first (Data), then switch statement on tag + /* check common case first (Data), then switch statement on tag */ if(tag == Data) { - // Lexing didn't pay attention to SGML record boundary rules: - // \n after start tag or before end tag to be discarded. - // (Lex has already discarded all \r's). - // Some pages assume this doesn't happen in <PRE> text, - // so we won't do it if literal is true. - // BUG: won't discard \n before a start tag that begins - // the next bufferful of tokens. + /* Lexing didn't pay attention to SGML record boundary rules: */ + /* \n after start tag or before end tag to be discarded. */ + /* (Lex has already discarded all \r's). */ + /* Some pages assume this doesn't happen in <PRE> text, */ + /* so we won't do it if literal is true. */ + /* BUG: won't discard \n before a start tag that begins */ + /* the next bufferful of tokens. */ s = tok->text; n = _Strlen(s); if(!ps->literal) { @@ -842,8 +842,8 @@ getitems(ItemSource* is, uchar* data, int datalen) j = n; if(toki > 0) { pt = toks[toki - 1].tag; - // IE and Netscape both ignore this rule (contrary to spec) - // if previous tag was img + /* IE and Netscape both ignore this rule (contrary to spec) */ + /* if previous tag was img */ if(pt < Numtags && pt != Timg && j > 0 && s[0] == '\n') i++; } @@ -873,26 +873,28 @@ getitems(ItemSource* is, uchar* data, int datalen) if(s != nil) ps->skipwhite = 0; } - tok->text = nil; // token doesn't own string anymore - if(s != nil) + tok->text = nil; /* token doesn't own string anymore */ + if(s != nil){ addtext(ps, s); + s = nil; + } } else switch(tag) { - // Some abbrevs used in following DTD comments - // %text = #PCDATA - // | TT | I | B | U | STRIKE | BIG | SMALL | SUB | SUP - // | EM | STRONG | DFN | CODE | SAMP | KBD | VAR | CITE - // | A | IMG | APPLET | FONT | BASEFONT | BR | SCRIPT | MAP - // | INPUT | SELECT | TEXTAREA - // %block = P | UL | OL | DIR | MENU | DL | PRE | DL | DIV | CENTER - // | BLOCKQUOTE | FORM | ISINDEX | HR | TABLE - // %flow = (%text | %block)* - // %body.content = (%heading | %text | %block | ADDRESS)* - - // <!ELEMENT A - - (%text) -(A)> - // Anchors are not supposed to be nested, but you sometimes see - // href anchors inside destination anchors. + /* Some abbrevs used in following DTD comments */ + /* %text = #PCDATA */ + /* | TT | I | B | U | STRIKE | BIG | SMALL | SUB | SUP */ + /* | EM | STRONG | DFN | CODE | SAMP | KBD | VAR | CITE */ + /* | A | IMG | APPLET | FONT | BASEFONT | BR | SCRIPT | MAP */ + /* | INPUT | SELECT | TEXTAREA */ + /* %block = P | UL | OL | DIR | MENU | DL | PRE | DL | DIV | CENTER */ + /* | BLOCKQUOTE | FORM | ISINDEX | HR | TABLE */ + /* %flow = (%text | %block)* */ + /* %body.content = (%heading | %text | %block | ADDRESS)* */ + + /* <!ELEMENT A - - (%text) -(A)> */ + /* Anchors are not supposed to be nested, but you sometimes see */ + /* href anchors inside destination anchors. */ case Ta: if(ps->curanchor != 0) { if(warn) @@ -901,18 +903,18 @@ getitems(ItemSource* is, uchar* data, int datalen) } name = aval(tok, Aname); href = aurlval(tok, Ahref, nil, di->base); - // ignore rel, rev, and title attrs + /* ignore rel, rev, and title attrs */ if(href != nil) { target = atargval(tok, di->target); di->anchors = newanchor(++is->nanchors, name, href, target, di->anchors); if(name != nil) - name = _Strdup(name); // for DestAnchor construction, below + name = _Strdup(name); /* for DestAnchor construction, below */ ps->curanchor = is->nanchors; ps->curfg = push(&ps->fgstk, di->link); ps->curul = push(&ps->ulstk, ULunder); } if(name != nil) { - // add a null item to be destination + /* add a null item to be destination */ additem(ps, newispacer(ISPnull), tok); di->dests = newdestanchor(++is->nanchors, name, ps->lastit, di->dests); } @@ -926,16 +928,16 @@ getitems(ItemSource* is, uchar* data, int datalen) } break; - // <!ELEMENT APPLET - - (PARAM | %text)* > - // We can't do applets, so ignore PARAMS, and let - // the %text contents appear for the alternative rep + /* <!ELEMENT APPLET - - (PARAM | %text)* > */ + /* We can't do applets, so ignore PARAMS, and let */ + /* the %text contents appear for the alternative rep */ case Tapplet: case Tapplet+RBRA: if(warn && tag == Tapplet) fprint(2, "warning: <APPLET> ignored\n"); break; - // <!ELEMENT AREA - O EMPTY> + /* <!ELEMENT AREA - O EMPTY> */ case Tarea: map = di->maps; if(map == nil) { @@ -950,7 +952,7 @@ getitems(ItemSource* is, uchar* data, int datalen) setdimarray(tok, Acoords, &map->areas->coords, &map->areas->ncoords); break; - // <!ELEMENT (B|STRONG) - - (%text)*> + /* <!ELEMENT (B|STRONG) - - (%text)*> */ case Tb: case Tstrong: pushfontstyle(ps, FntB); @@ -971,7 +973,7 @@ getitems(ItemSource* is, uchar* data, int datalen) popfontstyle(ps); break; - // <!ELEMENT BASE - O EMPTY> + /* <!ELEMENT BASE - O EMPTY> */ case Tbase: t = di->base; di->base = aurlval(tok, Ahref, di->base, di->base); @@ -980,12 +982,12 @@ getitems(ItemSource* is, uchar* data, int datalen) di->target = atargval(tok, di->target); break; - // <!ELEMENT BASEFONT - O EMPTY> + /* <!ELEMENT BASEFONT - O EMPTY> */ case Tbasefont: ps->adjsize = aintval(tok, Asize, 3) - 3; break; - // <!ELEMENT (BIG|SMALL) - - (%text)*> + /* <!ELEMENT (BIG|SMALL) - - (%text)*> */ case Tbig: case Tsmall: sz = ps->adjsize; @@ -1001,7 +1003,7 @@ getitems(ItemSource* is, uchar* data, int datalen) popfontsize(ps); break; - // <!ELEMENT BLOCKQUOTE - - %body.content> + /* <!ELEMENT BLOCKQUOTE - - %body.content> */ case Tblockquote: changeindent(ps, BQTAB); break; @@ -1010,7 +1012,7 @@ getitems(ItemSource* is, uchar* data, int datalen) changeindent(ps, -BQTAB); break; - // <!ELEMENT BODY O O %body.content> + /* <!ELEMENT BODY O O %body.content> */ case Tbody: ps->skipping = 0; bg = makebackground(nil, acolorval(tok, Abgcolor, di->background.color)); @@ -1018,8 +1020,8 @@ getitems(ItemSource* is, uchar* data, int datalen) 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 ... + /* really should remove old item from di->images list, */ + /* but there should only be one BODY element ... */ di->backgrounditem = (Iimage*)newiimage(bgurl, nil, ALnone, 0, 0, 0, 0, 0, 0, nil); di->backgrounditem->nextimage = di->images; di->images = di->backgrounditem; @@ -1037,17 +1039,17 @@ getitems(ItemSource* is, uchar* data, int datalen) break; case Tbody+RBRA: - // HTML spec says ignore things after </body>, - // but IE and Netscape don't - // ps.skipping = 1; + /* HTML spec says ignore things after </body>, */ + /* but IE and Netscape don't */ + /* ps.skipping = 1; */ break; - // <!ELEMENT BR - O EMPTY> + /* <!ELEMENT BR - O EMPTY> */ case Tbr: addlinebrk(ps, atabval(tok, Aclear, clear_tab, NCLEARTAB, 0)); break; - // <!ELEMENT CAPTION - - (%text;)*> + /* <!ELEMENT CAPTION - - (%text;)*> */ case Tcaption: if(curtab == nil) { if(warn) @@ -1089,7 +1091,7 @@ getitems(ItemSource* is, uchar* data, int datalen) popjust(ps); break; - // <!ELEMENT DD - O %flow > + /* <!ELEMENT DD - O %flow > */ case Tdd: if(ps->hangstk.n == 0) { if(warn) @@ -1104,8 +1106,8 @@ getitems(ItemSource* is, uchar* data, int datalen) push(&ps->hangstk, 0); break; - //<!ELEMENT (DIR|MENU) - - (LI)+ -(%block) > - //<!ELEMENT (OL|UL) - - (LI)+> + /*<!ELEMENT (DIR|MENU) - - (LI)+ -(%block) > */ + /*<!ELEMENT (OL|UL) - - (LI)+> */ case Tdir: case Tmenu: case Tol: @@ -1130,7 +1132,7 @@ getitems(ItemSource* is, uchar* data, int datalen) changeindent(ps, -LISTTAB); break; - // <!ELEMENT DL - - (DT|DD)+ > + /* <!ELEMENT DL - - (DT|DD)+ > */ case Tdl: changeindent(ps, LISTTAB); push(&ps->hangstk, 0); @@ -1148,7 +1150,7 @@ getitems(ItemSource* is, uchar* data, int datalen) pop(&ps->hangstk); break; - // <!ELEMENT DT - O (%text)* > + /* <!ELEMENT DT - O (%text)* > */ case Tdt: if(ps->hangstk.n == 0) { if(warn) @@ -1163,7 +1165,7 @@ getitems(ItemSource* is, uchar* data, int datalen) push(&ps->hangstk, 1); break; - // <!ELEMENT FONT - - (%text)*> + /* <!ELEMENT FONT - - (%text)*> */ case Tfont: sz = top(&ps->fntsizestk, Normal); if(_tokaval(tok, Asize, &nsz, 0)) { @@ -1188,7 +1190,7 @@ getitems(ItemSource* is, uchar* data, int datalen) popfontsize(ps); break; - // <!ELEMENT FORM - - %body.content -(FORM) > + /* <!ELEMENT FORM - - %body.content -(FORM) > */ case Tform: if(is->curform != nil) { if(warn) @@ -1216,12 +1218,12 @@ getitems(ItemSource* is, uchar* data, int datalen) fprint(2, "warning: unexpected </FORM>\n"); continue; } - // put fields back in input order + /* put fields back in input order */ is->curform->fields = (Formfield*)_revlist((List*)is->curform->fields); is->curform = nil; break; - // <!ELEMENT FRAME - O EMPTY> + /* <!ELEMENT FRAME - O EMPTY> */ case Tframe: ks = is->kidstk; if(ks == nil) { @@ -1246,7 +1248,7 @@ getitems(ItemSource* is, uchar* data, int datalen) kd->flags |= FRnoresize; break; - // <!ELEMENT FRAMESET - - (FRAME|FRAMESET)+> + /* <!ELEMENT FRAMESET - - (FRAME|FRAMESET)+> */ case Tframeset: ks = newkidinfo(1, nil); pks = is->kidstk; @@ -1279,8 +1281,8 @@ getitems(ItemSource* is, uchar* data, int datalen) continue; } ks = is->kidstk; - // put kids back in original order - // and add blank frames to fill out cells + /* put kids back in original order */ + /* and add blank frames to fill out cells */ n = ks->nrows*ks->ncols; nblank = n - _listlen((List*)ks->kidinfos); while(nblank-- > 0) @@ -1288,13 +1290,13 @@ getitems(ItemSource* is, uchar* data, int datalen) ks->kidinfos = (Kidinfo*)_revlist((List*)ks->kidinfos); is->kidstk = is->kidstk->nextframeset; if(is->kidstk == nil) { - // end input + /* end input */ ans = nil; goto return_ans; } break; - // <!ELEMENT H1 - - (%text;)*>, etc. + /* <!ELEMENT H1 - - (%text;)*>, etc. */ case Th1: case Th2: case Th3: @@ -1330,16 +1332,16 @@ getitems(ItemSource* is, uchar* data, int datalen) break; case Thead: - // HTML spec says ignore regular markup in head, - // but Netscape and IE don't - // ps.skipping = 1; + /* HTML spec says ignore regular markup in head, */ + /* but Netscape and IE don't */ + /* ps.skipping = 1; */ break; case Thead+RBRA: ps->skipping = 0; break; - // <!ELEMENT HR - O EMPTY> + /* <!ELEMENT HR - O EMPTY> */ case Thr: al = atabval(tok, Aalign, align_tab, NALIGNTAB, ALcenter); sz = auintval(tok, Asize, HRSZ); @@ -1360,7 +1362,7 @@ getitems(ItemSource* is, uchar* data, int datalen) pushfontstyle(ps, FntI); break; - // <!ELEMENT IMG - O EMPTY> + /* <!ELEMENT IMG - O EMPTY> */ case Timg: map = nil; oldcuranchor = ps->curanchor; @@ -1400,7 +1402,7 @@ getitems(ItemSource* is, uchar* data, int datalen) map); if(align == ALleft || align == ALright) { additem(ps, newifloat(img, align), tok); - // if no hspace specified, use FLTIMGHSPACE + /* if no hspace specified, use FLTIMGHSPACE */ if(!_tokaval(tok, Ahspace, &val, 0)) ((Iimage*)img)->hspace = FLTIMGHSPACE; } @@ -1415,7 +1417,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->curanchor = oldcuranchor; break; - // <!ELEMENT INPUT - O EMPTY> + /* <!ELEMENT INPUT - O EMPTY> */ case Tinput: ps->skipwhite = 0; if(is->curform == nil) { @@ -1475,9 +1477,9 @@ getitems(ItemSource* is, uchar* data, int datalen) fprint(2, "warning: image form field missing src\n"); continue; } - // width and height attrs aren't specified in HTML 3.2, - // but some people provide them and they help avoid - // a relayout + /* width and height attrs aren't specified in HTML 3.2, */ + /* but some people provide them and they help avoid */ + /* a relayout */ field->image = newiimage(src, astrval(tok, Aalt, L(Lsubmit)), atabval(tok, Aalign, align_tab, NALIGNTAB, ALbottom), @@ -1504,7 +1506,7 @@ getitems(ItemSource* is, uchar* data, int datalen) field->events = ffit->genattr->events; break; - // <!ENTITY ISINDEX - O EMPTY> + /* <!ENTITY ISINDEX - O EMPTY> */ case Tisindex: ps->skipwhite = 0; prompt = astrval(tok, Aprompt, L(Lindex)); @@ -1531,7 +1533,7 @@ getitems(ItemSource* is, uchar* data, int datalen) addbrk(ps, 1, 0); break; - // <!ELEMENT LI - O %flow> + /* <!ELEMENT LI - O %flow> */ case Tli: if(ps->listtypestk.n == 0) { if(warn) @@ -1556,7 +1558,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->skipwhite = 1; break; - // <!ELEMENT MAP - - (AREA)+> + /* <!ELEMENT MAP - - (AREA)+> */ case Tmap: if(_tokaval(tok, Aname, &name, 0)) is->curmap = getmap(di, name); @@ -1595,7 +1597,7 @@ getitems(ItemSource* is, uchar* data, int datalen) } break; - // Nobr is NOT in HMTL 4.0, but it is ubiquitous on the web + /* Nobr is NOT in HMTL 4.0, but it is ubiquitous on the web */ case Tnobr: ps->skipwhite = 0; ps->curstate &= ~IFwrap; @@ -1605,7 +1607,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->curstate |= IFwrap; break; - // We do frames, so skip stuff in noframes + /* We do frames, so skip stuff in noframes */ case Tnoframes: ps->skipping = 1; break; @@ -1614,7 +1616,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->skipping = 0; break; - // We do scripts (if enabled), so skip stuff in noscripts + /* We do scripts (if enabled), so skip stuff in noscripts */ case Tnoscript: if(doscripts) ps->skipping = 1; @@ -1625,7 +1627,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->skipping = 0; break; - // <!ELEMENT OPTION - O ( //PCDATA)> + /* <!ELEMENT OPTION - O ( //PCDATA)> */ case Toption: if(is->curform == nil || is->curform->fields == nil) { if(warn) @@ -1646,7 +1648,7 @@ getitems(ItemSource* is, uchar* data, int datalen) option->value = _Strdup(option->display); break; - // <!ELEMENT P - O (%text)* > + /* <!ELEMENT P - O (%text)* > */ case Tp: pushjust(ps, atabval(tok, Aalign, align_tab, NALIGNTAB, ps->curjust)); ps->inpar = 1; @@ -1656,12 +1658,12 @@ getitems(ItemSource* is, uchar* data, int datalen) case Tp+RBRA: break; - // <!ELEMENT PARAM - O EMPTY> - // Do something when we do applets... + /* <!ELEMENT PARAM - O EMPTY> */ + /* Do something when we do applets... */ case Tparam: break; - // <!ELEMENT PRE - - (%text)* -(IMG|BIG|SMALL|SUB|SUP|FONT) > + /* <!ELEMENT PRE - - (%text)* -(IMG|BIG|SMALL|SUB|SUP|FONT) > */ case Tpre: ps->curstate &= ~IFwrap; ps->literal = 1; @@ -1677,13 +1679,13 @@ getitems(ItemSource* is, uchar* data, int datalen) } break; - // <!ELEMENT SCRIPT - - CDATA> + /* <!ELEMENT SCRIPT - - CDATA> */ case Tscript: if(doscripts) { if(!di->hasscripts) { if(di->scripttype == TextJavascript) { - // TODO: initialize script if nec. - // initjscript(di); + /* TODO: initialize script if nec. */ + /* initjscript(di); */ di->hasscripts = 1; } } @@ -1716,7 +1718,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->skipping = 0; break; - // <!ELEMENT SELECT - - (OPTION+)> + /* <!ELEMENT SELECT - - (OPTION+)> */ case Tselect: if(is->curform == nil) { if(warn) @@ -1738,7 +1740,7 @@ getitems(ItemSource* is, uchar* data, int datalen) additem(ps, ffit, tok); if(ffit->genattr != nil) field->events = ffit->genattr->events; - // throw away stuff until next tag (should be <OPTION>) + /* throw away stuff until next tag (should be <OPTION>) */ s = getpcdata(toks, tokslen, &toki); if(s != nil) free(s); @@ -1753,11 +1755,11 @@ getitems(ItemSource* is, uchar* data, int datalen) field = is->curform->fields; if(field->ftype != Fselect) continue; - // put options back in input order + /* put options back in input order */ field->options = (Option*)_revlist((List*)field->options); break; - // <!ELEMENT (STRIKE|U) - - (%text)*> + /* <!ELEMENT (STRIKE|U) - - (%text)*> */ case Tstrike: case Tu: ps->curul = push(&ps->ulstk, (tag==Tstrike)? ULmid : ULunder); @@ -1773,7 +1775,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->curul = popretnewtop(&ps->ulstk, ULnone); break; - // <!ELEMENT STYLE - - CDATA> + /* <!ELEMENT STYLE - - CDATA> */ case Tstyle: if(warn) fprint(2, "warning: unimplemented <STYLE>\n"); @@ -1784,7 +1786,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps->skipping = 0; break; - // <!ELEMENT (SUB|SUP) - - (%text)*> + /* <!ELEMENT (SUB|SUP) - - (%text)*> */ case Tsub: case Tsup: if(tag == Tsub) @@ -1807,7 +1809,7 @@ getitems(ItemSource* is, uchar* data, int datalen) popfontsize(ps); break; - // <!ELEMENT TABLE - - (CAPTION?, TR+)> + /* <!ELEMENT TABLE - - (CAPTION?, TR+)> */ case Ttable: ps->skipwhite = 0; tab = newtable(++is->ntables, @@ -1876,10 +1878,10 @@ getitems(ItemSource* is, uchar* data, int datalen) addbrk(ps, 0, 0); break; - // <!ELEMENT (TH|TD) - O %body.content> - // Cells for a row are accumulated in reverse order. - // We push ps on a stack, and use a new one to accumulate - // the contents of the cell. + /* <!ELEMENT (TH|TD) - O %body.content> */ + /* Cells for a row are accumulated in reverse order. */ + /* We push ps on a stack, and use a new one to accumulate */ + /* the contents of the cell. */ case Ttd: case Tth: if(curtab == nil) { @@ -1951,7 +1953,7 @@ getitems(ItemSource* is, uchar* data, int datalen) ps = finishcell(curtab, ps); break; - // <!ELEMENT TEXTAREA - - ( //PCDATA)> + /* <!ELEMENT TEXTAREA - - ( //PCDATA)> */ case Ttextarea: if(is->curform == nil) { if(warn) @@ -1978,15 +1980,15 @@ getitems(ItemSource* is, uchar* data, int datalen) field->events = ffit->genattr->events; break; - // <!ELEMENT TITLE - - ( //PCDATA)* -(%head.misc)> + /* <!ELEMENT TITLE - - ( //PCDATA)* -(%head.misc)> */ case Ttitle: di->doctitle = getpcdata(toks, tokslen, &toki); if(warn && toki < tokslen - 1 && toks[toki + 1].tag != Ttitle + RBRA) fprint(2, "warning: <TITLE> data ended by %T\n", &toks[toki + 1]); break; - // <!ELEMENT TR - O (TH|TD)+> - // rows are accumulated in reverse order in curtab->rows + /* <!ELEMENT TR - O (TH|TD)+> */ + /* rows are accumulated in reverse order in curtab->rows */ case Ttr: if(curtab == nil) { if(warn) @@ -2024,7 +2026,7 @@ getitems(ItemSource* is, uchar* data, int datalen) tr->flags = 0; break; - // <!ELEMENT (TT|CODE|KBD|SAMP) - - (%text)*> + /* <!ELEMENT (TT|CODE|KBD|SAMP) - - (%text)*> */ case Ttt: case Tcode: case Tkbd: @@ -2032,7 +2034,7 @@ getitems(ItemSource* is, uchar* data, int datalen) pushfontstyle(ps, FntT); break; - // Tags that have empty action + /* Tags that have empty action */ case Tabbr: case Tabbr+RBRA: case Tacronym: @@ -2061,7 +2063,7 @@ getitems(ItemSource* is, uchar* data, int datalen) break; - // Tags not implemented + /* Tags not implemented */ case Tbdo: case Tbdo+RBRA: case Tbutton: @@ -2097,7 +2099,7 @@ getitems(ItemSource* is, uchar* data, int datalen) break; } } - // some pages omit trailing </table> + /* some pages omit trailing </table> */ while(curtab != nil) { if(warn) fprint(2, "warning: <TABLE> not closed\n"); @@ -2124,12 +2126,12 @@ getitems(ItemSource* is, uchar* data, int datalen) } outerps = lastps(ps); ans = outerps->items->next; - // note: ans may be nil and di->kids not nil, if there's a frameset! + /* note: ans may be nil and di->kids not nil, if there's a frameset! */ outerps->items = newispacer(ISPnull); outerps->lastit = outerps->items; is->psstk = ps; if(ans != nil && di->hasscripts) { - // TODO evalscript(nil); + /* TODO evalscript(nil); */ ; } @@ -2144,10 +2146,10 @@ return_ans: return ans; } -// Concatenate together maximal set of Data tokens, starting at toks[toki+1]. -// Lexer has ensured that there will either be a following non-data token or -// we will be at eof. -// Return emallocd trimmed concatenation, and update *ptoki to last used toki +/* Concatenate together maximal set of Data tokens, starting at toks[toki+1]. */ +/* Lexer has ensured that there will either be a following non-data token or */ +/* we will be at eof. */ +/* Return emallocd trimmed concatenation, and update *ptoki to last used toki */ static Rune* getpcdata(Token* toks, int tokslen, int* ptoki) { @@ -2161,7 +2163,7 @@ getpcdata(Token* toks, int tokslen, int* ptoki) ans = nil; anslen = 0; - // first find length of answer + /* first find length of answer */ toki = (*ptoki) + 1; while(toki < tokslen) { tok = &toks[toki]; @@ -2172,7 +2174,7 @@ getpcdata(Token* toks, int tokslen, int* ptoki) else break; } - // now make up the initial answer + /* now make up the initial answer */ if(anslen > 0) { ans = _newstr(anslen); p = ans; @@ -2198,9 +2200,9 @@ getpcdata(Token* toks, int tokslen, int* ptoki) return ans; } -// If still parsing head of curtab->cells list, finish it off -// by transferring the items on the head of psstk to the cell. -// Then pop the psstk and return the new psstk. +/* If still parsing head of curtab->cells list, finish it off */ +/* by transferring the items on the head of psstk to the cell. */ +/* Then pop the psstk and return the new psstk. */ static Pstate* finishcell(Table* curtab, Pstate* psstk) { @@ -2226,8 +2228,8 @@ finishcell(Table* curtab, Pstate* psstk) return psstk; } -// Make a new Pstate for a cell, based on the old pstate, oldps. -// Also, put the new ps on the head of the oldps stack. +/* Make a new Pstate for a cell, based on the old pstate, oldps. */ +/* Also, put the new ps on the head of the oldps stack. */ static Pstate* cell_pstate(Pstate* oldps, int ishead) { @@ -2251,8 +2253,8 @@ cell_pstate(Pstate* oldps, int ishead) return ps; } -// Return a new Pstate with default starting state. -// Use link to add it to head of a list, if any. +/* Return a new Pstate with default starting state. */ +/* Use link to add it to head of a list, if any. */ static Pstate* newpstate(Pstate* link) { @@ -2273,7 +2275,7 @@ newpstate(Pstate* link) return ps; } -// Return last Pstate on psl list +/* Return last Pstate on psl list */ static Pstate* lastps(Pstate* psl) { @@ -2283,9 +2285,9 @@ lastps(Pstate* psl) return psl; } -// Add it to end of ps item chain, adding in current state from ps. -// Also, if tok is not nil, scan it for generic attributes and assign -// the genattr field of the item accordingly. +/* Add it to end of ps item chain, adding in current state from ps. */ +/* Also, if tok is not nil, scan it for generic attributes and assign */ +/* the genattr field of the item accordingly. */ static void additem(Pstate* ps, Item* it, Token* tok) { @@ -2350,8 +2352,8 @@ additem(Pstate* ps, Item* it, Token* tok) ps->lastit = it; } -// Make a text item out of s, -// using current font, foreground, vertical offset and underline state. +/* Make a text item out of s, */ +/* using current font, foreground, vertical offset and underline state. */ static Item* textit(Pstate* ps, Rune* s) { @@ -2359,19 +2361,19 @@ textit(Pstate* ps, Rune* s) return newitext(s, ps->curfont, ps->curfg, ps->curvoff + Voffbias, ps->curul); } -// Add text item or items for s, paying attention to -// current font, foreground, baseline offset, underline state, -// and literal mode. Unless we're in literal mode, compress -// whitespace to single blank, and, if curstate has a break, -// trim any leading whitespace. Whether in literal mode or not, -// turn nonbreaking spaces into spacer items with IFnobrk set. -// -// In literal mode, break up s at newlines and add breaks instead. -// Also replace tabs appropriate number of spaces. -// In nonliteral mode, break up the items every 100 or so characters -// just to make the layout algorithm not go quadratic. -// -// addtext assumes ownership of s. +/* Add text item or items for s, paying attention to */ +/* current font, foreground, baseline offset, underline state, */ +/* and literal mode. Unless we're in literal mode, compress */ +/* whitespace to single blank, and, if curstate has a break, */ +/* trim any leading whitespace. Whether in literal mode or not, */ +/* turn nonbreaking spaces into spacer items with IFnobrk set. */ +/* */ +/* In literal mode, break up s at newlines and add breaks instead. */ +/* Also replace tabs appropriate number of spaces. */ +/* In nonliteral mode, break up the items every 100 or so characters */ +/* just to make the layout algorithm not go quadratic. */ +/* */ +/* addtext assumes ownership of s. */ static void addtext(Pstate* ps, Rune* s) { @@ -2396,7 +2398,7 @@ addtext(Pstate* ps, Rune* s) while(i < n) { if(s[i] == '\n') { if(i > j) { - // trim trailing blanks from line + /* trim trailing blanks from line */ for(k = i; k > j; k--) if(s[k - 1] != ' ') break; @@ -2411,7 +2413,7 @@ addtext(Pstate* ps, Rune* s) if(s[i] == '\t') { col += i - j; nsp = 8 - (col%8); - // make ss = s[j:i] + nsp spaces + /* make ss = s[j:i] + nsp spaces */ ss = _newstr(i-j+nsp); p = _Stradd(ss, s+j, i-j); p = _Stradd(p, L(Ltab2space), nsp); @@ -2432,7 +2434,7 @@ addtext(Pstate* ps, Rune* s) } if(i > j) { if(j == 0 && i == n) { - // just transfer s over + /* just transfer s over */ additem(ps, textit(ps, s), nil); } else { @@ -2441,7 +2443,7 @@ addtext(Pstate* ps, Rune* s) } } } - else { // not literal mode + else { /* not literal mode */ if((ps->curstate&IFbrk) || ps->lastit == ps->items) while(i < n) { c = s[i]; @@ -2488,7 +2490,7 @@ addtext(Pstate* ps, Rune* s) assert(p+i-j < buf+SMALLBUFSIZE-1); p = _Stradd(p, s+j, i-j); } - // don't add a space if previous item ended in a space + /* don't add a space if previous item ended in a space */ if(p-buf == 1 && buf[0] == ' ' && ps->lastit != nil) { it = ps->lastit; if(it->tag == Itexttag) { @@ -2504,14 +2506,14 @@ addtext(Pstate* ps, Rune* s) } } -// Add a break to ps->curstate, with extra space if sp is true. -// If there was a previous break, combine this one's parameters -// with that to make the amt be the max of the two and the clr -// be the most general. (amt will be 0 or 1) -// Also, if the immediately preceding item was a text item, -// trim any whitespace from the end of it, if not in literal mode. -// Finally, if this is at the very beginning of the item list -// (the only thing there is a null spacer), then don't add the space. +/* Add a break to ps->curstate, with extra space if sp is true. */ +/* If there was a previous break, combine this one's parameters */ +/* with that to make the amt be the max of the two and the clr */ +/* be the most general. (amt will be 0 or 1) */ +/* Also, if the immediately preceding item was a text item, */ +/* trim any whitespace from the end of it, if not in literal mode. */ +/* Finally, if this is at the very beginning of the item list */ +/* (the only thing there is a null spacer), then don't add the space. */ static void addbrk(Pstate* ps, int sp, int clr) { @@ -2534,8 +2536,8 @@ addbrk(Pstate* ps, int sp, int clr) if(!ps->literal && ps->lastit->tag == Itexttag) { t = (Itext*)ps->lastit; _splitr(t->s, _Strlen(t->s), notwhitespace, &l, &nl, &r, &nr); - // try to avoid making empty items - // but not crucial f the occasional one gets through + /* try to avoid making empty items */ + /* but not crucial f the occasional one gets through */ if(nl == 0 && ps->prelastit != nil) { ps->lastit = ps->prelastit; ps->lastit->next = nil; @@ -2544,8 +2546,8 @@ addbrk(Pstate* ps, int sp, int clr) else { s = t->s; if(nl == 0) { - // need a non-nil pointer to empty string - // (_Strdup(L(Lempty)) returns nil) + /* need a non-nil pointer to empty string */ + /* (_Strdup(L(Lempty)) returns nil) */ t->s = emalloc(sizeof(Rune)); t->s[0] = 0; } @@ -2558,13 +2560,13 @@ addbrk(Pstate* ps, int sp, int clr) } } -// Add break due to a <br> or a newline within a preformatted section. -// We add a null item first, with current font's height and ascent, to make -// sure that the current line takes up at least that amount of vertical space. -// This ensures that <br>s on empty lines cause blank lines, and that -// multiple <br>s in a row give multiple blank lines. -// However don't add the spacer if the previous item was something that -// takes up space itself. +/* Add break due to a <br> or a newline within a preformatted section. */ +/* We add a null item first, with current font's height and ascent, to make */ +/* sure that the current line takes up at least that amount of vertical space. */ +/* This ensures that <br>s on empty lines cause blank lines, and that */ +/* multiple <br>s in a row give multiple blank lines. */ +/* However don't add the spacer if the previous item was something that */ +/* takes up space itself. */ static void addlinebrk(Pstate* ps, int clr) { @@ -2572,8 +2574,8 @@ addlinebrk(Pstate* ps, int clr) int b; int addit; - // don't want break before our null item unless the previous item - // was also a null item for the purposes of line breaking + /* don't want break before our null item unless the previous item */ + /* was also a null item for the purposes of line breaking */ obrkstate = ps->curstate&(IFbrk|IFbrksp); b = IFnobrk; addit = 0; @@ -2594,24 +2596,24 @@ addlinebrk(Pstate* ps, int clr) addbrk(ps, 0, clr); } -// Add a nonbreakable space +/* Add a nonbreakable space */ static void addnbsp(Pstate* ps) { - // if nbsp comes right where a break was specified, - // do the break anyway (nbsp is being used to generate undiscardable - // space rather than to prevent a break) + /* if nbsp comes right where a break was specified, */ + /* do the break anyway (nbsp is being used to generate undiscardable */ + /* space rather than to prevent a break) */ if((ps->curstate&IFbrk) == 0) ps->curstate |= IFnobrk; additem(ps, newispacer(ISPhspace), nil); - // but definitely no break on next item + /* but definitely no break on next item */ ps->curstate |= IFnobrk; } -// Change hang in ps.curstate by delta. -// The amount is in 1/10ths of tabs, and is the amount that -// the current contiguous set of items with a hang value set -// is to be shifted left from its normal (indented) place. +/* Change hang in ps.curstate by delta. */ +/* The amount is in 1/10ths of tabs, and is the amount that */ +/* the current contiguous set of items with a hang value set */ +/* is to be shifted left from its normal (indented) place. */ static void changehang(Pstate* ps, int delta) { @@ -2626,7 +2628,7 @@ changehang(Pstate* ps, int delta) ps->curstate = (ps->curstate&~IFhangmask)|amt; } -// Change indent in ps.curstate by delta. +/* Change indent in ps.curstate by delta. */ static void changeindent(Pstate* ps, int delta) { @@ -2641,7 +2643,7 @@ changeindent(Pstate* ps, int delta) ps->curstate = (ps->curstate&~IFindentmask)|(amt << IFindentshift); } -// Push val on top of stack, and also return value pushed +/* Push val on top of stack, and also return value pushed */ static int push(Stack* stk, int val) { @@ -2654,7 +2656,7 @@ push(Stack* stk, int val) return val; } -// Pop top of stack +/* Pop top of stack */ static void pop(Stack* stk) { @@ -2662,7 +2664,7 @@ pop(Stack* stk) --stk->n; } -//Return top of stack, using dflt if stack is empty +/*Return top of stack, using dflt if stack is empty */ static int top(Stack* stk, int dflt) { @@ -2671,7 +2673,7 @@ top(Stack* stk, int dflt) return stk->slots[stk->n-1]; } -// pop, then return new top, with dflt if empty +/* pop, then return new top, with dflt if empty */ static int popretnewtop(Stack* stk, int dflt) { @@ -2683,7 +2685,7 @@ popretnewtop(Stack* stk, int dflt) return stk->slots[stk->n-1]; } -// Copy fromstk entries into tostk +/* Copy fromstk entries into tostk */ static void copystack(Stack* tostk, Stack* fromstk) { @@ -2770,8 +2772,8 @@ setcurjust(Pstate* ps) } } -// Do final rearrangement after table parsing is finished -// and assign cells to grid points +/* Do final rearrangement after table parsing is finished */ +/* and assign cells to grid points */ static void finish_table(Table* t) { @@ -2802,7 +2804,7 @@ finish_table(Table* t) ncol = 0; r = nrow - 1; for(row = rl; row != nil; row = rownext) { - // copy the data from the allocated Tablerow into the array slot + /* copy the data from the allocated Tablerow into the array slot */ t->rows[r] = *row; rownext = row->next; row = &t->rows[r]; @@ -2810,12 +2812,12 @@ finish_table(Table* t) rcols = 0; c = row->cells; - // If rowspan is > 1 but this is the last row, - // reset the rowspan + /* If rowspan is > 1 but this is the last row, */ + /* reset the rowspan */ if(c != nil && c->rowspan > 1 && r == nrow-2) c->rowspan = 1; - // reverse row->cells list (along nextinrow pointers) + /* reverse row->cells list (along nextinrow pointers) */ row->cells = nil; while(c != nil) { cnext = c->nextinrow; @@ -2830,8 +2832,8 @@ finish_table(Table* t) t->ncol = ncol; t->cols = (Tablecol*)emalloc(ncol * sizeof(Tablecol)); - // Reverse cells just so they are drawn in source order. - // Also, trim their contents so they don't end in whitespace. + /* Reverse cells just so they are drawn in source order. */ + /* Also, trim their contents so they don't end in whitespace. */ t->cells = (Tablecell*)_revlist((List*)t->cells); for(c = t->cells; c != nil; c= c->next) trim_cell(c); @@ -2839,10 +2841,10 @@ finish_table(Table* t) for(i = 0; i < nrow; i++) t->grid[i] = (Tablecell**)emalloc(ncol * sizeof(Tablecell*)); - // The following arrays keep track of cells that are spanning - // multiple rows; rowspancnt[i] is the number of rows left - // to be spanned in column i. - // When done, cell's (row,col) is upper left grid point. + /* The following arrays keep track of cells that are spanning */ + /* multiple rows; rowspancnt[i] is the number of rows left */ + /* to be spanned in column i. */ + /* When done, cell's (row,col) is upper left grid point. */ rowspancnt = (int*)emalloc(ncol * sizeof(int)); rowspancell = (Tablecell**)emalloc(ncol * sizeof(Tablecell*)); for(ri = 0; ri < nrow; ri++) { @@ -2865,8 +2867,8 @@ finish_table(Table* t) cspan = c->colspan; rspan = c->rowspan; if(ci + cspan > ncol) { - // because of row spanning, we calculated - // ncol incorrectly; adjust it + /* because of row spanning, we calculated */ + /* ncol incorrectly; adjust it */ newncol = ci + cspan; t->cols = (Tablecol*)erealloc(t->cols, newncol * sizeof(Tablecol)); rowspancnt = (int*)erealloc(rowspancnt, newncol * sizeof(int)); @@ -2896,7 +2898,7 @@ finish_table(Table* t) } } -// Remove tail of cell content until it isn't whitespace. +/* Remove tail of cell content until it isn't whitespace. */ static void trim_cell(Tablecell* c) { @@ -2941,7 +2943,7 @@ trim_cell(Tablecell* c) } } -// Caller must free answer (eventually). +/* Caller must free answer (eventually). */ static Rune* listmark(uchar ty, int n) { @@ -2956,9 +2958,9 @@ listmark(uchar ty, int n) case LTsquare: case LTcircle: s = _newstr(1); - s[0] = (ty == LTdisc)? 0x2022 // bullet - : ((ty == LTsquare)? 0x220e // filled square - : 0x2218); // degree + s[0] = (ty == LTdisc)? 0x2022 /* bullet */ + : ((ty == LTsquare)? 0x220e /* filled square */ + : 0x2218); /* degree */ s[1] = 0; break; @@ -3009,9 +3011,9 @@ listmark(uchar ty, int n) return s; } -// Find map with given name in di.maps. -// If not there, add one, copying name. -// Ownership of map remains with di->maps list. +/* Find map with given name in di.maps. */ +/* If not there, add one, copying name. */ +/* Ownership of map remains with di->maps list. */ static Map* getmap(Docinfo* di, Rune* name) { @@ -3029,7 +3031,7 @@ getmap(Docinfo* di, Rune* name) return m; } -// Transfers ownership of href to Area +/* Transfers ownership of href to Area */ static Area* newarea(int shape, Rune* href, int target, Area* link) { @@ -3043,32 +3045,32 @@ newarea(int shape, Rune* href, int target, Area* link) return a; } -// Return string value associated with attid in tok, nil if none. -// Caller must free the result (eventually). +/* Return string value associated with attid in tok, nil if none. */ +/* Caller must free the result (eventually). */ static Rune* aval(Token* tok, int attid) { Rune* ans; - _tokaval(tok, attid, &ans, 1); // transfers string ownership from token to ans + _tokaval(tok, attid, &ans, 1); /* transfers string ownership from token to ans */ return ans; } -// Like aval, but use dflt if there was no such attribute in tok. -// Caller must free the result (eventually). +/* Like aval, but use dflt if there was no such attribute in tok. */ +/* Caller must free the result (eventually). */ static Rune* astrval(Token* tok, int attid, Rune* dflt) { Rune* ans; if(_tokaval(tok, attid, &ans, 1)) - return ans; // transfers string ownership from token to ans + return ans; /* transfers string ownership from token to ans */ else return _Strdup(dflt); } -// Here we're supposed to convert to an int, -// and have a default when not found +/* Here we're supposed to convert to an int, */ +/* and have a default when not found */ static int aintval(Token* tok, int attid, int dflt) { @@ -3080,7 +3082,7 @@ aintval(Token* tok, int attid, int dflt) return toint(ans); } -// Like aintval, but result should be >= 0 +/* Like aintval, but result should be >= 0 */ static int auintval(Token* tok, int attid, int dflt) { @@ -3095,7 +3097,7 @@ auintval(Token* tok, int attid, int dflt) } } -// int conversion, but with possible error check (if warning) +/* int conversion, but with possible error check (if warning) */ static int toint(Rune* s) { @@ -3113,7 +3115,7 @@ toint(Rune* s) return ans; } -// Attribute value when need a table to convert strings to ints +/* Attribute value when need a table to convert strings to ints */ static int atabval(Token* tok, int attid, StringInt* tab, int ntab, int dflt) { @@ -3131,7 +3133,7 @@ atabval(Token* tok, int attid, StringInt* tab, int ntab, int dflt) return ans; } -// Attribute value when supposed to be a color +/* Attribute value when supposed to be a color */ static int acolorval(Token* tok, int attid, int dflt) { @@ -3144,7 +3146,7 @@ acolorval(Token* tok, int attid, int dflt) return ans; } -// Attribute value when supposed to be a target frame name +/* Attribute value when supposed to be a target frame name */ static int atargval(Token* tok, int dflt) { @@ -3158,8 +3160,8 @@ atargval(Token* tok, int dflt) return ans; } -// special for list types, where "i" and "I" are different, -// but "square" and "SQUARE" are the same +/* special for list types, where "i" and "I" are different, */ +/* but "square" and "SQUARE" are the same */ static int listtyval(Token* tok, int dflt) { @@ -3207,9 +3209,9 @@ listtyval(Token* tok, int dflt) return ans; } -// Attribute value when value is a URL, possibly relative to base. -// FOR NOW: leave the url relative. -// Caller must free the result (eventually). +/* Attribute value when value is a URL, possibly relative to base. */ +/* FOR NOW: leave the url relative. */ +/* Caller must free the result (eventually). */ static Rune* aurlval(Token* tok, int attid, Rune* dflt, Rune* base) { @@ -3225,8 +3227,8 @@ aurlval(Token* tok, int attid, Rune* dflt, Rune* base) return ans; } -// Return copy of s but with all whitespace (even internal) removed. -// This fixes some buggy URL specification strings. +/* Return copy of s but with all whitespace (even internal) removed. */ +/* This fixes some buggy URL specification strings. */ static Rune* removeallwhite(Rune* s) { @@ -3258,8 +3260,8 @@ removeallwhite(Rune* s) return ans; } -// Attribute value when mere presence of attr implies value of 1, -// but if there is an integer there, return it as the value. +/* Attribute value when mere presence of attr implies value of 1, */ +/* but if there is an integer there, return it as the value. */ static int aflagval(Token* tok, int attid) { @@ -3285,7 +3287,7 @@ makealign(int halign, int valign) return al; } -// Make an Align (two alignments, horizontal and vertical) +/* Make an Align (two alignments, horizontal and vertical) */ static Align aalign(Token* tok) { @@ -3294,7 +3296,7 @@ aalign(Token* tok) atabval(tok, Avalign, align_tab, NALIGNTAB, ALnone)); } -// Make a Dimen, based on value of attid attr +/* Make a Dimen, based on value of attid attr */ static Dimen adimen(Token* tok, int attid) { @@ -3306,7 +3308,7 @@ adimen(Token* tok, int attid) return makedimen(Dnone, 0); } -// Parse s[0:n] as num[.[num]][unit][%|*] +/* Parse s[0:n] as num[.[num]][unit][%|*] */ static Dimen parsedim(Rune* s, int ns) { @@ -3444,7 +3446,7 @@ newirule(int align, int size, int noshade, Dimen wspec) return (Item*)r; } -// Map is owned elsewhere. +/* Map is owned elsewhere. */ static Item* newiimage(Rune* src, Rune* altrep, int align, int width, int height, int hspace, int vspace, int border, int ismap, Map* map) @@ -3517,7 +3519,7 @@ newispacer(int spkind) return (Item*)s; } -// Free one item (caller must deal with next pointer) +/* Free one item (caller must deal with next pointer) */ static void freeitem(Item* it) { @@ -3557,7 +3559,7 @@ freeitem(Item* it) free(it); } -// Free list of items chained through next pointer +/* Free list of items chained through next pointer */ void freeitems(Item* ithead) { @@ -3601,8 +3603,8 @@ freetable(Table* t) if(t == nil) return; - // We'll find all the unique cells via t->cells and next pointers. - // (Other pointers to cells in the table are duplicates of these) + /* We'll find all the unique cells via t->cells and next pointers. */ + /* (Other pointers to cells in the table are duplicates of these) */ for(c = t->cells; c != nil; c = cnext) { cnext = c->next; freeitems(c->content); @@ -3626,7 +3628,7 @@ freeform(Form* f) free(f->name); free(f->action); - // Form doesn't own its fields (Iformfield items do) + /* Form doesn't own its fields (Iformfield items do) */ free(f); } @@ -3768,13 +3770,13 @@ freedocinfo(Docinfo* d) freedestanchors(d->dests); freeforms(d->forms); freemaps(d->maps); - // tables, images, and formfields are freed when - // the items pointing at them are freed + /* tables, images, and formfields are freed when */ + /* the items pointing at them are freed */ free(d); } -// Currently, someone else owns all the memory -// pointed to by things in a Pstate. +/* Currently, someone else owns all the memory */ +/* pointed to by things in a Pstate. */ static void freepstate(Pstate* p) { @@ -3926,7 +3928,7 @@ Iconv(Fmt *f) return fmtstrcpy(f, buf); } -// String version of alignment 'a' +/* String version of alignment 'a' */ static Rune* stringalign(int a) { @@ -3938,8 +3940,8 @@ stringalign(int a) return s; } -// Put at most nbuf chars of representation of d into buf, -// and return number of characters put +/* Put at most nbuf chars of representation of d into buf, */ +/* and return number of characters put */ static int dimprint(char* buf, int nbuf, Dimen d) { @@ -4002,7 +4004,7 @@ newformfield(int ftype, int fieldid, Form* form, Rune* name, return ff; } -// Transfers ownership of value and display to Option. +/* Transfers ownership of value and display to Option. */ static Option* newoption(int selected, Rune* value, Rune* display, Option* link) { @@ -4210,8 +4212,8 @@ resetdocinfo(Docinfo* d) d->frameid = -1; } -// Use targetmap array to keep track of name <-> targetid mapping. -// Use real malloc(), and never free +/* Use targetmap array to keep track of name <-> targetid mapping. */ +/* Use real malloc(), and never free */ static void targetmapinit(void) { @@ -4263,10 +4265,10 @@ targetname(int targid) return L(Lquestion); } -// Convert HTML color spec to RGB value, returning dflt if can't. -// Argument is supposed to be a valid HTML color, or "". -// Return the RGB value of the color, using dflt if s -// is nil or an invalid color. +/* Convert HTML color spec to RGB value, returning dflt if can't. */ +/* Argument is supposed to be a valid HTML color, or "". */ +/* Return the RGB value of the color, using dflt if s */ +/* is nil or an invalid color. */ static int color(Rune* s, int dflt) { @@ -4285,12 +4287,12 @@ color(Rune* s, int dflt) return dflt; } -// Debugging +/* Debugging */ #define HUGEPIX 10000 -// A "shallow" validitem, that doesn't follow next links -// or descend into tables. +/* A "shallow" validitem, that doesn't follow next links */ +/* or descend into tables. */ static int validitem(Item* i) { @@ -4308,8 +4310,8 @@ validitem(Item* i) (i->ascent > -HUGEPIX && i->ascent < HUGEPIX) && (i->anchorid >= 0) && (i->genattr == nil || validptr(i->genattr)); - // also, could check state for ridiculous combinations - // also, could check anchorid for within-doc-range + /* also, could check state for ridiculous combinations */ + /* also, could check anchorid for within-doc-range */ if(ok) switch(i->tag) { case Itexttag: @@ -4357,9 +4359,9 @@ validitem(Item* i) return ok; } -// "deep" validation, that checks whole list of items, -// and descends into tables and floated tables. -// nil is ok for argument. +/* "deep" validation, that checks whole list of items, */ +/* and descends into tables and floated tables. */ +/* nil is ok for argument. */ int validitems(Item* i) { @@ -4401,12 +4403,12 @@ validformfield(Formfield* f) (f->options == nil || validptr(f->options)) && (f->image == nil || validitem(f->image)) && (f->events == nil || validptr(f->events)); - // when all built, should have f->fieldid < f->form->nfields, - // but this may be called during build... + /* when all built, should have f->fieldid < f->form->nfields, */ + /* but this may be called during build... */ return ok; } -// "deep" validation -- checks cell contents too +/* "deep" validation -- checks cell contents too */ static int validtable(Table* t) { @@ -4428,10 +4430,10 @@ validtable(Table* t) (t->totw >= 0 && t->totw < HUGEPIX) && (t->toth >= 0 && t->toth < HUGEPIX) && (t->tabletok == nil || validptr(t->tabletok)); - // during parsing, t->rows has list; - // only when parsing is done is t->nrow set > 0 + /* during parsing, t->rows has list; */ + /* only when parsing is done is t->nrow set > 0 */ if(ok && t->nrow > 0 && t->ncol > 0) { - // table is "finished" + /* table is "finished" */ for(i = 0; i < t->nrow && ok; i++) ok = validtablerow(t->rows+i); for(j = 0; j < t->ncol && ok; j++) @@ -4528,9 +4530,9 @@ validtablecell(Tablecell* c) static int validptr(void* p) { - // TODO: a better job of this. - // For now, just dereference, which cause a bomb - // if not valid + /* TODO: a better job of this. */ + /* For now, just dereference, which cause a bomb */ + /* if not valid */ static char c; c = *((char*)p); diff --git a/src/libhtml/impl.h b/src/libhtml/impl.h index 1dfa689c..170505c7 100644 --- a/src/libhtml/impl.h +++ b/src/libhtml/impl.h @@ -1,9 +1,9 @@ -// UTILS +/* UTILS */ typedef struct List List; typedef struct Strlist Strlist; -// List of integers (and also generic list with next pointer at beginning) +/* List of integers (and also generic list with next pointer at beginning) */ struct List { List* next; @@ -45,10 +45,10 @@ extern void _trimwhite(Rune* s, int n, Rune** pans, int* panslen); extern Rune notwhitespace[]; extern Rune whitespace[]; -// STRINTTAB +/* STRINTTAB */ typedef struct StringInt StringInt; -// Element of String-Int table (used for keyword lookup) +/* Element of String-Int table (used for keyword lookup) */ struct StringInt { Rune* key; @@ -59,17 +59,17 @@ extern int _lookup(StringInt* t, int n, Rune* key, int keylen, int* pans); extern StringInt* _makestrinttab(Rune** a, int n); extern Rune* _revlookup(StringInt* t, int n, int val); -// Colors, in html format, not Plan 9 format. (RGB values in bottom 3 bytes) +/* Colors, in html format, not Plan 9 format. (RGB values in bottom 3 bytes) */ enum { White = 0xFFFFFF, Black = 0x000000, - Blue = 0x0000CC, + Blue = 0x0000CC }; -// LEX +/* LEX */ -// HTML 4.0 tags (plus blink, nobr) -// sorted in lexical order; used as array indices +/* HTML 4.0 tags (plus blink, nobr) */ +/* sorted in lexical order; used as array indices */ enum { Notfound, Comment, @@ -101,8 +101,8 @@ enum { Data = Numtags+RBRA }; -// HTML 4.0 tag attributes -// Keep sorted in lexical order +/* HTML 4.0 tag attributes */ +/* Keep sorted in lexical order */ enum { Aabbr, Aaccept_charset, Aaccess_key, Aaction, Aalign, Aalink, Aalt, Aarchive, Aaxis, @@ -138,17 +138,17 @@ enum { struct Attr { - Attr* next; // in list of attrs for a token - int attid; // Aabbr, etc. + Attr* next; /* in list of attrs for a token */ + int attid; /* Aabbr, etc. */ Rune* value; }; struct Token { - int tag; // Ta, etc - Rune* text; // text in Data, attribute text in tag - Attr* attr; // list of Attrs - int starti; // index into source buffer of token start + int tag; /* Ta, etc */ + Rune* text; /* text in Data, attribute text in tag */ + Attr* attr; /* list of Attrs */ + int starti; /* index into source buffer of token start */ }; extern Rune** tagnames; diff --git a/src/libhtml/lex.c b/src/libhtml/lex.c index cc368ac2..12127b58 100644 --- a/src/libhtml/lex.c +++ b/src/libhtml/lex.c @@ -8,11 +8,11 @@ typedef struct TokenSource TokenSource; struct TokenSource { - int i; // index of next byte to use - uchar* data; // all the data - int edata; // data[0:edata] is valid - int chset; // one of US_Ascii, etc. - int mtype; // TextHtml or TextPlain + int i; /* index of next byte to use */ + uchar* data; /* all the data */ + int edata; /* data[0:edata] is valid */ + int chset; /* one of US_Ascii, etc. */ + int mtype; /* TextHtml or TextPlain */ }; enum { @@ -25,8 +25,8 @@ enum { #define SMALLBUFSIZE 240 #define BIGBUFSIZE 2000 -// HTML 4.0 tag names. -// Keep sorted, and in correspondence with enum in iparse.h. +/* HTML 4.0 tag names. */ +/* Keep sorted, and in correspondence with enum in iparse.h. */ Rune **tagnames; char *_tagnames[] = { " ", @@ -127,8 +127,8 @@ char *_tagnames[] = { "var" }; -// HTML 4.0 attribute names. -// Keep sorted, and in correspondence with enum in i.h. +/* HTML 4.0 attribute names. */ +/* Keep sorted, and in correspondence with enum in i.h. */ Rune **attrnames; char* _attrnames[] = { "abbr", @@ -250,8 +250,8 @@ char* _attrnames[] = { }; -// Character entity to unicode character number map. -// Keep sorted by name. +/* Character entity to unicode character number map. */ +/* Keep sorted by name. */ StringInt *chartab; AsciiInt _chartab[] = { {"AElig", 198}, @@ -405,22 +405,22 @@ AsciiInt _chartab[] = { }; #define NCHARTAB (sizeof(_chartab)/sizeof(_chartab[0])) -// Characters Winstart..Winend are those that Windows -// uses interpolated into the Latin1 set. -// They aren't supposed to appear in HTML, but they do.... +/* Characters Winstart..Winend are those that Windows */ +/* uses interpolated into the Latin1 set. */ +/* They aren't supposed to appear in HTML, but they do.... */ enum { Winstart = 127, Winend = 159 }; -static int winchars[]= { 8226, // 8226 is a bullet +static int winchars[]= { 8226, /* 8226 is a bullet */ 8226, 8226, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 8226, 8226, 8226, 8226, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 8226, 8226, 376}; -static StringInt* tagtable; // initialized from tagnames -static StringInt* attrtable; // initialized from attrnames +static StringInt* tagtable; /* initialized from tagnames */ +static StringInt* attrtable; /* initialized from attrnames */ static void lexinit(void); static int getplaindata(TokenSource* ts, Token* a, int* pai); @@ -431,11 +431,11 @@ static Rune* buftostr(Rune* s, Rune* buf, int j); static int comment(TokenSource* ts); static int findstr(TokenSource* ts, Rune* s); static int ampersand(TokenSource* ts); -//static int lowerc(int c); +/*static int lowerc(int c); */ static int getchar(TokenSource* ts); static void ungetchar(TokenSource* ts, int c); static void backup(TokenSource* ts, int savei); -//static void freeinsidetoken(Token* t); +/*static void freeinsidetoken(Token* t); */ static void freeattrs(Attr* ahead); static Attr* newattr(int attid, Rune* value, Attr* link); static int Tconv(Fmt* f); @@ -475,8 +475,8 @@ enum { ToksChunk = 500 }; -// Call this to get the tokens. -// The number of returned tokens is returned in *plen. +/* Call this to get the tokens. */ +/* The number of returned tokens is returned in *plen. */ Token* _gettoks(uchar* data, int datalen, int chset, int mtype, int* plen) { @@ -509,7 +509,7 @@ _gettoks(uchar* data, int datalen, int chset, int mtype, int* plen) if(c == '<'){ tag = gettag(ts, starti, a, &ai); if(tag == Tscript){ - // special rules for getting Data after.... + /* special rules for getting Data after.... */ starti = ts->i; c = getchar(ts); tag = getscriptdata(ts, c, starti, a, &ai); @@ -524,7 +524,7 @@ _gettoks(uchar* data, int datalen, int chset, int mtype, int* plen) } } else { - // plain text (non-html) tokens + /* plain text (non-html) tokens */ for(;;){ if(ai == alen){ a = (Token*)erealloc(a, (alen+ToksChunk)*sizeof(Token)); @@ -545,12 +545,12 @@ _gettoks(uchar* data, int datalen, int chset, int mtype, int* plen) return a; } -// For case where source isn't HTML. -// Just make data tokens, one per line (or partial line, -// at end of buffer), ignoring non-whitespace control -// characters and dumping \r's. -// If find non-empty token, fill in a[*pai], bump *pai, and return Data. -// Otherwise return -1; +/* For case where source isn't HTML. */ +/* Just make data tokens, one per line (or partial line, */ +/* at end of buffer), ignoring non-whitespace control */ +/* characters and dumping \r's. */ +/* If find non-empty token, fill in a[*pai], bump *pai, and return Data. */ +/* Otherwise return -1; */ static int getplaindata(TokenSource* ts, Token* a, int* pai) { @@ -568,8 +568,8 @@ getplaindata(TokenSource* ts, Token* a, int* pai) if(c < ' '){ if(isspace(c)){ if(c == '\r'){ - // ignore it unless no following '\n', - // in which case treat it like '\n' + /* ignore it unless no following '\n', */ + /* in which case treat it like '\n' */ c = getchar(ts); if(c != '\n'){ if(c >= 0) @@ -602,7 +602,7 @@ getplaindata(TokenSource* ts, Token* a, int* pai) return Data; } -// Return concatenation of s and buf[0:j] +/* Return concatenation of s and buf[0:j] */ static Rune* buftostr(Rune* s, Rune* buf, int j) { @@ -614,11 +614,11 @@ buftostr(Rune* s, Rune* buf, int j) return s; } -// Gather data up to next start-of-tag or end-of-buffer. -// Translate entity references (&). -// Ignore non-whitespace control characters and get rid of \r's. -// If find non-empty token, fill in a[*pai], bump *pai, and return Data. -// Otherwise return -1; +/* Gather data up to next start-of-tag or end-of-buffer. */ +/* Translate entity references (&). */ +/* Ignore non-whitespace control characters and get rid of \r's. */ +/* If find non-empty token, fill in a[*pai], bump *pai, and return Data. */ +/* Otherwise return -1; */ static int getdata(TokenSource* ts, int firstc, int starti, Token* a, int* pai) { @@ -640,8 +640,8 @@ getdata(TokenSource* ts, int firstc, int starti, Token* a, int* pai) else if(c < ' '){ if(isspace(c)){ if(c == '\r'){ - // ignore it unless no following '\n', - // in which case treat it like '\n' + /* ignore it unless no following '\n', */ + /* in which case treat it like '\n' */ c = getchar(ts); if(c != '\n'){ if(c >= 0) @@ -680,8 +680,8 @@ getdata(TokenSource* ts, int firstc, int starti, Token* a, int* pai) return Data; } -// The rules for lexing scripts are different (ugh). -// Gather up everything until see a </SCRIPT>. +/* The rules for lexing scripts are different (ugh). */ +/* Gather up everything until see a </SCRIPT>. */ static int getscriptdata(TokenSource* ts, int firstc, int starti, Token* a, int* pai) { @@ -702,7 +702,7 @@ getscriptdata(TokenSource* ts, int firstc, int starti, Token* a, int* pai) done = 0; while(c >= 0){ if(c == '<'){ - // other browsers ignore stuff to end of line after <! + /* other browsers ignore stuff to end of line after <! */ savei = ts->i; c = getchar(ts); if(c == '!'){ @@ -725,7 +725,7 @@ getscriptdata(TokenSource* ts, int firstc, int starti, Token* a, int* pai) done = 1; break; } - // here tag was not </SCRIPT>, so take as regular data + /* here tag was not </SCRIPT>, so take as regular data */ c = getchar(ts); } } @@ -754,13 +754,13 @@ getscriptdata(TokenSource* ts, int firstc, int starti, Token* a, int* pai) return -1; } -// We've just seen a '<'. Gather up stuff to closing '>' (if buffer -// ends before then, return -1). -// If it's a tag, look up the name, gather the attributes, and return -// the appropriate token. -// Else it's either just plain data or some kind of ignorable stuff: -// return Data or Comment as appropriate. -// If it's not a Comment, put it in a[*pai] and bump *pai. +/* We've just seen a '<'. Gather up stuff to closing '>' (if buffer */ +/* ends before then, return -1). */ +/* If it's a tag, look up the name, gather the attributes, and return */ +/* the appropriate token. */ +/* Else it's either just plain data or some kind of ignorable stuff: */ +/* return Data or Comment as appropriate. */ +/* If it's not a Comment, put it in a[*pai] and bump *pai. */ static int gettag(TokenSource* ts, int starti, Token* a, int* pai) { @@ -795,7 +795,7 @@ gettag(TokenSource* ts, int starti, Token* a, int* pai) if(c < 0) goto eob_done; if(c >= 256 || !isalpha(c)){ - // not a tag + /* not a tag */ if(c == '!'){ ans = comment(ts); if(ans != -1) @@ -810,7 +810,7 @@ gettag(TokenSource* ts, int starti, Token* a, int* pai) return Data; } } - // c starts a tagname + /* c starts a tagname */ buf[0] = c; i = 1; for(;;){ @@ -819,20 +819,20 @@ gettag(TokenSource* ts, int starti, Token* a, int* pai) goto eob_done; if(!ISNAMCHAR(c)) break; - // if name is bigger than buf it won't be found anyway... + /* if name is bigger than buf it won't be found anyway... */ if(i < BIGBUFSIZE) buf[i++] = c; } if(_lookup(tagtable, Numtags, buf, i, &tag)) tok->tag = tag + rbra; else - tok->text = _Strndup(buf, i); // for warning print, in build + tok->text = _Strndup(buf, i); /* for warning print, in build */ - // attribute gathering loop + /* attribute gathering loop */ al = nil; for(;;){ - // look for "ws name" or "ws name ws = ws val" (ws=whitespace) - // skip whitespace + /* look for "ws name" or "ws name ws = ws val" (ws=whitespace) */ + /* skip whitespace */ attrloop_continue: while(c < 256 && isspace(c)){ c = getchar(ts); @@ -850,7 +850,7 @@ attrloop_continue: if(c >= 256 || !isalpha(c)){ if(warn) fprint(2, "warning: expected attribute name\n"); - // skipt to next attribute name + /* skipt to next attribute name */ for(;;){ c = getchar(ts); if(c < 0) @@ -867,7 +867,7 @@ attrloop_continue: goto attrloop_done; } } - // gather attribute name + /* gather attribute name */ buf[0] = c; i = 1; for(;;){ @@ -884,7 +884,7 @@ attrloop_continue: buf[i] = 0; fprint(2, "warning: unknown attribute name %S\n", buf); } - // skip whitespace + /* skip whitespace */ while(c < 256 && isspace(c)){ c = getchar(ts); if(c < 0) @@ -895,7 +895,7 @@ attrloop_continue: al = newattr(attid, nil, al); goto attrloop_continue; } - //# c is '=' here; skip whitespace + /*# c is '=' here; skip whitespace */ for(;;){ c = getchar(ts); if(c < 0) @@ -918,9 +918,9 @@ valloop_continue: goto eob_done; if(c == '>'){ if(quote){ - // c might be part of string (though not good style) - // but if line ends before close quote, assume - // there was an unmatched quote + /* c might be part of string (though not good style) */ + /* but if line ends before close quote, assume */ + /* there was an unmatched quote */ ti = ts->i; for(;;){ c = getchar(ts); @@ -999,18 +999,18 @@ eob_done: return Data; } -// We've just read a '<!' at position starti, -// so this may be a comment or other ignored section, or it may -// be just a literal string if there is no close before end of file -// (other browsers do that). -// The accepted practice seems to be (note: contrary to SGML spec!): -// If see <!--, look for --> to close, or if none, > to close. -// If see <!(not --), look for > to close. -// If no close before end of file, leave original characters in as literal data. -// -// If we see ignorable stuff, return Comment. -// Else return nil (caller should back up and try again when more data arrives, -// unless at end of file, in which case caller should just make '<' a data token). +/* We've just read a '<!' at position starti, */ +/* so this may be a comment or other ignored section, or it may */ +/* be just a literal string if there is no close before end of file */ +/* (other browsers do that). */ +/* The accepted practice seems to be (note: contrary to SGML spec!): */ +/* If see <!--, look for --> to close, or if none, > to close. */ +/* If see <!(not --), look for > to close. */ +/* If no close before end of file, leave original characters in as literal data. */ +/* */ +/* If we see ignorable stuff, return Comment. */ +/* Else return nil (caller should back up and try again when more data arrives, */ +/* unless at end of file, in which case caller should just make '<' a data token). */ static int comment(TokenSource* ts) { @@ -1043,9 +1043,9 @@ comment(TokenSource* ts) return -1; } -// Look for string s in token source. -// If found, return 1, with buffer at next char after s, -// else return 0 (caller should back up). +/* Look for string s in token source. */ +/* If found, return 1, with buffer at next char after s, */ +/* else return 0 (caller should back up). */ static int findstr(TokenSource* ts, Rune* s) { @@ -1093,13 +1093,13 @@ xdigit(int c) return -1; } -// We've just read an '&'; look for an entity reference -// name, and if found, return translated char. -// if there is a complete entity name but it isn't known, -// try prefixes (gets around some buggy HTML out there), -// and if that fails, back up to just past the '&' and return '&'. -// If the entity can't be completed in the current buffer, back up -// to the '&' and return -1. +/* We've just read an '&'; look for an entity reference */ +/* name, and if found, return translated char. */ +/* if there is a complete entity name but it isn't known, */ +/* try prefixes (gets around some buggy HTML out there), */ +/* and if that fails, back up to just past the '&' and return '&'. */ +/* If the entity can't be completed in the current buffer, back up */ +/* to the '&' and return -1. */ static int ampersand(TokenSource* ts) { @@ -1164,7 +1164,7 @@ ampersand(TokenSource* ts) if(c >= 0){ fnd = _lookup(chartab, NCHARTAB, buf, k, &ans); if(!fnd){ - // Try prefixes of s + /* Try prefixes of s */ if(c == ';' || c == '\n' || c == '\r') ungetchar(ts, c); i = k; @@ -1188,8 +1188,8 @@ ampersand(TokenSource* ts) return ans; } -// Get next char, obeying ts.chset. -// Returns -1 if no complete character left before current end of data. +/* Get next char, obeying ts.chset. */ +/* Returns -1 if no complete character left before current end of data. */ static int getchar(TokenSource* ts) { @@ -1226,19 +1226,19 @@ getchar(TokenSource* ts) c = r; } else { - // not enough bytes in buf to complete utf-8 char - ts->i = ts->edata; // mark "all used" + /* not enough bytes in buf to complete utf-8 char */ + ts->i = ts->edata; /* mark "all used" */ c = -1; } break; case Unicode: if(ts->i < ts->edata - 1){ - //standards say most-significant byte first + /*standards say most-significant byte first */ c = (c << 8)|(buf[ts->i + 1]); ts->i += 2; } else { - ts->i = ts->edata; // mark "all used" + ts->i = ts->edata; /* mark "all used" */ c = -1; } break; @@ -1246,9 +1246,9 @@ getchar(TokenSource* ts) return c; } -// Assuming c was the last character returned by getchar, set -// things up so that next getchar will get that same character -// followed by the current 'next character', etc. +/* Assuming c was the last character returned by getchar, set */ +/* things up so that next getchar will get that same character */ +/* followed by the current 'next character', etc. */ static void ungetchar(TokenSource* ts, int c) { @@ -1271,7 +1271,7 @@ ungetchar(TokenSource* ts, int c) ts->i -= n; } -// Restore ts so that it is at the state where the index was savei. +/* Restore ts so that it is at the state where the index was savei. */ static void backup(TokenSource* ts, int savei) { @@ -1281,14 +1281,14 @@ backup(TokenSource* ts, int savei) } -// Look for value associated with attribute attid in token t. -// If there is one, return 1 and put the value in *pans, -// else return 0. -// If xfer is true, transfer ownership of the string to the caller -// (nil it out here); otherwise, caller must duplicate the answer -// if it needs to save it. -// OK to have pans==0, in which case this is just looking -// to see if token is present. +/* Look for value associated with attribute attid in token t. */ +/* If there is one, return 1 and put the value in *pans, */ +/* else return 0. */ +/* If xfer is true, transfer ownership of the string to the caller */ +/* (nil it out here); otherwise, caller must duplicate the answer */ +/* if it needs to save it. */ +/* OK to have pans==0, in which case this is just looking */ +/* to see if token is present. */ int _tokaval(Token* t, int attid, Rune** pans, int xfer) { @@ -1356,8 +1356,8 @@ Tconv(Fmt *f) return fmtstrcpy(f, buf); } -// Attrs own their constituent strings, but build may eventually -// transfer some values to its items and nil them out in the Attr. +/* Attrs own their constituent strings, but build may eventually */ +/* transfer some values to its items and nil them out in the Attr. */ static Attr* newattr(int attid, Rune* value, Attr* link) { @@ -1370,7 +1370,7 @@ newattr(int attid, Rune* value, Attr* link) return ans; } -// Free list of Attrs linked through next field +/* Free list of Attrs linked through next field */ static void freeattrs(Attr* ahead) { @@ -1386,11 +1386,11 @@ freeattrs(Attr* ahead) } } -// Free array of Tokens. -// Allocated space might have room for more than n tokens, -// but only n of them are initialized. -// If caller has transferred ownership of constitutent strings -// or attributes, it must have nil'd out the pointers in the Tokens. +/* Free array of Tokens. */ +/* Allocated space might have room for more than n tokens, */ +/* but only n of them are initialized. */ +/* If caller has transferred ownership of constitutent strings */ +/* or attributes, it must have nil'd out the pointers in the Tokens. */ void _freetokens(Token* tarray, int n) { diff --git a/src/libhtml/runetab.h b/src/libhtml/runetab.h index 42f4928d..767b9483 100644 --- a/src/libhtml/runetab.h +++ b/src/libhtml/runetab.h @@ -46,7 +46,7 @@ enum { Lrefresh, Lselect, Lsquare, - Ltextarea, + Ltextarea }; #define L(x) runeconsttab[(x)] diff --git a/src/libhtml/strinttab.c b/src/libhtml/strinttab.c index 7883c044..df52e3fe 100644 --- a/src/libhtml/strinttab.c +++ b/src/libhtml/strinttab.c @@ -4,10 +4,10 @@ #include <html.h> #include "impl.h" -// Do case-insensitive lookup of key[0:keylen] in t[0:n] (key part), -// returning 1 if found, 0 if not. -// Array t must be sorted in increasing lexicographic order of key. -// If found, return corresponding val in *pans. +/* Do case-insensitive lookup of key[0:keylen] in t[0:n] (key part), */ +/* returning 1 if found, 0 if not. */ +/* Array t must be sorted in increasing lexicographic order of key. */ +/* If found, return corresponding val in *pans. */ int _lookup(StringInt* t, int n, Rune* key, int keylen, int* pans) { @@ -33,8 +33,8 @@ _lookup(StringInt* t, int n, Rune* key, int keylen, int* pans) return 0; } -// Return first key in t[0:n] that corresponds to val, -// nil if none. +/* Return first key in t[0:n] that corresponds to val, */ +/* nil if none. */ Rune* _revlookup(StringInt* t, int n, int val) { @@ -46,8 +46,8 @@ _revlookup(StringInt* t, int n, int val) return nil; } -// Make a StringInt table out of a[0:n], mapping each string -// to its index. Check that entries are in alphabetical order. +/* Make a StringInt table out of a[0:n], mapping each string */ +/* to its index. Check that entries are in alphabetical order. */ StringInt* _makestrinttab(Rune** a, int n) { diff --git a/src/libhtml/utils.c b/src/libhtml/utils.c index 32fd70d0..f8d2a19a 100644 --- a/src/libhtml/utils.c +++ b/src/libhtml/utils.c @@ -8,8 +8,8 @@ Rune whitespace[] = { ' ', '\t', '\n', '\r', '\0' }; Rune notwhitespace[] = { '^', ' ', '\t', '\n', '\r' , '\0'}; -// All lists start out like List structure. -// List itself can be used as list of int. +/* All lists start out like List structure. */ +/* List itself can be used as list of int. */ int _listlen(List* l) { @@ -22,7 +22,7 @@ _listlen(List* l) return n; } -// Cons +/* Cons */ List* _newlist(int val, List* rest) { @@ -34,7 +34,7 @@ _newlist(int val, List* rest) return ans; } -// Reverse a list in place +/* Reverse a list in place */ List* _revlist(List* l) { @@ -51,15 +51,15 @@ _revlist(List* l) return newl; } -// The next few routines take a "character class" as argument. -// e.g., "a-zA-Z", or "^ \t\n" -// (ranges indicated by - except in first position; -// ^ is first position means "not in" the following class) +/* The next few routines take a "character class" as argument. */ +/* e.g., "a-zA-Z", or "^ \t\n" */ +/* (ranges indicated by - except in first position; */ +/* ^ is first position means "not in" the following class) */ -// Splitl splits s[0:n] just before first character of class cl. -// Answers go in (p1, n1) and (p2, n2). -// If no split, the whole thing goes in the first component. -// Note: answers contain pointers into original string. +/* Splitl splits s[0:n] just before first character of class cl. */ +/* Answers go in (p1, n1) and (p2, n2). */ +/* If no split, the whole thing goes in the first component. */ +/* Note: answers contain pointers into original string. */ void _splitl(Rune* s, int n, Rune* cl, Rune** p1, int* n1, Rune** p2, int* n2) { @@ -79,10 +79,10 @@ _splitl(Rune* s, int n, Rune* cl, Rune** p1, int* n1, Rune** p2, int* n2) } } -// Splitr splits s[0:n] just after last character of class cl. -// Answers go in (p1, n1) and (p2, n2). -// If no split, the whole thing goes in the last component. -// Note: answers contain pointers into original string. +/* Splitr splits s[0:n] just after last character of class cl. */ +/* Answers go in (p1, n1) and (p2, n2). */ +/* If no split, the whole thing goes in the last component. */ +/* Note: answers contain pointers into original string. */ void _splitr(Rune* s, int n, Rune* cl, Rune** p1, int* n1, Rune** p2, int* n2) { @@ -103,11 +103,11 @@ _splitr(Rune* s, int n, Rune* cl, Rune** p1, int* n1, Rune** p2, int* n2) } } -// Splitall splits s[0:n] into parts that are separated by characters from class cl. -// Each part will have nonzero length. -// At most alen parts are found, and pointers to their starts go into -// the strarr array, while their lengths go into the lenarr array. -// The return value is the number of parts found. +/* Splitall splits s[0:n] into parts that are separated by characters from class cl. */ +/* Each part will have nonzero length. */ +/* At most alen parts are found, and pointers to their starts go into */ +/* the strarr array, while their lengths go into the lenarr array. */ +/* The return value is the number of parts found. */ int _splitall(Rune* s, int n, Rune* cl, Rune** strarr, int* lenarr, int alen) { @@ -138,8 +138,8 @@ _splitall(Rune* s, int n, Rune* cl, Rune** strarr, int* lenarr, int alen) return i; } -// Find part of s that excludes leading and trailing whitespace, -// and return that part in *pans (and its length in *panslen). +/* Find part of s that excludes leading and trailing whitespace, */ +/* and return that part in *pans (and its length in *panslen). */ void _trimwhite(Rune* s, int n, Rune** pans, int* panslen) { @@ -159,8 +159,8 @@ _trimwhite(Rune* s, int n, Rune** pans, int* panslen) *panslen = n; } -// _Strclass returns a pointer to the first element of s that is -// a member of class cl, nil if none. +/* _Strclass returns a pointer to the first element of s that is */ +/* a member of class cl, nil if none. */ Rune* _Strclass(Rune* s, Rune* cl) { @@ -172,8 +172,8 @@ _Strclass(Rune* s, Rune* cl) return nil; } -// _Strnclass returns a pointer to the first element of s[0:n] that is -// a member of class cl, nil if none. +/* _Strnclass returns a pointer to the first element of s[0:n] that is */ +/* a member of class cl, nil if none. */ Rune* _Strnclass(Rune* s, Rune* cl, int n) { @@ -185,8 +185,8 @@ _Strnclass(Rune* s, Rune* cl, int n) return nil; } -// _Strrclass returns a pointer to the last element of s that is -// a member of class cl, nil if none +/* _Strrclass returns a pointer to the last element of s that is */ +/* a member of class cl, nil if none */ Rune* _Strrclass(Rune* s, Rune* cl) { @@ -203,8 +203,8 @@ _Strrclass(Rune* s, Rune* cl) return nil; } -// _Strnrclass returns a pointer to the last element of s[0:n] that is -// a member of class cl, nil if none +/* _Strnrclass returns a pointer to the last element of s[0:n] that is */ +/* a member of class cl, nil if none */ Rune* _Strnrclass(Rune* s, Rune* cl, int n) { @@ -221,7 +221,7 @@ _Strnrclass(Rune* s, Rune* cl, int n) return nil; } -// Is c in the class cl? +/* Is c in the class cl? */ int _inclass(Rune c, Rune* cl) { @@ -258,7 +258,7 @@ _inclass(Rune c, Rune* cl) return ans; } -// Is pre a prefix of s? +/* Is pre a prefix of s? */ int _prefix(Rune* pre, Rune* s) { @@ -277,7 +277,7 @@ _prefix(Rune* pre, Rune* s) return 1; } -// Number of runes in (null-terminated) s +/* Number of runes in (null-terminated) s */ int _Strlen(Rune* s) { @@ -286,7 +286,7 @@ _Strlen(Rune* s) return runestrlen(s); } -// -1, 0, 1 as s1 is lexicographically less, equal greater than s2 +/* -1, 0, 1 as s1 is lexicographically less, equal greater than s2 */ int _Strcmp(Rune *s1, Rune *s2) { @@ -297,11 +297,11 @@ _Strcmp(Rune *s1, Rune *s2) return runestrcmp(s1, s2); } -// Like Strcmp, but use exactly n chars of s1 (assume s1 has at least n chars). -// Also, do a case-insensitive match, assuming s2 -// has no chars in [A-Z], only their lowercase versions. -// (This routine is used for in-place keyword lookup, where s2 is in a keyword -// list and s1 is some substring, possibly mixed-case, in a buffer.) +/* Like Strcmp, but use exactly n chars of s1 (assume s1 has at least n chars). */ +/* Also, do a case-insensitive match, assuming s2 */ +/* has no chars in [A-Z], only their lowercase versions. */ +/* (This routine is used for in-place keyword lookup, where s2 is in a keyword */ +/* list and s1 is some substring, possibly mixed-case, in a buffer.) */ int _Strncmpci(Rune *s1, int n1, Rune *s2) { @@ -325,7 +325,7 @@ _Strncmpci(Rune *s1, int n1, Rune *s2) } } -// emalloc and copy +/* emalloc and copy */ Rune* _Strdup(Rune* s) { @@ -334,9 +334,9 @@ _Strdup(Rune* s) return _Strndup(s, runestrlen(s)); } -// emalloc and copy n chars of s (assume s is at least that long), -// and add 0 terminator. -// Return nil if n==0. +/* emalloc and copy n chars of s (assume s is at least that long), */ +/* and add 0 terminator. */ +/* Return nil if n==0. */ Rune* _Strndup(Rune* s, int n) { @@ -349,15 +349,15 @@ _Strndup(Rune* s, int n) ans[n] = 0; return ans; } -// emalloc enough room for n Runes, plus 1 null terminator. -// (Not initialized to anything.) +/* emalloc enough room for n Runes, plus 1 null terminator. */ +/* (Not initialized to anything.) */ Rune* _newstr(int n) { return (Rune*)emalloc((n+1)*sizeof(Rune)); } -// emalloc and copy s+t +/* emalloc and copy s+t */ Rune* _Strdup2(Rune* s, Rune* t) { @@ -376,7 +376,7 @@ _Strdup2(Rune* s, Rune* t) return ans; } -// Return emalloc'd substring s[start:stop], +/* Return emalloc'd substring s[start:stop], */ Rune* _Strsubstr(Rune* s, int start, int stop) { @@ -388,7 +388,7 @@ _Strsubstr(Rune* s, int start, int stop) return t; } -// Copy n chars to s1 from s2, and return s1+n +/* Copy n chars to s1 from s2, and return s1+n */ Rune* _Stradd(Rune* s1, Rune* s2, int n) { @@ -398,10 +398,10 @@ _Stradd(Rune* s1, Rune* s2, int n) return s1+n; } -// Like strtol, but converting from Rune* string +/* Like strtol, but converting from Rune* string */ -//#define LONG_MAX 2147483647L -//#define LONG_MIN -2147483648L +/*#define LONG_MAX 2147483647L */ +/*#define LONG_MIN -2147483648L */ long _Strtol(Rune* nptr, Rune** endptr, int base) @@ -493,8 +493,8 @@ _Strtol(Rune* nptr, Rune** endptr, int base) return n; } -// Convert buf[0:n], bytes whose character set is chset, -// into a emalloc'd null-terminated Unicode string. +/* Convert buf[0:n], bytes whose character set is chset, */ +/* into a emalloc'd null-terminated Unicode string. */ Rune* toStr(uchar* buf, int n, int chset) { @@ -534,9 +534,9 @@ toStr(uchar* buf, int n, int chset) return ans; } -// Convert buf[0:n], Unicode characters, -// into an emalloc'd null-terminated string in character set chset. -// Use 0x80 for unconvertable characters. +/* Convert buf[0:n], Unicode characters, */ +/* into an emalloc'd null-terminated string in character set chset. */ +/* Use 0x80 for unconvertable characters. */ uchar* fromStr(Rune* buf, int n, int chset) { @@ -580,7 +580,7 @@ fromStr(Rune* buf, int n, int chset) } -// Convert n to emalloc'd String. +/* Convert n to emalloc'd String. */ Rune* _ltoStr(int n) { |