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

Q&A's, tips, howto's
Locked
unya
Posts: 27
Joined: Fri Feb 26, 2010 8:30 am
Contact:

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

Post by 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)

Code: Select all

---- 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
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

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

Post by TedWalther »

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Post by Lutz »

Thank you Unya and Ted.

This is fixed for v.10.2.0:

http://www.newlisp.org/downloads/develo ... t/nl-xml.c

unya
Posts: 27
Joined: Fri Feb 26, 2010 8:30 am
Contact:

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

Post by unya »

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

Locked