35#define XML_USE_MSC_EXTENSIONS 1
40#ifndef XML_STATUS_ERROR
41#define XML_STATUS_ERROR 0
91static void lexerror(
const char *name)
98typedef int (*attrFn) (
void *,
char *);
99typedef int (*bcmpfn) (
const void *,
const void *);
107#define ISIZE (sizeof(attr_item))
112static int icmp(
const void *name,
const void *
item) {
113 const attr_item *j =
item;
114 return strcasecmp(name, j->name);
137 unsigned short flags = 0;
155 agwarningf(
"Unrecognized character '%c' (%d) in sides attribute\n", c, c);
166 p->
title = strdup(v);
193 agwarningf(
"Illegal value %.*s for STYLE - ignored\n", (
int)tk.
size,
220static int doInt(
char *v,
char *
s,
int min,
int max,
long *ul)
224 long b = strtol(v, &ep, 10);
227 agwarningf(
"Improper %s value %s - ignored",
s, v);
229 }
else if (b > max) {
230 agwarningf(
"%s value %s > %d - too large - ignored",
s, v, max);
232 }
else if (b < min) {
233 agwarningf(
"%s value %s < %d - too small - ignored",
s, v, min);
241static int gradientanglefn(
htmldata_t * p,
char *v)
245 if (doInt(v,
"GRADIENTANGLE", 0, 360, &u))
256 if (doInt(v,
"BORDER", 0, UCHAR_MAX, &u))
258 p->
border = (
unsigned char) u;
263static int cellpaddingfn(
htmldata_t * p,
char *v)
267 if (doInt(v,
"CELLPADDING", 0, UCHAR_MAX, &u))
269 p->
pad = (
unsigned char) u;
274static int cellspacingfn(
htmldata_t * p,
char *v)
278 if (doInt(v,
"CELLSPACING", SCHAR_MIN, SCHAR_MAX, &u))
280 p->
space = (
signed char) u;
285static int cellborderfn(
htmltbl_t * p,
char *v)
289 if (doInt(v,
"CELLBORDER", 0,
INT8_MAX, &u))
295static int columnsfn(
htmltbl_t * p,
char *v)
298 agwarningf(
"Unknown value %s for COLUMNS - ignored\n", v);
308 agwarningf(
"Unknown value %s for ROWS - ignored\n", v);
315static int fixedsizefn(
htmldata_t * p,
char *v)
318 if (!strcasecmp(v,
"TRUE"))
320 else if (strcasecmp(v,
"FALSE")) {
321 agwarningf(
"Illegal value %s for FIXEDSIZE - ignored\n", v);
330 if (!strcasecmp(v,
"BOTTOM"))
332 else if (!strcasecmp(v,
"TOP"))
334 else if (strcasecmp(v,
"MIDDLE")) {
335 agwarningf(
"Illegal value %s for VALIGN - ignored\n", v);
344 if (!strcasecmp(v,
"LEFT"))
346 else if (!strcasecmp(v,
"RIGHT"))
348 else if (strcasecmp(v,
"CENTER")) {
349 agwarningf(
"Illegal value %s for ALIGN - ignored\n", v);
355static int cell_halignfn(
htmldata_t * p,
char *v)
358 if (!strcasecmp(v,
"LEFT"))
360 else if (!strcasecmp(v,
"RIGHT"))
362 else if (!strcasecmp(v,
"TEXT"))
364 else if (strcasecmp(v,
"CENTER"))
367 agwarningf(
"Illegal value %s for ALIGN in TD - ignored\n", v);
374 if (!strcasecmp(v,
"LEFT"))
376 else if (!strcasecmp(v,
"RIGHT"))
378 else if (strcasecmp(v,
"CENTER"))
381 agwarningf(
"Illegal value %s for BALIGN in TD - ignored\n", v);
389 if (doInt(v,
"HEIGHT", 0, USHRT_MAX, &u))
391 p->
height = (
unsigned short) u;
399 if (doInt(v,
"WIDTH", 0, USHRT_MAX, &u))
401 p->
width = (
unsigned short) u;
412 agwarningf(
"ROWSPAN value cannot be 0 - ignored\n");
426 agwarningf(
"COLSPAN value cannot be 0 - ignored\n");
433static int fontcolorfn(
textfont_t * p,
char *v)
449 if (doInt(v,
"POINT-SIZE", 0, UCHAR_MAX, &u))
451 p->
size = (double) u;
461static int scalefn(
htmlimg_t * p,
char *v)
463 p->
scale = strdup(v);
467static int alignfn(
int *p,
char *v)
470 if (!strcasecmp(v,
"RIGHT"))
472 else if (!strcasecmp(v,
"LEFT"))
474 else if (!strcasecmp(v,
"CENTER"))
477 agwarningf(
"Illegal value %s for ALIGN - ignored\n", v);
484static attr_item tbl_items[] = {
485 {
"align", (attrFn) halignfn},
486 {
"bgcolor", (attrFn) bgcolorfn},
487 {
"border", (attrFn) borderfn},
488 {
"cellborder", (attrFn) cellborderfn},
489 {
"cellpadding", (attrFn) cellpaddingfn},
490 {
"cellspacing", (attrFn) cellspacingfn},
491 {
"color", (attrFn) pencolorfn},
492 {
"columns", (attrFn) columnsfn},
493 {
"fixedsize", (attrFn) fixedsizefn},
494 {
"gradientangle", (attrFn) gradientanglefn},
495 {
"height", (attrFn) heightfn},
496 {
"href", (attrFn) hreffn},
497 {
"id", (attrFn) idfn},
498 {
"port", (attrFn) portfn},
499 {
"rows", (attrFn) rowsfn},
500 {
"sides", (attrFn) sidesfn},
501 {
"style", (attrFn) stylefn},
502 {
"target", (attrFn) targetfn},
503 {
"title", (attrFn) titlefn},
504 {
"tooltip", (attrFn) titlefn},
505 {
"valign", (attrFn) valignfn},
506 {
"width", (attrFn) widthfn},
509static attr_item cell_items[] = {
510 {
"align", (attrFn) cell_halignfn},
511 {
"balign", (attrFn) balignfn},
512 {
"bgcolor", (attrFn) bgcolorfn},
513 {
"border", (attrFn) borderfn},
514 {
"cellpadding", (attrFn) cellpaddingfn},
515 {
"cellspacing", (attrFn) cellspacingfn},
516 {
"color", (attrFn) pencolorfn},
517 {
"colspan", (attrFn) colspanfn},
518 {
"fixedsize", (attrFn) fixedsizefn},
519 {
"gradientangle", (attrFn) gradientanglefn},
520 {
"height", (attrFn) heightfn},
521 {
"href", (attrFn) hreffn},
522 {
"id", (attrFn) idfn},
523 {
"port", (attrFn) portfn},
524 {
"rowspan", (attrFn) rowspanfn},
525 {
"sides", (attrFn) sidesfn},
526 {
"style", (attrFn) stylefn},
527 {
"target", (attrFn) targetfn},
528 {
"title", (attrFn) titlefn},
529 {
"tooltip", (attrFn) titlefn},
530 {
"valign", (attrFn) valignfn},
531 {
"width", (attrFn) widthfn},
534static attr_item font_items[] = {
535 {
"color", (attrFn) fontcolorfn},
536 {
"face", (attrFn) facefn},
537 {
"point-size", (attrFn) ptsizefn},
540static attr_item img_items[] = {
541 {
"scale", (attrFn) scalefn},
542 {
"src", (attrFn) srcfn},
545static attr_item br_items[] = {
546 {
"align", (attrFn) alignfn},
557static void doAttrs(
void *tp, attr_item *items,
size_t nel,
char **atts,
563 while ((name = *atts++) !=
NULL) {
565 ip = bsearch(name, items, nel, ISIZE, icmp);
569 agwarningf(
"Illegal attribute %s in %s - ignored\n", name,
576static void mkBR(
char **atts)
579 doAttrs(&
htmllval.
i, br_items,
sizeof(br_items) / ISIZE, atts,
"<BR>");
586 doAttrs(img, img_items,
sizeof(img_items) / ISIZE, atts,
"<IMG>");
596 assert(
flags <= FLAGS_MAX);
597 tf.
flags = (
unsigned char)(
flags & FLAGS_MAX);
599 doAttrs(&tf, font_items,
sizeof(font_items) / ISIZE, atts,
"<FONT>");
610 doAttrs(
cell, cell_items,
sizeof(cell_items) / ISIZE, atts,
"<TD>");
621 doAttrs(tbl, tbl_items,
sizeof(tbl_items) / ISIZE, atts,
"<TABLE>");
626static void startElement(
void *user,
const char *name,
char **atts)
630 if (strcasecmp(name,
"TABLE") == 0) {
634 }
else if (strcasecmp(name,
"TR") == 0 || strcasecmp(name,
"TH") == 0) {
637 }
else if (strcasecmp(name,
"TD") == 0) {
641 }
else if (strcasecmp(name,
"FONT") == 0) {
644 }
else if (strcasecmp(name,
"B") == 0) {
647 }
else if (strcasecmp(name,
"S") == 0) {
650 }
else if (strcasecmp(name,
"U") == 0) {
653 }
else if (strcasecmp(name,
"O") == 0) {
656 }
else if (strcasecmp(name,
"I") == 0) {
659 }
else if (strcasecmp(name,
"SUP") == 0) {
662 }
else if (strcasecmp(name,
"SUB") == 0) {
665 }
else if (strcasecmp(name,
"BR") == 0) {
668 }
else if (strcasecmp(name,
"HR") == 0) {
670 }
else if (strcasecmp(name,
"VR") == 0) {
672 }
else if (strcasecmp(name,
"IMG") == 0) {
675 }
else if (strcasecmp(name,
"HTML") == 0) {
682static void endElement(
void *user,
const char *name)
686 if (strcasecmp(name,
"TABLE") == 0) {
689 }
else if (strcasecmp(name,
"TR") == 0 || strcasecmp(name,
"TH") == 0) {
691 }
else if (strcasecmp(name,
"TD") == 0) {
694 }
else if (strcasecmp(name,
"HTML") == 0) {
696 }
else if (strcasecmp(name,
"FONT") == 0) {
698 }
else if (strcasecmp(name,
"B") == 0) {
700 }
else if (strcasecmp(name,
"U") == 0) {
702 }
else if (strcasecmp(name,
"O") == 0) {
704 }
else if (strcasecmp(name,
"I") == 0) {
706 }
else if (strcasecmp(name,
"SUP") == 0) {
708 }
else if (strcasecmp(name,
"SUB") == 0) {
710 }
else if (strcasecmp(name,
"S") == 0) {
712 }
else if (strcasecmp(name,
"BR") == 0) {
717 }
else if (strcasecmp(name,
"HR") == 0) {
722 }
else if (strcasecmp(name,
"VR") == 0) {
727 }
else if (strcasecmp(name,
"IMG") == 0) {
744static void characterData(
void *user,
const char *
s,
int length)
752 for (i = length; i; i--) {
778 XML_SetElementHandler(
state.parser,
779 (XML_StartElementHandler) startElement,
781 XML_SetCharacterDataHandler(
state.parser, characterData);
787 "Not built with libexpat. Table formatting is not available.\n");
798 XML_ParserFree(
state.parser);
822static char *eatComment(
char *p)
828 while (depth && (c = *
s++)) {
849static char *findNext(
char *
s,
agxbuf* xb)
856 t = eatComment(t + 3);
858 while (*t && *t !=
'>')
861 agwarningf(
"Label closed before end of HTML element\n");
867 while ((c = *t) && c !=
'<') {
868 if (c ==
'&' && *(t+1) !=
'#') {
896static void protect_rsqb(
agxbuf *xb) {
905 size_t size = strlen(
data);
907 if (
data[size - 1] !=
']') {
913 data[size - 1] =
'\0';
923 return XML_GetCurrentLineNumber(
state.parser);
930static void printTok(
int tok)
1054 fprintf(stderr,
"%s \"%s\"\n",
s, token_text);
1057 fprintf(stderr,
"%s\n",
s);
1065 static char *begin_html =
"<HTML>";
1066 static char *end_html =
"</HTML>";
1090 len = (size_t)(endp -
s);
1101 assert(llen <= (
size_t)INT_MAX &&
"XML token too long for expat API");
1104 assert(
len <= (
size_t)INT_MAX &&
"XML token too long for expat API");
1105 rv = XML_Parse(
state.parser,
s, (
int)
len,
len ? 0 : 1);
static void agxbfree(agxbuf *xb)
free any malloced resources
static size_t agxbput(agxbuf *xb, const char *s)
append string s into xb
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
static void agxbclear(agxbuf *xb)
resets pointer to data
static size_t agxblen(const agxbuf *xb)
return number of characters currently stored
static int agxbputc(agxbuf *xb, char c)
add character to buffer
static char * agxbuse(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
static void * gv_alloc(size_t size)
char * scanEntity(char *t, agxbuf *xb)
static double len(glCompPoint p)
static int cnt(Dict_t *d, Dtlink_t **set)
void agwarningf(const char *fmt,...)
void agerrorf(const char *fmt,...)
int agerr(agerrlevel_t level, const char *fmt,...)
replacements for ctype.h functions
static char gv_tolower(int c)
static UNUSED void agxbput_move(agxbuf *dst, const char *src)
agxbput, but assume that source and destination may overlap
void htmlerror(const char *msg)
int initHTMLlexer(char *src, agxbuf *xb, htmlenv_t *env)
unsigned long htmllineno(void)
static void error_context(void)
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
platform abstraction for case-insensitive string functions
result of partitioning available space, part of maze
size_t row_count
number of rows
bool hrule
horizontal rule
a non-owning string reference
const char * data
start of the pointed to string
size_t size
extent of the string in bytes
state for an in-progress string tokenization
Non-owning string references.
static bool strview_case_str_eq(strview_t a, const char *b)
compare a string reference to a string for case insensitive equality
#define GV_TEXTFONT_FLAGS_WIDTH
static strview_t tok_get(const tok_t *t)
get the current token
static tok_t tok(const char *input, const char *separators)
begin tokenization of a new string
static bool tok_end(const tok_t *t)
is this tokenizer exhausted?
static void tok_next(tok_t *t)
advance to the next token in the string being scanned
abstraction for squashing compiler warnings for unused symbols