[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: gnetlist backend for xml-bom generation



Hi guys

In my part of the world it's been Mardi Gras, so I've been out of the
office.  Sorry for the late reply.

Thank Peter for your input it helped lots. I really started
understanding things better once I figured out the "gnetlist
backend->guile->scheme->lisp" lineage.

After following the examples you provided, and much trial and error, I
got the following to do what I need it to do.


(define (string-insert s i t) (string-replace s t i i))

(define xmlsearchandreplace
  (lambda (s1 sstring rstring spos)
        (let ((fpos1 (string-contains s1 sstring spos))) 
                (if fpos1   
                (begin 
                        (xmlsearchandreplace (string-insert s1 (+ 1
fpos1) rstring ) sstring rstring (+ fpos1 (string-length rstring)))
                )
                (begin
                        s1
                )
                )
        )
  )
)  

and then to use it, I do something like this;

(display (xmlsearchandreplace (car ls) "&" "amp;" 0) port)

It's not perfect as it doesn't really replace the "&", but rather
appends the "amp;", but it generates correct xml, so I'm happy.

I'll post a patch soon.

Thanks again for your quick reply!

On Tue, 2009-02-24 at 00:03 +0000, Peter Clifton wrote:
> On Mon, 2009-02-23 at 16:55 -0600, Mike Crowe wrote:
> > Hello all
> > 
> > I've generated a preliminary gnetlist backend for generating an xml
> > based bill of materials.
> > 
> > It seems to be working except that I have to filter the file with sed
> > after generating the netlist to convert "&" to "&".
> >
> > Two questions
> > 1) Does anyone know how to do this filter conversion directly with the
> > backend toolset (guile)?
> 
> The hard question... (best ask a scheme guru).
> 
> You might find a way with the srfi13 library. There are these examples
> in the docs:
> 
> ;;; Convert a string to a list of chars.
> (string-fold-right cons '() s)
> 
> ;;; Count the number of lower-case characters in a string.
> (string-fold (lambda (c count)
>                (if (char-lower-case? c)
>                    (+ count 1)
>                    count))
>              0
>              s)
> 
> ;;; Double every backslash character in S.
> (let* ((ans-len (string-fold (lambda (c sum)
>                                (+ sum (if (char=? c #\\) 2 1)))
>                              0 s))
>        (ans (make-string ans-len)))
>   (string-fold (lambda (c i)
>                  (let ((i (if (char=? c #\\)
>                               (begin (string-set! ans i #\\) (+ i 1))
>                               i)))
>                    (string-set! ans i c)
>                    (+ i 1)))
>                0 s)
>   ans)
> 
> 
> You might find some combination of that, and string-append is useful.
> OTOH, I'm no scheme guru, and have no idea how fast either of those
> would be.
> 
> You might write a procedure which searches for the & character, splits
> the string on it, then makes a concationation of <before &>&amp;<after
> &>.
> 
> I suspect you could operate recursively on the split string's second
> half.
> 
> Don't ask me to figure out what functions are required to find / split
> the string. You might find something suitable here though:
> 
> http://srfi.schemers.org/srfi-13/srfi-13.html
> 
> If you're going to use recursion, tail-recursion is best (to avoid
> running out of stack space). If I'm getting the explanation right.. the
> last call (before it returns) in the the recursive procedure should be
> the one which calls its-self.
> 
> http://en.wikipedia.org/wiki/Tail_recursion
> 
> > 2) Who do I contact to get my little backend into the main code
> > branch? :-)
> 
> Send a patch to this list.. talk to Ales, or one of the other developers
> etc..
> 
> Post a patch to sourceforge tracker (but prod us on-list if you don't
> want it to get ignored / forgotten).
> 
> Best wishes,
> 
-- 
+---------------------------------------------------------------+
Mike Crowe
Gulf Coast Data Concepts
611 Nicholson Ave
Waveland, MS  39576
e-mail: mcrowe@xxxxxxxxxxxxxxxxxx
phone: 228.424.6307
30d 17.753' North  089d 22.022' West
home of the USB-Accelerometer 
http://www.gcdataconcepts.com/xlr8r-1.html
+---------------------------------------------------------------+



_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user