FreeCalypso > hg > ueda-linux
comparison ueda/libuschem/graphsym.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 20 Jul 2015 00:24:37 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cd92449fdb51 |
---|---|
1 /* | |
2 * Functions for working with graphical symbols | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <ctype.h> | |
8 #include <strings.h> | |
9 #include "schemstruct.h" | |
10 #include "graphsym.h" | |
11 | |
12 extern char *malloc(); | |
13 extern char *copystr(); | |
14 | |
15 extern FILE *find_symlib_file(); | |
16 extern char sought_libfile_fullpath[]; | |
17 | |
18 #define HASH_SIZE 1103 | |
19 | |
20 static struct graphsym *graphsym_hash[HASH_SIZE]; | |
21 int total_graphsyms; | |
22 | |
23 static int | |
24 hash_graphsym_name(str) | |
25 char *str; | |
26 { | |
27 register u_long accum = 0; | |
28 register char *cp; | |
29 register int c, i; | |
30 | |
31 for (cp = str, i = 1; c = *cp; cp++, i++) | |
32 accum += c * i; | |
33 return(accum % HASH_SIZE); | |
34 } | |
35 | |
36 struct graphsym * | |
37 fetch_graphsym(symname) | |
38 char *symname; | |
39 { | |
40 register struct graphsym *gs, **gsp; | |
41 FILE *f; | |
42 | |
43 for (gsp = graphsym_hash + hash_graphsym_name(symname); gs = *gsp; | |
44 gsp = &gs->gs_nextinhash) | |
45 if (!strcmp(gs->gs_name, symname)) | |
46 return(gs); | |
47 | |
48 gs = (struct graphsym *) malloc(sizeof(struct graphsym)); | |
49 bzero(gs, sizeof(struct graphsym)); | |
50 gs->gs_name = symname; | |
51 f = find_symlib_file(symname, ".sym"); | |
52 if (!f) { | |
53 fprintf(stderr, "Cannot locate graphical symbol \"%s\"\n", | |
54 symname); | |
55 exit(1); | |
56 } | |
57 gs->gs_pathname = copystr(sought_libfile_fullpath); | |
58 read_symbol_file(gs, f); | |
59 fclose(f); | |
60 | |
61 *gsp = gs; | |
62 total_graphsyms++; | |
63 return(gs); | |
64 } | |
65 | |
66 load_graphsyms(schem) | |
67 struct schem *schem; | |
68 { | |
69 register struct schemobj *obj; | |
70 | |
71 for (obj = schem->obj_next; obj != (struct schemobj *)schem; | |
72 obj = obj->obj_next) | |
73 switch (obj->obj_type) { | |
74 case OBJTYPE_COMPINST: | |
75 if (!obj->compobj_isgraph) | |
76 continue; | |
77 /* FALL THRU */ | |
78 case OBJTYPE_GRAPHSYM: | |
79 obj->compobj_graphsym = | |
80 fetch_graphsym(obj->compobj_graph_symname); | |
81 load_decor_graphsyms(obj); | |
82 break; | |
83 } | |
84 } | |
85 | |
86 load_decor_graphsyms(obj) | |
87 struct schemobj *obj; | |
88 { | |
89 register struct decoration *decor; | |
90 | |
91 for (decor = obj->obj_decorations; decor; decor = decor->decor_next) { | |
92 if (decor->decor_type != DECOR_TYPE_SYMONPIN) | |
93 continue; | |
94 decor->decorpinsym_gs = | |
95 fetch_graphsym(decor->decorpinsym_symname); | |
96 } | |
97 } | |
98 | |
99 graphsym_forall(callback) | |
100 int (*callback)(); | |
101 { | |
102 register struct graphsym *gs, **hb; | |
103 register int i; | |
104 | |
105 for (hb = graphsym_hash, i = 0; i < HASH_SIZE; hb++, i++) | |
106 for (gs = *hb; gs; gs = gs->gs_nextinhash) | |
107 callback(gs); | |
108 } | |
109 | |
110 report_graphsym_hash_quality() | |
111 { | |
112 register struct graphsym *gs, **hb; | |
113 register int i, curchain; | |
114 int maxchain = 0; | |
115 | |
116 for (hb = graphsym_hash, i = 0; i < HASH_SIZE; hb++, i++) { | |
117 curchain = 0; | |
118 for (gs = *hb; gs; gs = gs->gs_nextinhash) | |
119 curchain++; | |
120 if (curchain > maxchain) | |
121 maxchain = curchain; | |
122 } | |
123 printf("%d graphsyms total, longest hash chain is %d\n", | |
124 total_graphsyms, maxchain); | |
125 } |