comparison ueda/sverp-bind/starpoints.c @ 16:65a515c20db8

unet-bind: starpoint entry implemented
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sun, 02 Aug 2015 01:12:18 +0000
parents
children
comparison
equal deleted inserted replaced
15:c59f52e4bacf 16:65a515c20db8
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <strings.h>
5 #include "struct.h"
6
7 extern struct instance *enter_instance();
8
9 extern char *starpoints_file;
10
11 struct outcomp *starpoint_list_head;
12 static struct outcomp **global_tailp = &starpoint_list_head;
13
14 process_starpoints_file()
15 {
16 FILE *stream;
17 char linebuf[256];
18 int lineno;
19 register char *cp;
20 char *instname, *numstr;
21 int npins;
22 register struct instance *inst;
23 register struct outcomp *oc;
24
25 stream = fopen(starpoints_file, "r");
26 if (!stream) {
27 perror(starpoints_file);
28 exit(1);
29 }
30 for (lineno = 1; fgets(linebuf, sizeof linebuf, stream); lineno++) {
31 cp = index(linebuf, '\n');
32 if (!cp) {
33 fprintf(stderr,
34 "error: %s line %d is too long or unterminated\n",
35 starpoints_file, lineno);
36 exit(1);
37 }
38 *cp = '\0';
39 for (cp = linebuf; isspace(*cp); cp++)
40 ;
41 if (*cp == '\0' || *cp == '#')
42 continue;
43 instname = cp;
44 while (*cp && !isspace(*cp))
45 cp++;
46 if (*cp)
47 *cp++ = '\0';
48 while (isspace(*cp))
49 cp++;
50 if (*cp == '\0' || *cp == '#') {
51 npins_error: fprintf(stderr,
52 "error in %s line %d: expected number of pins after the instance name\n",
53 starpoints_file, lineno);
54 exit(1);
55 }
56 numstr = cp;
57 while (*cp && !isspace(*cp))
58 cp++;
59 if (*cp)
60 *cp++ = '\0';
61 if (!string_is_valid_decnum(numstr))
62 goto npins_error;
63 npins = atoi(numstr);
64 if (npins < 2) {
65 fprintf(stderr,
66 "error in %s line %d: a starpoint must have 2 or more pins\n",
67 starpoints_file, lineno);
68 exit(1);
69 }
70 inst = enter_instance(instname);
71 oc = (struct outcomp *)
72 malloc(sizeof(struct outcomp) +
73 sizeof(struct pinconn *) * npins);
74 if (!oc) {
75 perror("malloc");
76 exit(1);
77 }
78 bzero(oc, sizeof(struct outcomp) +
79 sizeof(struct pinconn *) * npins);
80 oc->name = inst->name;
81 oc->npins = npins;
82 oc->conn_array = (struct pinconn **)(oc + 1);
83 inst->outcomp = oc;
84 *global_tailp = oc;
85 global_tailp = &oc->next;
86 }
87 fclose(stream);
88 }