1 ; Copyright (C) 2001-2010 MIYAMOTO Takanori
2 ; gnet-partslist-csv.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-from-path "gnet-partslist-common.scm")
21 (define partslist-csv:write-top-header
23 (display "device,value,footprint,vendor,vendor_part_number,quantity,refdes\n" port)))
25 (define (partslist-csv:write-partslist ls port)
28 (begin (write-one-row (cdar ls) "," "," port)
29 (write-one-row (caar ls) " " "\n" port)
30 (partslist-csv:write-partslist (cdr ls) port))))
32 (define (count-same-parts ls)
35 (let* ((parts-table-no-uref (let ((result '()))
36 (for-each (lambda (l) (set! result (cons (cdr l) result))) (reverse ls))
38 (first-ls (car parts-table-no-uref))
39 (match-length (length (member first-ls (reverse parts-table-no-uref))))
40 (rest-ls (list-tail ls match-length))
41 (match-ls (list-tail (reverse ls) (- (length ls) match-length)))
42 (uref-ls (let ((result '()))
43 (for-each (lambda (l) (set! result (cons (car l) result))) match-ls)
45 (cons (cons uref-ls (append first-ls (list match-length))) (count-same-parts rest-ls)))))
49 (gnetlist:get-package-attribute package "vendor")))
51 (define get-vendor-part-number
53 (gnetlist:get-package-attribute package "vendor_part_number")))
57 (gnetlist:get-package-attribute package "footprint")))
59 (define get-loadstatus
61 (gnetlist:get-package-attribute package "loadstatus")))
63 (define (get-parts-table-csv packages)
66 (let ((package (car packages)))
67 (if (string=? (get-device package) "include")
68 (get-parts-table-csv (cdr packages))
69 (if (string=? (get-loadstatus package) "smt")
73 (get-footprint package)
75 (get-vendor-part-number package)) ;; sdb change
76 (get-parts-table-csv (cdr packages)))
77 (get-parts-table-csv (cdr packages)))))))
80 (lambda (output-filename)
81 (let ((port (open-output-file output-filename))
82 (parts-table (marge-sort-with-multikey (get-parts-table-csv packages) '(1 2 3 0))))
83 (set! parts-table (count-same-parts parts-table))
84 (partslist-csv:write-top-header port)
85 (partslist-csv:write-partslist parts-table port)
86 (close-output-port port))))