diff --git a/libqhtml/Makefile b/libqhtml/Makefile index fe0746b..fea3124 100644 --- a/libqhtml/Makefile +++ b/libqhtml/Makefile @@ -1,7 +1,7 @@ # Libqhtml tiny HTML/CSS rendering library for QEmacs # # Copyright (c) 2000-2002 Fabrice Bellard. -# Copyright (c) 2000-2024 Charlie Gordon. +# Copyright (c) 2000-2025 Charlie Gordon. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/libqhtml/css.c b/libqhtml/css.c index 2025e68..1056f8b 100644 --- a/libqhtml/css.c +++ b/libqhtml/css.c @@ -2,7 +2,7 @@ * CSS core for qemacs. * * Copyright (c) 2000-2002 Fabrice Bellard. - * Copyright (c) 2007-2024 Charlie Gordon. + * Copyright (c) 2007-2025 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -533,12 +533,9 @@ static inline int attribute_match(CSSStyleSheetAttributeEntry *e, CSSIdent attr; int op; - /* no match possible if no attribute */ - if (!a) - return 0; attr = e->attr; op = e->op; - do { + for (; a != NULL; a = a->next) { if (attr == a->attr) { switch (op) { case CSS_ATTR_OP_SET: @@ -554,16 +551,14 @@ static inline int attribute_match(CSSStyleSheetAttributeEntry *e, break; } } - a = a->next; - } while (a != NULL); + } return 0; } /* return true if (box,pelement) matches simple selector ss (may recurse) */ /* XXX: exclude anonymous boxes */ -static int selector_match(CSSSimpleSelector *ss, - CSSBox *box) +static int selector_match(CSSSimpleSelector *ss, CSSBox *box) { CSSStyleSheetAttributeEntry *ae; CSSBox *box1, *lbox; diff --git a/libqhtml/css.h b/libqhtml/css.h index f6602d6..b606a60 100644 --- a/libqhtml/css.h +++ b/libqhtml/css.h @@ -2,7 +2,7 @@ * CSS core for qemacs. * * Copyright (c) 2000-2002 Fabrice Bellard. - * Copyright (c) 2007-2024 Charlie Gordon. + * Copyright (c) 2007-2025 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/libqhtml/cssparse.c b/libqhtml/cssparse.c index a20eadf..298885d 100644 --- a/libqhtml/cssparse.c +++ b/libqhtml/cssparse.c @@ -2,6 +2,7 @@ * CSS2 parser for qemacs. * * Copyright (c) 2000-2002 Fabrice Bellard. + * Copyright (c) 2007-2025 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -875,7 +876,8 @@ static void beat(CSSParseState *b, int *ch_ptr, const char *str) *ch_ptr = ch; } -static void parse_simple_selector(CSSSimpleSelector *ss, CSSParseState *b, +static void parse_simple_selector(CSSSimpleSelector *ss, // output only + CSSParseState *b, int *ch_ptr) { char value[1024]; diff --git a/libqhtml/csstoqe.c b/libqhtml/csstoqe.c index cc9ecb5..597230a 100644 --- a/libqhtml/csstoqe.c +++ b/libqhtml/csstoqe.c @@ -3,7 +3,10 @@ * linked with qemacs * * Copyright (c) 2002 Fabrice Bellard. - * Copyright (c) 2007-2023 Charlie Gordon. + * Copyright (c) 2007-2025 Charlie Gordon. + * + * This utility generates C source code for a string containing the minimized + * version of the css input file for embedding in a C application. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/libqhtml/xmlparse.c b/libqhtml/xmlparse.c index 75dbeb1..3a6ba16 100644 --- a/libqhtml/xmlparse.c +++ b/libqhtml/xmlparse.c @@ -2,6 +2,7 @@ * XML/HTML parser for qemacs. * * Copyright (c) 2000-2002 Fabrice Bellard. + * Copyright (c) 2007-2025 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -162,10 +163,10 @@ enum XMLParseState { /* string buffer optimized for strings lengths <= STRING_BUF_SIZE */ typedef struct StringBuffer { - unsigned char *buf; + char *buf; int allocated_size; int size; - unsigned char buf1[STRING_BUF_SIZE]; + char buf1[STRING_BUF_SIZE]; } StringBuffer; static inline void strbuf_init(StringBuffer *b) @@ -185,7 +186,7 @@ static inline void strbuf_reset(StringBuffer *b) static void strbuf_addch1(StringBuffer *b, char32_t ch) { int size1; - unsigned char *ptr; + char *ptr; size1 = b->allocated_size + STRING_BUF_SIZE; ptr = b->buf; @@ -197,15 +198,15 @@ static void strbuf_addch1(StringBuffer *b, char32_t ch) b->buf = ptr; b->allocated_size = size1; - b->size += utf8_encode((char*)b->buf + b->size, ch); + b->size += utf8_encode(b->buf + b->size, ch); } } static inline void strbuf_addch(StringBuffer *b, char32_t ch) { - if (b->size < b->allocated_size) { + if (b->size + UTF8_CHAR_LEN_MAX < b->allocated_size) { /* fast case */ - b->size += utf8_encode((char*)b->buf + b->size, ch); + b->size += utf8_encode(b->buf + b->size, ch); } else { strbuf_addch1(b, ch); } @@ -789,10 +790,10 @@ static void html_eval_tag(XMLState *s, CSSBox *box) value = css_attr_str(box, CSS_ID_style); if (value) { CSSParseState b1, *b = &b1; - + b->error_opaque = s->error_opaque; b->ptr = NULL; - b->line_num = s->line_num; /* XXX: slightly incorrect */ b->filename = s->filename; + b->line_num = s->line_num; /* XXX: slightly incorrect */ b->ignore_case = s->ignore_case; *last_prop = css_parse_properties(b, value); } @@ -1119,7 +1120,7 @@ static int xml_parse_internal(XMLState *s, const char *buf_start, int buf_len, case XML_STATE_TAG: if (ch == '>') { strbuf_addch(&s->str, '\0'); - ret = parse_tag(s, (char *)s->str.buf); + ret = parse_tag(s, s->str.buf); switch (ret) { default: case XML_STATE_TEXT: @@ -1151,7 +1152,7 @@ static int xml_parse_internal(XMLState *s, const char *buf_start, int buf_len, not flush if comment */ if (buf) { strbuf_addch(&s->str, '\0'); - flush_text(s, (char *)s->str.buf); + flush_text(s, s->str.buf); strbuf_reset(&s->str); } else { flush_text_buffer(s, b, text_offset_start, offset0); @@ -1195,16 +1196,16 @@ static int xml_parse_internal(XMLState *s, const char *buf_start, int buf_len, if (len >= 0 && s->str.buf[len] == '<' && s->str.buf[len + 1] == '/' && - !xml_tagcmp((char *)s->str.buf + len + 2, s->pretag)) { + !xml_tagcmp(s->str.buf + len + 2, s->pretag)) { s->str.buf[len] = '\0'; if (!xml_tagcmp(s->pretag, "style")) { if (s->style_sheet) { CSSParseState b1, *bp = &b1; bp->error_opaque = s->error_opaque; - bp->ptr = (char *)s->str.buf; - bp->line_num = s->line_num; /* XXX: incorrect */ + bp->ptr = s->str.buf; bp->filename = s->filename; + bp->line_num = s->line_num; /* XXX: incorrect */ bp->ignore_case = s->ignore_case; css_parse_style_sheet(s->style_sheet, bp); } @@ -1213,7 +1214,7 @@ static int xml_parse_internal(XMLState *s, const char *buf_start, int buf_len, } else { /* just add the content */ if (buf) { - flush_text(s, (char *)s->str.buf); + flush_text(s, s->str.buf); } else { /* XXX: would be incorrect if non ascii chars */ flush_text_buffer(s, b, text_offset_start, offset - taglen);