impl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. // UTILS
  10. typedef struct List List;
  11. typedef struct Strlist Strlist;
  12. // List of integers (and also generic list with next pointer at beginning)
  13. struct List
  14. {
  15. List* next;
  16. int val;
  17. };
  18. struct Strlist
  19. {
  20. Strlist* next;
  21. Rune* val;
  22. };
  23. extern int _inclass(Rune c, Rune* cl);
  24. extern int _listlen(List* l);
  25. extern List* _newlist(int val, List* rest);
  26. extern Rune* _newstr(int n);
  27. extern int _prefix(Rune* pre, Rune* s);
  28. extern List* _revlist(List* l);
  29. extern void _splitl(Rune* s, int n, Rune* cl, Rune** p1, int* n1, Rune** p2, int* n2);
  30. extern void _splitr(Rune* s, int n, Rune* cl, Rune** p1, int* n1, Rune** p2, int* n2);
  31. extern int _splitall(Rune* s, int n, Rune* cl, Rune** strarr, int* lenarr, int alen);
  32. extern Rune* _Stradd(Rune*s1, Rune* s2, int n);
  33. extern Rune* _Strclass(Rune* s, Rune* cl);
  34. extern int _Strcmp(Rune* s1, Rune* s2);
  35. extern Rune* _Strdup(Rune* s);
  36. extern Rune* _Strdup2(Rune* s, Rune* t);
  37. extern int _Streqn(Rune* s1, int n1, Rune* s2);
  38. extern int _Strlen(Rune* s);
  39. extern Rune* _Strnclass(Rune* s, Rune* cl, int n);
  40. extern int _Strncmpci(Rune* s1, int n1, Rune* s2);
  41. extern Rune* _Strndup(Rune* s, int n);
  42. extern Rune* _Strnrclass(Rune* s, Rune* cl, int n);
  43. extern Rune* _Strrclass(Rune* s, Rune* cl);
  44. extern Rune* _Strsubstr(Rune* s, int start, int stop);
  45. extern int32_t _Strtol(Rune* s, Rune** eptr, int base);
  46. extern void _trimwhite(Rune* s, int n, Rune** pans, int* panslen);
  47. extern Rune* notwhitespace;
  48. extern Rune* whitespace;
  49. // STRINTTAB
  50. typedef struct StringInt StringInt;
  51. // Element of String-Int table (used for keyword lookup)
  52. struct StringInt
  53. {
  54. Rune* key;
  55. int val;
  56. };
  57. extern int _lookup(StringInt* t, int n, Rune* key, int keylen, int* pans);
  58. extern StringInt* _makestrinttab(Rune** a, int n);
  59. extern Rune* _revlookup(StringInt* t, int n, int val);
  60. // Colors, in html format, not Plan 9 format. (RGB values in bottom 3 bytes)
  61. enum {
  62. White = 0xFFFFFF,
  63. Black = 0x000000,
  64. Blue = 0x0000CC,
  65. };
  66. // LEX
  67. // HTML 4.0 tags (plus blink, nobr)
  68. // sorted in lexical order; used as array indices
  69. enum {
  70. Notfound,
  71. Comment,
  72. Ta, Tabbr, Tacronym, Taddress, Tapplet, Tarea,
  73. Tb, Tbase, Tbasefont, Tbdo, Tbig, Tblink,
  74. Tblockquote, Tbody, Tbq, Tbr, Tbutton,
  75. Tcaption, Tcenter, Tcite, Tcode, Tcol, Tcolgroup,
  76. Tdd, Tdel, Tdfn, Tdir, Tdiv, Tdl, Tdt,
  77. Tem,
  78. Tfieldset, Tfont, Tform, Tframe, Tframeset,
  79. Th1, Th2, Th3, Th4, Th5, Th6,
  80. Thead, Thr, Thtml,
  81. Ti, Tiframe, Timg, Tinput, Tins, Tisindex,
  82. Tkbd,
  83. Tlabel, Tlegend, Tli, Tlink,
  84. Tmap, Tmenu, Tmeta,
  85. Tnobr, Tnoframes, Tnoscript,
  86. Tobject, Tol, Toptgroup, Toption,
  87. Tp, Tparam, Tpre,
  88. Tq,
  89. Ts, Tsamp, Tscript, Tselect, Tsmall,
  90. Tspan, Tstrike, Tstrong, Tstyle, Tsub, Tsup,
  91. Ttable, Ttbody, Ttd, Ttextarea, Ttfoot,
  92. Tth, Tthead, Ttitle, Ttr, Ttt,
  93. Tu, Tul,
  94. Tvar,
  95. Numtags,
  96. RBRA = Numtags,
  97. Data = Numtags+RBRA
  98. };
  99. // HTML 4.0 tag attributes
  100. // Keep sorted in lexical order
  101. enum {
  102. Aabbr, Aaccept_charset, Aaccess_key, Aaction,
  103. Aalign, Aalink, Aalt, Aarchive, Aaxis,
  104. Abackground, Abgcolor, Aborder,
  105. Acellpadding, Acellspacing, Achar, Acharoff,
  106. Acharset, Achecked, Acite, Aclass, Aclassid,
  107. Aclear, Acode, Acodebase, Acodetype, Acolor,
  108. Acols, Acolspan, Acompact, Acontent, Acoords,
  109. Adata, Adatetime, Adeclare, Adefer, Adir, Adisabled,
  110. Aenctype,
  111. Aface, Afor, Aframe, Aframeborder,
  112. Aheaders, Aheight, Ahref, Ahreflang, Ahspace, Ahttp_equiv,
  113. Aid, Aismap,
  114. Alabel, Alang, Alink, Alongdesc,
  115. Amarginheight, Amarginwidth, Amaxlength,
  116. Amedia, Amethod, Amultiple,
  117. Aname, Anohref, Anoresize, Anoshade, Anowrap,
  118. Aobject, Aonblur, Aonchange, Aonclick, Aondblclick,
  119. Aonfocus, Aonkeypress, Aonkeyup, Aonload,
  120. Aonmousedown, Aonmousemove, Aonmouseout,
  121. Aonmouseover, Aonmouseup, Aonreset, Aonselect,
  122. Aonsubmit, Aonunload,
  123. Aprofile, Aprompt,
  124. Areadonly, Arel, Arev, Arows, Arowspan, Arules,
  125. Ascheme, Ascope, Ascrolling, Aselected, Ashape,
  126. Asize, Aspan, Asrc, Astandby, Astart, Astyle, Asummary,
  127. Atabindex, Atarget, Atext, Atitle, Atype,
  128. Ausemap,
  129. Avalign, Avalue, Avaluetype, Aversion, Avlink, Avspace,
  130. Awidth,
  131. Numattrs
  132. };
  133. struct Attr
  134. {
  135. Attr* next; // in list of attrs for a token
  136. int attid; // Aabbr, etc.
  137. Rune* value;
  138. };
  139. struct Token
  140. {
  141. int tag; // Ta, etc
  142. Rune* text; // text in Data, attribute text in tag
  143. Attr* attr; // list of Attrs
  144. int starti; // index into source buffer of token start
  145. };
  146. extern Rune* tagnames[];
  147. extern Rune* attrnames[];
  148. extern void _freetokens(Token* tarray, int n);
  149. extern Token* _gettoks(unsigned char* data, int datalen, int chset, int mtype, int* plen);
  150. extern int _tokaval(Token* t, int attid, Rune** pans, int xfer);
  151. #pragma varargck type "T" Token*