1 ; Copyright (C) 2001-2010 MIYAMOTO Takanori
2 ; gnet-partslist-keithp.scm
4 ; This program is free software; you can redistribute it and/or modify
5 ; it under the terms of the GNU General Public License as published by
6 ; the Free Software Foundation; either version 2 of the License, or
7 ; (at your option) any later version.
9 ; This program is distributed in the hope that it will be useful,
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ; GNU General Public License for more details.
14 ; You should have received a copy of the GNU General Public License
15 ; along with this program; if not, write to the Free Software
16 ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 ; The /'s may not work on win32
19 (load (string-append gedadata "/scheme/gnet-partslist-common.scm"))
21 (define partslist-keithp:write-top-header
23 (display ".START\n" port)
24 (display "..device\tvalue\tfootprint\t\tvendor\tvendor_part_number\tquantity\trefdes\n" port)))
26 (define (partslist-keithp:write-partslist ls port)
29 (begin (write-one-row (cdar ls) "\t" "\t" port)
30 (write-one-row (caar ls) " " "\n" port)
31 (partslist-keithp:write-partslist (cdr ls) port))))
33 (define partslist-keithp:write-bottom-footer
38 (define (count-same-parts ls)
41 (let* ((parts-table-no-uref (let ((result '()))
42 (for-each (lambda (l) (set! result (cons (cdr l) result))) (reverse ls))
44 (first-ls (car parts-table-no-uref))
45 (match-length (length (member first-ls (reverse parts-table-no-uref))))
46 (rest-ls (list-tail ls match-length))
47 (match-ls (list-tail (reverse ls) (- (length ls) match-length)))
48 (uref-ls (let ((result '()))
49 (for-each (lambda (l) (set! result (cons (car l) result))) match-ls)
51 (cons (cons uref-ls (append first-ls (list match-length))) (count-same-parts rest-ls)))))
55 (gnetlist:get-package-attribute package "vendor")))
57 (define get-vendor-part-number
59 (gnetlist:get-package-attribute package "vendor_part_number")))
63 (gnetlist:get-package-attribute package "footprint")))
65 (define (get-parts-table-keithp packages)
68 (let ((package (car packages)))
69 (if (string=? (get-device package) "include")
70 (get-parts-table-keithp (cdr packages))
74 (get-footprint package)
76 (get-vendor-part-number package)) ;; sdb change
77 (get-parts-table-keithp (cdr packages)))))))
79 (define partslist-keithp
80 (lambda (output-filename)
81 (let ((port (open-output-file output-filename))
82 (parts-table (marge-sort-with-multikey (get-parts-table-keithp packages) '(1 2 3 0))))
83 (set! parts-table (count-same-parts parts-table))
84 (partslist-keithp:write-top-header port)
85 (partslist-keithp:write-partslist parts-table port)
86 (close-output-port port))))