File: tpos.c

package info (click to toggle)
irsim 9.7.75-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,596 kB
  • sloc: ansic: 24,733; sh: 6,803; makefile: 411; csh: 269; tcl: 76
file content (142 lines) | stat: -rw-r--r-- 3,187 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* 
 *     ********************************************************************* 
 *     * Copyright (C) 1988, 1990 Stanford University.                     * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  Stanford University                 * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     ********************************************************************* 
 */

#include <stdio.h>
#include "defs.h"
#include "net.h"
#include "globals.h"

#define	HASHSIZE	1021
#define	HN1		1103515245
#define	HN2		12345


public	int	txt_coords = 0;		/* # of trans. with coordinates */

private tptr	tpostbl[ HASHSIZE ];	/* hash table of trans position */

private	tptr	other_t = NULL;		/* transistors without coords */
private struct Trans  OtherT;


#define	UN( N )		( (Ulong) ( N ) )
#define	HashPos( X, Y )	( UN( UN( X ) * HN1 + UN( Y ) + HN2 ) % HASHSIZE )


public void EnterPos( tran, is_pos )
  tptr  tran;
  int   is_pos;
  {
    long  n;

    if( is_pos )
      {
	n = HashPos( tran->x.pos, tran->y.pos );

	tran->tlink = tpostbl[n];
	tpostbl[n] = tran;
	txt_coords ++;
      }
    else
      {
	if( other_t == NULL )
	    other_t = OtherT.x.ptr = OtherT.y.ptr = &OtherT;
	tran->y.ptr = other_t;
	tran->x.ptr = other_t->x.ptr;
	other_t->x.ptr->y.ptr = tran;
	other_t->y.ptr = tran;
	tran->tlink = tran;
      }
  }


public tptr FindTxtorPos( x, y )
  register long  x, y;
  {
    register tptr  t;
    long           n;

    n = HashPos( x, y );

    for( t = tpostbl[n]; t != NULL; t = t->tlink )
      {
	if( t->x.pos == x and t->y.pos == y )
	    return( t );
      }
    return( NULL );
  }


public void DeleteTxtorPos( tran )
  tptr  tran;
  {
    register tptr  *t;
    long           n;

    n = HashPos( tran->x.pos, tran->y.pos );

    for( t = &(tpostbl[n]); *t != NULL; t = &((*t)->tlink) )
      {
	if( *t == tran )
	  {
	    *t = tran->tlink;
	    tran->tlink = tran;
	    txt_coords --;
	    break;
	  }
      }
  }


public nptr FindNode_TxtorPos( s )
  char  *s;
  {
    long  x, y;
    tptr  t;

    if( sscanf( &s[3], "%ld,%ld", &x, &y ) != 2 )
	return( NULL );

    if( (t = FindTxtorPos( x, y )) == NULL )
	return( NULL );

    switch( s[2] )
      {
	case 'g': return( t->gate );
	case 'd': return( t->drain );
	case 's': return( t->source );
      }
    return( NULL );
  }


public void walk_trans( func, arg )
  void  (*func)();
  char  *arg;
  {
    register int   index;
    register tptr  t;

    for( index = 0; index < HASHSIZE; index++ )
      {
	for( t = tpostbl[ index ]; t != NULL; t = t->tlink )
	    (*func)( t, arg );
      }

    if( other_t != NULL )
      {
	for( t = other_t->x.ptr; t != other_t; t = t->x.ptr )
	    (*func)( t, arg );
      }
  }