comparison netdiff/match/rdpass.c @ 140:d3eb3790386d

netdiff: donl-netmatch put together
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 04:57:37 +0000
parents
children
comparison
equal deleted inserted replaced
139:bf188727e606 140:d3eb3790386d
1 #include <ctype.h>
2 #include <string.h>
3 #include <strings.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "struct.h"
7
8 extern char *infnames[2];
9 extern struct pin_info *database;
10
11 #define MAX_FIELDS 2
12
13 static int pass;
14 static FILE *inf;
15 static char linebuf[512];
16 static int lineno;
17 static char *fields[MAX_FIELDS];
18 static unsigned nfields;
19
20 static void
21 parse_into_fields()
22 {
23 char *cp;
24
25 nfields = 0;
26 for (cp = linebuf; ; ) {
27 while (isspace(*cp))
28 cp++;
29 if (*cp == '\0' || *cp == '#')
30 break;
31 if (nfields >= MAX_FIELDS) {
32 fprintf(stderr, "%s line %d: too many fields\n",
33 infnames[pass], lineno);
34 exit(1);
35 }
36 fields[nfields++] = cp;
37 while (*cp && !isspace(*cp))
38 cp++;
39 if (*cp)
40 *cp++ = '\0';
41 }
42 }
43
44 static void
45 existing_pin(p, netname)
46 struct pin_info *p;
47 char *netname;
48 {
49 char *dp;
50
51 if (p->netnames[pass]) {
52 fprintf(stderr, "%s line %d: multiple nets to pin %s\n",
53 infnames[pass], lineno, p->pin_name);
54 exit(1);
55 }
56 dp = malloc(strlen(netname) + 1);
57 if (!dp) {
58 perror("malloc");
59 exit(1);
60 }
61 strcpy(dp, netname);
62 p->netnames[pass] = dp;
63 }
64
65 static void
66 process_connect(netname, pinname)
67 char *netname, *pinname;
68 {
69 struct pin_info *p, **pp;
70 char *dp;
71
72 for (pp = &database; p = *pp; pp = &p->next) {
73 if (!strcmp(p->pin_name, pinname)) {
74 existing_pin(p, netname);
75 return;
76 }
77 }
78 p = malloc(sizeof(struct pin_info) + strlen(netname) + strlen(pinname)
79 + 2);
80 if (!p) {
81 perror("malloc");
82 exit(1);
83 }
84 bzero(p, sizeof(struct pin_info));
85 dp = (char *)(p + 1);
86 p->pin_name = dp;
87 strcpy(dp, pinname);
88 dp += strlen(pinname) + 1;
89 p->netnames[pass] = dp;
90 strcpy(dp, netname);
91 *pp = p;
92 }
93
94 static void
95 process_line()
96 {
97 parse_into_fields();
98 if (!nfields)
99 return;
100 if (nfields != 2) {
101 fprintf(stderr, "%s line %d: expected 2 fields\n",
102 infnames[pass], lineno);
103 exit(1);
104 }
105 process_connect(fields[0], fields[1]);
106 }
107
108 read_pass(pass_no)
109 {
110 pass = pass_no;
111 inf = fopen(infnames[pass], "r");
112 if (!inf) {
113 perror(infnames[pass]);
114 exit(1);
115 }
116 lineno = 0;
117 while (fgets(linebuf, sizeof linebuf, inf)) {
118 lineno++;
119 process_line();
120 }
121 fclose(inf);
122 return 0;
123 }