1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gschem - gEDA Schematic Capture
3 ;;; Copyright (C) 1998-2010 Ales Hvezda
4 ;;; Copyright (C) 1998-2019 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., 51 Franklin Street, Fifth Floor, Boston,
19 ;;; MA 02111-1301 USA.
21 ; This function resets all the refdes in a list of objects.
23 ; objects: a list of gschem schematic objects
25 (define (auto-refdes-reset! objects)
29 (refdes-name "refdes")
30 (refdes-regex "^([^0-9])+([0-9]+)(.*)$")
31 (refdes-regex-prefix 1)
32 (refdes-regex-suffix 3))
35 ; This function rebuilds the refdes string with the question-mark in place
38 ; If this function can't parse the refdes, it returns the original refdes
39 ; unmodified. This unparsable case includes when the refdes number is
40 ; already a question mark.
42 ; refdes: a string containing the refdes
43 ; return: a string containing the reset refdes
45 (define (rebuild-refdes refdes)
46 (let ((match (string-match refdes-regex refdes)))
49 (string-append (match:substring match refdes-regex-prefix)
51 (match:substring match refdes-regex-suffix))
55 ; This predicate determines if an object represets a refdes and can be
58 ; object: a gschem schematic object
59 ; return: #t if the object represents a refdes attribute that can be reset
61 (define (resetable-refdes? object)
64 (not (attrib-inherited? object))
65 (string=? refdes-name (attrib-name object))))
68 ; This function resets the refdes of the given object
70 ; object: a gschem schematic object representing a refdes attribute
72 (define (reset-refdes! object)
73 (let ((next-refdes (rebuild-refdes (attrib-value object))))
75 (set-attrib-value! object next-refdes)))
78 ; iterate through the list of objects and reset all the refdes attributes
80 (for-each reset-refdes! (filter resetable-refdes? objects))))