xml-parse - patch file for nl-xml.c

Started by unya, February 26, 2010, 01:22:30 AM

Previous topic - Next topic

unya

Because a tag of utf8(utf8 version newlisp) was not made in xml-parse, I made a patch.



pathed newlisp work in this for the time being.



But please teach it because this revision method does not understand whether it is a right method for newlisp.



(translated by http://honyaku.yahoo.co.jp/transtext">http://honyaku.yahoo.co.jp/transtext)



---- example.xml ----
<?xml version="1.0" ?>
<DATABASE name="example.xml">
<!--This is a database of fruits-->
    <果物>
        <名前>リンゴ - apple</名前>
        <色>赤 - red</色>
        <価格>0.80</価格>
    </果物>

    <果物>
        <名前>オレンジ - orange</名前>
        <色>オレンジ - orange</色>
        <価格>1.00</価格>
    </果物>

    <果物>
       <名前>バナナ - banana</名前>
       <色>黄色 - yellow</色>
       <価格>0.60</価格>
    </果物>
</DATABASE>
---- example.xml ----

---- after patched ----
(first (xml-parse (read-file "example.xml") (+ 1 2)))
("ELEMENT" "DATABASE" (("name" "example.xml")) (("COMMENT" "This is a database of fruits")
  ("ELEMENT" "果物FRUIT" (("ELEMENT" "名前" (("TEXT" "リンゴ - apple"))) (
     "ELEMENT" "色"
     (("TEXT" "赤 - red")))
    ("ELEMENT" "価格" (("TEXT" "0.80")))))
  ("ELEMENT" "果物FRUIT" (("ELEMENT" "名前" (("TEXT" "オレンジ - orange")))
    ("ELEMENT" "色" (("TEXT" "オレンジ - orange")))
    ("ELEMENT" "価格" (("TEXT" "1.00")))))
  ("ELEMENT" "果物FRUIT" (("ELEMENT" "名前" (("TEXT" "バナナ - banana")))
    ("ELEMENT" "色" (("TEXT" "黄色 - yellow")))
    ("ELEMENT" "価格" (("TEXT" "0.60")))))))
---- after patched ----


$ diff -crN nl-xml.c.org nl-xml.c
*** nl-xml.c.org        Mon Nov 23 02:45:16 2009
--- nl-xml.c    Fri Feb 26 16:59:46 2010
***************
*** 441,451 ****
 
  ++source; /* skip '/' */
 
! while(*source <= ' ' && source < endSrc) ++source; /* skip whitespace */
 
  tagStart = source;
  tagLen = 0;
! while(*source > ' ' && source < endSrc) ++source, ++tagLen; /* find tag end */
 
  attributes = parseAttributes(endSrc);
  if(optionsFlag & OPTION_SXML_ATTRIBUTES)
--- 441,451 ----
 
  ++source; /* skip '/' */
 
! while((unsigned char)*source <= ' ' && source < endSrc) ++source; /* skip whitespace */
 
  tagStart = source;
  tagLen = 0;
! while((unsigned char)*source > ' ' && source < endSrc) ++source, ++tagLen; /* find tag end */
 
  attributes = parseAttributes(endSrc);
  if(optionsFlag & OPTION_SXML_ATTRIBUTES)
***************
*** 519,530 ****
 
  while(!xmlError && source < endSrc)
        {
!       while(*source <= ' ' && source < endSrc) source++; /* strip leading space */
        namePos = source;
        nameLen = 0;
!       while(*source > ' ' && *source != '=' && source < endSrc) source++, nameLen++; /* get end */
        if(nameLen == 0) break;
!       while(*source <= ' ' && source < endSrc) source++; /* strip leading space */
        if(*source != '=')
                {
                xmlError = "expected '=' in attributes";
--- 519,530 ----
 
  while(!xmlError && source < endSrc)
        {
!       while((unsigned char)*source <= ' ' && source < endSrc) source++; /* strip leading space */
        namePos = source;
        nameLen = 0;
!       while((unsigned char)*source > ' ' && *source != '=' && source < endSrc) source++, nameLen++; /* get end */
        if(nameLen == 0) break;
!       while((unsigned char)*source <= ' ' && source < endSrc) source++; /* strip leading space */
        if(*source != '=')
                {
                xmlError = "expected '=' in attributes";
***************
*** 532,538 ****
                return nilCell;
                }
        else source++;
!       while(*source <= ' ' && source < endSrc) source++; /* strip spaces */
        if(*source != '"' && *source != ''')
                {
                xmlError = "attribute values must be delimited by " or ' ";
--- 532,538 ----
                return nilCell;
                }
        else source++;
!       while((unsigned char)*source <= ' ' && source < endSrc) source++; /* strip spaces */
        if(*source != '"' && *source != ''')
                {
                xmlError = "attribute values must be delimited by " or ' ";

TedWalther

#1
Can you please post the patch in unified diff format?  Also, to get the patch included, standard procedure is to email Lutz your modified file in its entirety, NOT the patch file.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.

Lutz

#2
Thank you Unya and Ted.



This is fixed for v.10.2.0:



http://www.newlisp.org/downloads/development/latest/nl-xml.c">http://www.newlisp.org/downloads/develo ... t/nl-xml.c">http://www.newlisp.org/downloads/development/latest/nl-xml.c

unya

#3
Thank you Lutz got to fix,Thanks for the advice TedWalther's.