[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs htmlsrc.c qestyles.h xml.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs htmlsrc.c qestyles.h xml.c |
Date: |
Thu, 10 Apr 2014 08:03:09 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/04/10 08:03:09
Modified files:
. : htmlsrc.c qestyles.h xml.c
Log message:
improve xml and htmlsrc colorizers
* match script and style tags exactly
* handle short tags
* simplify recursive colorizing for script tags
* use c-mode colorizer for css styles
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/htmlsrc.c?cvsroot=qemacs&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/qemacs/qestyles.h?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.18&r2=1.19
Patches:
Index: htmlsrc.c
===================================================================
RCS file: /sources/qemacs/qemacs/htmlsrc.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- htmlsrc.c 5 Apr 2014 15:49:14 -0000 1.13
+++ htmlsrc.c 10 Apr 2014 08:03:04 -0000 1.14
@@ -54,28 +54,45 @@
return p - p_start;
}
-/* color colorization states */
+/* colorization states */
enum {
- IN_HTML_COMMENT = 0x01, /* <!-- <> --> */
- IN_HTML_COMMENT1 = 0x02, /* <! ... > */
- IN_HTML_STRING = 0x04, /* " ... " */
- IN_HTML_STRING1 = 0x08, /* ' ... ' */
- IN_HTML_TAG = 0x10, /* <tag ... > */
- IN_HTML_ENTITY = 0x20, /* &name[;] / {[;] */
- IN_HTML_SCRIPTTAG = 0x40, /* <SCRIPT ...> */
- IN_HTML_SCRIPT = 0x80, /* <SCRIPT> [...] </SCRIPT> */
+ IN_HTML_COMMENT = 0x001, /* <!-- ... --> */
+ IN_HTML_COMMENT1 = 0x002, /* <! ... > */
+ IN_HTML_STRING = 0x004, /* " ... " */
+ IN_HTML_STRING1 = 0x008, /* ' ... ' */
+ IN_HTML_ENTITY = 0x010, /* &name[;] / {[;] */
+ IN_HTML_TAG = 0x020, /* <tag ... > */
+ IN_HTML_SCRIPT_TAG = 0x040, /* <script ... > */
+ IN_HTML_SCRIPT = 0x080, /* <script> [...] </script> */
+ IN_HTML_STYLE_TAG = 0x100, /* <style ... > */
+ IN_HTML_STYLE = 0x200, /* <style> [...] </style> */
};
enum {
HTML_STYLE_PREPROCESS = QE_STYLE_PREPROCESS,
- HTML_STYLE_SCRIPT = QE_STYLE_HTML_SCRIPT,
HTML_STYLE_COMMENT = QE_STYLE_HTML_COMMENT,
- HTML_TYLE_ENTITY = QE_STYLE_HTML_ENTITY,
+ HTML_STYLE_COMMENT1 = QE_STYLE_HTML_COMMENT,
+ HTML_STYLE_ENTITY = QE_STYLE_HTML_ENTITY,
HTML_STYLE_STRING = QE_STYLE_HTML_STRING,
HTML_STYLE_TAG = QE_STYLE_HTML_TAG,
+ HTML_STYLE_CSS = QE_STYLE_CSS,
//HTML_STYLE_TEXT = QE_STYLE_HTML_TEXT,
};
+static int htmlsrc_tag_match(const unsigned int *buf, int i, const char *str,
+ int *iend)
+{
+ const unsigned int *p;
+
+ if (ustristart(buf + i, str, &p) && !qe_isalnum_(*p)) {
+ if (iend)
+ *iend = p - buf;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
void htmlsrc_colorize_line(QEColorizeContext *cp,
unsigned int *str, int n, int mode_flags)
{
@@ -93,36 +110,46 @@
start = i;
c = str[i];
- if (state & IN_HTML_SCRIPTTAG) {
- while (i < n) {
- if (str[i++] == '>') {
- state = IN_HTML_SCRIPT;
- break;
- }
- }
- SET_COLOR(str, start, i, HTML_STYLE_SCRIPT);
- continue;
- }
if (state & IN_HTML_SCRIPT) {
for (; i < n; i++) {
- if (str[i] == '<' && ustristart(str + i, "</script>", NULL))
+ if (str[i] == '<'
+ && htmlsrc_tag_match(str, i + 1, "/script", NULL)) {
break;
}
- state &= ~IN_HTML_SCRIPT;
- cp->colorize_state = state;
+ }
c = str[i]; /* save char to set '\0' delimiter */
str[i] = '\0';
+ state &= ~IN_HTML_SCRIPT;
+ cp->colorize_state = state;
/* XXX: should have js_colorize_func */
c_colorize_line(cp, str + start, i - start,
CLANG_JS | CLANG_REGEX);
- str[i] = c;
state = cp->colorize_state;
state |= IN_HTML_SCRIPT;
- if (i < n) {
- start = i;
- i += strlen("</script>");
+ str[i] = c;
+ if (c) {
+ state = 0;
+ }
+ continue;
+ }
+ if (state & IN_HTML_STYLE) {
+ for (; i < n; i++) {
+ if (str[i] == '<'
+ && htmlsrc_tag_match(str, i + 1, "/style", NULL)) {
+ break;
+ }
+ }
+ c = str[i]; /* save char to set '\0' delimiter */
+ str[i] = '\0';
+ state &= ~IN_HTML_STYLE;
+ cp->colorize_state = state;
+ /* XXX: should have css_colorize_func */
+ c_colorize_line(cp, str + start, i - start, 0);
+ state = cp->colorize_state;
+ state |= IN_HTML_STYLE;
+ str[i] = c;
+ if (c) {
state = 0;
- SET_COLOR(str, start, i, HTML_STYLE_SCRIPT);
}
continue;
}
@@ -145,7 +172,7 @@
break;
}
}
- SET_COLOR(str, start, i, HTML_STYLE_COMMENT);
+ SET_COLOR(str, start, i, HTML_STYLE_COMMENT1);
continue;
}
if (state & IN_HTML_ENTITY) {
@@ -154,7 +181,7 @@
else
i += len;
state &= ~IN_HTML_ENTITY;
- SET_COLOR(str, start, i, HTML_TYLE_ENTITY);
+ SET_COLOR(str, start, i, HTML_STYLE_ENTITY);
continue;
}
if (state & (IN_HTML_STRING | IN_HTML_STRING1)) {
@@ -179,22 +206,34 @@
SET_COLOR(str, start, i, HTML_STYLE_STRING);
continue;
}
- if (state & IN_HTML_TAG) {
+ if (state & (IN_HTML_TAG | IN_HTML_SCRIPT_TAG | IN_HTML_STYLE_TAG)) {
for (; i < n; i++) {
- if (str[i] == '&' && get_html_entity(str + i)) {
+ c = str[i];
+ if (c == '&' && get_html_entity(str + i)) {
state |= IN_HTML_ENTITY;
break;
}
- if (str[i] == '\"') {
+ if (c == '\"') {
state |= IN_HTML_STRING;
break;
}
- if (str[i] == '\'') {
+ if (c == '\'') {
state |= IN_HTML_STRING1;
break;
}
- if (str[i] == '>') {
+ if (c == '/' && str[i + 1] == '>') {
+ i += 2;
+ state = 0;
+ break;
+ }
+ if (c == '>') {
i++;
+ if (state & IN_HTML_SCRIPT_TAG)
+ state = IN_HTML_SCRIPT;
+ else
+ if (state & IN_HTML_STYLE_TAG)
+ state = IN_HTML_STYLE;
+ else
state &= ~IN_HTML_TAG;
break;
}
@@ -214,7 +253,11 @@
//SET_COLOR(str, start, i, HTML_STYLE_TEXT);
start = i;
if (ustristart(str + i, "<script", NULL)) {
- state |= IN_HTML_SCRIPTTAG;
+ state |= IN_HTML_SCRIPT_TAG;
+ break;
+ }
+ if (ustristart(str + i, "<style", NULL)) {
+ state |= IN_HTML_STYLE_TAG;
break;
}
if (str[i + 1] == '!') {
Index: qestyles.h
===================================================================
RCS file: /sources/qemacs/qemacs/qestyles.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- qestyles.h 9 Jan 2008 13:41:41 -0000 1.7
+++ qestyles.h 10 Apr 2014 08:03:09 -0000 1.8
@@ -75,9 +75,6 @@
STYLE_DEF(QE_STYLE_HTML_STRING, "html-string",
QERGB(0xf8, 0xa0, 0x78), COLOR_TRANSPARENT,
0, 0)
- STYLE_DEF(QE_STYLE_HTML_SCRIPT, "html-script",
- QERGB(0x98, 0xf8, 0x98), COLOR_TRANSPARENT,
- 0, 0)
STYLE_DEF(QE_STYLE_HTML_ENTITY, "html-entity",
QERGB(0xe8, 0xdc, 0x80), COLOR_TRANSPARENT,
0, 0)
Index: xml.c
===================================================================
RCS file: /sources/qemacs/qemacs/xml.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- xml.c 5 Apr 2014 15:49:16 -0000 1.18
+++ xml.c 10 Apr 2014 08:03:09 -0000 1.19
@@ -2,6 +2,7 @@
* XML text mode for QEmacs.
*
* Copyright (c) 2002 Fabrice Bellard.
+ * Copyright (c) 2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -26,8 +27,8 @@
IN_XML_COMMENT,
IN_XML_TAG_SCRIPT,
IN_XML_TAG_STYLE,
- IN_XML_STYLE,
- IN_XML_SCRIPT = 0x80, /* special mode for inside a script, ored with c
mode */
+ IN_XML_SCRIPT = 0x80, /* Inside a script tag, ored with c-mode state */
+ IN_XML_STYLE = 0x100, /* Inside a style tag, ored with c-mode state */
};
enum {
@@ -36,25 +37,41 @@
XML_STYLE_CSS = QE_STYLE_CSS,
};
+static int xml_tag_match(const unsigned int *buf, int i, const char *str,
+ int *iend)
+{
+ const unsigned int *p;
+
+ if (ustristart(buf + i, str, &p) && !qe_isalnum_(*p)) {
+ if (iend)
+ *iend = p - buf;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
static void xml_colorize_line(QEColorizeContext *cp,
unsigned int *str, int n, int mode_flags)
{
- int i = 0, i1, start, c, state;
- const unsigned int *p;
+ int i = 0, start = i, c;
+ int state = cp->colorize_state;
- state = cp->colorize_state;
+ /* XXX: should recognize and colorize entities, attribute strings */
/* if already in a state, go directly in the code parsing it */
if (state & IN_XML_SCRIPT)
goto parse_script;
+ if (state & IN_XML_STYLE)
+ goto parse_style;
+
switch (state) {
case IN_XML_COMMENT:
goto parse_comment;
case IN_XML_TAG:
case IN_XML_TAG_SCRIPT:
+ case IN_XML_TAG_STYLE:
goto parse_tag;
- case IN_XML_STYLE:
- goto parse_style;
default:
break;
}
@@ -70,31 +87,34 @@
if (str[i] == '!' && str[i + 1] == '-' && str[i + 2] == '-') {
i += 3;
state = IN_XML_COMMENT;
- /* wait until end of comment */
parse_comment:
- while (str[i] != '\0') {
+ /* scan for end of comment */
+ for (; str[i] != '\0'; i++) {
if (str[i] == '-' && str[i + 1] == '-'
&& str[i + 2] == '>') {
i += 3;
state = 0;
break;
- } else {
- i++;
}
}
SET_COLOR(str, start, i, XML_STYLE_COMMENT);
} else {
/* we are in a tag */
- if (ustristart(str + i, "SCRIPT", &p)) {
+ if (xml_tag_match(str, i, "script", &i)) {
state = IN_XML_TAG_SCRIPT;
} else
- if (ustristart(str + i, "STYLE", &p)) {
+ if (xml_tag_match(str, i, "style", &i)) {
state = IN_XML_TAG_STYLE;
}
parse_tag:
- /* XXX: bogus for <style src="toto" /> */
while (str[i] != '\0') {
- if (str[i++] == '>') {
+ c = str[i++];
+ if (c == '/' && str[i] == '>') {
+ i++;
+ state = 0;
+ break;
+ }
+ if (c == '>') {
if (state == IN_XML_TAG_SCRIPT)
state = IN_XML_SCRIPT;
else
@@ -106,68 +126,51 @@
}
}
SET_COLOR(str, start, i, XML_STYLE_TAG);
- if (state == IN_XML_SCRIPT) {
- /* javascript coloring */
start = i;
+ if (state & IN_XML_SCRIPT) {
+ /* javascript coloring */
parse_script:
- for (;; i++) {
- if (str[i] == '\0') {
- state &= ~IN_XML_SCRIPT;
- cp->colorize_state = state;
- /* XXX: should have js_colorize_func */
- c_colorize_line(cp, str + start, i - start,
- CLANG_JS | CLANG_REGEX);
- state = cp->colorize_state;
- state |= IN_XML_SCRIPT;
- break;
- } else
- if (ustristart(str + i, "</SCRIPT", &p)) {
- i1 = p - str;
- /* XXX: bogus for </script LF > */
- while (str[i1] != '\0') {
- if (str[i1++] == '>')
+ for (; str[i] != '\0'; i++) {
+ if (str[i] == '<'
+ && xml_tag_match(str, i + 1, "/script", NULL)) {
break;
}
- c = str[i];
+ }
+ c = str[i]; /* save char to set '\0' delimiter */
str[i] = '\0';
state &= ~IN_XML_SCRIPT;
cp->colorize_state = state;
/* XXX: should have js_colorize_func */
c_colorize_line(cp, str + start, i - start,
CLANG_JS | CLANG_REGEX);
+ state = cp->colorize_state;
+ state |= IN_XML_SCRIPT;
str[i] = c;
+ if (c) {
state = 0;
- start = i;
- i = i1;
- SET_COLOR(str, start, i, XML_STYLE_TAG);
- break;
- }
}
+ continue;
} else
- if (state == IN_XML_STYLE) {
+ if (state & IN_XML_STYLE) {
/* stylesheet coloring */
- start = i;
parse_style:
- for (;; i++) {
- if (str[i] == '\0') {
- /* XXX: should use css_colorize_line */
- SET_COLOR(str, start, i, XML_STYLE_CSS);
- break;
- } else
- if (ustristart(str + i, "</STYLE", &p)) {
- /* XXX: bogus for </style LF > */
- i1 = p - str;
- while (str[i1] != '\0') {
- if (str[i1++] != '>')
+ for (; str[i] != '\0'; i++) {
+ if (str[i] == '<'
+ && xml_tag_match(str, i + 1, "/style", NULL)) {
break;
}
- /* XXX: should use css_colorize_line */
- SET_COLOR(str, start, i, XML_STYLE_CSS);
- SET_COLOR(str, i, i1, XML_STYLE_TAG);
- i = i1;
- state = 0;
- break;
}
+ c = str[i];
+ str[i] = '\0';
+ state &= ~IN_XML_STYLE;
+ cp->colorize_state = state;
+ /* XXX: should have css_colorize_func */
+ c_colorize_line(cp, str + start, i - start, 0);
+ state = cp->colorize_state;
+ state |= IN_XML_STYLE;
+ str[i] = c;
+ if (c) {
+ state = 0;
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs htmlsrc.c qestyles.h xml.c,
Charlie Gordon <=