[GtkAda] Patch for glib-xml.adb
Bobby D. Bryant
bdbryant at mail.utexas.edu
Thu May 25 07:17:52 CEST 2000
Attached is a patch for glib-xml.adb.
The patch is a diff -u against the version that shipped with GtkAda
1.2.7. (I installed from the ALT's RPM rather than from the tarball
available at the GtkAda site, but I assume the source file was
unchanged.)
The patch addresses the following issues:
o function Parse bombed off whenever it encountered a comment.
o function Parse bombed off whenever it encountered <!DOCTYPE *>.
o Procedure Print reduplicated the '/' for valueless tags of the form
"<tag/>", yielding "<tag//>". (However, it already worked OK for
<tag></tag>, and also for <tag /> with a space.)
With this patch, tags beginning with '!' are simply ignored during the
parse. This means that if you Parse a file and then immediately Print
the loaded structure, you will *not* see these ignored values in the
resulting printout. (I recognize that this is not the optimal
behavior. However, I did not want to introduce a supra-node into the
data structure simply to preserve comments and <!DOCTYPE *> declarations
preceding the actual structure to be parsed in. That decision in turn
predicated ignoring any additional comments within the actual structure,
because I did not want to introduce the inconsistent behavior of
ignoring some comments and retaining others. Whether optimal or not, I
hope you will at least agree that this is an improvement, since at least
it no longer bombs off when it encounters these elements!)
***WARNING***
I have tested the patch on the material I have been working with, but
you should do some additional testing before incorporating it into your
library or any essential applications.
Bobby Bryant
Austin, Texas
-------------- next part --------------
--- /usr/lib/ada/adainclude/glib-xml.adb Sun May 21 09:27:12 2000
+++ glib-xml.adb Wed May 24 23:44:06 2000
@@ -241,59 +241,65 @@
Index_Save := Index.all;
Get_Buf (Buf, Index.all, '>', N.Tag);
- -- Here we have to deal with the attributes of the form
- -- <tag attrib='xyyzy'>
+ -- Check to see whether it is a comment, !DOCTYPE, or the like:
+ if (N.Tag(N.Tag.all'First) = '!') then
+ return Get_Node( Buf, Index );
+ else
- Extract_Attrib (N.Tag, N.Attributes, Empty_Node);
+ -- Here we have to deal with the attributes of the form
+ -- <tag attrib='xyyzy'>
- -- it is possible to have a child-less node that has the form
- -- <tag /> or <tag attrib='xyyzy'/>
+ Extract_Attrib (N.Tag, N.Attributes, Empty_Node);
- if Empty_Node then
- N.Value := new String' ("");
- else
- if Buf (Index.all) = '<' then
- if Buf (Index.all + 1) = '/' then
+ -- it is possible to have a child-less node that has the form
+ -- <tag /> or <tag attrib='xyyzy'/>
- -- No value contained on this node
+ if Empty_Node then
+ N.Value := new String' ("");
+ else
+ if Buf (Index.all) = '<' then
+ if Buf (Index.all + 1) = '/' then
- N.Value := new String' ("");
- Index.all := Index.all + 1;
+ -- No value contained on this node
- else
+ N.Value := new String' ("");
+ Index.all := Index.all + 1;
- -- Parse the children
+ else
- N.Child := Get_Node (Buf, Index);
- N.Child.Parent := N;
- Last_Child := N.Child;
- pragma Assert (Buf (Index.all) = '<');
-
- while Buf (Index.all + 1) /= '/' loop
- Q := Last_Child;
- Q.Next := Get_Node (Buf, Index);
- Q.Next.Parent := N;
- Last_Child := Q.Next;
+ -- Parse the children
+
+ N.Child := Get_Node (Buf, Index);
+ N.Child.Parent := N;
+ Last_Child := N.Child;
pragma Assert (Buf (Index.all) = '<');
- end loop;
- Index.all := Index.all + 1;
- end if;
+ while Buf (Index.all + 1) /= '/' loop
+ Q := Last_Child;
+ Q.Next := Get_Node (Buf, Index);
+ Q.Next.Parent := N;
+ Last_Child := Q.Next;
+ pragma Assert (Buf (Index.all) = '<');
+ end loop;
- else
+ Index.all := Index.all + 1;
+ end if;
- -- Get the value of this node
+ else
+
+ -- Get the value of this node
+
+ Get_Buf (Buf, Index.all, '<', N.Value);
+ end if;
- Get_Buf (Buf, Index.all, '<', N.Value);
+ pragma Assert (Buf (Index.all) = '/');
+ Index.all := Index.all + 1;
+ Get_Buf (Buf, Index.all, '>', S);
+ pragma Assert (N.Tag.all = S.all);
end if;
- pragma Assert (Buf (Index.all) = '/');
- Index.all := Index.all + 1;
- Get_Buf (Buf, Index.all, '>', S);
- pragma Assert (N.Tag.all = S.all);
+ return N;
end if;
-
- return N;
end Get_Node;
-----------
@@ -335,7 +341,13 @@
else
if N.Value.all = "" then
- Put_Line ("/>");
+ -- The following handles the difference between what you got
+ -- when you parsed <tag/> vs. <tag />.
+ if ( N.Tag.all(N.Tag.all'last) = '/') then
+ Put_Line (">");
+ else
+ Put_Line ("/>");
+ end if;
else
Put (">");
Put (N.Value.all);
More information about the gtkada
mailing list