pin.c

来自「circuit calculation program」· C语言 代码 · 共 85 行

C
85
字号
#include <string.h>
#include "types.h"
#include "component.h"
#include "graph.h"

static int n_pins;  

pin_t *pins;
char *pin_flag;

int pins_alloc (int count)
{
	int i = n_pins;
	
	n_pins += count;
	
	if (n_pins < 0) { /* roll back when overflow */
		error( __FILE__,__LINE__,ETOO_MANYPINS);
		
		return -1;
	}
	return i;
}


int pin_map_str_str (char *string, char *id)
{
	comp_t *p = get_component (string);
	int pin_gid;
	
	if (!p ) return -2;
	pin_gid = CLASS(p)->str_to_pin_gid ?
		  CLASS(p)->str_to_pin_gid (p, id) : -1;
		  
	if (pin_gid>0) 
		pins[ pin_gid ].comp = p;
		
	return pin_gid;
}
int pin_map_str_pin (char *string, int id)
{
	comp_t *p = get_component (string);
	int pin_gid;
	
	if (!p ) return -2;
	
	id --;  /* in netlist, pin starts with 1*/
	pin_gid = CLASS(p)->pin_to_pin_gid ?
		  CLASS(p)->pin_to_pin_gid (p, id) : -1;	
		  
	if (pin_gid>=0) 
		pins[ pin_gid ].comp = p;
		
	return pin_gid;
}


int pin_init()
{
	pin_flag = (char *) malloc (n_pins);
	if (pin_flag) 
		memset (pin_flag, 0, n_pins);
	
	pins = (pin_t *) malloc (n_pins * sizeof (pin_t));
	if (pins) 
		memset (pins, 0,(n_pins * sizeof (pin_t)));
	return !!pin_flag;
}	


int dump_pins()
{
	int i;
	for (i = 0; i < n_pins; i++ ) {
		printf ("<%d> ",i);
//		assert(pins[ i ].comp);
		
		
		printf ("%s ",(pins[ i ].comp)? pins[ i ].comp->label : "<NULL>");
		printf ("%d\n",pins[ i ].node_id);
		
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?