Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gnetlist / scheme / gnet-calay.scm
blob0238d03223d57698f0b107c532afe65e2405afb7
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
5 ;;;
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.
10 ;;;
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.
15 ;;;
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)
24   (let ((k ""))
25     (for-each (lambda (in-string)
26                 (set! k (string-append k in-string)))
27               (map (lambda (net)
28                      (string-append " " (car net) "(" (car (cdr net)) ")"))
29                    nets))
30     (string-append k ";\n")))
31     
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)))
40         (cond ((not pos)
41                (display "Couldn't wrap string  at requested position\n")
42                " Wrap error!")
43               (else
44                (string-append 
45                 (substring string-to-wrap 0 pos) 
46                 ",\n          "
47                 (calay:wrap (substring string-to-wrap (+ pos 1)) wrap-length)))))))
49 ;; Translate netnames
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)))
60         (display "/" port)
61         (display (gnetlist:alias-net netname) port)
62         (display "\t" 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)))