annotate ueda/unet-bind/starpoints.c @ 130:c165882efdf1

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