📄 comp.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include "component.h"
#include "ansidecl.h"
#include "hash.h"
static struct hash_control *class_tbl;
static struct hash_control *comp_tbl;
extern compclass_t resistor,capacitor,inductor;
static comp_t *alloc_comp (compclass_t *class,char *label )
{
struct compinfo *comp;
comp = (comp_t *) malloc (sizeof (comp_t) + class->extra_bytes + strlen (label)+1);
if (comp) {
comp->label = (char *)(comp+1)+class->extra_bytes;
strcpy ( comp->label, label);
comp->pins_start = pins_alloc (class->n_pins);
comp->vars_start = vars_alloc (class->n_curs);
comp->class = class;
}
return comp;
}
comp_t *new_component_by_name (char *class, char *label, void *value )
{
compclass_t *cls;
cls = hash_find (class_tbl, class );
if (!cls) return NULL;
return new_component (cls, label, value);
}
comp_t *new_component (compclass_t *cls, char *label, void *value )
{
comp_t *comp;
comp = alloc_comp (cls,label);
if (comp) {
cls->init (comp, value);
hash_insert (comp_tbl,comp->label,comp );
}
return comp;
}
comp_t *new_basic_component (comptype_t type, char *label, VA_value_t value )
{
comp_t *comp;
switch (type) {
case COMP_RES:
comp = alloc_comp (&resistor,label);
if (comp) resistor.init (comp,&value);
break;
case COMP_CAP:
comp = alloc_comp (&capacitor,label);
if (comp) capacitor.init (comp,&value);
break;
case COMP_IND:
comp = alloc_comp (&inductor,label);
if (comp) inductor.init (comp,&value);
break;
default:
comp = NULL;
}
if (comp)
hash_insert (comp_tbl,comp->label,comp );
return comp;
}
comp_t *get_component (char *label)
{
return hash_find (comp_tbl, label );
}
compclass_t *get_class (char *name)
{
return hash_find (class_tbl, name );
}
int add_class (compclass_t *class)
{
hash_insert (class_tbl,class->name, class);
}
comp_init()
{
class_tbl = hash_new();
comp_tbl = hash_new();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -