FreeCalypso > hg > ueda-linux
annotate ueda/unet-utils/unet2pads.c @ 135:25634b3977a9
ueda: unet2tedax added
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 07 Sep 2020 01:22:36 +0000 |
parents | a0d227fc9569 |
children |
rev | line source |
---|---|
33
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <stdio.h> |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <stdlib.h> |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include <string.h> |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include <strings.h> |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <unistd.h> |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include "../libunet/unetrd.h" |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include "../libunet/nethash.h" |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 extern struct net *enter_net_object(); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 extern struct net *find_net_by_name(); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 extern struct net *net_list_head; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 static char *input_filename, *output_filename; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 static struct unetrd_state rdstate; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 static struct unetrd_out rdout; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 static FILE *tempFILE, *outFILE; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 static int no_parttype_errors; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 struct netextra { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 struct netmember *head; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 struct netmember **tailp; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 }; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 struct netmember { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 char *name; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 struct netmember *next; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 }; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 static FILE * |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 tempfile() |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 char template[16]; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 register int fd; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 register FILE *f; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 strcpy(template, "/tmp/uedaXXXXXX"); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 fd = mkstemp(template); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 if (fd < 0) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 perror("mkstemp"); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 unlink(template); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 f = fdopen(fd, "r+w"); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 if (!f) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 perror("fdopen"); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 return(f); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 static void |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 dump_tempfile() |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 register FILE *inf = tempFILE; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 register FILE *outf = outFILE; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 register int c; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 rewind(inf); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 while ((c = getc(inf)) != EOF) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 putc(c, outf); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 fclose(inf); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 static void |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 process_pin_connect(compname) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 char *compname; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 register struct net *n; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 register struct netextra *nx; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 register struct netmember *nm; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 n = find_net_by_name(rdout.connect_to_net); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 nx = (struct netextra *)(n + 1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 nm = (struct netmember *) malloc(sizeof(struct netmember) + |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 strlen(compname) + |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 strlen(rdout.objname) + 2); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 if (!nm) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 perror("malloc"); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 nm->name = (char *)(nm + 1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 sprintf(nm->name, "%s.%s", compname, rdout.objname); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 nm->next = 0; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 *nx->tailp = nm; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 nx->tailp = &nm->next; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 static void |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 process_component() |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 char compname[64]; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 int parttype_seen = 0; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 strcpy(compname, rdout.objname); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 for (;;) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 if (!read_unet_line(&rdstate, &rdout)) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 fprintf(stderr, "%s error: EOF in COMPONENT block\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 input_filename); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 if (rdout.typecode == UNETOBJ_CLOSINGBRACE) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 break; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 switch(rdout.typecode) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 case UNETOBJ_PRIMITIVE: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 case UNETOBJ_ALTNAME: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 continue; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 case UNETOBJ_ATTR: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 if (strcmp(rdout.objname, "pads_parttype")) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 continue; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 if (parttype_seen) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 fprintf(stderr, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 "%s lind %d: duplicate ATTR pads_parttype for COMPONENT %s\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 input_filename, rdstate.lineno, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 compname); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 fprintf(tempFILE, "%s %s\n", compname, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 rdout.attr_value); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 parttype_seen = 1; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 continue; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 case UNETOBJ_PIN: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 if (rdout.connect_to_net) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 process_pin_connect(compname); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 continue; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 case UNETOBJ_PINMAP: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 fprintf(stderr, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 "%s line %d: PINMAP objects not expected in unet2pads input\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 input_filename, rdstate.lineno); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 default: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 fprintf(stderr, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 "%s line %d: object type %s unexpected in COMPONENT block\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 input_filename, rdstate.lineno, rdout.keyword); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 if (!parttype_seen) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 fprintf(stderr, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 "error: component %s has no pads_parttype set\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 compname); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 no_parttype_errors++; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 static void |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 process_input_unet() |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 struct net *n; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 struct netextra *nx; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 open_unet_input_file(input_filename, &rdstate); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 while (read_unet_line(&rdstate, &rdout)) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 switch(rdout.typecode) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 case UNETOBJ_CLOSINGBRACE: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 fprintf(stderr, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 "%s line %d: unexpected '}' outside of component block\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 input_filename, rdstate.lineno); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 case UNETOBJ_NET: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 n = enter_net_object(rdout.objname, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 sizeof(struct netextra)); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 nx = (struct netextra *)(n + 1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 nx->head = 0; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 nx->tailp = &nx->head; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 continue; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 case UNETOBJ_COMPONENT: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 if (!tempFILE) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 tempFILE = tempfile(); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 process_component(); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 continue; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 case UNETOBJ_STARPOINT: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 fprintf(stderr, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 "error: STARPOINT objects not expected in unet2pads input (%s line %d)\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
174 input_filename, rdstate.lineno); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
175 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 default: |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 fprintf(stderr, |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 "%s line %d: unexpected object type %s\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 input_filename, rdstate.lineno, rdout.keyword); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 if (!tempFILE) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 fprintf(stderr, "error: no components found in %s input!\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 input_filename); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 static void |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 output_nets() |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 struct net *n; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 struct netextra *nx; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 register struct netmember *nm; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 int linelen; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
198 fputs("*NET*\n", outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 for (n = net_list_head; n; n = n->nextinlist) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 nx = (struct netextra *)(n + 1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 fprintf(outFILE, "*SIG* %s\n", n->name); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 linelen = 0; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 for (nm = nx->head; nm; nm = nm->next) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
204 if (linelen && linelen + strlen(nm->name) + 1 > 79) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
205 putc('\n', outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
206 linelen = 0; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 if (linelen) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 putc(' ', outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 linelen++; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 fputs(nm->name, outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 linelen += strlen(nm->name); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
215 if (linelen) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
216 putc('\n', outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
217 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
218 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
219 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
220 static void |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
221 generate_output() |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
222 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
223 if (output_filename) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
224 outFILE = fopen(output_filename, "w"); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
225 if (!outFILE) { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
226 perror(output_filename); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
227 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
228 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
229 } else |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
230 outFILE = stdout; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
231 fputs("!PADS-POWERPCB-V3.0-MILS! DESIGN DATABASE ASCII FILE 2.0\n\n", |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
232 outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
233 fputs("*PART* ITEMS\n", outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
234 dump_tempfile(); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
235 putc('\n', outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
236 output_nets(); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
237 fputs("\n*END* OF ASCII OUTPUT FILE\n", outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
238 if (outFILE != stdout) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
239 fclose(outFILE); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
240 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
241 |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
242 main(argc, argv) |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
243 char **argv; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
244 { |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
245 if (argc < 2 || argc > 3) { |
36
a0d227fc9569
unet2pads: minor fix in the usage message
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
34
diff
changeset
|
246 fprintf(stderr, "usage: %s input.unet [output-file]\n", |
33
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
247 argv[0]); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
248 exit(1); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
249 } |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
250 input_filename = argv[1]; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
251 output_filename = argv[2]; |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
252 process_input_unet(); |
34
bc465afed423
unet2pads: exit with an error if the pads_parttype is missing on any component
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
33
diff
changeset
|
253 if (no_parttype_errors) |
bc465afed423
unet2pads: exit with an error if the pads_parttype is missing on any component
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
33
diff
changeset
|
254 exit(1); |
33
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
255 generate_output(); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
256 exit(0); |
2af4a85daf89
unet2pads program written, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
257 } |