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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 ;; Calay format (modified from Ales's gnet-PCB.scm by jpd)
21 ;; Netname translation cleaned up at Dan McMahill'suggestion -jpd
23 (define (calay:display-connections nets)
25 (for-each (lambda (in-string)
26 (set! k (string-append k in-string)))
28 (string-append " " (car net) "(" (car (cdr net)) ")"))
30 (string-append k ";\n")))
33 ;; Wrap a string into lines no longer than wrap-length
34 ;; (from Stefan Petersen)
35 ;; (Modified for Calay format by jpd)
36 (define (calay:wrap string-to-wrap wrap-length)
37 (if (> wrap-length (string-length string-to-wrap))
38 string-to-wrap ; Last snippet of string
39 (let ((pos (string-rindex string-to-wrap #\space 0 wrap-length)))
41 (display "Couldn't wrap string at requested position\n")
45 (substring string-to-wrap 0 pos)
47 (calay:wrap (substring string-to-wrap (+ pos 1)) wrap-length)))))))
50 ;; For the nonce, this just turns "_" into "-"
52 (define (calay:translate string-to-translate)
53 (let ((pos (string-index string-to-translate #\_)))
54 (if pos (calay:translate (string-append (substring string-to-translate 0
55 pos) "-" (substring string-to-translate (+ 1 pos)))) string-to-translate)))
57 (define (calay:write-net netnames port)
58 (if (not (null? netnames))
59 (let ((netname (car netnames)))
61 (display (gnetlist:alias-net netname) port)
63 (display (calay:wrap (calay:display-connections
64 (gnetlist:get-all-connections netname)) 66) port)
65 (calay:write-net (cdr netnames) port))))
68 (define (calay output-filename)
69 (let ((port (open-output-file output-filename)))
70 (gnetlist:build-net-aliases calay:translate all-unique-nets)
71 (calay:write-net (gnetlist:get-all-unique-nets "dummy") port)
72 (close-output-port port)))