5 getTok(const char **pp)
7 /* inComment means one level of nesting; inComment+1 means two levels etc */
8 enum { inAtom, inString, init, inComment };
10 const char *tokStart = 0;
27 if (state != inString)
33 else if (state != inString)
74 /* key must be lowercase ASCII */
77 matchkey(const char *start, const char *end, const char *key)
81 for (; start != end; start++, key++)
82 if (*start != *key && *start != 'A' + (*key - 'a'))
88 getXMLCharset(const char *buf, char *charset)
95 if (matchkey(p, next, "text"))
96 strcpy(charset, "us-ascii");
97 else if (!matchkey(p, next, "application"))
104 if (!matchkey(p, next, "xml") && charset[0] == '\0')
111 if (matchkey(p, next, "charset")) {
113 if (p && *p == '=') {
118 while (++p != next - 1) {
121 if (s == charset + CHARSET_MAX - 1) {
130 if (next - p > CHARSET_MAX - 1)
152 main(int argc, char *argv[])
154 char buf[CHARSET_MAX];
157 printf("%s\n", argv[1]);
158 getXMLCharset(argv[1], buf);
159 printf("charset=\"%s\"\n", buf);