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

gEDA-cvs: gaf.git: branch: master updated (1.7.0-20110116-15-geb2a355)



The branch, master has been updated
       via  eb2a355b688053d917dcb85981062451b27c5e8f (commit)
       via  ef5108e96d5745746c2820290738fa2740320e48 (commit)
       via  0255a45d7a06830c5b7a6e927a6cbdde5083ba33 (commit)
      from  9b9080e184607b3cb449a1ccb6082207ed39738f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 gnetlist/scheme/gnet-gsch2pcb.scm.in |  107 ++++++++++++++-------------------
 1 files changed, 45 insertions(+), 62 deletions(-)


=================
 Commit Messages
=================

commit eb2a355b688053d917dcb85981062451b27c5e8f
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gsch2pcb: Don't pass invalid function names to m4.
    
    This fixes a long-standing bug with gsch2pcb.  gsch2pcb expects
    `footprint' attributes to be of the form:
    
      footprint=NAME ARG1 ARG2
    
    This gets transformed to:
    
      PKG_NAME (`NAME-ARG1-ARG2',`refdes',`value',`ARG1',`ARG2')
    
    for macro-expansion by M4.  For this to work, it requires that NAME
    matches the regular expression ^[A-Za-z0-9_]$ so that PKG_NAME is a
    valid M4 function name.
    
    It is quite common for users (especially those using John Luciani's
    footprint library) to define and wish to use footprint names which
    contain hyphens '-'.  Since this character is not valid in M4 function
    names, this practice causes non-obvious breakage to occur.
    
    This patch stops gsch2pcb from ever attempting to macro-expand a
    footprint NAME which is obviously not valid as part of an M4 function
    name.
    
    Closes-bug: lp-698806

:100644 100644 e449ed9... ae4eeb7... M	gnetlist/scheme/gnet-gsch2pcb.scm.in

commit ef5108e96d5745746c2820290738fa2740320e48
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gnetlist: Use `string-join' in gsch2pcb backend.
    
    The gsch2pcb backend for gnetlist has its own version of the
    `string-join' function from the Guile standard library.

:100644 100644 b7d67c8... e449ed9... M	gnetlist/scheme/gnet-gsch2pcb.scm.in

commit 0255a45d7a06830c5b7a6e927a6cbdde5083ba33
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gnetlist: Use `string-split' in gsch2pcb backend.
    
    The gsch2pcb backend for gnetlist has its own version of string-split.
    Use the Guile standard library version instead.

:100644 100644 afe0251... b7d67c8... M	gnetlist/scheme/gnet-gsch2pcb.scm.in

=========
 Changes
=========

commit eb2a355b688053d917dcb85981062451b27c5e8f
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gsch2pcb: Don't pass invalid function names to m4.
    
    This fixes a long-standing bug with gsch2pcb.  gsch2pcb expects
    `footprint' attributes to be of the form:
    
      footprint=NAME ARG1 ARG2
    
    This gets transformed to:
    
      PKG_NAME (`NAME-ARG1-ARG2',`refdes',`value',`ARG1',`ARG2')
    
    for macro-expansion by M4.  For this to work, it requires that NAME
    matches the regular expression ^[A-Za-z0-9_]$ so that PKG_NAME is a
    valid M4 function name.
    
    It is quite common for users (especially those using John Luciani's
    footprint library) to define and wish to use footprint names which
    contain hyphens '-'.  Since this character is not valid in M4 function
    names, this practice causes non-obvious breakage to occur.
    
    This patch stops gsch2pcb from ever attempting to macro-expand a
    footprint NAME which is obviously not valid as part of an M4 function
    name.
    
    Closes-bug: lp-698806

diff --git a/gnetlist/scheme/gnet-gsch2pcb.scm.in b/gnetlist/scheme/gnet-gsch2pcb.scm.in
index e449ed9..ae4eeb7 100644
--- a/gnetlist/scheme/gnet-gsch2pcb.scm.in
+++ b/gnetlist/scheme/gnet-gsch2pcb.scm.in
@@ -72,30 +72,45 @@
    (lambda (x) (not (string=? "" x)))
    (string-split the-string #\space)))
 
-
-(define gsch2pcb:write-value-footprint
-  (lambda (pipe ls)
-    (if (not (null? ls))
-;;       refdes contains the first element of ls        
-        (let* ((refdes (car ls))
-               (value (gnetlist:get-package-attribute refdes "value"))
-               (footprint (gsch2pcb:split-to-list
-                          (gnetlist:get-package-attribute refdes  "footprint") ) ) 
-	       (lquote (if gsch2pcb:use-m4 "`" ""))
-	       (rquote (if gsch2pcb:use-m4 "'" ""))
-
-	       )
-
-               (display (string-append "PKG_" (car footprint)) pipe)
-               (display (string-append "(" lquote (car footprint)) pipe)
-               (display (string-join (cdr footprint) "-" 'prefix) pipe)
-               (display (string-append rquote "," lquote refdes rquote "," lquote ) pipe)
-
-               (display value pipe)
-               (display (string-join (cdr footprint) (string-append rquote "," lquote) 'prefix) pipe)
-               (display (string-append rquote ")") pipe)
-               (newline pipe)
-               (gsch2pcb:write-value-footprint pipe (cdr ls))) )))
+;; Check if `str' contains only characters valid in an M4 function
+;; name.  Note that this *doesn't* check that str is a valid M4
+;; function name.
+(define gsch2pcb:m4-valid?
+  (let ((rx (make-regexp "^[A-Za-z0-9_]*$")))
+    (lambda (str)
+      (regexp-exec rx str))))
+
+;; Quote a string to protect from M4 macro expansion
+(define (gsch2pcb:m4-quote str)
+  (string-append "`" str "'"))
+
+;; Write the footprint for the package `refdes' to `port'.  If M4
+;; footprints are enabled, writes in a format suitable for
+;; macro-expansion by M4.  Any footprint names that obviously can't be
+;; M4 footprints are protected from macro-expansion.
+(define (gsch2pcb:write-value-footprint refdes port)
+
+  (let* ((value (gnetlist:get-package-attribute refdes "value"))
+         (footprint (gsch2pcb:split-to-list
+                     (gnetlist:get-package-attribute refdes "footprint")))
+         (fp (car footprint))
+         (fp-args (cdr footprint))
+
+         (nq (lambda (x) x)) ; A non-quoting operator
+         (q (if gsch2pcb:use-m4 gsch2pcb:m4-quote nq))) ; A quoting operator
+
+    (format port "~A(~A,~A,~A~A)\n"
+            ;; If the footprint is obviously not an M4 footprint,
+            ;; protect it from macro-expansion.
+            ((if (gsch2pcb:m4-valid? fp) nq q) (string-append "PKG_" fp))
+            (q (string-join footprint "-"))
+            (q refdes)
+            (q value)
+            (string-join (map q fp-args) "," 'prefix))))
+
+;; Write the footprints for all the refdes' in `lst'.
+(define (gsch2pcb:write-value-footprints port lst)
+  (for-each (lambda (x) (gsch2pcb:write-value-footprint x port)) lst))
 
 ;;
 ;;
@@ -188,13 +203,13 @@
 	
 	(display "Using the m4 processor for pcb footprints\n")
 	;; packages is a list with the different refdes value
-	(gsch2pcb:write-value-footprint pipe packages)
+	(gsch2pcb:write-value-footprints pipe packages)
 	(close-pipe pipe)
 	)
       
       (let ((port  (open output-filename (logior O_WRONLY O_APPEND))))
 	(display "Skipping the m4 processor for pcb footprints\n")
-	(gsch2pcb:write-value-footprint port packages)
+	(gsch2pcb:write-value-footprints port packages)
 	(close-port port)
 	)
       )

commit ef5108e96d5745746c2820290738fa2740320e48
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gnetlist: Use `string-join' in gsch2pcb backend.
    
    The gsch2pcb backend for gnetlist has its own version of the
    `string-join' function from the Guile standard library.

diff --git a/gnetlist/scheme/gnet-gsch2pcb.scm.in b/gnetlist/scheme/gnet-gsch2pcb.scm.in
index b7d67c8..e449ed9 100644
--- a/gnetlist/scheme/gnet-gsch2pcb.scm.in
+++ b/gnetlist/scheme/gnet-gsch2pcb.scm.in
@@ -72,14 +72,6 @@
    (lambda (x) (not (string=? "" x)))
    (string-split the-string #\space)))
 
-;; Joins the elements of a list of strings into a single string,
-;; with each element prefixed by a given prefix string.
-(define (gsch2pcb:list-join-with-prefixes the-list prefix)
-  (if (null? the-list)
-      ""
-      (string-append prefix (car the-list)
-                     (gsch2pcb:list-join-with-prefixes (cdr the-list) prefix))))
-
 
 (define gsch2pcb:write-value-footprint
   (lambda (pipe ls)
@@ -96,11 +88,11 @@
 
                (display (string-append "PKG_" (car footprint)) pipe)
                (display (string-append "(" lquote (car footprint)) pipe)
-               (display (gsch2pcb:list-join-with-prefixes (cdr footprint) "-") pipe)
+               (display (string-join (cdr footprint) "-" 'prefix) pipe)
                (display (string-append rquote "," lquote refdes rquote "," lquote ) pipe)
 
                (display value pipe)
-               (display (gsch2pcb:list-join-with-prefixes (cdr footprint) (string-append rquote "," lquote)) pipe)
+               (display (string-join (cdr footprint) (string-append rquote "," lquote) 'prefix) pipe)
                (display (string-append rquote ")") pipe)
                (newline pipe)
                (gsch2pcb:write-value-footprint pipe (cdr ls))) )))

commit 0255a45d7a06830c5b7a6e927a6cbdde5083ba33
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Commit: Peter TB Brett <peter@xxxxxxxxxxxxx>

    gnetlist: Use `string-split' in gsch2pcb backend.
    
    The gsch2pcb backend for gnetlist has its own version of string-split.
    Use the Guile standard library version instead.

diff --git a/gnetlist/scheme/gnet-gsch2pcb.scm.in b/gnetlist/scheme/gnet-gsch2pcb.scm.in
index afe0251..b7d67c8 100644
--- a/gnetlist/scheme/gnet-gsch2pcb.scm.in
+++ b/gnetlist/scheme/gnet-gsch2pcb.scm.in
@@ -65,36 +65,12 @@
 ;;
 ;;
 
-;; Split string at current split-char and returns
-;; a pair with substrings. If string is not splitable
-;; it returns #f.
-(define (gsch2pcb:string-split the-string split-char)
-;;string-index is Guile specific
-  (let ((split-index (string-index the-string split-char))
-        (last-index (- (string-length the-string) 1)))
-;;Check if split-char happens to be in the beginning or end of the string
-    (cond ((not split-index)
-           #f)
-          ((= split-index 0)
-           (gsch2pcb:string-split
-            (substring the-string 1 (string-length the-string)) 
-            split-char))
-          ((= split-index last-index)
-           #f)
-          (split-index
-           (cons (substring the-string 0 split-index)
-                 (substring the-string (+ split-index 1) 
-                            (string-length the-string))))
-          (else
-           #f))))
-
 ;; Splits a string with space separated words and returns a list
 ;; of the words (still as strings).
 (define (gsch2pcb:split-to-list the-string)
-  (let ((the-list (gsch2pcb:string-split the-string #\space)))
-    (if the-list
-        (cons (car the-list) (gsch2pcb:split-to-list (cdr the-list)))
-        (list the-string))))
+  (filter!
+   (lambda (x) (not (string=? "" x)))
+   (string-split the-string #\space)))
 
 ;; Joins the elements of a list of strings into a single string,
 ;; with each element prefixed by a given prefix string.




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