1 
2 #ifndef lint
3 static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/resis/ResChecks.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
4 #endif  /* not lint */
5 
6 #include <stdio.h>
7 #include <string.h>
8 #include <ctype.h>
9 #include <math.h>
10 
11 #include "utils/magic.h"
12 #include "utils/geometry.h"
13 #include "utils/geofast.h"
14 #include "tiles/tile.h"
15 #include "utils/hash.h"
16 #include "database/database.h"
17 #include "utils/malloc.h"
18 #include "textio/textio.h"
19 #include "extract/extract.h"
20 #include "extract/extractInt.h"
21 #include "windows/windows.h"
22 #include "dbwind/dbwind.h"
23 #include "utils/utils.h"
24 #include "utils/tech.h"
25 #include "textio/txcommands.h"
26 #include "utils/stack.h"
27 #include "resis/resis.h"
28 
29 #ifdef PARANOID
30 
31 /*
32  *-------------------------------------------------------------------------
33  *
34  * ResSanityChecks -- Checks that resistor and node lists are consistant.
35  *	Make sure that all resistors are connected, and that each node
36  *	to which a resistor is connected has the correct pointer in its list.
37  *
38  * Results: none
39  *
40  * Side Effects: prints out error messages if it finds something bogus.
41  *
42  *-------------------------------------------------------------------------
43  */
44 
45 void
ResSanityChecks(nodename,resistorList,nodeList,devlist)46 ResSanityChecks(nodename, resistorList, nodeList, devlist)
47     char	*nodename;
48     resResistor	*resistorList;
49     resNode	*nodeList;
50     resDevice	*devlist;
51 
52 {
53     resResistor	*resistor;
54     resNode	*node;
55     resDevice	*dev;
56     resElement	*rcell;
57     static	Stack	*resSanityStack = NULL;
58     int		reached, foundorigin;
59 
60     if (resSanityStack == NULL)
61     {
62      	resSanityStack = StackNew(64);
63     }
64     for (node = nodeList; node != NULL; node=node->rn_more)
65     {
66      	node->rn_status &= ~RES_REACHED_NODE;
67 	if (node->rn_why == RES_NODE_ORIGIN)
68 	  		STACKPUSH((ClientData) node, resSanityStack);
69     }
70     for (resistor = resistorList; resistor != NULL; resistor = resistor->rr_nextResistor)
71     {
72     	resistor->rr_status &= ~RES_REACHED_RESISTOR;
73     }
74 
75     /* Check:  Are the resistors and nodes all connected? */
76     while (!StackEmpty(resSanityStack))
77     {
78      	node = (resNode *)STACKPOP(resSanityStack);
79 	if (node->rn_status & RES_REACHED_NODE) continue;
80 	node->rn_status |= RES_REACHED_NODE;
81 	for (rcell = node->rn_re; rcell != NULL; rcell = rcell->re_nextEl)
82 	{
83 	    resistor = rcell->re_thisEl;
84 	    if (resistor->rr_status & RES_REACHED_RESISTOR) continue;
85 	    resistor->rr_status |= RES_REACHED_RESISTOR;
86 	    if (resistor->rr_connection1 != node &&
87 	           resistor->rr_connection2 != node)
88 	    {
89 		TxError("Stray resElement pointer- node %s, pointer %d\n",
90 			    nodename, rcell);
91 		continue;
92 	    }
93 	    if ((resistor->rr_connection1->rn_status & RES_REACHED_NODE) == 0)
94 	    {
95 	       	STACKPUSH((ClientData)resistor->rr_connection1, resSanityStack);
96 	    }
97 	    if ((resistor->rr_connection2->rn_status & RES_REACHED_NODE) == 0)
98 	    {
99 	       	STACKPUSH((ClientData)resistor->rr_connection2, resSanityStack);
100 	    }
101 	}
102     }
103     for (resistor = resistorList; resistor != NULL; resistor = resistor->rr_nextResistor)
104     {
105      	if ((resistor->rr_status & RES_REACHED_RESISTOR) == 0)
106 	{
107 	    TxError("Unreached resistor in %s\n", nodename);
108 	}
109 	resistor->rr_status &= ~RES_REACHED_RESISTOR;
110      }
111      for (dev = devlist; dev != NULL; dev = dev->rd_nextDev)
112      {
113      	int i;
114 
115 	if (dev->rd_status & RES_DEV_PLUG) continue;
116 	reached = FALSE;
117 	for (i = 0; i != dev->rd_nterms; i++)
118 	{
119 	    if (dev->rd_terminals[i] != NULL)
120 	    {
121 	        reached = TRUE;
122 	        if ((dev->rd_terminals[i]->rn_status & RES_REACHED_NODE) == 0)
123 	        {
124 	       	    TxError("Device node %d unreached in %s\n", i, nodename);
125 	        }
126 	    }
127 	}
128 	if (reached == 0)
129 	{
130 	     TxError("Unreached device in %s at %d %d\n",
131 				nodename,
132 	       			dev->rd_inside.r_xbot,
133 	       			dev->rd_inside.r_ybot);
134 	}
135     }
136     foundorigin = 0;
137     for (node = nodeList; node != NULL; node=node->rn_more)
138     {
139      	if ((node->rn_status & RES_REACHED_NODE) == 0)
140 	{
141 	    TxError("Unreached node in %s at %d, %d\n", nodename,
142 			node->rn_loc.p_x, node->rn_loc.p_y);
143 	}
144 	node->rn_status &= ~RES_REACHED_NODE;
145 	if (node->rn_why & RES_NODE_ORIGIN)
146 	{
147 	    foundorigin = 1;
148 	}
149     }
150     if (foundorigin == 0)
151     {
152 	TxError("Starting node not found in %s\n", nodename);
153     }
154 }
155 #endif
156