2004-05-29 10:17:37 +00:00
|
|
|
/*
|
|
|
|
|
* XML text mode for QEmacs.
|
2007-12-03 16:10:38 +00:00
|
|
|
*
|
2004-05-29 10:17:37 +00:00
|
|
|
* Copyright (c) 2002 Fabrice Bellard.
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
2007-12-03 16:10:38 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
#include "qe.h"
|
|
|
|
|
|
|
|
|
|
/* colorization states */
|
|
|
|
|
enum {
|
|
|
|
|
XML_TAG = 1,
|
2008-01-03 09:51:29 +00:00
|
|
|
XML_COMMENT,
|
2004-05-29 10:17:37 +00:00
|
|
|
XML_TAG_SCRIPT,
|
|
|
|
|
XML_TAG_STYLE,
|
|
|
|
|
XML_STYLE,
|
2014-01-20 18:04:00 +00:00
|
|
|
XML_SCRIPT = 0x80, /* special mode for inside a script, ored with c mode */
|
2004-05-29 10:17:37 +00:00
|
|
|
};
|
|
|
|
|
|
2014-01-20 18:04:00 +00:00
|
|
|
static void xml_colorize_line(unsigned int *buf, int len,
|
2006-12-31 19:34:00 +00:00
|
|
|
int *colorize_state_ptr, int state_only)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
int c, state;
|
|
|
|
|
unsigned int *p, *p_start, *p1;
|
2008-01-03 09:51:29 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
state = *colorize_state_ptr;
|
|
|
|
|
p = buf;
|
|
|
|
|
p_start = p;
|
|
|
|
|
|
|
|
|
|
/* if already in a state, go directly in the code parsing it */
|
|
|
|
|
if (state & XML_SCRIPT)
|
|
|
|
|
goto parse_script;
|
2005-05-11 15:12:14 +00:00
|
|
|
switch (state) {
|
2004-05-29 10:17:37 +00:00
|
|
|
case XML_COMMENT:
|
|
|
|
|
goto parse_comment;
|
|
|
|
|
case XML_TAG:
|
|
|
|
|
case XML_TAG_SCRIPT:
|
|
|
|
|
goto parse_tag;
|
|
|
|
|
case XML_STYLE:
|
|
|
|
|
goto parse_style;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 15:12:14 +00:00
|
|
|
for (;;) {
|
2004-05-29 10:17:37 +00:00
|
|
|
p_start = p;
|
|
|
|
|
c = *p;
|
2014-01-20 18:04:00 +00:00
|
|
|
|
|
|
|
|
if (c == '\0')
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (c == '<' && state == 0) {
|
2004-05-29 10:17:37 +00:00
|
|
|
p++;
|
|
|
|
|
if (p[0] == '!' && p[1] == '-' && p[2] == '-') {
|
|
|
|
|
p += 3;
|
|
|
|
|
state = XML_COMMENT;
|
|
|
|
|
/* wait until end of comment */
|
|
|
|
|
parse_comment:
|
2014-01-20 18:04:00 +00:00
|
|
|
while (*p != '\0') {
|
2004-05-29 10:17:37 +00:00
|
|
|
if (p[0] == '-' && p[1] == '-' && p[2] == '>') {
|
|
|
|
|
p += 3;
|
|
|
|
|
state = 0;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
simplified set_color API, made in inline
improved command parsing, refined argval handling, pass as optional arg
pass command arguments as an array of unions
use correct type in command dispatcher (upto 2 arguments)
merged do_goto_byte, do_goto_line, do_goto_char, extend syntax
fixed kill commands: kills are appended/prepended to kill buffer
added append_next_kill command
added do_kill_line (split from do_kill_region)
added do_kill_word (removed do_delete_word)
added do_kill_paragraph
pass argval to do_backspace and do_delete_char, fix kill behaviour
fixed kill-ring initial state bug
fixed do_yank: set mark and this_cmd_func
fixed do_yank_pop: test last_cmd_func, use eb_delete instead of do_undo
fixed do_yank_pop kill-ring bug
added clamp(int x, int min, int max);
added qs->this_cmd_func so commands can override qs->last_cmd_func
allow KEY_ESC + extended key as command binding
added do_c_forward_block, needs rewrite using colorization code
added do_c_kill_block
added insert-char command (argval repeats instead of forcing char value)
renamed delete-word to kill-word
renamed backward-delete-word to backward-kill-word
added kill-beginning-of-line
2007-12-12 02:51:05 +00:00
|
|
|
set_color(p_start, p, QE_STYLE_COMMENT);
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
|
|
|
|
/* we are in a tag */
|
|
|
|
|
if (ustristart(p, "SCRIPT", (const unsigned int **)&p)) {
|
|
|
|
|
state = XML_TAG_SCRIPT;
|
2014-01-20 18:04:00 +00:00
|
|
|
} else
|
|
|
|
|
if (ustristart(p, "STYLE", (const unsigned int **)&p)) {
|
2004-05-29 10:17:37 +00:00
|
|
|
state = XML_TAG_STYLE;
|
|
|
|
|
}
|
|
|
|
|
parse_tag:
|
2014-01-20 18:04:00 +00:00
|
|
|
while (*p != '\0') {
|
2004-05-29 10:17:37 +00:00
|
|
|
if (*p == '>') {
|
|
|
|
|
p++;
|
|
|
|
|
if (state == XML_TAG_SCRIPT)
|
|
|
|
|
state = XML_SCRIPT;
|
2014-01-20 18:04:00 +00:00
|
|
|
else
|
|
|
|
|
if (state == XML_TAG_STYLE)
|
2004-05-29 10:17:37 +00:00
|
|
|
state = XML_STYLE;
|
|
|
|
|
else
|
|
|
|
|
state = 0;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
simplified set_color API, made in inline
improved command parsing, refined argval handling, pass as optional arg
pass command arguments as an array of unions
use correct type in command dispatcher (upto 2 arguments)
merged do_goto_byte, do_goto_line, do_goto_char, extend syntax
fixed kill commands: kills are appended/prepended to kill buffer
added append_next_kill command
added do_kill_line (split from do_kill_region)
added do_kill_word (removed do_delete_word)
added do_kill_paragraph
pass argval to do_backspace and do_delete_char, fix kill behaviour
fixed kill-ring initial state bug
fixed do_yank: set mark and this_cmd_func
fixed do_yank_pop: test last_cmd_func, use eb_delete instead of do_undo
fixed do_yank_pop kill-ring bug
added clamp(int x, int min, int max);
added qs->this_cmd_func so commands can override qs->last_cmd_func
allow KEY_ESC + extended key as command binding
added do_c_forward_block, needs rewrite using colorization code
added do_c_kill_block
added insert-char command (argval repeats instead of forcing char value)
renamed delete-word to kill-word
renamed backward-delete-word to backward-kill-word
added kill-beginning-of-line
2007-12-12 02:51:05 +00:00
|
|
|
set_color(p_start, p, QE_STYLE_TAG);
|
2004-05-29 10:17:37 +00:00
|
|
|
if (state == XML_SCRIPT) {
|
|
|
|
|
/* javascript coloring */
|
|
|
|
|
p_start = p;
|
|
|
|
|
parse_script:
|
2005-05-11 15:12:14 +00:00
|
|
|
for (;;) {
|
2014-01-20 18:04:00 +00:00
|
|
|
if (*p == '\0') {
|
2004-05-29 10:17:37 +00:00
|
|
|
state &= ~XML_SCRIPT;
|
2014-01-20 18:04:00 +00:00
|
|
|
/* XXX: should have javascript specific colorize_func */
|
2004-05-29 10:17:37 +00:00
|
|
|
c_colorize_line(p_start, p - p_start, &state, state_only);
|
|
|
|
|
state |= XML_SCRIPT;
|
|
|
|
|
break;
|
2014-01-20 18:04:00 +00:00
|
|
|
} else
|
|
|
|
|
if (ustristart(p, "</SCRIPT", (const unsigned int **)&p1)) {
|
|
|
|
|
while (*p1 != '\0') {
|
|
|
|
|
if (*p1++ == '>')
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-05-29 10:17:37 +00:00
|
|
|
state &= ~XML_SCRIPT;
|
2014-01-20 18:04:00 +00:00
|
|
|
c = *p;
|
|
|
|
|
*p = '\0';
|
|
|
|
|
/* XXX: should have javascript specific colorize_func */
|
2004-05-29 10:17:37 +00:00
|
|
|
c_colorize_line(p_start, p - p_start, &state, state_only);
|
2014-01-20 18:04:00 +00:00
|
|
|
*p = c;
|
2004-05-29 10:17:37 +00:00
|
|
|
state |= XML_SCRIPT;
|
simplified set_color API, made in inline
improved command parsing, refined argval handling, pass as optional arg
pass command arguments as an array of unions
use correct type in command dispatcher (upto 2 arguments)
merged do_goto_byte, do_goto_line, do_goto_char, extend syntax
fixed kill commands: kills are appended/prepended to kill buffer
added append_next_kill command
added do_kill_line (split from do_kill_region)
added do_kill_word (removed do_delete_word)
added do_kill_paragraph
pass argval to do_backspace and do_delete_char, fix kill behaviour
fixed kill-ring initial state bug
fixed do_yank: set mark and this_cmd_func
fixed do_yank_pop: test last_cmd_func, use eb_delete instead of do_undo
fixed do_yank_pop kill-ring bug
added clamp(int x, int min, int max);
added qs->this_cmd_func so commands can override qs->last_cmd_func
allow KEY_ESC + extended key as command binding
added do_c_forward_block, needs rewrite using colorization code
added do_c_kill_block
added insert-char command (argval repeats instead of forcing char value)
renamed delete-word to kill-word
renamed backward-delete-word to backward-kill-word
added kill-beginning-of-line
2007-12-12 02:51:05 +00:00
|
|
|
set_color(p, p1, QE_STYLE_TAG);
|
2004-05-29 10:17:37 +00:00
|
|
|
p = p1;
|
|
|
|
|
state = 0;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-20 18:04:00 +00:00
|
|
|
} else
|
|
|
|
|
if (state == XML_STYLE) {
|
2004-05-29 10:17:37 +00:00
|
|
|
/* stylesheet coloring */
|
|
|
|
|
p_start = p;
|
|
|
|
|
parse_style:
|
2005-05-11 15:12:14 +00:00
|
|
|
for (;;) {
|
2014-01-20 18:04:00 +00:00
|
|
|
if (*p == '\0') {
|
simplified set_color API, made in inline
improved command parsing, refined argval handling, pass as optional arg
pass command arguments as an array of unions
use correct type in command dispatcher (upto 2 arguments)
merged do_goto_byte, do_goto_line, do_goto_char, extend syntax
fixed kill commands: kills are appended/prepended to kill buffer
added append_next_kill command
added do_kill_line (split from do_kill_region)
added do_kill_word (removed do_delete_word)
added do_kill_paragraph
pass argval to do_backspace and do_delete_char, fix kill behaviour
fixed kill-ring initial state bug
fixed do_yank: set mark and this_cmd_func
fixed do_yank_pop: test last_cmd_func, use eb_delete instead of do_undo
fixed do_yank_pop kill-ring bug
added clamp(int x, int min, int max);
added qs->this_cmd_func so commands can override qs->last_cmd_func
allow KEY_ESC + extended key as command binding
added do_c_forward_block, needs rewrite using colorization code
added do_c_kill_block
added insert-char command (argval repeats instead of forcing char value)
renamed delete-word to kill-word
renamed backward-delete-word to backward-kill-word
added kill-beginning-of-line
2007-12-12 02:51:05 +00:00
|
|
|
set_color(p_start, p, QE_STYLE_CSS);
|
2004-05-29 10:17:37 +00:00
|
|
|
break;
|
2014-01-20 18:04:00 +00:00
|
|
|
} else
|
|
|
|
|
if (ustristart(p, "</STYLE", (const unsigned int **)&p1)) {
|
|
|
|
|
while (*p1 != '\0') {
|
|
|
|
|
if (*p1++ != '>')
|
|
|
|
|
break;
|
|
|
|
|
}
|
simplified set_color API, made in inline
improved command parsing, refined argval handling, pass as optional arg
pass command arguments as an array of unions
use correct type in command dispatcher (upto 2 arguments)
merged do_goto_byte, do_goto_line, do_goto_char, extend syntax
fixed kill commands: kills are appended/prepended to kill buffer
added append_next_kill command
added do_kill_line (split from do_kill_region)
added do_kill_word (removed do_delete_word)
added do_kill_paragraph
pass argval to do_backspace and do_delete_char, fix kill behaviour
fixed kill-ring initial state bug
fixed do_yank: set mark and this_cmd_func
fixed do_yank_pop: test last_cmd_func, use eb_delete instead of do_undo
fixed do_yank_pop kill-ring bug
added clamp(int x, int min, int max);
added qs->this_cmd_func so commands can override qs->last_cmd_func
allow KEY_ESC + extended key as command binding
added do_c_forward_block, needs rewrite using colorization code
added do_c_kill_block
added insert-char command (argval repeats instead of forcing char value)
renamed delete-word to kill-word
renamed backward-delete-word to backward-kill-word
added kill-beginning-of-line
2007-12-12 02:51:05 +00:00
|
|
|
set_color(p_start, p, QE_STYLE_CSS);
|
|
|
|
|
set_color(p, p1, QE_STYLE_TAG);
|
2004-05-29 10:17:37 +00:00
|
|
|
p = p1;
|
|
|
|
|
state = 0;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* text */
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*colorize_state_ptr = state;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 17:26:30 +00:00
|
|
|
static int xml_mode_probe(ModeDef *mode, ModeProbeData *p1)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2007-12-26 09:52:07 +00:00
|
|
|
const u8 *p;
|
2004-05-29 10:17:37 +00:00
|
|
|
|
2007-12-26 09:52:07 +00:00
|
|
|
p = p1->buf;
|
|
|
|
|
while (qe_isspace(*p))
|
2004-05-29 10:17:37 +00:00
|
|
|
p++;
|
|
|
|
|
if (*p != '<')
|
|
|
|
|
return 0;
|
|
|
|
|
p++;
|
2007-12-26 09:52:07 +00:00
|
|
|
if (*p != '!' && *p != '?' && !qe_isalpha(*p))
|
2004-05-29 10:17:37 +00:00
|
|
|
return 0;
|
|
|
|
|
return 90; /* leave some room for more specific XML parser */
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 17:26:30 +00:00
|
|
|
ModeDef xml_mode;
|
2004-05-29 10:17:37 +00:00
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static int xml_init(void)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2014-01-04 17:26:30 +00:00
|
|
|
/* xml mode is almost like the text mode, so we copy and patch it */
|
2004-05-29 10:17:37 +00:00
|
|
|
memcpy(&xml_mode, &text_mode, sizeof(ModeDef));
|
|
|
|
|
xml_mode.name = "xml";
|
|
|
|
|
xml_mode.mode_probe = xml_mode_probe;
|
2014-01-05 23:42:54 +00:00
|
|
|
xml_mode.colorize_func = xml_colorize_line;
|
2004-05-29 10:17:37 +00:00
|
|
|
|
|
|
|
|
qe_register_mode(&xml_mode);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qe_module_init(xml_init);
|