3 ;;; gEDA - GNU Electronic Design Automation
4 ;;; gnetlist - GNU Netlist
5 ;;; Copyright (C) 1998-2001 Ales V. Hvezda
7 ;;; This program is free software; you can redistribute it and/or modify
8 ;;; it under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 2 of the License, or
10 ;;; (at your option) any later version.
12 ;;; This program is distributed in the hope that it will be useful,
13 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with this program; if not, write to the Free Software
19 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 ;; --------------------------------------------------------------------------
24 ;; Bill of Material backend written by Matt Ettus starts here
27 ;;; Bill Of Materials Generator
28 ;;; You must have a file called attribs in the pwd
29 ;;; The file should be a text list of attributes you want listed,
30 ;;; One per line. No comments are allowed in the file.
31 ;;; Questions? Contact matt@ettus.com
32 ;;; This software is released under the terms of the GNU GPL
34 (use-modules (ice-9 rdelim)) ;; guile-1.8 fix
37 (lambda (output-filename)
38 (let ((port (if (string=? "-" output-filename)
40 (open-output-file output-filename)))
41 (attriblist (bom2:parseconfig (open-input-file "attribs"))))
42 (bom2:printlist (cons 'refdes attriblist) port #\:)
44 (bom2:printbom port (bom2:components packages attriblist))
45 (close-output-port port))))
48 (lambda (port bomlist)
49 (if (not (null? bomlist))
50 (if (not (null? (caar bomlist)))
52 (display (caaar bomlist) port)
53 (if (not (null? (cdaar bomlist)))
54 (write-char #\, port))
55 (bom2:printbom port (cons (cons (cdaar bomlist)(cdar bomlist))(cdr bomlist))))
58 (bom2:printlist (cdar bomlist) port #\:)
60 (bom2:printbom port (cdr bomlist)))))))
62 (define bom2:printlist
63 (lambda (ls port delimiter)
67 (display (car ls) port)
68 (if (not (null? (cdr ls)))
69 (write-char delimiter port))
70 (bom2:printlist (cdr ls) port delimiter)))))
72 ; Parses attrib file. Returns a list of read attributes.
73 (define bom2:parseconfig
75 (let ((read-from-file (read-delimited " \n\t" port)))
76 (cond ((eof-object? read-from-file)
78 ((= 0 (string-length read-from-file))
79 (bom2:parseconfig port))
81 (cons read-from-file (bom2:parseconfig port)))))))
83 (define bom2:match-list?
86 ((and (null? l1)(null? l2))#t)
89 ((not (string=? (car l1)(car l2)))#f)
90 (#t (bom2:match-list? (cdr l1)(cdr l2))))))
93 (lambda (uref attriblist bomlist)
95 (list (cons (list uref) attriblist))
96 (if (bom2:match-list? attriblist (cdar bomlist))
97 ;; (cons (cons (cons uref (caar bomlist)) (cdar bomlist))(cdr bomlist))
98 (cons (cons (merge (list uref) (caar bomlist) string<? ) (cdar bomlist))(cdr bomlist))
99 (cons (car bomlist)(bom2:match? uref attriblist (cdr bomlist)))))))
101 (define bom2:components
102 (lambda (ls attriblist)
105 (let ((package (car ls))
106 (bomlist (bom2:components (cdr ls) attriblist))
107 (attribs (bom2:find-attribs (car ls) attriblist)))
108 (if (not (string=? "unknown" (gnetlist:get-package-attribute package "nobom")))
110 (bom2:match? package attribs bomlist))))))
112 (define bom2:find-attribs
113 (lambda (package attriblist)
114 (if (null? attriblist)
116 (cons (gnetlist:get-package-attribute package (car attriblist))
117 (bom2:find-attribs package (cdr attriblist))))))
120 ;; Bill of Material backend written by Matt Ettus ends here
122 ;; --------------------------------------------------------------------------