1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 1998-2010 Ales Hvezda
4 ;;; Copyright (C) 2006-2010 John P. Doty
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 2 of the License, or
9 ;;; (at your option) any later version.
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 ;;; MA 02111-1301 USA.
21 ;; Calay format (modified from Ales's gnet-PCB.scm by jpd)
22 ;; Netname translation cleaned up at Dan McMahill'suggestion -jpd
24 (define (calay:display-connections nets)
26 (for-each (lambda (in-string)
27 (set! k (string-append k in-string)))
29 (string-append " " (car net) "(" (car (cdr net)) ")"))
31 (string-append k ";\n")))
34 ;; Wrap a string into lines no longer than wrap-length
35 ;; (from Stefan Petersen)
36 ;; (Modified for Calay format by jpd)
37 (define (calay:wrap string-to-wrap wrap-length)
38 (if (> wrap-length (string-length string-to-wrap))
39 string-to-wrap ; Last snippet of string
40 (let ((pos (string-rindex string-to-wrap #\space 0 wrap-length)))
42 (display "Couldn't wrap string at requested position\n")
46 (substring string-to-wrap 0 pos)
48 (calay:wrap (substring string-to-wrap (+ pos 1)) wrap-length)))))))
51 ;; For the nonce, this just turns "_" into "-"
53 (define (calay:translate string-to-translate)
54 (let ((pos (string-index string-to-translate #\_)))
55 (if pos (calay:translate (string-append (substring string-to-translate 0
56 pos) "-" (substring string-to-translate (+ 1 pos)))) string-to-translate)))
58 (define (calay:write-net netnames)
59 (if (not (null? netnames))
60 (let ((netname (car netnames)))
62 (display (gnetlist:alias-net netname))
64 (display (calay:wrap (calay:display-connections
65 (gnetlist:get-all-connections netname)) 66))
66 (calay:write-net (cdr netnames)))))
69 (define (calay output-filename)
70 (set-current-output-port (gnetlist:output-port output-filename))
71 (gnetlist:build-net-aliases calay:translate all-unique-nets)
72 (calay:write-net (gnetlist:get-all-unique-nets "dummy"))
73 (close-output-port (current-output-port)))