From 25c8a3d592b3b839e1f39bdde02f46cc1bdff13a Mon Sep 17 00:00:00 2001 From: Thien-Thi Nguyen Date: Wed, 8 Jan 2003 12:19:28 +0000 Subject: [PATCH] (Xml_print_attributes): Do "&" replacement before any others that might introduce "&" into the stream. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4230 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/xml.cxx | 127 +++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/Source/Modules/xml.cxx b/Source/Modules/xml.cxx index 261f3e348..9051d0dca 100644 --- a/Source/Modules/xml.cxx +++ b/Source/Modules/xml.cxx @@ -1,13 +1,13 @@ -/* ----------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- * Xml.cxx * * A web-base parse tree Xml using SWILL. This is an optional * feature that's normally disabled. - * + * * Author(s) : David Beazley (beazley@cs.uchicago.edu) * * Copyright (C) 2002. The University of Chicago - * See the file LICENSE for information on usage and redistribution. + * See the file LICENSE for information on usage and redistribution. * ----------------------------------------------------------------------------- */ char cvsroot_xml_cxx[] = "$Header$"; @@ -20,9 +20,9 @@ XML Options (available with -xml)\n\ //static Node *view_top = 0; static File *out = 0; - -class XML -: public Language + +class XML +: public Language { @@ -55,7 +55,7 @@ public: Swig_mark_arg (iX); String * outfile = NewString( argv[iX] ); out = NewFile(outfile,"w"); - if (!out) + if (!out) { Printf(stderr,"*** Can't open '%s'\n", outfile); SWIG_exit(EXIT_FAILURE); @@ -75,18 +75,18 @@ public: fputs( usage, stderr ); } } - } + } /* Top of the parse tree */ - virtual int top(Node *n) + virtual int top(Node *n) { if( out == 0 ) { String *outfile = Getattr(n,"outfile"); Replaceall(outfile,"_wrap.cxx", ".xml"); out = NewFile(outfile,"w"); - if (!out) + if (!out) { Printf(stderr,"*** Can't open '%s'\n", outfile); SWIG_exit(EXIT_FAILURE); @@ -99,22 +99,22 @@ public: - void print_indent(int l) + void print_indent(int l) { int i; - for (i = 0; i < indent_level; i++) + for (i = 0; i < indent_level; i++) { Printf(out, " "); } - if (l) + if (l) { Printf(out, " "); } } - void Xml_print_tree(DOH *obj) + void Xml_print_tree(DOH *obj) { - while (obj) + while (obj) { Xml_print_node(obj); obj = nextSibling(obj); @@ -127,61 +127,62 @@ public: indent_level += 4; print_indent(0); Printf( out, "\n", ++id, obj ); - indent_level += 4; + indent_level += 4; k = Firstkey(obj); - while (k) + while (k) { - if ((Cmp(k,"nodeType") == 0) - || (Cmp(k,"firstChild") == 0) - || (Cmp(k,"lastChild") == 0) - || (Cmp(k,"parentNode") == 0) - || (Cmp(k,"nextSibling") == 0) - || (Cmp(k,"previousSibling") == 0) - || (*(Char(k)) == '$')) + if ((Cmp(k,"nodeType") == 0) + || (Cmp(k,"firstChild") == 0) + || (Cmp(k,"lastChild") == 0) + || (Cmp(k,"parentNode") == 0) + || (Cmp(k,"nextSibling") == 0) + || (Cmp(k,"previousSibling") == 0) + || (*(Char(k)) == '$')) { /* Do nothing */ - } - else if (Cmp(k,"module") == 0) + } + else if (Cmp(k,"module") == 0) { Xml_print_module( Getattr(obj,k) ); - } - else if (Cmp(k,"baselist") == 0) + } + else if (Cmp(k,"baselist") == 0) { Xml_print_baselist( Getattr(obj,k) ); - } - else if (Cmp(k,"typescope") == 0) + } + else if (Cmp(k,"typescope") == 0) { Xml_print_typescope( Getattr(obj,k) ); - } - else if (Cmp(k,"typetab") == 0) + } + else if (Cmp(k,"typetab") == 0) { Xml_print_typetab( Getattr(obj,k) ); - } - else if (Cmp(k,"kwargs") == 0) + } + else if (Cmp(k,"kwargs") == 0) { Xml_print_kwargs( Getattr(obj,k) ); - } - else if (Cmp(k,"parms") == 0 || Cmp(k, "pattern") == 0 ) + } + else if (Cmp(k,"parms") == 0 || Cmp(k, "pattern") == 0 ) { Xml_print_parmlist( Getattr(obj,k) ); - } - else + } + else { DOH *o; print_indent(0); - if (DohIsString(Getattr(obj,k))) + if (DohIsString(Getattr(obj,k))) { o = Str(Getattr(obj,k)); Replaceall( k, ":", "_" ); - Replaceall( o, "<", "<" ); + /* Do first to avoid aliasing errors. */ Replaceall( o, "&", "&" ); + Replaceall( o, "<", "<" ); Replaceall( o, "\"", """ ); Replaceall( o, "\\", "\\\\" ); Printf(out,"\n", k, o, ++id, o ); Delete(o); - } - else + } + else { o = Getattr(obj,k); Replaceall( k, ":", "_" ); @@ -196,22 +197,22 @@ public: indent_level -= 4; } - void Xml_print_node(Node *obj) + void Xml_print_node(Node *obj) { Node *cobj; - + print_indent(0); Printf(out,"<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj); Xml_print_attributes( obj ); cobj = firstChild(obj); - if (cobj) + if (cobj) { indent_level += 4; Printf(out,"\n"); Xml_print_tree(cobj); indent_level -= 4; - } - else + } + else { print_indent(1); Printf(out,"\n"); @@ -221,13 +222,13 @@ public: } - void Xml_print_parmlist(ParmList *p) + void Xml_print_parmlist(ParmList *p) { print_indent(0); Printf( out, "\n", ++id, p ); - indent_level += 4; - while(p) + indent_level += 4; + while(p) { print_indent(0); Printf( out, "\n", ++id ); @@ -236,62 +237,62 @@ public: Printf( out, "\n" ); p = nextSibling(p); } - indent_level -= 4; + indent_level -= 4; print_indent(0); Printf( out, "\n" ); } - void Xml_print_baselist(List *p) + void Xml_print_baselist(List *p) { print_indent(0); Printf( out, "\n", ++id, p ); - indent_level += 4; + indent_level += 4; String *s; - for (s = Firstitem(p); s; s = Nextitem(p)) + for (s = Firstitem(p); s; s = Nextitem(p)) { print_indent(0); Printf( out, "\n", s, ++id, s ); } - indent_level -= 4; + indent_level -= 4; print_indent(0); Printf( out, "\n" ); } - void Xml_print_module(Node *p) + void Xml_print_module(Node *p) { print_indent(0); Printf( out, "\n", Getattr( p, "name"), ++id, p ); } - void Xml_print_kwargs(Hash *p) + void Xml_print_kwargs(Hash *p) { Xml_print_hash( p, "kwargs" ); } - void Xml_print_typescope(Hash *p) + void Xml_print_typescope(Hash *p) { Xml_print_hash( p, "typescope" ); } - void Xml_print_typetab(Hash *p) + void Xml_print_typetab(Hash *p) { Xml_print_hash( p, "typetab" ); } - void Xml_print_hash(Hash *p, const char * markup) + void Xml_print_hash(Hash *p, const char * markup) { print_indent(0); Printf( out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p ); Xml_print_attributes( p ); - indent_level += 4; + indent_level += 4; Node * n = Firstitem( p ); - while(n) + while(n) { print_indent(0); Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n ); @@ -301,7 +302,7 @@ public: Printf( out, " />\n" ); n = Nextkey(p); } - indent_level -= 4; + indent_level -= 4; print_indent(0); Printf( out, "\n", markup ); }