From 173e68ccfa768342ddc7073efaaa2a1bc5f5690b Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 6 Jan 2006 12:00:30 +0100 Subject: [PATCH 01/64] Support for pasting from GNU screen clipboard --- src/osdep/osdep.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/osdep/osdep.c b/src/osdep/osdep.c index 9e1af2801..96091075f 100644 --- a/src/osdep/osdep.c +++ b/src/osdep/osdep.c @@ -347,10 +347,21 @@ exe(unsigned char *path) unsigned char * get_clipboard_text(void) /* !!! FIXME */ { - unsigned char *ret = mem_alloc(1); + unsigned char *ret; + /* GNU Screen's clipboard */ + if (is_gnuscreen()) { + struct string str; + + if (!init_string(&str)) return; + + add_to_string(&str, "screen -X paste ."); + if (str.length) exe(str.source); + if (str.source) done_string(&str); + } + + ret = mem_alloc(1); if (ret) ret[0] = 0; - return ret; } From f18de1d3f3c2e96aba5bb6791a663a40be402fc1 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 6 Jan 2006 12:02:51 +0100 Subject: [PATCH 02/64] Internal clipboard support --- src/osdep/osdep.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/osdep/osdep.c b/src/osdep/osdep.c index 96091075f..d22ace621 100644 --- a/src/osdep/osdep.c +++ b/src/osdep/osdep.c @@ -344,11 +344,11 @@ exe(unsigned char *path) #endif -unsigned char * -get_clipboard_text(void) /* !!! FIXME */ -{ - unsigned char *ret; +static unsigned char *clipboard; +unsigned char * +get_clipboard_text(void) +{ /* GNU Screen's clipboard */ if (is_gnuscreen()) { struct string str; @@ -360,9 +360,7 @@ get_clipboard_text(void) /* !!! FIXME */ if (str.source) done_string(&str); } - ret = mem_alloc(1); - if (ret) ret[0] = 0; - return ret; + return stracpy(clipboard ? clipboard : ""); } void @@ -381,7 +379,8 @@ set_clipboard_text(unsigned char *data) if (str.source) done_string(&str); } - /* TODO: internal clipboard */ + if (clipboard) mem_free(clipboard); + clipboard = stracpy(data); } /* Set xterm-like term window's title. */ From 0c40ff05c94cb581763cd0e0c13e7279c736344c Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 6 Jan 2006 15:48:15 +0100 Subject: [PATCH 03/64] Fix compilation of get_clipboard_text() --- src/osdep/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osdep/osdep.c b/src/osdep/osdep.c index d22ace621..14710a7fa 100644 --- a/src/osdep/osdep.c +++ b/src/osdep/osdep.c @@ -353,14 +353,14 @@ get_clipboard_text(void) if (is_gnuscreen()) { struct string str; - if (!init_string(&str)) return; + if (!init_string(&str)) return NULL; add_to_string(&str, "screen -X paste ."); if (str.length) exe(str.source); if (str.source) done_string(&str); } - return stracpy(clipboard ? clipboard : ""); + return stracpy(empty_string_or_(clipboard)); } void From a637349b324f2763d20956388e2dc5073bb50c60 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 6 Jan 2006 17:08:38 +0100 Subject: [PATCH 04/64] Prevent complaining about leaking clipboard --- src/osdep/osdep.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/osdep/osdep.c b/src/osdep/osdep.c index 14710a7fa..1503f84db 100644 --- a/src/osdep/osdep.c +++ b/src/osdep/osdep.c @@ -379,8 +379,9 @@ set_clipboard_text(unsigned char *data) if (str.source) done_string(&str); } - if (clipboard) mem_free(clipboard); - clipboard = stracpy(data); + /* Shouldn't complain about leaks. */ + if (clipboard) free(clipboard); + clipboard = strdup(data); } /* Set xterm-like term window's title. */ From b1514c7a3573509ea03db83aaedd844f3fc0f4a0 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 6 Jan 2006 17:46:55 +0100 Subject: [PATCH 05/64] Check if the test 'trash' directory could be entered Original patch by Alex Riesen for GIT. --- test/libtest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libtest.sh b/test/libtest.sh index 2d40a9162..12de5c920 100755 --- a/test/libtest.sh +++ b/test/libtest.sh @@ -162,4 +162,4 @@ test_done () { test=trash rm -fr "$test" mkdir "$test" -cd "$test" +cd "$test" || error "Cannot setup test environment" From 5f5c78a87ff5feab5252537e8d376e6b8a75fb94 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 6 Jan 2006 18:32:22 +0100 Subject: [PATCH 06/64] Realign the test docs with reality --- src/dom/test/README | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/dom/test/README b/src/dom/test/README index a980f16ed..2c4bcd008 100644 --- a/src/dom/test/README +++ b/src/dom/test/README @@ -1,7 +1,7 @@ -Core GIT Tests -============== +ELinks testing infrastructure +============================= -This directory holdstest scripts for the DOM implementation. The first part of +This directory holds test scripts for the DOM implementation. The first part of this short document describes how to run the tests and read their output. When fixing the tools or adding enhancements, you are strongly encouraged to @@ -27,7 +27,7 @@ The easiest way to run tests is to say "make test". This runs all the tests. Or you can run each test individually from command line, like this: - $ sh ./test-sgml-parser-basic + $ TEST_LIB=${path_to_top_srcdir}/test/libtest.sh sh ./test-sgml-parser-basic * ok 1: parse a small document. ... * ok 23: parse a CDATA section. @@ -49,6 +49,10 @@ command line argument to the test. This causes the test to immediately exit upon the first failed test. +Note, these options can be passed indirectly to all tests when running test using +make by setting TEST_OPTS, like this: + + make test TEST_OPTS=--immediate Naming Tests ------------ @@ -91,20 +95,23 @@ The test script is written as a shell script. It should start with the standard Source 'libtest' --------------------- +---------------- -After assigning test_description, the test script should source test-lib.sh -like this: +After assigning test_description, the test script should source the shell test +library like this: - . ./libtest + . "$TEST_LIB" + +This assumes that the TEST_LIB environment variable has been set and is needed +for test to run from out of tree builds. This test harness library does the following things: - If the script is invoked with command line argument --help (or -h), it shows the test_description and exits. - - Creates an empty test directory. This directory is 'test/trash' if you must - know, but I do not think you care. + - Creates an empty test directory. This directory is 'trash' if you must know, + but I do not think you care. - Defines standard test helper functions for your scripts to use. These functions are designed to make all scripts behave consistently when command From c08d932433a0baf8b61cc39fd9f9216a1a4126e0 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Fri, 6 Jan 2006 21:34:57 +0100 Subject: [PATCH 07/64] Merge is_hotkey(), is_not_so_hotkey() and check_hotkeys_common() to reduce code redundancy and speed up things. --- src/bfu/hotkey.c | 79 ++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/src/bfu/hotkey.c b/src/bfu/hotkey.c index 42222c449..107fa5a4b 100644 --- a/src/bfu/hotkey.c +++ b/src/bfu/hotkey.c @@ -121,52 +121,9 @@ refresh_hotkeys(struct terminal *term, struct menu *menu) #endif } -/* Returns true if key (upcased) matches one of the hotkeys in menu */ -static int -is_hotkey(struct menu_item *item, unsigned char key, struct terminal *term) -{ - unsigned char *text; - int key_pos; - - assert(item); - if_assert_failed return 0; - - if (!mi_has_left_text(item)) return 0; - - text = item->text; - if (mi_text_translate(item)) text = _(text, term); - if (!text || !*text) return 0; - - key_pos = item->hotkey_pos; - -#ifdef CONFIG_DEBUG - if (key_pos < 0) key_pos = -key_pos; -#endif - - return (key_pos && (toupper(text[key_pos]) == key)); -} - -/* Returns true if key (upcased) matches first letter of menu item left text. */ -static int -is_not_so_hotkey(struct menu_item *item, unsigned char key, struct terminal *term) -{ - unsigned char *text; - - assert(item); - if_assert_failed return 0; - - if (!mi_has_left_text(item)) return 0; - - text = item->text; - if (mi_text_translate(item)) text = _(text, term); - if (!text || !*text) return 0; - - return (toupper(*text) == key); -} - static int check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *term, - int (*func)(struct menu_item *, unsigned char, struct terminal *)) + int check_mode) { unsigned char key = toupper(hotkey); int i = menu->selected; @@ -179,9 +136,37 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t start = i; do { + struct menu_item *item; + unsigned char *text; + int res; + if (++i == menu->size) i = 0; - if (func(&menu->items[i], key, term)) { + item = &menu->items[i]; + + if (!mi_has_left_text(item)) continue; + + text = item->text; + if (mi_text_translate(item)) text = _(text, term); + if (!text || !*text) continue; + + if (check_mode == 0) { + /* Does the key (upcased) matches one of the + * hotkeys in menu ? */ + int key_pos = item->hotkey_pos; + +#ifdef CONFIG_DEBUG + if (key_pos < 0) key_pos = -key_pos; +#endif + res = (key_pos && (toupper(text[key_pos]) == key)); + + } else { + /* Does the key (upcased) matches first letter + * of menu item left text ? */ + res = (toupper(*text) == key); + } + + if (res) { menu->selected = i; return 1; } @@ -195,7 +180,7 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t int check_hotkeys(struct menu *menu, unsigned char key, struct terminal *term) { - return check_hotkeys_common(menu, key, term, is_hotkey); + return check_hotkeys_common(menu, key, term, 0); } /* Search if first letter of an entry in menu matches the key (caseless comp.). @@ -205,5 +190,5 @@ check_hotkeys(struct menu *menu, unsigned char key, struct terminal *term) int check_not_so_hot_keys(struct menu *menu, unsigned char key, struct terminal *term) { - return check_hotkeys_common(menu, key, term, is_not_so_hotkey); + return check_hotkeys_common(menu, key, term, 1); } From d767650585952d5c0d478992e7ba90569c6c51c9 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Fri, 6 Jan 2006 21:37:36 +0100 Subject: [PATCH 08/64] check_hotkeys_common(): @res -> @found. --- src/bfu/hotkey.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bfu/hotkey.c b/src/bfu/hotkey.c index 107fa5a4b..0c3078dec 100644 --- a/src/bfu/hotkey.c +++ b/src/bfu/hotkey.c @@ -138,7 +138,7 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t do { struct menu_item *item; unsigned char *text; - int res; + int found; if (++i == menu->size) i = 0; @@ -158,15 +158,15 @@ check_hotkeys_common(struct menu *menu, unsigned char hotkey, struct terminal *t #ifdef CONFIG_DEBUG if (key_pos < 0) key_pos = -key_pos; #endif - res = (key_pos && (toupper(text[key_pos]) == key)); + found = (key_pos && (toupper(text[key_pos]) == key)); } else { /* Does the key (upcased) matches first letter * of menu item left text ? */ - res = (toupper(*text) == key); + found = (toupper(*text) == key); } - if (res) { + if (found) { menu->selected = i; return 1; } From 84f8973720c21699caf781290ab9244dc6d8e7cd Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 6 Jan 2006 22:08:49 +0100 Subject: [PATCH 09/64] Make the compile macro use -o and append any 2nd argument --- Makefile.lib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.lib b/Makefile.lib index 7e102c3d4..a56d45cd1 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -33,8 +33,8 @@ mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1)) ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $($(mquiet)cmd_$(1)) &&) $(cmd_$(1)) quiet_cmd_compile = ' [$(CC_COLOR)CC$(END_COLOR)] $(RELPATH)$@' - masq_cmd_compile = $(COMPILE) -c $< - cmd_compile = $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + masq_cmd_compile = $(COMPILE) -o $(@) -c $< $(2) + cmd_compile = $(COMPILE) -o $(@) -Wp,-MD,.deps/$(*F).pp -c $< $(2) # Rule to compile a set of .o files into one .o file quiet_cmd_ld_objs = " [$(LD_COLOR)LD$(END_COLOR)] $(RELPATH)$@" From 215d7ec1589dee752b9e66a52c467227f492ff17 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 6 Jan 2006 22:11:45 +0100 Subject: [PATCH 10/64] Append memdebug to test dependencies in Makefile.lib --- Makefile.lib | 1 + src/dom/test/Makefile | 2 -- src/protocol/ftp/Makefile | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile.lib b/Makefile.lib index a56d45cd1..4cedf9124 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -153,6 +153,7 @@ clean-test: test-default: ifdef TEST_PROGS +TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o TESTDEPS += $(TESTDEPS-yes) TESTS = $(wildcard $(srcdir)test-*) diff --git a/src/dom/test/Makefile b/src/dom/test/Makefile index 3b7bd24d5..2bf9957e9 100644 --- a/src/dom/test/Makefile +++ b/src/dom/test/Makefile @@ -14,6 +14,4 @@ TESTDEPS = \ $(top_builddir)/src/util/string.o \ $(top_builddir)/src/util/memory.o -TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o \ - include $(top_srcdir)/Makefile.lib diff --git a/src/protocol/ftp/Makefile b/src/protocol/ftp/Makefile index 9aa1dc759..115744b79 100644 --- a/src/protocol/ftp/Makefile +++ b/src/protocol/ftp/Makefile @@ -16,6 +16,4 @@ TESTDEPS = \ $(top_builddir)/src/util/string.o \ $(top_builddir)/src/util/time.o -TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o - include $(top_srcdir)/Makefile.lib From 3fd2828fb0dc3c389dea810eeec583f32e1e106d Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 6 Jan 2006 22:18:11 +0100 Subject: [PATCH 11/64] Add a simple test script of the mailcap cache It has a few nasty hacks to reduce the dependencies on defined symbols. --- src/mime/backend/Makefile | 22 ++++++ src/mime/backend/mailcap.c | 111 ++++++++++++++++++++++++++++ src/mime/backend/test-mailcap-cache | 95 ++++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100755 src/mime/backend/test-mailcap-cache diff --git a/src/mime/backend/Makefile b/src/mime/backend/Makefile index b1e61a0c0..eb9300cc5 100644 --- a/src/mime/backend/Makefile +++ b/src/mime/backend/Makefile @@ -6,4 +6,26 @@ OBJS-$(CONFIG_MIMETYPES) += mimetypes.o OBJS = common.o default.o +TEST_PROGS = \ + mailcap-cache + +# The dependencies are a bit funny here! I don't know why. Just remember to +# make clean before making the test. --jonas +mailcap-cache.o: mailcap.c + $(call cmd,compile,-DTEST_MAILCAP) + +TESTDEPS = \ + common.o \ + $(top_builddir)/src/osdep/osdep.o \ + $(top_builddir)/src/osdep/stub.o \ + $(top_builddir)/src/util/conv.o \ + $(top_builddir)/src/util/error.o \ + $(top_builddir)/src/util/file.o \ + $(top_builddir)/src/util/hash.o \ + $(top_builddir)/src/util/memory.o \ + $(top_builddir)/src/util/string.o \ + $(top_builddir)/src/util/time.o + +TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o + include $(top_srcdir)/Makefile.lib diff --git a/src/mime/backend/mailcap.c b/src/mime/backend/mailcap.c index bf9daec38..e3eccec55 100644 --- a/src/mime/backend/mailcap.c +++ b/src/mime/backend/mailcap.c @@ -443,6 +443,8 @@ done_mailcap(struct module *module) mailcap_map_size = 0; } +#ifndef TEST_MAILCAP + static int change_hook_mailcap(struct session *ses, struct option *current, struct option *changed) { @@ -469,6 +471,10 @@ init_mailcap(struct module *module) get_mailcap_enable() = 0; } +#else +#define init_mailcap NULL +#endif /* TEST_MAILCAP */ + /* The command semantics include the following: * * %s is the filename that contains the mail body data @@ -673,3 +679,108 @@ struct module mailcap_mime_module = struct_module( /* init: */ init_mailcap, /* done: */ done_mailcap ); + +#ifdef TEST_MAILCAP +/* Some ugly shortcuts for getting defined symbols to work. */ +int default_mime_backend, + install_signal_handler, + mimetypes_mime_backend; +struct list_head terminals; + +void die(const char *msg, ...) +{ + va_list args; + + if (msg) { + va_start(args, msg); + vfprintf(stderr, msg, args); + fputs("\n", stderr); + va_end(args); + } + + exit(1); +} + +int +main(int argc, char *argv[]) +{ + unsigned char *format = "description,ask,block,program"; + int has_gotten = 0; + int i; + + for (i = 1; i < argc; i++) { + char *arg = argv[i]; + + if (strncmp(arg, "--", 2)) + break; + + arg += 2; + + if (!strncmp(arg, "path", 4)) { + arg += 4; + if (*arg == '=') { + arg++; + get_mailcap_path() = arg; + } else { + i++; + if (i >= argc) + die("--path expects a parameter"); + get_mailcap_path() = argv[i]; + } + done_mailcap(NULL); + + } else if (!strncmp(arg, "format", 6)) { + arg += 6; + if (*arg == '=') { + arg++; + format = arg; + } else { + i++; + if (i >= argc) + die("--format expects a parameter"); + format = argv[i]; + } + + } else if (!strncmp(arg, "get", 3)) { + struct mime_handler *handler; + + arg += 3; + if (*arg == '=') { + arg++; + } else { + i++; + if (i >= argc) + die("--get expects a parameter"); + arg = argv[i]; + } + + if (has_gotten) + printf("\n"); + has_gotten = 1; + printf("type: %s\n", arg); + handler = get_mime_handler_mailcap(arg, 0); + if (!handler) continue; + + if (strstr(format, "description")) + printf("description: %s\n", handler->description); + + if (strstr(format, "ask")) + printf("ask: %d\n", handler->ask); + + if (strstr(format, "block")) + printf("block: %d\n", handler->block); + + if (strstr(format, "program")) + printf("program: %s\n", handler->program); + + } else { + die("Unknown argument '%s'", arg - 2); + } + } + + done_mailcap(NULL); + + return 0; +} + +#endif /* TEST_MAILCAP */ diff --git a/src/mime/backend/test-mailcap-cache b/src/mime/backend/test-mailcap-cache new file mode 100755 index 000000000..6bd9bbf07 --- /dev/null +++ b/src/mime/backend/test-mailcap-cache @@ -0,0 +1,95 @@ +#!/bin/sh +# +# Copyright (c) 2005 Jonas Fonseca +# + +test_description='Test mailcap parsing and querying + +This tests the parsing of various mailcap files, if they are +"prioritised" correctly, if the test are run correctly and +if querying returns the expected mailcap entry. +' + +. "$TEST_LIB" + +# Set PAGER to something recognisable since it gets appended as +# "|copiousoutput_handler" to entries with copiousoutput. +export PAGER=copiousoutput_handler + +################################################################ +# Parse a simple mailcap file + +cat > mailcap-basic <&1 ; copiousoutput +EOF + +mailcap-cache \ + --path "mailcap-basic" \ + --format "block,program" \ + --get "text/html" \ + --get "text/x-csh" \ + --get "application/postscript" \ + --get "application/foo" \ + > output + +cat > expected < mailcap-simple-with-test < output + +cat > expected < Date: Fri, 6 Jan 2006 22:32:07 +0100 Subject: [PATCH 12/64] Fix a few typos --- src/mime/backend/test-mailcap-cache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mime/backend/test-mailcap-cache b/src/mime/backend/test-mailcap-cache index 6bd9bbf07..5440066c3 100755 --- a/src/mime/backend/test-mailcap-cache +++ b/src/mime/backend/test-mailcap-cache @@ -62,7 +62,7 @@ test_expect_success \ 'cmp output expected' \ ################################################################ -# Parse a two simple mailcap file; first one with tests +# Parse a two simple mailcap files; first one with tests touch DISPLAY @@ -89,7 +89,7 @@ program: gv % EOF test_expect_success \ - 'Parse two simple mailcap file; first one with tests.' \ + 'Parse two simple mailcap files; first one with tests.' \ 'cmp output expected' \ test_done From bca330fcbdd20c4ee1475b92cac36089b37f381e Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 01:22:14 +0100 Subject: [PATCH 13/64] Simplify incomplete test helper and fix quoting problem --- src/dom/test/test-sgml-parser-basic | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dom/test/test-sgml-parser-basic b/src/dom/test/test-sgml-parser-basic index 4a379c265..28daae50e 100755 --- a/src/dom/test/test-sgml-parser-basic +++ b/src/dom/test/test-sgml-parser-basic @@ -43,8 +43,9 @@ test_expect_incomplete () { y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; s/[^a-zA-Z0-9-]//g;')" - test_expect_code 1 "$desc" \ - "sgml-parser --uri '$URI' --src '$src' --incomplete" + sgml-parser --uri "$URI" --src "$src" --incomplete + test_expect_success "$desc" \ + "test $? = 1" } @@ -354,7 +355,7 @@ test_expect_incomplete \ test_expect_incomplete \ 'Check incomplete attribute quoted value. (II)' \ -' Date: Sat, 7 Jan 2006 01:25:42 +0100 Subject: [PATCH 14/64] scan_sgml_tokens(): Drop local variable and use scanner->current ... so lower level scanners can change the next token to use. --- src/dom/sgml/scanner.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/dom/sgml/scanner.c b/src/dom/sgml/scanner.c index 6399b4395..7396b7933 100644 --- a/src/dom/sgml/scanner.c +++ b/src/dom/sgml/scanner.c @@ -622,35 +622,34 @@ static struct dom_scanner_token * scan_sgml_tokens(struct dom_scanner *scanner) { struct dom_scanner_token *table_end = scanner->table + DOM_SCANNER_TOKENS; - struct dom_scanner_token *current; if (!begin_dom_token_scanning(scanner)) return get_dom_scanner_token(scanner); /* Scan tokens until we fill the table */ - for (current = scanner->table + scanner->tokens; - current < table_end && scanner->position < scanner->end; - current++) { + for (scanner->current = scanner->table + scanner->tokens; + scanner->current < table_end && scanner->position < scanner->end; + scanner->current++) { if (scanner->state == SGML_STATE_ELEMENT || (*scanner->position == '<' && scanner->state != SGML_STATE_PROC_INST)) { skip_sgml_space(scanner, &scanner->position); if (scanner->position >= scanner->end) break; - scan_sgml_element_token(scanner, current); + scan_sgml_element_token(scanner, scanner->current); /* Shall we scratch this token? */ - if (current->type == SGML_TOKEN_SKIP) { - current--; + if (scanner->current->type == SGML_TOKEN_SKIP) { + scanner->current--; } } else if (scanner->state == SGML_STATE_TEXT) { - scan_sgml_text_token(scanner, current); + scan_sgml_text_token(scanner, scanner->current); } else { - scan_sgml_proc_inst_token(scanner, current); + scan_sgml_proc_inst_token(scanner, scanner->current); } } - return end_dom_token_scanning(scanner, current); + return end_dom_token_scanning(scanner, scanner->current); } From c9c41e38a2d3b8bfa21cda74949062c2dc96f27a Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 01:27:48 +0100 Subject: [PATCH 15/64] test_expect_incomplete(): Put sgml-parser output to /dev/null --- src/dom/test/test-sgml-parser-basic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dom/test/test-sgml-parser-basic b/src/dom/test/test-sgml-parser-basic index 28daae50e..c3a5e2e8a 100755 --- a/src/dom/test/test-sgml-parser-basic +++ b/src/dom/test/test-sgml-parser-basic @@ -43,7 +43,7 @@ test_expect_incomplete () { y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; s/[^a-zA-Z0-9-]//g;')" - sgml-parser --uri "$URI" --src "$src" --incomplete + sgml-parser --uri "$URI" --src "$src" --incomplete >/dev/null test_expect_success "$desc" \ "test $? = 1" } From 450e44a598d394e4090fad8256fd03afc127ddc4 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sat, 7 Jan 2006 01:28:54 +0100 Subject: [PATCH 16/64] exec_on_terminal(): simplify code. --- src/terminal/terminal.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 895e89806..7b9241eb8 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -201,17 +201,17 @@ void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char *delete, int fg) { - int plen; - int dlen = strlen(delete); + int plen, dlen; - if (path && !*path) return; - if (!path) { - path = ""; - plen = 0; + if (path) { + if (!*path) return; } else { - plen = strlen(path); + path = ""; } - + + plen = strlen(path); + dlen = strlen(delete); + #ifdef NO_FG_EXEC fg = 0; #endif From 7c65c06b413ac81eb62b67dcde0f246e46b0380f Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 01:29:44 +0100 Subject: [PATCH 17/64] Move up enum sgml_parser_code declaration --- src/dom/sgml/parser.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/dom/sgml/parser.h b/src/dom/sgml/parser.h index de836a9f8..4764c91b7 100644 --- a/src/dom/sgml/parser.h +++ b/src/dom/sgml/parser.h @@ -38,6 +38,16 @@ struct sgml_parser_state { struct dom_scanner_token end_token; }; +enum sgml_parser_code { + SGML_PARSER_CODE_OK, /* The parsing was successful */ + SGML_PARSER_CODE_INCOMPLETE, /* The parsing could not be completed */ + SGML_PARSER_CODE_MEM_ALLOC, /* Failed to allocate memory */ + + /* FIXME: For when we will add support for requiring stricter parsing + * or even a validator. */ + SGML_PARSER_CODE_ERROR, +}; + struct sgml_parser { enum sgml_parser_type type; /* Stream or tree */ enum sgml_parser_flag flags; /* Flags that control the behaviour */ @@ -57,16 +67,6 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype, void done_sgml_parser(struct sgml_parser *parser); -enum sgml_parser_code { - SGML_PARSER_CODE_OK, /* The parsing was successful */ - SGML_PARSER_CODE_INCOMPLETE, /* The parsing could not be completed */ - SGML_PARSER_CODE_MEM_ALLOC, /* Failed to allocate memory */ - - /* FIXME: For when we will add support for requiring stricter parsing - * or even a validator. */ - SGML_PARSER_CODE_ERROR, -}; - enum sgml_parser_code parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete); From 7ff2cb26074e35cdf21f5681bc1f639673d80eba Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 01:41:07 +0100 Subject: [PATCH 18/64] Improve a comment a bit --- src/dom/sgml/scanner.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dom/sgml/scanner.c b/src/dom/sgml/scanner.c index 7396b7933..041d1b57d 100644 --- a/src/dom/sgml/scanner.c +++ b/src/dom/sgml/scanner.c @@ -599,7 +599,8 @@ scan_sgml_proc_inst_token(struct dom_scanner *scanner, struct dom_scanner_token } if (!string) { - /* Makes the next succeed when checking for incompletion. */ + /* Makes the next succeed when checking for incompletion, and + * puts the rest of the text within the token. */ string = scanner->end; if (check_sgml_incomplete(scanner, string)) { From a2b9d8bb780777728b5624185b8ab86ef77dbffb Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sat, 7 Jan 2006 01:47:36 +0100 Subject: [PATCH 19/64] Explode exec_on_terminal() to new exec_on_master_terminal() and exec_on_slave_terminal(). --- src/terminal/terminal.c | 155 ++++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 70 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 7b9241eb8..8dd536319 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -197,91 +197,106 @@ unblock_terminal(struct terminal *term) textarea_edit(1, NULL, NULL, NULL, NULL); } + +static void +exec_on_master_terminal(struct terminal *term, + unsigned char *path, int plen, + unsigned char *delete, int dlen, + int fg) +{ + int blockh; + unsigned char *param; + int param_size; + + if (is_blocked() && fg) { + unlink(delete); + return; + } + + param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */; + param = mem_alloc(param_size); + if (!param) return; + + param[0] = fg; + memcpy(param + 1, path, plen + 1); + memcpy(param + 1 + plen + 1, delete, dlen + 1); + + if (fg == 1) block_itrm(term->fdin); + + blockh = start_thread((void (*)(void *, int)) exec_thread, + param, param_size); + if (blockh == -1) { + if (fg == 1) unblock_itrm(term->fdin); + mem_free(param); + return; + } + + mem_free(param); + if (fg == 1) { + term->blocked = blockh; + set_handlers(blockh, + (select_handler_T) unblock_terminal, + NULL, + (select_handler_T) unblock_terminal, + term); + set_handlers(term->fdin, NULL, NULL, + (select_handler_T) destroy_terminal, + term); + /* block_itrm(term->fdin); */ + } else { + set_handlers(blockh, close_handle, NULL, + close_handle, (void *) (long) blockh); + } +} + +static void +exec_on_slave_terminal( struct terminal *term, + unsigned char *path, int plen, + unsigned char *delete, int dlen, + int fg) +{ + int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */; + unsigned char *data = mem_alloc(data_size); + + if (data) { + data[0] = 0; + data[1] = fg; + memcpy(data + 2, path, plen + 1); + memcpy(data + 2 + plen + 1, delete, dlen + 1); + hard_write(term->fdout, data, data_size); + mem_free(data); + } +} + void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char *delete, int fg) { - int plen, dlen; - if (path) { if (!*path) return; } else { path = ""; } - - plen = strlen(path); - dlen = strlen(delete); - + #ifdef NO_FG_EXEC fg = 0; #endif + if (term->master) { - if (!*path) dispatch_special(delete); - else { - int blockh; - unsigned char *param; - int param_size; - - if (is_blocked() && fg) { - unlink(delete); - return; - } - - param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */; - param = mem_alloc(param_size); - if (!param) return; - - param[0] = fg; - memcpy(param + 1, path, plen + 1); - memcpy(param + 1 + plen + 1, delete, dlen + 1); - - if (fg == 1) block_itrm(term->fdin); - - blockh = start_thread((void (*)(void *, int)) exec_thread, - param, param_size); - if (blockh == -1) { - if (fg == 1) unblock_itrm(term->fdin); - mem_free(param); - return; - } - - mem_free(param); - if (fg == 1) { - term->blocked = blockh; - set_handlers(blockh, - (select_handler_T) unblock_terminal, - NULL, - (select_handler_T) unblock_terminal, - term); - set_handlers(term->fdin, NULL, NULL, - (select_handler_T) destroy_terminal, - term); - /* block_itrm(term->fdin); */ - } else { - set_handlers(blockh, close_handle, NULL, - close_handle, (void *) (long) blockh); - } + if (!*path) { + dispatch_special(delete); + return; } + + exec_on_master_terminal(term, + path, strlen(path), + delete, strlen(delete), + fg); } else { - int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */; - unsigned char *data = mem_alloc(data_size); - - if (data) { - data[0] = 0; - data[1] = fg; - memcpy(data + 2, path, plen + 1); - memcpy(data + 2 + plen + 1, delete, dlen + 1); - hard_write(term->fdout, data, data_size); - mem_free(data); - } -#if 0 - char x = 0; - hard_write(term->fdout, &x, 1); - x = fg; - hard_write(term->fdout, &x, 1); - hard_write(term->fdout, path, strlen(path) + 1); - hard_write(term->fdout, delete, strlen(delete) + 1); -#endif + exec_on_slave_terminal( term, + path, strlen(path), + delete, strlen(delete), + fg); } } From dee8ac5b45f4e863bb4207c1568aa2f234ffcc0f Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 01:48:51 +0100 Subject: [PATCH 20/64] Move test for incompleteness to own file --- src/dom/test/test-sgml-parser-basic | 97 ------------------- src/dom/test/test-sgml-parser-incomplete | 115 +++++++++++++++++++++++ 2 files changed, 115 insertions(+), 97 deletions(-) create mode 100755 src/dom/test/test-sgml-parser-incomplete diff --git a/src/dom/test/test-sgml-parser-basic b/src/dom/test/test-sgml-parser-basic index c3a5e2e8a..742e81280 100755 --- a/src/dom/test/test-sgml-parser-basic +++ b/src/dom/test/test-sgml-parser-basic @@ -31,23 +31,6 @@ test_output_equals () { test_expect_success "$desc" 'cmp output expected' } -test_expect_incomplete () { - desc="$1"; shift - src="$1"; shift - - URI="test:$(echo "$desc" | sed ' - s/^[ \t]*\[[^]]*\][ \t]*//; - s/[:., \t][:., \t]*/-/g; - s/_/-/g; - # *cough* - y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; - s/[^a-zA-Z0-9-]//g;')" - - sgml-parser --uri "$URI" --src "$src" --incomplete >/dev/null - test_expect_success "$desc" \ - "test $? = 1" -} - ################################################################ # Parse various SGML node types. @@ -300,85 +283,5 @@ test_output_equals \ ' 8' \ --print-lines - -test_expect_incomplete \ -'Check incomplete comment. (I)' \ -'/dev/null + test_expect_success "$desc" \ + "test $? = 1" +} + + +################################################################ +# Check for incompleteness + +test_expect_incomplete \ +'Check incomplete comment. (I)' \ +' Date: Sat, 7 Jan 2006 01:49:12 +0100 Subject: [PATCH 21/64] exec_on_slave_terminal(): reduce indentation level and use fmem_alloc() instead of mem_alloc(). --- src/terminal/terminal.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 8dd536319..205f148d9 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -256,16 +256,16 @@ exec_on_slave_terminal( struct terminal *term, int fg) { int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */; - unsigned char *data = mem_alloc(data_size); + unsigned char *data = fmem_alloc(data_size); - if (data) { - data[0] = 0; - data[1] = fg; - memcpy(data + 2, path, plen + 1); - memcpy(data + 2 + plen + 1, delete, dlen + 1); - hard_write(term->fdout, data, data_size); - mem_free(data); - } + if (!data) return; + + data[0] = 0; + data[1] = fg; + memcpy(data + 2, path, plen + 1); + memcpy(data + 2 + plen + 1, delete, dlen + 1); + hard_write(term->fdout, data, data_size); + fmem_free(data); } void From df138c775abff99d1fcb9b124c4779fb7f975208 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sat, 7 Jan 2006 01:52:35 +0100 Subject: [PATCH 22/64] exec_on_master_terminal(): reduce code redundancy a bit and use fmem_alloc() instead of mem_alloc(). --- src/terminal/terminal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 205f148d9..6922ed690 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -214,7 +214,7 @@ exec_on_master_terminal(struct terminal *term, } param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */; - param = mem_alloc(param_size); + param = fmem_alloc(param_size); if (!param) return; param[0] = fg; @@ -225,13 +225,12 @@ exec_on_master_terminal(struct terminal *term, blockh = start_thread((void (*)(void *, int)) exec_thread, param, param_size); + fmem_free(param); if (blockh == -1) { if (fg == 1) unblock_itrm(term->fdin); - mem_free(param); return; } - mem_free(param); if (fg == 1) { term->blocked = blockh; set_handlers(blockh, From 16e2724c12a5987cfeaf6a5cef94d68a55752084 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sat, 7 Jan 2006 01:54:44 +0100 Subject: [PATCH 23/64] exec_on_master_terminal(): move code to caller instead. --- src/terminal/terminal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 6922ed690..2657be6c4 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -208,11 +208,6 @@ exec_on_master_terminal(struct terminal *term, unsigned char *param; int param_size; - if (is_blocked() && fg) { - unlink(delete); - return; - } - param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */; param = fmem_alloc(param_size); if (!param) return; @@ -287,6 +282,11 @@ exec_on_terminal(struct terminal *term, unsigned char *path, return; } + if (fg && is_blocked()) { + unlink(delete); + return; + } + exec_on_master_terminal(term, path, strlen(path), delete, strlen(delete), From 2e67ca1df9e415617ef353809951a6a4533b0090 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sat, 7 Jan 2006 01:55:18 +0100 Subject: [PATCH 24/64] exec_on_master_terminal(): drop old commented code. --- src/terminal/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 2657be6c4..528c31cc5 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -236,7 +236,7 @@ exec_on_master_terminal(struct terminal *term, set_handlers(term->fdin, NULL, NULL, (select_handler_T) destroy_terminal, term); - /* block_itrm(term->fdin); */ + } else { set_handlers(blockh, close_handle, NULL, close_handle, (void *) (long) blockh); From ee0dc57771ebc11b477ea0934763aef0833ff4e0 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sat, 7 Jan 2006 01:57:11 +0100 Subject: [PATCH 25/64] exec_on_master_terminal(): tidy up. --- src/terminal/terminal.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 528c31cc5..51ae23790 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -205,11 +205,9 @@ exec_on_master_terminal(struct terminal *term, int fg) { int blockh; - unsigned char *param; - int param_size; + int param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */; + unsigned char *param = fmem_alloc(param_size); - param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */; - param = fmem_alloc(param_size); if (!param) return; param[0] = fg; @@ -253,7 +251,7 @@ exec_on_slave_terminal( struct terminal *term, unsigned char *data = fmem_alloc(data_size); if (!data) return; - + data[0] = 0; data[1] = fg; memcpy(data + 2, path, plen + 1); From f1c3c90a4f2f224367ff58b001acc1d753662f3c Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 02:02:21 +0100 Subject: [PATCH 26/64] Move line counting tests to own file; simplifies a few things --- src/dom/test/sgml-parser.c | 3 +- src/dom/test/test-sgml-parser-basic | 39 +---------------- src/dom/test/test-sgml-parser-lines | 67 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 39 deletions(-) create mode 100755 src/dom/test/test-sgml-parser-lines diff --git a/src/dom/test/sgml-parser.c b/src/dom/test/sgml-parser.c index 01d4c95ca..642548ae8 100644 --- a/src/dom/test/sgml-parser.c +++ b/src/dom/test/sgml-parser.c @@ -104,7 +104,8 @@ sgml_parser_test_tree(struct dom_stack *stack, struct dom_node *node, void *data struct dom_string *name = get_dom_node_name(node); /* Always print the URI for identification. */ - update_number_of_lines(stack); + if (update_number_of_lines(stack)) + return; print_indent(stack); printf("%.*s: %.*s\n", diff --git a/src/dom/test/test-sgml-parser-basic b/src/dom/test/test-sgml-parser-basic index 742e81280..a203a78ac 100755 --- a/src/dom/test/test-sgml-parser-basic +++ b/src/dom/test/test-sgml-parser-basic @@ -24,7 +24,7 @@ test_output_equals () { y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; s/[^a-zA-Z0-9-]//g;')" - sgml-parser --uri "$URI" --src "$src" $@ | sed 's/^ //' > output + sgml-parser --uri "$URI" --src "$src" | sed 's/^ //' > output echo "#document: $URI" > expected echo "$out" | sed -n '2,$p' >> expected @@ -247,41 +247,4 @@ element: root attribute: ns:attr -> value proc-instruction: target -> data' -test_output_equals \ -'Check line numbers. (I)' \ -' number ' \ -' -1' \ ---print-lines - -test_output_equals \ -'Check line numbers. (II)' \ -'< -line:2 -line:3 -= -"line:5" ->' \ -' -10' \ ---print-lines - -test_output_equals \ -'Check line numbers. (III)' \ -'1 -2 -3 -4 -5 -6 -7 -8' \ -' -8' \ ---print-lines - test_done diff --git a/src/dom/test/test-sgml-parser-lines b/src/dom/test/test-sgml-parser-lines new file mode 100755 index 000000000..fac0a433a --- /dev/null +++ b/src/dom/test/test-sgml-parser-lines @@ -0,0 +1,67 @@ +#!/bin/sh +# +# Copyright (c) 2005 Jonas Fonseca +# + +test_description='Test the SGML parsers counting of lines + +Checks that the SGML parser correctly reports how many lines the +source has. +' + +. "$TEST_LIB" + +test_output_line_numbers () { + desc="$1"; shift + src="$1"; shift + expected_lines="$1"; shift + + URI="test:$(echo "$desc" | sed ' + s/^[ \t]*\[[^]]*\][ \t]*//; + s/[:., \t][:., \t]*/-/g; + s/_/-/g; + # *cough* + y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; + s/[^a-zA-Z0-9-]//g;')" + + lines=$(sgml-parser --uri "$URI" --src "$src" --print-lines) + + test_expect_success "$desc" "test $lines = $expected_lines" +} + + +################################################################ +# Check line numbers + +test_output_line_numbers \ +'Check line numbers. (I)' \ +' number ' \ +1 + +test_output_line_numbers \ +'Check line numbers. (II)' \ +'< +line:2 +line:3 += +"line:5" +>' \ +10 + +test_output_line_numbers \ +'Check line numbers. (III)' \ +'1 +2 +3 +4 +5 +6 +7 +8' \ +8 + +test_done From a1e512218338713813239244fd5e75229af09d52 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 02:14:45 +0100 Subject: [PATCH 27/64] Drop unnneeded URL argument and simplify test helpers --- src/dom/test/test-sgml-parser-incomplete | 10 +--------- src/dom/test/test-sgml-parser-lines | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/dom/test/test-sgml-parser-incomplete b/src/dom/test/test-sgml-parser-incomplete index 697c951d7..2135e94b9 100755 --- a/src/dom/test/test-sgml-parser-incomplete +++ b/src/dom/test/test-sgml-parser-incomplete @@ -15,15 +15,7 @@ test_expect_incomplete () { desc="$1"; shift src="$1"; shift - URI="test:$(echo "$desc" | sed ' - s/^[ \t]*\[[^]]*\][ \t]*//; - s/[:., \t][:., \t]*/-/g; - s/_/-/g; - # *cough* - y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; - s/[^a-zA-Z0-9-]//g;')" - - sgml-parser --uri "$URI" --src "$src" --incomplete >/dev/null + sgml-parser --src "$src" --incomplete >/dev/null test_expect_success "$desc" \ "test $? = 1" } diff --git a/src/dom/test/test-sgml-parser-lines b/src/dom/test/test-sgml-parser-lines index fac0a433a..e021d59ff 100755 --- a/src/dom/test/test-sgml-parser-lines +++ b/src/dom/test/test-sgml-parser-lines @@ -16,15 +16,7 @@ test_output_line_numbers () { src="$1"; shift expected_lines="$1"; shift - URI="test:$(echo "$desc" | sed ' - s/^[ \t]*\[[^]]*\][ \t]*//; - s/[:., \t][:., \t]*/-/g; - s/_/-/g; - # *cough* - y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; - s/[^a-zA-Z0-9-]//g;')" - - lines=$(sgml-parser --uri "$URI" --src "$src" --print-lines) + lines=$(sgml-parser --src "$src" --print-lines) test_expect_success "$desc" "test $lines = $expected_lines" } From 5defc48eb3fe50ce0378ef9dbd5e0b7541aeb2ad Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 04:21:39 +0100 Subject: [PATCH 28/64] Add basic support for requesting error detection; SGML scanner part missing --- src/dom/scanner.c | 3 ++- src/dom/scanner.h | 8 ++++++- src/dom/select.c | 2 +- src/dom/sgml/parser.c | 47 ++++++++++++++++++++++++++++++++++++++++-- src/dom/sgml/parser.h | 9 ++++++++ src/dom/sgml/scanner.h | 4 ++++ 6 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/dom/scanner.c b/src/dom/scanner.c index aea8e2d18..c3cd1baa4 100644 --- a/src/dom/scanner.c +++ b/src/dom/scanner.c @@ -155,7 +155,7 @@ init_dom_scanner_info(struct dom_scanner_info *scanner_info) void init_dom_scanner(struct dom_scanner *scanner, struct dom_scanner_info *scanner_info, struct dom_string *string, int state, int count_lines, int complete, - int check_complete) + int check_complete, int detect_errors) { if (!scanner_info->initialized) { init_dom_scanner_info(scanner_info); @@ -173,6 +173,7 @@ init_dom_scanner(struct dom_scanner *scanner, struct dom_scanner_info *scanner_i scanner->count_lines = !!count_lines; scanner->incomplete = !complete; scanner->check_complete = !!check_complete; + scanner->detect_errors = !!detect_errors; scanner->lineno = scanner->count_lines; scanner->info->scan(scanner); } diff --git a/src/dom/scanner.h b/src/dom/scanner.h index cb9906d44..eabe95746 100644 --- a/src/dom/scanner.h +++ b/src/dom/scanner.h @@ -20,6 +20,9 @@ struct dom_scanner_token { /* Some precedence value */ int precedence; + /* The line number; used for error tokens */ + unsigned int lineno; + /* The start of the token string and the token length */ struct dom_string string; }; @@ -93,7 +96,7 @@ struct dom_scanner_info { /* Initializes the scanner. */ void init_dom_scanner(struct dom_scanner *scanner, struct dom_scanner_info *scanner_info, struct dom_string *string, int state, int count_lines, int complete, - int check_complete); + int check_complete, int detect_error); /* The number of tokens in the scanners token table: * At best it should be big enough to contain properties with space separated @@ -130,6 +133,9 @@ struct dom_scanner { unsigned int check_complete:1; /* Only generate complete tokens */ unsigned int incomplete:1; /* The scanned string is incomplete */ + unsigned int detect_errors:1; /* Check for markup errors */ + unsigned int found_error; /* Did we already report this error? */ + unsigned int count_lines:1; /* Is line counting enbaled? */ unsigned int lineno; /* Line # of the last scanned token */ diff --git a/src/dom/select.c b/src/dom/select.c index 1c53f61c3..a0e5d7644 100644 --- a/src/dom/select.c +++ b/src/dom/select.c @@ -391,7 +391,7 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack, struct dom_scanner scanner; struct dom_select_node sel; - init_dom_scanner(&scanner, &dom_css_scanner_info, string, 0, 0, 1, 0); + init_dom_scanner(&scanner, &dom_css_scanner_info, string, 0, 0, 1, 0, 0); memset(&sel, 0, sizeof(sel)); diff --git a/src/dom/sgml/parser.c b/src/dom/sgml/parser.c index 0c5b4a3b4..81227d09a 100644 --- a/src/dom/sgml/parser.c +++ b/src/dom/sgml/parser.c @@ -154,6 +154,17 @@ add_sgml_node(struct dom_stack *stack, enum dom_node_type type, struct dom_scann /* SGML parser main handling: */ +static enum sgml_parser_code +call_sgml_error_function(struct dom_stack *stack, struct dom_scanner_token *token) +{ + struct sgml_parser *parser = get_sgml_parser(stack); + unsigned int line = get_sgml_parser_line_number(parser); + + assert(parser->error_func); + + return parser->error_func(parser, &token->string, line); +} + static inline enum sgml_parser_code parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) { @@ -217,6 +228,17 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) case SGML_TOKEN_INCOMPLETE: return SGML_PARSER_CODE_INCOMPLETE; + case SGML_TOKEN_ERROR: + { + enum sgml_parser_code code; + + code = call_sgml_error_function(stack, token); + if (code != SGML_PARSER_CODE_OK) + return code; + + skip_dom_scanner_token(scanner); + break; + } default: skip_dom_scanner_token(scanner); } @@ -326,7 +348,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) /* The attribute souce is complete. */ init_dom_scanner(&attr_scanner, &sgml_scanner_info, &token->string, SGML_STATE_ELEMENT, - scanner->count_lines, 1, 0); + scanner->count_lines, 1, 0, 0); if (dom_scanner_has_tokens(&attr_scanner)) { /* Ignore parser codes from this @@ -350,6 +372,17 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) case SGML_TOKEN_INCOMPLETE: return SGML_PARSER_CODE_INCOMPLETE; + case SGML_TOKEN_ERROR: + { + enum sgml_parser_code code; + + code = call_sgml_error_function(stack, token); + if (code != SGML_PARSER_CODE_OK) + return code; + + skip_dom_scanner_token(scanner); + break; + } case SGML_TOKEN_SPACE: case SGML_TOKEN_TEXT: default: @@ -403,11 +436,13 @@ sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data) int count_lines = !!(parser->flags & SGML_PARSER_COUNT_LINES); int complete = !!(parser->flags & SGML_PARSER_COMPLETE); int incremental = !!(parser->flags & SGML_PARSER_INCREMENTAL); + int detect_errors = !!(parser->flags & SGML_PARSER_DETECT_ERRORS); parsing->depth = parser->stack.depth; get_dom_stack_top(&parser->stack)->immutable = 1; init_dom_scanner(&parsing->scanner, &sgml_scanner_info, &node->string, - SGML_STATE_TEXT, count_lines, complete, incremental); + SGML_STATE_TEXT, count_lines, complete, incremental, + detect_errors); } static void @@ -494,6 +529,11 @@ get_sgml_parser_line_number(struct sgml_parser *parser) assert(pstate->scanner.count_lines && pstate->scanner.lineno); + if (pstate->scanner.current + && pstate->scanner.current < pstate->scanner.table + DOM_SCANNER_TOKENS + && pstate->scanner.current->type == SGML_TOKEN_ERROR) + return pstate->scanner.current->lineno; + return pstate->scanner.lineno; } @@ -553,6 +593,9 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype, return NULL; } + if (flags & SGML_PARSER_DETECT_ERRORS) + flags |= SGML_PARSER_COUNT_LINES; + parser->type = type; parser->flags = flags; parser->info = get_sgml_info(doctype); diff --git a/src/dom/sgml/parser.h b/src/dom/sgml/parser.h index 4764c91b7..b81c6a933 100644 --- a/src/dom/sgml/parser.h +++ b/src/dom/sgml/parser.h @@ -7,6 +7,7 @@ #include "dom/sgml/sgml.h" #include "dom/scanner.h" +struct sgml_parser; struct string; struct uri; @@ -26,6 +27,7 @@ enum sgml_parser_flag { SGML_PARSER_COUNT_LINES = 1, SGML_PARSER_COMPLETE = 2, SGML_PARSER_INCREMENTAL = 4, + SGML_PARSER_DETECT_ERRORS = 8, }; struct sgml_parser_state { @@ -48,6 +50,11 @@ enum sgml_parser_code { SGML_PARSER_CODE_ERROR, }; +/* If the return code is not SGML_PARSER_CODE_OK the parsing will be ended and + * that code will be returned. */ +typedef enum sgml_parser_code +(*sgml_error_T)(struct sgml_parser *, struct dom_string *, unsigned int); + struct sgml_parser { enum sgml_parser_type type; /* Stream or tree */ enum sgml_parser_flag flags; /* Flags that control the behaviour */ @@ -57,6 +64,8 @@ struct sgml_parser { struct dom_string uri; /* The URI of the DOM document */ struct dom_node *root; /* The document root node */ + sgml_error_T error_func; + struct dom_stack stack; /* A stack for tracking parsed nodes */ struct dom_stack parsing; /* Used for tracking parsing states */ }; diff --git a/src/dom/sgml/scanner.h b/src/dom/sgml/scanner.h index 3857ad78e..fc58b0aa4 100644 --- a/src/dom/sgml/scanner.h +++ b/src/dom/sgml/scanner.h @@ -52,6 +52,10 @@ enum sgml_token_type { * not complete. Only meaningful if scanner->complete is incomplete. */ SGML_TOKEN_INCOMPLETE, + /* A special token for reporting that an error in the markup was found. + * Only in effect when error checking has been requested. */ + SGML_TOKEN_ERROR, + /* Token type used internally when scanning to signal that the token * should not be recorded in the scanners token table. */ SGML_TOKEN_SKIP, From c993a0012e28a957fd68d148809101944f211bf8 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 7 Jan 2006 04:26:08 +0100 Subject: [PATCH 29/64] Add basic support for detection errors while scanning It mostly uses the checking for incompleteness already in place. Tested lightly so it will definately need some more work. --- src/dom/sgml/scanner.c | 90 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 6 deletions(-) diff --git a/src/dom/sgml/scanner.c b/src/dom/sgml/scanner.c index 041d1b57d..b8544a0c1 100644 --- a/src/dom/sgml/scanner.c +++ b/src/dom/sgml/scanner.c @@ -117,6 +117,35 @@ set_sgml_incomplete(struct dom_scanner *scanner, struct dom_scanner_token *token scanner->position = scanner->end; } + +static inline int +check_sgml_error(struct dom_scanner *scanner) +{ + unsigned int found_error = scanner->found_error; + + /* Toggle if we found an error previously. */ + scanner->found_error = 0; + + return scanner->detect_errors && !found_error; +} + +static struct dom_scanner_token * +set_sgml_error(struct dom_scanner *scanner, unsigned char *end) +{ + struct dom_scanner_token *token = scanner->current; + + assert(!scanner->found_error); + + scanner->found_error = 1; + + token->type = SGML_TOKEN_ERROR; + token->lineno = scanner->lineno; + set_dom_string(&token->string, scanner->position, end - scanner->position); + + return scanner->found_error ? NULL : scanner->current; +} + + /* Text token scanning */ /* I think it is faster to not check the table here --jonas */ @@ -155,9 +184,17 @@ scan_sgml_text_token(struct dom_scanner *scanner, struct dom_scanner_token *toke } /* We want the biggest possible text token. */ - if (check_sgml_incomplete(scanner, string) && !complete) { - set_sgml_incomplete(scanner, token); - return; + if (!complete) { + if (check_sgml_incomplete(scanner, string)) { + set_sgml_incomplete(scanner, token); + return; + } + + if (check_sgml_error(scanner)) { + token = set_sgml_error(scanner, string); + if (!token) + return; + } } } else { @@ -564,9 +601,44 @@ scan_sgml_element_token(struct dom_scanner *scanner, struct dom_scanner_token *t } } - if (possibly_incomplete && check_sgml_incomplete(scanner, string)) { - set_sgml_incomplete(scanner, token); - return; + if (possibly_incomplete) { + if (check_sgml_incomplete(scanner, string)) { + set_sgml_incomplete(scanner, token); + return; + } + + if (check_sgml_error(scanner)) { + unsigned char *end = string; + + DBG("%d %d", type, SGML_TOKEN_NOTATION_DOCTYPE); + switch (type) { + case SGML_TOKEN_CDATA_SECTION: + case SGML_TOKEN_NOTATION_ATTLIST: + case SGML_TOKEN_NOTATION_DOCTYPE: + case SGML_TOKEN_NOTATION_ELEMENT: + if (scanner->position + 9 < end) + end = scanner->position + 9; + break; + + case SGML_TOKEN_NOTATION_COMMENT: + /* Just include the '