[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
RE: gEDA-user: gnetlist output to stdout?
El lun, 14-02-2005 a las 08:14 +0000, Peter Brett escribió:
> > Currently there is no way to output to stdout, but it's easy
> > to add. To add such feature, each backend has to be modified.
>
> Ah, right. I know it would be hard work, but what about changing gnetlist so that it
> passes a file pointer (or the equivalent Scheme type) to the backend? That way the
> backends don't need to worry about where the data's going, they can just throw it at
> the given file pointer. I know nothing about Scheme, so I don't know if that's a
> practical suggestion.
> > I have modified the drc2 backend to output to stdout if the output
> > filename is "-". The changes are in CVS.
>
> That seems sensible: it's the way most of the GNU toolchain seems to handle it.
Why change good habits? ;-)
> > Which backend are you using?
>
> I've written quite a complicated Python script that takes the output of the redac
> and bom backends, renames all the components with a heirachical refdes to the toplevel
> (because having an 0402 capacitor with a refdes like "D1/A4/C3" is impractical for the
> silkscreen) and creates a new Racal Redac netlist & an Orcad-style BOM.
>
> If I could just read the output of gnetlist straight into a variable, it would be useful.
> As it is, I'm having to mess about with temporary files. :-(
I don't know what other developers think about your suggestion. By now,
I think the quickest solution is this: I attach some modified backends
so they can output to stdout if the output filename is "-". Just try
them! :-)
Disclaimer: I can't test them now, but only minor changes were required,
so I hope they are OK.
Cheers,
Carlos
;;; $Id: gnet-bom2.scm,v 1.7 2005/02/03 12:49:36 danmc Exp $
;;;
;;; gEDA - GNU Electronic Design Automation
;;; gnetlist - GNU Netlist
;;; Copyright (C) 1998-2001 Ales V. Hvezda
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;; --------------------------------------------------------------------------
;;
;; Bill of Material backend written by Matt Ettus starts here
;;
;;; Bill Of Materials Generator
;;; You must have a file called attribs in the pwd
;;; The file should be a text list of attributes you want listed,
;;; One per line. No comments are allowed in the file.
;;; Questions? Contact matt@xxxxxxxxx
;;; This software is released under the terms of the GNU GPL
(define bom2
(lambda (output-filename)
(let ((port (if (string=? "-" output-filename)
(current-output-port)
(open-output-file output-filename)))
(attriblist (bom2:parseconfig (open-input-file "attribs"))))
(bom2:printlist (cons 'package attriblist) port #\:)
(newline port)
(bom2:printbom port (bom2:components packages attriblist))
(close-output-port port))))
(define bom2:printbom
(lambda (port bomlist)
(if (not (null? bomlist))
(if (not (null? (caar bomlist)))
(begin
(display (caaar bomlist) port)
(if (not (null? (cdaar bomlist)))
(write-char #\, port))
(bom2:printbom port (cons (cons (cdaar bomlist)(cdar bomlist))(cdr bomlist))))
(begin
(display #\: port)
(bom2:printlist (cdar bomlist) port #\:)
(newline port)
(bom2:printbom port (cdr bomlist)))))))
(define bom2:printlist
(lambda (ls port delimiter)
(if (null? ls)
#f
(begin
(display (car ls) port)
(if (not (null? (cdr ls)))
(write-char delimiter port))
(bom2:printlist (cdr ls) port delimiter)))))
; Parses attrib file. Returns a list of read attributes.
(define bom2:parseconfig
(lambda (port)
(let ((read-from-file (read-delimited " \n\t" port)))
(cond ((eof-object? read-from-file)
'())
((= 0 (string-length read-from-file))
(bom2:parseconfig port))
(else
(cons read-from-file (bom2:parseconfig port)))))))
(define bom2:match-list?
(lambda (l1 l2)
(cond
((and (null? l1)(null? l2))#t)
((null? l1) #f)
((null? l2) #f)
((not (string=? (car l1)(car l2)))#f)
(#t (bom2:match-list? (cdr l1)(cdr l2))))))
(define bom2:match?
(lambda (uref attriblist bomlist)
(if (null? bomlist)
(list (cons (list uref) attriblist))
(if (bom2:match-list? attriblist (cdar bomlist))
;; (cons (cons (cons uref (caar bomlist)) (cdar bomlist))(cdr bomlist))
(cons (cons (merge (list uref) (caar bomlist) string<? ) (cdar bomlist))(cdr bomlist))
(cons (car bomlist)(bom2:match? uref attriblist (cdr bomlist)))))))
(define bom2:components
(lambda (ls attriblist)
(if (null? ls)
'()
(let ((package (car ls))
(bomlist (bom2:components (cdr ls) attriblist))
(attribs (bom2:find-attribs (car ls) attriblist)))
(if (not (string=? "unknown" (gnetlist:get-package-attribute package "nobom")))
bomlist
(bom2:match? package attribs bomlist))))))
(define bom2:find-attribs
(lambda (package attriblist)
(if (null? attriblist)
'()
(cons (gnetlist:get-package-attribute package (car attriblist))
(bom2:find-attribs package (cdr attriblist))))))
;;
;; Bill of Material backend written by Matt Ettus ends here
;;
;; --------------------------------------------------------------------------
;;; $Id: gnet-bom.scm,v 1.9 2005/02/03 12:49:36 danmc Exp $
;;;
;;; gEDA - GNU Electronic Design Automation
;;; gnetlist - GNU Netlist
;;; Copyright (C) 1998-2001 Ales V. Hvezda
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;; --------------------------------------------------------------------------
;;
;; Bill of Material backend written by Matt Ettus starts here
;;
;;; Bill Of Materials Generator
;;; You must have a file called attribs in the pwd
;;; The file should be a text list of attributes you want listed,
;;; One per line. No comments are allowed in the file.
;;; Questions? Contact matt@xxxxxxxxx
;;; This software is released under the terms of the GNU GPL
(define bom
(lambda (output-filename)
(let ((port (if (string=? "-" output-filename)
(current-output-port)
(open-output-file output-filename)))
(attriblist (bom:parseconfig (open-input-file "attribs"))))
(bom:printlist (cons 'package attriblist) port)
(bom:components port packages attriblist)
(close-output-port port))))
(define bom:printlist
(lambda (ls port)
(if (null? ls)
(newline port)
(begin
(display (car ls) port)
(write-char #\tab port)
(bom:printlist (cdr ls) port)))))
; Parses attrib file. Returns a list of read attributes.
(define bom:parseconfig
(lambda (port)
(let ((read-from-file (read-delimited " \n\t" port)))
(cond ((eof-object? read-from-file)
'())
((= 0 (string-length read-from-file))
(bom:parseconfig port))
(else
(cons read-from-file (bom:parseconfig port)))))))
(define bom:components
(lambda (port ls attriblist)
(if (not (null? ls))
(let ((package (car ls)))
(if (not (string=? "1" (gnetlist:get-package-attribute package "nobom")))
(begin
(display package port)
(write-char #\tab port)
(bom:printlist (bom:find-attribs package attriblist) port)))
(bom:components port (cdr ls) attriblist)))))
(define bom:find-attribs
(lambda (package attriblist)
(if (null? attriblist)
'()
(cons (gnetlist:get-package-attribute package (car attriblist))
(bom:find-attribs package (cdr attriblist))))))
;;
;; Bill of Material backend written by Matt Ettus ends here
;;
;; --------------------------------------------------------------------------
;;; $Id: gnet-redac.scm,v 1.2 2005/02/03 12:49:36 danmc Exp $
;;;
;;; gEDA - GNU Electronic Design Automation
;;; gnetlist - GNU Netlist
;;; Copyright (C) 1998-2000 Ales V. Hvezda
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;; RACAL-REDAC / Cadstar netlist format by Wojciech Kazubski 2003
;;
;; Display the individual net connections
;;
(define redac:display-connections
(lambda (nets port k)
(if (not (null? nets))
(let ((item (string-append (car (car nets)) " " (car (cdr (car nets))))))
(display item port)
(if (not (null? (cdr nets)))
(begin
(if (> k 0)
(begin
(display " " port)
(redac:display-connections (cdr nets) port (- k 1)))
(begin
(display (string-append "\r\n" item " ") port)
(redac:display-connections (cdr nets) port (+ k 6))))))))))
(define redac:write-net
(lambda (port netnames)
(if (not (null? netnames))
(let ((netname (car netnames)))
(display ".REM " port)
(display netname port)
(display "\r\n" port)
(redac:display-connections
(gnetlist:get-all-connections netname) port 7)
(display "\r\n" port)
(redac:write-net port (cdr netnames))
))))
(define redac
(lambda (filename)
(let ((port (if (string=? "-" output-filename)
(current-output-port)
(open-output-file output-filename))))
(display ".PCB\r\n" port)
(display ".REM CREATED BY gEDA GNETLIST\r\n" port)
(display ".CON\r\n" port)
(display ".COD 2\r\n\r\n" port)
(redac:write-net port (gnetlist:get-all-unique-nets "dummy"))
(display ".EOD\r\n" port)
(close-output-port port))))