4546 lines · 98.2 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <draw.h>#include <ctype.h>#include <html.h>#include "impl.h" /* A stack for holding integer values */enum {	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 */}; /* 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 */}; struct ItemSource{	Docinfo*		doc;	Pstate*		psstk;	int			nforms;	int			ntables;	int			nanchors;	int			nframes;	Form*		curform;	Map*		curmap;	Table*		tabstk;	Kidinfo*		kidstk;}; /* 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 */}; /* These tables must be sorted */static StringInt *align_tab;static AsciiInt _align_tab[] = {	{"baseline",	ALbaseline},	{"bottom",	ALbottom},	{"center",	ALcenter},	{"char",		ALchar},	{"justify",	ALjustify},	{"left",		ALleft},	{"middle",	ALmiddle},	{"right",		ALright},	{"top",		ALtop}};#define NALIGNTAB (sizeof(_align_tab)/sizeof(StringInt)) static StringInt *input_tab;static AsciiInt _input_tab[] = {	{"button",	Fbutton},	{"checkbox",	Fcheckbox},	{"file",		Ffile},	{"hidden",	Fhidden},	{"image",	Fimage},	{"password",	Fpassword},	{"radio",		Fradio},	{"reset",		Freset},	{"submit",	Fsubmit},	{"text",		Ftext}};#define NINPUTTAB (sizeof(_input_tab)/sizeof(StringInt)) static StringInt *clear_tab;static AsciiInt _clear_tab[] = {	{"all",	IFcleft|IFcright},	{"left",	IFcleft},	{"right",	IFcright}};#define NCLEARTAB (sizeof(_clear_tab)/sizeof(StringInt)) static StringInt *fscroll_tab;static AsciiInt _fscroll_tab[] = {	{"auto",	FRhscrollauto|FRvscrollauto},	{"no",	FRnoscroll},	{"yes",	FRhscroll|FRvscroll},};#define NFSCROLLTAB (sizeof(_fscroll_tab)/sizeof(StringInt)) static StringInt *shape_tab;static AsciiInt _shape_tab[] = {	{"circ",		SHcircle},	{"circle",		SHcircle},	{"poly",		SHpoly},	{"polygon",	SHpoly},	{"rect",		SHrect},	{"rectangle",	SHrect}};#define NSHAPETAB (sizeof(_shape_tab)/sizeof(StringInt)) static StringInt *method_tab;static AsciiInt _method_tab[] = {	{"get",		HGet},	{"post",		HPost}};#define NMETHODTAB (sizeof(_method_tab)/sizeof(StringInt)) static Rune** roman;static char* _roman[15]= {	"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X",	"XI", "XII", "XIII", "XIV", "XV"};#define NROMAN 15 /* List number types */enum {	LTdisc, LTsquare, LTcircle, LT1, LTa, LTA, LTi, LTI}; enum {	SPBefore = 2,	SPAfter = 4,	BL = 1,	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. */ static uchar blockbrk[Numtags]= {/*Notfound*/ 0,/*Comment*/ 0,/*Ta*/ 0,/*Tabbr*/ 0,/*Tacronym*/ 0,/*Taddress*/ BLBA,/*Tapplet*/ 0,/*Tarea*/ 0,/*Tb*/ 0,/*Tbase*/ 0,/*Tbasefont*/ 0,/*Tbdo*/ 0,/*Tbig*/ 0,/*Tblink*/ 0,/*Tblockquote*/ BLBA,/*Tbody*/ 0,/*Tbq*/ 0,/*Tbr*/ 0,/*Tbutton*/ 0,/*Tcaption*/ 0,/*Tcenter*/ BL,/*Tcite*/ 0,/*Tcode*/ 0,/*Tcol*/ 0,/*Tcolgroup*/ 0,/*Tdd*/ BL,/*Tdel*/ 0,/*Tdfn*/ 0,/*Tdir*/ BLBA,/*Tdiv*/ BL,/*Tdl*/ BLBA,/*Tdt*/ BL,/*Tem*/ 0,/*Tfieldset*/ 0,/*Tfont*/ 0,/*Tform*/ BLBA,/*Tframe*/ 0,/*Tframeset*/ 0,/*Th1*/ BL,/*Th2*/ BL,/*Th3*/ BL,/*Th4*/ BL,/*Th5*/ BL,/*Th6*/ BL,/*Thead*/ 0,/*Thr*/ BL,/*Thtml*/ 0,/*Ti*/ 0,/*Tiframe*/ 0,/*Timg*/ 0,/*Tinput*/ 0,/*Tins*/ 0,/*Tisindex*/ BLBA,/*Tkbd*/ 0,/*Tlabel*/ 0,/*Tlegend*/ 0,/*Tli*/ BL,/*Tlink*/ 0,/*Tmap*/ 0,/*Tmenu*/ BLBA,/*Tmeta*/ 0,/*Tnobr*/ 0,/*Tnoframes*/ 0,/*Tnoscript*/ 0,/*Tobject*/ 0,/*Tol*/ BLBA,/*Toptgroup*/ 0,/*Toption*/ 0,/*Tp*/ BLBA,/*Tparam*/ 0,/*Tpre*/ BLBA,/*Tq*/ 0,/*Ts*/ 0,/*Tsamp*/ 0,/*Tscript*/ 0,/*Tselect*/ 0,/*Tsmall*/ 0,/*Tspan*/ 0,/*Tstrike*/ 0,/*Tstrong*/ 0,/*Tstyle*/ 0,/*Tsub*/ 0,/*Tsup*/ 0,/*Ttable*/ 0,/*Ttbody*/ 0,/*Ttd*/ 0,/*Ttextarea*/ 0,/*Ttfoot*/ 0,/*Tth*/ 0,/*Tthead*/ 0,/*Ttitle*/ 0,/*Ttr*/ 0,/*Ttt*/ 0,/*Tu*/ 0,/*Tul*/ BLBA,/*Tvar*/ 0,}; enum {	AGEN = 1}; /* 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,/*Aaccess_key*/ 0,/*Aaction*/ 0,/*Aalign*/ 0,/*Aalink*/ 0,/*Aalt*/ 0,/*Aarchive*/ 0,/*Aaxis*/ 0,/*Abackground*/ 0,/*Abgcolor*/ 0,/*Aborder*/ 0,/*Acellpadding*/ 0,/*Acellspacing*/ 0,/*Achar*/ 0,/*Acharoff*/ 0,/*Acharset*/ 0,/*Achecked*/ 0,/*Acite*/ 0,/*Aclass*/ AGEN,/*Aclassid*/ 0,/*Aclear*/ 0,/*Acode*/ 0,/*Acodebase*/ 0,/*Acodetype*/ 0,/*Acolor*/ 0,/*Acols*/ 0,/*Acolspan*/ 0,/*Acompact*/ 0,/*Acontent*/ 0,/*Acoords*/ 0,/*Adata*/ 0,/*Adatetime*/ 0,/*Adeclare*/ 0,/*Adefer*/ 0,/*Adir*/ 0,/*Adisabled*/ 0,/*Aenctype*/ 0,/*Aface*/ 0,/*Afor*/ 0,/*Aframe*/ 0,/*Aframeborder*/ 0,/*Aheaders*/ 0,/*Aheight*/ 0,/*Ahref*/ 0,/*Ahreflang*/ 0,/*Ahspace*/ 0,/*Ahttp_equiv*/ 0,/*Aid*/ AGEN,/*Aismap*/ 0,/*Alabel*/ 0,/*Alang*/ 0,/*Alink*/ 0,/*Alongdesc*/ 0,/*Amarginheight*/ 0,/*Amarginwidth*/ 0,/*Amaxlength*/ 0,/*Amedia*/ 0,/*Amethod*/ 0,/*Amultiple*/ 0,/*Aname*/ 0,/*Anohref*/ 0,/*Anoresize*/ 0,/*Anoshade*/ 0,/*Anowrap*/ 0,/*Aobject*/ 0,/*Aonblur*/ AGEN,/*Aonchange*/ AGEN,/*Aonclick*/ AGEN,/*Aondblclick*/ AGEN,/*Aonfocus*/ AGEN,/*Aonkeypress*/ AGEN,/*Aonkeyup*/ AGEN,/*Aonload*/ AGEN,/*Aonmousedown*/ AGEN,/*Aonmousemove*/ AGEN,/*Aonmouseout*/ AGEN,/*Aonmouseover*/ AGEN,/*Aonmouseup*/ AGEN,/*Aonreset*/ AGEN,/*Aonselect*/ AGEN,/*Aonsubmit*/ AGEN,/*Aonunload*/ AGEN,/*Aprofile*/ 0,/*Aprompt*/ 0,/*Areadonly*/ 0,/*Arel*/ 0,/*Arev*/ 0,/*Arows*/ 0,/*Arowspan*/ 0,/*Arules*/ 0,/*Ascheme*/ 0,/*Ascope*/ 0,/*Ascrolling*/ 0,/*Aselected*/ 0,/*Ashape*/ 0,/*Asize*/ 0,/*Aspan*/ 0,/*Asrc*/ 0,/*Astandby*/ 0,/*Astart*/ 0,/*Astyle*/ AGEN,/*Asummary*/ 0,/*Atabindex*/ 0,/*Atarget*/ 0,/*Atext*/ 0,/*Atitle*/ AGEN,/*Atype*/ 0,/*Ausemap*/ 0,/*Avalign*/ 0,/*Avalue*/ 0,/*Avaluetype*/ 0,/*Aversion*/ 0,/*Avlink*/ 0,/*Avspace*/ 0,/*Awidth*/ 0,}; static uchar scriptev[Numattrs]= {/*Aabbr*/ 0,/*Aaccept_charset*/ 0,/*Aaccess_key*/ 0,/*Aaction*/ 0,/*Aalign*/ 0,/*Aalink*/ 0,/*Aalt*/ 0,/*Aarchive*/ 0,/*Aaxis*/ 0,/*Abackground*/ 0,/*Abgcolor*/ 0,/*Aborder*/ 0,/*Acellpadding*/ 0,/*Acellspacing*/ 0,/*Achar*/ 0,/*Acharoff*/ 0,/*Acharset*/ 0,/*Achecked*/ 0,/*Acite*/ 0,/*Aclass*/ 0,/*Aclassid*/ 0,/*Aclear*/ 0,/*Acode*/ 0,/*Acodebase*/ 0,/*Acodetype*/ 0,/*Acolor*/ 0,/*Acols*/ 0,/*Acolspan*/ 0,/*Acompact*/ 0,/*Acontent*/ 0,/*Acoords*/ 0,/*Adata*/ 0,/*Adatetime*/ 0,/*Adeclare*/ 0,/*Adefer*/ 0,/*Adir*/ 0,/*Adisabled*/ 0,/*Aenctype*/ 0,/*Aface*/ 0,/*Afor*/ 0,/*Aframe*/ 0,/*Aframeborder*/ 0,/*Aheaders*/ 0,/*Aheight*/ 0,/*Ahref*/ 0,/*Ahreflang*/ 0,/*Ahspace*/ 0,/*Ahttp_equiv*/ 0,/*Aid*/ 0,/*Aismap*/ 0,/*Alabel*/ 0,/*Alang*/ 0,/*Alink*/ 0,/*Alongdesc*/ 0,/*Amarginheight*/ 0,/*Amarginwidth*/ 0,/*Amaxlength*/ 0,/*Amedia*/ 0,/*Amethod*/ 0,/*Amultiple*/ 0,/*Aname*/ 0,/*Anohref*/ 0,/*Anoresize*/ 0,/*Anoshade*/ 0,/*Anowrap*/ 0,/*Aobject*/ 0,/*Aonblur*/ SEonblur,/*Aonchange*/ SEonchange,/*Aonclick*/ SEonclick,/*Aondblclick*/ SEondblclick,/*Aonfocus*/ SEonfocus,/*Aonkeypress*/ SEonkeypress,/*Aonkeyup*/ SEonkeyup,/*Aonload*/ SEonload,/*Aonmousedown*/ SEonmousedown,/*Aonmousemove*/ SEonmousemove,/*Aonmouseout*/ SEonmouseout,/*Aonmouseover*/ SEonmouseover,/*Aonmouseup*/ SEonmouseup,/*Aonreset*/ SEonreset,/*Aonselect*/ SEonselect,/*Aonsubmit*/ SEonsubmit,/*Aonunload*/ SEonunload,/*Aprofile*/ 0,/*Aprompt*/ 0,/*Areadonly*/ 0,/*Arel*/ 0,/*Arev*/ 0,/*Arows*/ 0,/*Arowspan*/ 0,/*Arules*/ 0,/*Ascheme*/ 0,/*Ascope*/ 0,/*Ascrolling*/ 0,/*Aselected*/ 0,/*Ashape*/ 0,/*Asize*/ 0,/*Aspan*/ 0,/*Asrc*/ 0,/*Astandby*/ 0,/*Astart*/ 0,/*Astyle*/ 0,/*Asummary*/ 0,/*Atabindex*/ 0,/*Atarget*/ 0,/*Atext*/ 0,/*Atitle*/ 0,/*Atype*/ 0,

Lines 1–500 of 4546.