1 /*$Id: findbr.cc,v 1.2 2009-12-13 17:55:01 felix Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
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 3, or (at your option)
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., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
22 * find a branch with matching label
23 * returns the branch pointer
25 //testing=script,sparse 2006.07.17
28 #include "e_cardlist.h"
31 /*--------------------------------------------------------------------------*/
32 /* findbranch: find a matching label, by (ugh) linear search
33 * label to look for is in command line (cmd).
34 * start "here". Look only after "here".
35 * return pointer to next match if exists (and eat input)
36 * pointer to a non-existent branch if no match (don't eat input)
37 * caution: caller must check return value before using
39 CARD_LIST::fat_iterator
findbranch(CS
& cmd
, CARD_LIST::fat_iterator here
)
41 unsigned save
= cmd
.cursor();
43 char labelwanted
[BUFLEN
+1];
44 cmd
.ctostr(labelwanted
, BUFLEN
, TOKENTERM
);
46 if (!labelwanted
[0]) { // nothing to look for
52 char* local_part
; // part before last dot, the thing inside
53 char* last_part
; // part after last dot, top level
55 char* dot
= strrchr(labelwanted
,'.');
56 if (dot
) {itested(); // split the string into 2 parts at the last dot
57 *dot
= '\0'; // before is the new "local_part", shortened
58 last_part
= dot
+ 1; // after is the "last_part".
59 local_part
= labelwanted
;
61 last_part
= labelwanted
;
68 // at the end of the list - done, fails.
71 }else if (wmatch((**here
).short_label(), last_part
)) {
74 // requested a simple name, found it .. done.
77 // there are dots, so look inside subckt
79 if ((**here
).subckt()) {untested();
81 // has a subckt, and its name matches, doing fine
82 CS
want(CS::_STRING
, local_part
); // recursion
83 CARD_LIST::fat_iterator subbrh
=findbranch(want
,(**here
).subckt());
84 if (!subbrh
.is_end()) {untested();
85 // found it in a subckt
88 // didn't find anything in this subckt
89 // keep looking for another with the same name
95 // keep looking for something with this name that has a subckt
102 // label doesn't match
103 // keep looking for one that does. (linear search)
108 /*--------------------------------------------------------------------------*/
109 /*--------------------------------------------------------------------------*/
110 // vim:ts=8:sw=2:noet: