1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 1998-2010 Ales Hvezda
4 ;;; Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
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.
21 ;; --------------------------------------------------------------------------
23 ;; Bill of Material backend written by Matt Ettus starts here
26 ;;; Bill Of Materials Generator
27 ;;; You must have a file called attribs in the pwd
28 ;;; The file should be a text list of attributes you want listed,
29 ;;; One per line. No comments are allowed in the file.
30 ;;; Questions? Contact matt@ettus.com
31 ;;; This software is released under the terms of the GNU GPL
33 (use-modules (ice-9 rdelim)) ;; guile-1.8 fix
36 (lambda (output-filename)
37 (let ((port (if (string=? "-" output-filename)
39 (open-output-file output-filename)))
40 (attriblist (bom2:parseconfig (open-input-file "attribs"))))
41 (bom2:printlist (append (cons 'refdes attriblist) (list "qty")) port #\:)
43 (bom2:printbom port (bom2:components packages attriblist) 0)
44 (close-output-port port))))
47 (lambda (port bomlist count)
48 (if (not (null? bomlist))
49 (if (not (null? (caar bomlist)))
51 (display (caaar bomlist) port)
52 (if (not (null? (cdaar bomlist)))
53 (write-char #\, port))
54 (bom2:printbom port (cons (cons (cdaar bomlist)(cdar bomlist))(cdr bomlist)) (+ count 1))
58 (bom2:printlist (cdar bomlist) port #\:)
62 (bom2:printbom port (cdr bomlist) 0)
65 (define bom2:printlist
66 (lambda (ls port delimiter)
70 (display (car ls) port)
71 (if (not (null? (cdr ls)))
72 (write-char delimiter port))
73 (bom2:printlist (cdr ls) port delimiter)))))
75 ; Parses attrib file. Returns a list of read attributes.
76 (define bom2:parseconfig
78 (let ((read-from-file (read-delimited " \n\t" port)))
79 (cond ((eof-object? read-from-file)
81 ((= 0 (string-length read-from-file))
82 (bom2:parseconfig port))
84 (cons read-from-file (bom2:parseconfig port)))))))
86 (define bom2:match-list?
89 ((and (null? l1)(null? l2))#t)
92 ((not (string=? (car l1)(car l2)))#f)
93 (#t (bom2:match-list? (cdr l1)(cdr l2))))))
96 (lambda (uref attriblist bomlist)
98 (list (cons (list uref) attriblist))
99 (if (bom2:match-list? attriblist (cdar bomlist))
100 ;; (cons (cons (cons uref (caar bomlist)) (cdar bomlist))(cdr bomlist))
101 (cons (cons (merge (list uref) (caar bomlist) string<? ) (cdar bomlist))(cdr bomlist))
102 (cons (car bomlist)(bom2:match? uref attriblist (cdr bomlist)))))))
104 (define (bom2:in-bom? package)
106 (gnetlist:get-package-attribute package "nobom")))
108 (define (bom2:components-impl ls attriblist bomlist)
111 (let* ((package (car ls))
112 (attribs (bom2:find-attribs package attriblist)))
113 (bom2:components-impl (cdr ls) attriblist
114 (if (bom2:in-bom? package)
115 (bom2:match? package attribs bomlist)
118 (define (bom2:components ls attriblist)
119 (bom2:components-impl ls attriblist '()))
121 (define bom2:find-attribs
122 (lambda (package attriblist)
123 (if (null? attriblist)
125 (cons (gnetlist:get-package-attribute package (car attriblist))
126 (bom2:find-attribs package (cdr attriblist))))))
129 ;; Bill of Material backend written by Matt Ettus ends here
131 ;; --------------------------------------------------------------------------