Skip to content

Commit

Permalink
* Various patches, see ChangeLog
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker committed Dec 18, 2000
1 parent acd29dc commit ab759a7
Show file tree
Hide file tree
Showing 39 changed files with 456 additions and 91 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
* FIXED: Proper parsing of <!NOTATION ...> declaration. Also fixed
dtd_property(DTD, notations(Notations)) and modified
dtd_property(DTD, notation(N, Decl)).

* ADDED: <!ENTITY #DEFAULT ...> (Richard O'Keefe).

* FIXED: Ignore newline after entity

* FIXED: Allow omitted ; expanding entities in CDATA attributes

* FIXED: Possible crash with SHORTREF endding in &#RE.

* FIXED: avoid crash on illegal syntax in DTD omited-tag declaration
Expand Down
8 changes: 8 additions & 0 deletions Test/bar.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE bar [
<!ELEMENT bar - O EMPTY>
<!ATTLIST bar a CDATA #REQUIRED b NAME #REQUIRED c NUMBER #REQUIRED
d CDATA #REQUIRED>
]>

<bar a="Major Mynah" b="&#65;&#66;&#67;" c="&#49;&#50;" d="foo
bar ugh">
7 changes: 7 additions & 0 deletions Test/ce.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE test [
<!ELEMENT test - - (#PCDATA)>
]>

<test>
Test for handling character entities: &#65; &#RS;
</test>
13 changes: 13 additions & 0 deletions Test/cmt.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE a
[ <!ENTITY %attrs
"id ID #implied -- document-wide unique id --
class CDATA #IMPLIED -- comment --">

<!ELEMENT a - - (#PCDATA) -- foo-bar -->
<!ATTLIST a %attrs;>
]
>

<!-- x -->

<a></a>
8 changes: 8 additions & 0 deletions Test/conref.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE con [
<!ELEMENT con - - (foo,bar)>
<!ATTLIST con missing (missing) #CONREF>
<!ELEMENT (foo|bar) - O (#PCDATA)>
]>

<con missing>

10 changes: 10 additions & 0 deletions Test/defent.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE def [
<!ENTITY #DEFAULT SDATA "?">
<!ELEMENT def - - RCDATA>
]>

<def>&#65
&#66 &#67
&b
&#66
&c</def>
7 changes: 7 additions & 0 deletions Test/foo.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE foo [
<!ELEMENT foo O O (name+)>
<!ELEMENT name - O (#PCDATA)>
<!ATTLIST name title cdata #implied sex cdata #implied>
]>
<name title=Dr sex=M>Neddie Seagoon
<name title=Miss sex=F>Minnie Bannister
12 changes: 12 additions & 0 deletions Test/i.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE test [
<!ENTITY QS "<q>">
<!ENTITY QE ENDTAG "q">
<!ENTITY Q2 CDATA "<q>">
<!ENTITY S SDATA "special">
<!ELEMENT test - - (#PCDATA|q)*>
<!ELEMENT q - - (#PCDATA)>
]>

<test>
&Q2;! Hello &QS;you there&QE;, I'm &S;
</test>
13 changes: 13 additions & 0 deletions Test/not.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE not [
<!ELEMENT not - - (Formula*)>
<!NOTATION TeX SYSTEM "">
<!NOTATION Eqn SYSTEM "">
<!ELEMENT formula - O CDATA>
<!ATTLIST formula notation NOTATION (TeX|Eqn) #CURRENT>
]>

<not>
<formula notation=TeX>
$$E = MC^2$$
</formula>
</not>
1 change: 1 addition & 0 deletions Test/ok/bar.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(bar, [a='Major Mynah', b=abc, c='12', d='foo bar ugh'], [])].
1 change: 1 addition & 0 deletions Test/ok/ce.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(test, [], ['Test for handling character entities: A \n'])].
1 change: 1 addition & 0 deletions Test/ok/cmt.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(a, [], [])].
1 change: 1 addition & 0 deletions Test/ok/conref.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(con, [missing=missing], [])].
1 change: 1 addition & 0 deletions Test/ok/defent.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(def, [], ['AB C', sdata(?), 'B', sdata(?)])].
1 change: 1 addition & 0 deletions Test/ok/foo.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(foo, [], [element(name, [title='Dr', sex='M'], ['Neddie Seagoon']), element(name, [title='Miss', sex='F'], ['Minnie Bannister'])])].
1 change: 1 addition & 0 deletions Test/ok/i.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(test, [], ['<q>! Hello ', element(q, [], ['you there']), ', I\'m ', sdata(special)])].
1 change: 1 addition & 0 deletions Test/ok/not.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(not, [], [element(formula, [notation=tex], ['$$E = MC^2$$'])])].
1 change: 1 addition & 0 deletions Test/ok/omit1.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(bar, [], [element(foo, [], [element(a, [], [element(b, [], [x]), element(c, [], [y])]), element(a, [], [element(b, [], [x]), element(c, [], [y])]), element(a, [], [element(b, [], [x]), element(c, [], [y])]), element(a, [], [element(b, [], [x]), element(c, [], [y])])])])].
1 change: 1 addition & 0 deletions Test/ok/per.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(per, [], [element(jim, [], [snark])])].
1 change: 1 addition & 0 deletions Test/ok/rcdata.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(doc, [], [element(t, [], ['This is rcdata Hello & World Hello']), element(a, [], ['This is an a'])])].
1 change: 1 addition & 0 deletions Test/ok/sdata.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(text, [], ['Van Alpha tot ', sdata('\\Omega')])].
1 change: 1 addition & 0 deletions Test/ok/shortval.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(num, [val='2'], [])].
1 change: 1 addition & 0 deletions Test/ok/sr.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(test, [], [element(p, [], ['Peter said: ', element(q, [], ['He, this is a nice program']), '.']), element(p, [], ['Bob said: ', element(q, [], ['Yes, it is'])])])].
1 change: 1 addition & 0 deletions Test/ok/sr2.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(test, [], [element(t, [], [element(name, [], [n]), element(arg, [], [a])])])].
1 change: 1 addition & 0 deletions Test/ok/ugh.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[element(ugh, [], [element(extension, [missing=missing, exchange='479'], []), element(extension, [exchange='479'], ['8494']), element(extension, [exchange='555'], ['1234']), element(extension, [exchange='03-555'], ['1234'])])].
14 changes: 14 additions & 0 deletions Test/omit1.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE bar [
<!ELEMENT bar - - (foo)>
<!ELEMENT foo O O (a+)>
<!ELEMENT a O O (b,c)>
<!ELEMENT b - O (#PCDATA)>
<!ELEMENT c - O (#PCDATA)>
]>

<bar>
<b>x<c>y
<b>x<c>y
<b>x<c>y
<b>x<c>y
</bar>
9 changes: 9 additions & 0 deletions Test/per.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE per [
<!ENTITY % fred "jim">
<!ELEMENT per - - (%fred;)>
<!ELEMENT %fred - - (#PCDATA)>
<!ATTLIST %fred tom (dick|harry) #IMPLIED>
<!USEMAP #EMPTY %fred>
]>

<per><jim>snark</jim></per>
19 changes: 19 additions & 0 deletions Test/rcdata.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE doc
[ <!ELEMENT doc - - (t|a)*>
<!ELEMENT a - - (#PCDATA)>
<!ELEMENT t - - rcdata>
<!ENTITY hello "Hello">
<!ENTITY world "World &hello;">
]
>

<!-- coment -->

<doc>
<t>
This is rcdata &hello; & &world
</t>

<a>This is an a</a>

</doc>
8 changes: 8 additions & 0 deletions Test/sdata.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE text [
<!ENTITY Omega SDATA "\Omega">
<!ELEMENT text - - (#PCDATA)>
]>

<text>
Van Alpha tot &Omega;
</text>
6 changes: 6 additions & 0 deletions Test/shortval.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE num [
<!ELEMENT num - O EMPTY>
<!ATTLIST num val (1|2|3) #REQUIRED>
]>

<num 2>
20 changes: 20 additions & 0 deletions Test/sr.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE test [
<!ELEMENT test - - p*>
<!ELEMENT p o o (#PCDATA|q)*>
<!ELEMENT q - - (#PCDATA)>

<!ENTITY beg..q "<q><!USEMAP in..q>">
<!ENTITY end..q ENDTAG "q">
<!ENTITY beg..p STARTTAG "p">

<!SHORTREF in..p '"' beg..q
'&#RS;B&#RE' beg..p>
<!SHORTREF in..q '"' end..q>
<!USEMAP in..p p>
]>

<test>
Peter said: "He, this is a nice program".

Bob said: "Yes, it is"
</test>
25 changes: 25 additions & 0 deletions Test/sr2.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE test
[ <!ELEMENT test - - (t*)>
<!ELEMENT t - - ((name|op),arg)>
<!ELEMENT name o o (#PCDATA)>
<!ELEMENT op - - (#PCDATA)>
<!ELEMENT arg - - (#PCDATA)>
<!ELEMENT desc o o (#PCDATA)>

<!ENTITY end-t ENDTAG "t">
<!ENTITY beg-arg STARTTAG "arg">
<!ENTITY end-arg ENDTAG "arg">

<!SHORTREF in.t
'&#RE' end-t
'(' beg-arg>
<!SHORTREF in.arg
')' end-arg>

<!USEMAP in.t t>
<!USEMAP in.arg arg>
]>

<test>
<t>n(a)
</test>
103 changes: 103 additions & 0 deletions Test/test.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* $Id$
Part of SWI-Prolog SGML/XML parser
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi.psy.uva.nl/projects/SWI-Prolog/
Copying: LGPL-2. See the file COPYING or http://www.gnu.org
Copyright (C) 1990-2000 SWI, University of Amsterdam. All rights reserved.
*/

:- module(sgml_test,
[ test/1, % +File
testdir/1, % +Dir
pass/1, % +File
show/1, % +File
test/0
]).

test :-
testdir(.).

testdir(Dir) :-
atom_concat(Dir, '/*', Pattern),
expand_file_name(Pattern, Files),
checklist(dotest, Files).

dotest(File) :-
file_name_extension(_, Ext, File),
memberchk(Ext, [sgml, xml, html]), !,
test(File).
dotest(_).

test(File) :-
format('Test ~w ... ', [File]),
flush_output,
load_file(File, Term),
ground(Term), % make sure
okfile(File, OkFile),
( exists_file(OkFile)
-> load_prolog_file(OkFile, TermOk),
( compare_dom(Term, TermOk)
-> format('ok~n')
; format('WRONG~n')
)
; format('Loaded, no validating data~n'),
pp(Term)
).

show(File) :-
load_file(File, Term),
pp(Term).

pass(File) :-
load_file(File, Term),
okfile(File, OkFile),
open(OkFile, write, Fd),
format(Fd, '~q.~n', [Term]),
close(Fd).

load_file(File, Term) :-
load_pred(Ext, Pred),
file_name_extension(_, Ext, File), !,
call(Pred, File, Term).
load_file(Base, Term) :-
load_pred(Ext, Pred),
file_name_extension(Base, Ext, File),
exists_file(File), !,
call(Pred, File, Term).


load_pred(sgml, load_sgml_file).
load_pred(xml, load_xml_file).
load_pred(html, load_html_file).

okfile(File, OkFile) :-
file_name_extension(Base, _, File),
file_directory_name(Base, Dir),
concat_atom([Dir, '/ok/', Base, '.ok'], OkFile).

load_prolog_file(File, Term) :-
open(File, read, Fd),
read(Fd, Term),
close(Fd).

compare_dom([], []) :- !.
compare_dom([H1|T1], [H2|T2]) :- !,
compare_dom(H1, H2),
compare_dom(T1, T2).
compare_dom(X, X) :- !.
compare_dom(element(Name, A1, Content1),
element(Name, A2, Content2)) :-
compare_attributes(A1, A2),
compare_dom(Content1, Content2).

compare_attributes(A1, A2) :-
sort(A1, L1),
sort(A2, L2),
L1 == L2.



9 changes: 9 additions & 0 deletions Test/ugh.sgml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE ugh [
<!ELEMENT ugh O O (extension+)>
<!ELEMENT extension - O (#PCDATA)>
<!ATTLIST extension exchange NUTOKEN 479 missing (missing) #CONREF>
]>
<extension missing>
<extension>8494
<extension exchange=555>1234
<extension exchange=03-555>1234
5 changes: 3 additions & 2 deletions doc/sgml2pl.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,9 @@ unbound.
</argdef>
<termitem>notations(ListOfNotations)
Returns a list holding the names of all <c/NOTATION/ declarations.
<termitem>notation(Name, File)
Yields the declared file for from a <c/NOTATION/ declaration.
<termitem>notation(Name, Decl)
Unify <aref/Decl/ with a list if <term>system(+File)</term> and/or
<term>public(+PublicId)</term>.
</argdef>
</definitions>

Expand Down
5 changes: 4 additions & 1 deletion dtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ typedef struct _dtd_entity

typedef struct _dtd_notation
{ dtd_symbol *name; /* name of the notation */
ichar *file; /* file with info */
entity_type type; /* ET_{PUBLIC|SYSTEM} */
ichar *public; /* public id */
ichar *system; /* file with info */
struct _dtd_notation *next; /* list-link */
} dtd_notation;

Expand Down Expand Up @@ -401,6 +403,7 @@ typedef struct _dtd
dtd_symbol_table *symbols; /* symbol-table */
dtd_entity *pentities; /* defined parameter entities */
dtd_entity *entities; /* defined entities */
dtd_entity *default_entity; /* default-entity (if any) */
dtd_notation *notations; /* Declared notations */
dtd_shortref *shortrefs; /* SHORTREF declarations */
dtd_element *elements; /* defined elements */
Expand Down
Loading

0 comments on commit ab759a7

Please sign in to comment.