Re: problem reading XML

2008-07-27 Thread Tomas Hlavaty
Hi Alex,

(in file
   (pipe (while (and (echo !--) (from --)))
  (xml) ) )

 I fact, I would like to remove that half-hearted comment feature from
 lib/xml.l. Does anybody have objections?

since the XML declaration is optional, I would need to write:

(or (in F (pipe (while (and (echo !--) (from --)))
 (and (xml?) (xml
(in F (pipe (while (and (echo !--) (from --)))
 (xml

to load xml data.

Would not it be better if the xml function simply handled it all, the
xml declaration, comments and xml elements?  It looks like the current
code is not far from it.

The following code handles optional declarations and comments (both
inside and outside the root element):

(de xml2 (Lst N)
   (if Lst
  (let Tag (pop 'Lst)
 (space (default N 0))
 (prin  Tag)
 (for X (pop 'Lst)
(prin   (car X) =\)
(escXml (cdr X))
(prin \) )
 (nond
(Lst (prinl /))
((or (cdr Lst) (pair (car Lst)))
   (prin )
   (escXml (car Lst))
   (prinl / Tag ) )
(NIL
   (prinl )
   (for X Lst
  (if (pair X)
 (xml X (+ 3 N))
 (space (+ 3 N))
 (escXml X)
 (prinl) ) )
   (space N)
   (prinl / Tag ) ) ) )
  (_xml2) ) )

(de _xml2 (Tok Decl In)
   #(println Tok)
   (cond
  ((not Tok)
   (skip)
   (unless (=  (char))
  (quit Bad XML start) )
   (_xml2 (till  /)))
  ((head '(? x m l) Tok)
   (if Decl
  (quit XML declaration too late)
  # TODO check decl validity
  (from ?)
  (skip)
  (unless (=  (char))
 (quit Bad XML element start) )
  (_xml2 (till  /) T)))
  ((head '(! - -) Tok)
   (from --)
   (unless In
  (skip)
  (unless (=  (char))
 (quit Bad XML element start) )
  (_xml2 (till  /) T)))
  (T
   (use X
  (make
 (link (intern (pack Tok)))
 (let L
(make
   (loop
  (NIL (skip) (quit XML parse error 1))
  (T (member @ '(/ )))
  (NIL (setq X (intern (till = T
  (char)
  (unless (= \ (char))
 (quit XML parse error 2 X) )
  (link (cons X (pack (xmlEsc (till \)
  (char) ) )
(if (= / (char))
   (prog (char) (and L (link L)))
   (link L)
   (loop
  (NIL (skip) (quit XML parse error 3 (pack Tok)))
  (T (and (=  (setq X (char))) (= / (peek)))
 (char)
 (unless (= Tok (till  /))
(quit Unbalanced XML (pack Tok) ))
 (char) )
  (if (=  X)
 (and (_xml2 (till  /) T T) (link @))
 (link
(pack (xmlEsc (trim (cons X (till 
^J)))

It can parse the following file:

?xml version=1.0?!--*- xml -*--
!-- comment 1 --
hi
   !-- another comment --
   bye123/bye
/hi
!-- comment 2 --
!-- last comment --

 Is this mailing list the right place to decide such changes?

How does current decision making work?

Thanks,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


pipes redirection

2008-07-27 Thread Tomas Hlavaty
Hi Alex,

is it possible in picolisp to create pipes from external programs,
e.g. like in bash?  I.e. create a pipe, write to it on one end and
read from it on the other end?  E.g. `base64 | wc -l`?

Also, is it possible in the following code to suppress the two prompts

Encryption key:
Again:

shown by bcrypt?  Maybe read the two lines in or redirect bcrypt
stdout to /dev/null?

: (de bcrypt (Data Salt)
   (default Salt (fmt64 (in '/dev/random (rd 42 # 56*3/4=42
   (unless (= 8 (length (pipe (prin Salt) (line T))) 56)
  (quit Length of Salt must be from 8 to 56 Salt))
   (let (F (pipe (call 'mktemp)
 (line T))
 G (pack F .bfe))
  (out F (print Data))
  (out (list 'bcrypt F)
 (prinl Salt)
 (prinl Salt))
  (prog1
 (cons Salt (pipe (call 'base64 '-w 0 G) (line T)))
 (call 'rm '-f G
- bcrypt
: (bcrypt hello)
Encryption key:
Again:
- (e07OZN8X;IWgm8bXjNgKrWG9Ib4c11hqEcRhol8DNHd1Mru2VqfhNRS . 
VAE/tAC/bQUOifdyG6SPS89pgd8ceWsaUHPDvCFKXSyHs358BUMR32qkfQEtwB/AIWEU9tTIXsW6+sC+VxbAg5b6x/HhRP8ie04H)
: 

Thank you,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]