// table.cpp // Copyright (c)1997-1999 Microsoft Corporation, All Rights Reserved // HTML keyword tables // If you modify the element, attribute, or entity tables, then you MUST // update Token.h. #include "stdafx.h" #include "resource.h" #include "guids.h" #include "table.h" #undef ASSERT #define ASSERT(b) _ASSERTE(b) // qsort/bsearch helper int CmpFunc(const void *a, const void *b); static const TCHAR szFileSig[] = _T("@HLX@"); static const TCHAR szElTag[] = _T("[Elements]"); static const TCHAR szAttTag[] = _T("[Attributes]"); static const TCHAR szEntTag[] = _T("[Entities]"); //////////////////////////////////////////////////////////////////////////// #ifdef _DEBUG // // table verification routines // int CheckWordTable(ReservedWord *arw, int cel, LPCTSTR szName /*= NULL*/) { int cerr = 0; int cch; for (int i = 0; i < cel; i++) { // table must be sorted in ascending alpha order // if (i > 1) { if (!(_tcscmp(arw[i-1].psz, arw[i].psz) < 0)) { ATLTRACE(_T("lexer:entries in %s out of order at %d: %s - %s\n"), szName?szName:_T("?"), i-1, arw[i-1].psz, arw[i].psz); cerr++; } } // length must match // cch = _tcslen(arw[i].psz); if (cch != arw[i].cb) { ATLTRACE(_T("lexer:Incorrect entry in %s: %s,%d should be %d\n"), szName?szName:_T("?"), arw[i].psz, arw[i].cb, cch); cerr++; } } return cerr; } int CheckWordTableIndex(ReservedWord *arw, int cel, int *ai, BOOL bCase /*= FALSE*/, LPCTSTR szName /* = NULL*/) { int cerr = 0; int index; int max = bCase ? 52 : 26; _ASSERTE(NULL != arw); _ASSERTE(NULL != ai); int aik[] = { //A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //a b c d e f g h i j k l m n o p q r s t u v w x y z 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; // Build correct index array on static aik cerr += MakeIndexHere( arw, cel, aik, bCase ); // Compare with declared arrray // if (0 != memcmp(aik, ai, max)) cerr++; // If errors, dump correct array if (cerr) { ATLTRACE(_T("lexer: Correct index array for %s: \n{\n\t"), szName ? szName : _T("?")); for (index = 0; index < max - 1; index++) { ATLTRACE(_T("%3d,"), aik[index]); if (index % 13 == 12) ATLTRACE(_T("\n\t")); } ATLTRACE(_T("%3d\n};\n"), aik[index]); } return cerr; } #endif int MakeIndexHere(ReservedWord *arw, int cel, int *ab, BOOL bCase /*= FALSE*/, LPCTSTR szName /*= NULL*/) { int cerr = 0; int index; ASSERT(ab != NULL); ASSERT(arw != NULL); for (int irw = cel - 1; irw > 0; irw--) { index = PeekIndex(*arw[irw].psz, bCase); if (-1 != index) ab[index] = irw; else { ATLTRACE(_T("lexer:error in %s: non-alpha token %s\n"), szName?szName:_T("?"), arw[irw].psz); cerr++; } } return cerr; } int MakeIndex(ReservedWord *arw, int cel, int **pab, BOOL bCase /*= FALSE*/, LPCTSTR szName /*= NULL*/) { ASSERT(NULL != arw); ASSERT(NULL != pab); *pab = new int[ bCase ? 52 : 26 ]; if (NULL == *pab) return -1; return MakeIndexHere(arw, cel, *pab, bCase, szName); } #define RW_Entry(string, attribute) \ _T( #string ), sizeof( #string ) - 1, attribute //////////////////////////////////////////////////////////////////////////// // reserved word table // Two tables: // reserved[] = sorted table of reserved words // index[initial(token)] = (index of first reserved word with that initial) // If you modify the element, attribute, or entity tables, then you MUST // update Token.h. // // NOTE: the "HPn" elements are considered obsolete // static ReservedWord _rgElementNames[] = {// psz cb att _T(""), 0, 0, RW_Entry(A ,ALL ), RW_Entry(ADDRESS ,ALL ), RW_Entry(APPLET ,IEXPn ), // ??? RW_Entry(AREA ,IEXPn ), RW_Entry(B ,ALL ), RW_Entry(BASE ,ALL ), RW_Entry(BASEFONT ,IEXPn ), RW_Entry(BGSOUND ,IEXPn ), // IExplore RW_Entry(BIG ,IEXP3 ), RW_Entry(BLINK ,IEXPn ), // Netscape RW_Entry(BLOCKQUOTE ,ALL ), RW_Entry(BODY ,ALL ), RW_Entry(BR ,ALL ), RW_Entry(BUTTON ,IE40 ), RW_Entry(CAPTION ,IEXPn ), // tables RW_Entry(CENTER ,IEXPn ), RW_Entry(CITE ,ALL ), RW_Entry(CODE ,ALL ), RW_Entry(COL ,IEXP3 ), RW_Entry(COLGROUP ,IEXP3 ), // HTML 3 tables? RW_Entry(COMMENT ,ALL ), // considered obsolete RW_Entry(DD ,ALL ), RW_Entry(DFN ,ALL ), // RFC1866: not in the RFC, but deployed. ital or bold ital RW_Entry(DIR ,ALL ), RW_Entry(DIV ,IEXP3 ), // HTML 3 RW_Entry(DL ,ALL ), RW_Entry(DT ,ALL ), RW_Entry(EM ,ALL ), RW_Entry(EMBED ,IEXP3 ), // netscape -- IEXP3 RW_Entry(FIELDSET ,IE40 ), RW_Entry(FONT ,IEXPn ), RW_Entry(FORM ,ALL ), // forms RW_Entry(FRAME ,IEXP3 ), // framesets RW_Entry(FRAMESET ,IEXP3 ), // framesets RW_Entry(H1 ,ALL ), // heading 1 RW_Entry(H2 ,ALL ), // heading 2 RW_Entry(H3 ,ALL ), // heading 3 RW_Entry(H4 ,ALL ), // heading 4 RW_Entry(H5 ,ALL ), // heading 5 RW_Entry(H6 ,ALL ), // heading 6 RW_Entry(HEAD ,ALL ), // document head RW_Entry(HR ,ALL ), RW_Entry(HTML ,ALL ), RW_Entry(I ,ALL ), RW_Entry(IFRAME ,IEXP3 ), // inline frames RW_Entry(IMG ,ALL ), RW_Entry(INPUT ,ALL ), // forms RW_Entry(ISINDEX ,ALL ), RW_Entry(KBD ,ALL ), RW_Entry(LABEL ,IE40 ), RW_Entry(LEGEND ,IE40 ), RW_Entry(LI ,ALL ), RW_Entry(LINK ,ALL ), RW_Entry(LISTING ,ALL ), // RFC 1866: obsolete RW_Entry(MAP ,IEXPn ), RW_Entry(MARQUEE ,IEXPn ), // IExplore RW_Entry(MENU ,ALL ), RW_Entry(META ,ALL ), RW_Entry(METADATA ,ALL ), RW_Entry(NOBR ,IEXPn ), RW_Entry(NOFRAMES ,IEXP3 ), // framesets RW_Entry(NOSCRIPT ,IE40 ), // IE4 only RW_Entry(OBJECT ,IEXP3 ), // ActiveX RW_Entry(OL ,ALL ), RW_Entry(OPTION ,ALL ), // forms RW_Entry(P ,ALL ), RW_Entry(PARAM ,IEXP3 ), // ActiveX RW_Entry(PLAINTEXT ,ALL ), // RFC 1866: deprecated, noted as obsolete RW_Entry(PRE ,ALL ), RW_Entry(S ,IEXPn ), // (apparently) synonym for strike RW_Entry(SAMP ,ALL ), RW_Entry(SCRIPT ,IEXP3 ), // ActiveX RW_Entry(SELECT ,ALL ), RW_Entry(SMALL ,IEXP3 ), RW_Entry(SPAN ,IEXP3 ), // tables RW_Entry(STRIKE ,IEXPn ), // not in RFC 1866 DTD, but noted as deployed RW_Entry(STRONG ,ALL ), RW_Entry(STYLE ,IEXP3 ), // HTML 3 stylesheets RW_Entry(SUB ,IEXP3 ), // HTML3 ??? RW_Entry(SUP ,IEXP3 ), // HTML3 ??? RW_Entry(TABLE ,IEXPn ), // tables RW_Entry(TBODY ,IEXP3 ), // HTML 3 tables RW_Entry(TD ,IEXPn ), // tables RW_Entry(TEXTAREA ,ALL ), // forms RW_Entry(TFOOT ,IEXP3 ), // HTML 3 tables RW_Entry(TH ,IEXPn ), // tables RW_Entry(THEAD ,IEXP3 ), // HTML 3 tables RW_Entry(TITLE ,ALL ), RW_Entry(TR ,IEXPn ), // tables RW_Entry(TT ,ALL ), RW_Entry(U ,ALL ), // not in RFC 1866 DTD, but noted as deployed RW_Entry(UL ,ALL ), RW_Entry(VAR ,ALL ), RW_Entry(WBR ,IEXPn ), RW_Entry(XMP ,ALL ), // deprecated by RFC 1866 }; // If you modify the element, attribute, or entity tables, then you MUST // update Token.h. // The following array is a mapping of each letter to a position in the // table where tokens starting with that letter begin. // static int _rgIndexElementNames[] = // [Elements] { /* A */ TokElem_A , /* B */ TokElem_B , /* C */ TokElem_CAPTION , /* D */ TokElem_DD , /* E */ TokElem_EM , /* F */ TokElem_FIELDSET , /* G */ 0 , /* H */ TokElem_H1 , /* I */ TokElem_I , /* J */ 0 , /* K */ TokElem_KBD , /* L */ TokElem_LABEL , /* M */ TokElem_MAP , /* N */ TokElem_NOBR , /* O */ TokElem_OBJECT , /* P */ TokElem_P , /* Q */ 0 , /* R */ 0 , /* S */ TokElem_S , /* T */ TokElem_TABLE , /* U */ TokElem_U , /* V */ TokElem_VAR , /* W */ TokElem_WBR , /* X */ TokElem_XMP , /* Y */ 0 , /* Z */ 0 }; // If you modify the element, attribute, or entity tables, then you MUST // update Token.h. // // attribute name table // static ReservedWord _rgAttributeNames[] = {// psz cb att _T(""), 0, 0, RW_Entry(ACCESSKEY ,IEXP3 ), RW_Entry(ACTION ,ALL ), RW_Entry(ALIGN ,ALL ), RW_Entry(ALINK ,IEXPn ), RW_Entry(ALT ,ALL ), RW_Entry(APPNAME ,IE40 ), RW_Entry(APPVERSION ,IE40 ), RW_Entry(BACKGROUND ,IEXPn ), RW_Entry(BACKGROUNDATTACHMENT ,IE40 ), RW_Entry(BACKGROUNDCOLOR ,IE40 ), RW_Entry(BACKGROUNDIMAGE ,IE40 ), RW_Entry(BACKGROUNDPOSITION ,IE40 ), RW_Entry(BACKGROUNDPOSITIONX ,IE40 ), RW_Entry(BACKGROUNDPOSITIONY ,IE40 ), RW_Entry(BACKGROUNDREPEAT ,IE40 ), RW_Entry(BALANCE ,IE40 ), RW_Entry(BEHAVIOR ,IEXPn ), // MARQUEE RW_Entry(BGCOLOR ,IEXPn ), RW_Entry(BGPROPERTIES ,IEXPn ), RW_Entry(BORDER ,IEXPn ), RW_Entry(BORDERBOTTOM ,IE40 ), RW_Entry(BORDERBOTTOMCOLOR ,IE40 ), RW_Entry(BORDERBOTTOMSTYLE ,IE40 ), RW_Entry(BORDERBOTTOMWIDTH ,IE40 ), RW_Entry(BORDERCOLOR ,IEXPn ), // tables RW_Entry(BORDERCOLORDARK ,IEXPn ), // tables RW_Entry(BORDERCOLORLIGHT ,IEXPn ), // tables RW_Entry(BORDERLEFT ,IE40 ), RW_Entry(BORDERLEFTCOLOR ,IE40 ), RW_Entry(BORDERLEFTSTYLE ,IE40 ), RW_Entry(BORDERLEFTWIDTH ,IE40 ), RW_Entry(BORDERRIGHT ,IE40 ), RW_Entry(BORDERRIGHTCOLOR ,IE40 ), RW_Entry(BORDERRIGHTSTYLE ,IE40 ), RW_Entry(BORDERRIGHTWIDTH ,IE40 ), RW_Entry(BORDERSTYLE ,IE40 ), RW_Entry(BORDERTOP ,IE40 ), RW_Entry(BORDERTOPCOLOR ,IE40 ), RW_Entry(BORDERTOPSTYLE ,IE40 ), RW_Entry(BORDERTOPWIDTH ,IE40 ), RW_Entry(BORDERWIDTH ,IE40 ), RW_Entry(BOTTOMMARGIN ,IEXPn ), RW_Entry(BREAKPOINT ,IEXPn ), // (walts) hidden META tag attribute for brkpt mapping. RW_Entry(BUFFERDEPTH ,IE40 ), RW_Entry(BUTTON ,IE40 ), RW_Entry(CANCELBUBBLE ,IE40 ), RW_Entry(CELLPADDING ,IEXPn ), // tables RW_Entry(CELLSPACING ,IEXPn ), // tables RW_Entry(CENTER ,IEXPn ), RW_Entry(CHARSET ,IE40 ), RW_Entry(CHECKED ,ALL ), RW_Entry(CLASS ,IEXPn ), RW_Entry(CLASSID ,IEXP3 ), //objects RW_Entry(CLASSNAME ,IE40 ), RW_Entry(CLEAR ,IEXP3 ), RW_Entry(CLIP ,IE40 ), RW_Entry(CODE ,IEXPn ), RW_Entry(CODEBASE ,IEXP3 ), //objects RW_Entry(CODETYPE ,IE40 ), RW_Entry(COLOR ,IEXPn ), // font RW_Entry(COLORDEPTH ,IE40 ), RW_Entry(COLS ,ALL ), RW_Entry(COLSPAN ,IEXPn ), // tables RW_Entry(COMPACT ,ALL ), RW_Entry(COMPLETE ,IE40 ), RW_Entry(CONTENT ,ALL ), RW_Entry(CONTROLS ,IEXPn ), RW_Entry(COOKIE ,IE40 ), RW_Entry(COOKIEENABLED ,IE40 ), RW_Entry(COORDS ,IEXPn ), RW_Entry(CSSTEXT ,IE40 ), RW_Entry(CTRLKEY ,IE40 ), RW_Entry(CURSOR ,IE40 ), RW_Entry(DATA ,IEXP3 ), //objects RW_Entry(DATAFLD ,IE40 ), RW_Entry(DATAFORMATAS ,IE40 ), RW_Entry(DATAPAGESIZE ,IE40 ), RW_Entry(DATASRC ,IE40 ), RW_Entry(DECLARE ,IEXP3 ), //objects RW_Entry(DEFAULTCHECKED ,IE40 ), RW_Entry(DEFAULTSELECTED ,IE40 ), RW_Entry(DEFAULTSTATUS ,IE40 ), RW_Entry(DEFAULTVALUE ,IE40 ), RW_Entry(DIALOGARGUMENTS ,IE40 ), RW_Entry(DIALOGHEIGHT ,IE40 ), RW_Entry(DIALOGLEFT ,IE40 ), RW_Entry(DIALOGTOP ,IE40 ), RW_Entry(DIALOGWIDTH ,IE40 ), RW_Entry(DIR ,IEXP3 ), // HTML 3 ??? RW_Entry(DIRECTION ,IEXPn ), // MARQUEE RW_Entry(DISABLED ,IE40 ), RW_Entry(DISPLAY ,IE40 ), RW_Entry(DOMAIN ,IE40 ), RW_Entry(DYNSRC ,IEXPn ), RW_Entry(ENCODING ,IE40 ), RW_Entry(ENCTYPE ,ALL ), RW_Entry(ENDSPAN ,IE40 ), // Designer control tags RW_Entry(ENDSPAN-- ,IE40 ), // Designer control tags HACK to handle nonspace RW_Entry(EVENT ,IEXP3 ), // ActiveX