FreeCalypso > hg > ueda-linux
comparison ueda/uschem-netlist/main.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 #include <sys/types.h> | |
2 #include <stdio.h> | |
3 #include <strings.h> | |
4 #include "../libuschem/schemstruct.h" | |
5 | |
6 extern int optind; | |
7 extern char *optarg; | |
8 | |
9 extern char *MCLfile; | |
10 | |
11 extern struct schem *read_schem(); | |
12 | |
13 extern int pcb_netlist_output(); | |
14 extern int pinlist_output(); | |
15 extern int stats_output(); | |
16 | |
17 struct schem *curschem; | |
18 int allow_unnamed_nets, check_completeness, sort_netlist_output; | |
19 int global_errflag; | |
20 char *outfilename; | |
21 FILE *outfile; | |
22 int (*do_output)() = pcb_netlist_output; | |
23 | |
24 main(argc, argv) | |
25 char **argv; | |
26 { | |
27 register int c; | |
28 register struct schem *schem; | |
29 char **avp; | |
30 | |
31 while ((c = getopt(argc, argv, "cI:M:o:O:su")) != EOF) | |
32 switch (c) { | |
33 case 'c': | |
34 check_completeness++; | |
35 break; | |
36 case 'I': | |
37 add_symfile_dir(optarg); | |
38 break; | |
39 case 'M': | |
40 MCLfile = optarg; | |
41 break; | |
42 case 'o': | |
43 outfilename = optarg; | |
44 break; | |
45 case 'O': | |
46 select_output_backend(optarg); | |
47 break; | |
48 case 's': | |
49 sort_netlist_output++; | |
50 break; | |
51 case 'u': | |
52 allow_unnamed_nets++; | |
53 break; | |
54 default: | |
55 usage: fprintf(stderr, "usage: %s [-options] schemfile...\n", | |
56 argv[0]); | |
57 exit(1); | |
58 } | |
59 if (!argv[optind]) | |
60 goto usage; | |
61 | |
62 read_MCL(); | |
63 hash_MCL(); | |
64 set_default_sympath(); | |
65 read_pinouts(); | |
66 alloc_nlcomp_array(); | |
67 | |
68 for (avp = argv + optind; *avp; avp++) { | |
69 schem = read_schem(*avp); | |
70 curschem = schem; | |
71 match_schem_to_mcl(schem); | |
72 if (hash_component_instances(schem) < 0) | |
73 exit(1); | |
74 if (preen_graphnets(schem, 1, 0, 0, 0) < 0) | |
75 exit(1); | |
76 process_schem(); | |
77 } | |
78 if (global_errflag) | |
79 fprintf(stderr, "Errors found; netlist may be incomplete\n"); | |
80 do_output(); | |
81 | |
82 exit(0); | |
83 } | |
84 | |
85 process_schem() | |
86 { | |
87 register struct schemobj *obj; | |
88 int has_netlines = 0; | |
89 | |
90 for (obj = curschem->obj_next; obj != (struct schemobj *)curschem; | |
91 obj = obj->obj_next) | |
92 switch (obj->obj_type) { | |
93 case OBJTYPE_COMPINST: | |
94 check_compinst_pintonet(obj); | |
95 continue; | |
96 case OBJTYPE_NET: | |
97 case OBJTYPE_GRAPHNET: | |
98 process_netobj(obj); | |
99 continue; | |
100 case OBJTYPE_NETLINE: | |
101 if (!has_netlines) { | |
102 fprintf(stderr, | |
103 "%s contains NetLine objects which are not netlistable\n", | |
104 curschem->orig_filename); | |
105 has_netlines++; | |
106 global_errflag++; | |
107 } | |
108 continue; | |
109 } | |
110 } | |
111 | |
112 struct output_backend_spec { | |
113 char *keyword; | |
114 int (*func)(); | |
115 } output_backend_list[] = { | |
116 {"pcb", pcb_netlist_output}, | |
117 {"geda", pcb_netlist_output}, | |
118 {"pinlist", pinlist_output}, | |
119 {"stats", stats_output}, | |
120 {NULL, NULL}}; | |
121 | |
122 select_output_backend(arg) | |
123 char *arg; | |
124 { | |
125 register struct output_backend_spec *tp; | |
126 | |
127 for (tp = output_backend_list; tp->keyword; tp++) | |
128 if (!strcmp(tp->keyword, arg)) | |
129 break; | |
130 if (!tp->func) { | |
131 fprintf(stderr, "%s: unknown or unimplemented output backend\n", | |
132 arg); | |
133 exit(1); | |
134 } | |
135 do_output = tp->func; | |
136 } | |
137 | |
138 open_output_file() | |
139 { | |
140 if (outfilename) { | |
141 outfile = fopen(outfilename, "w"); | |
142 if (!outfile) { | |
143 perror(outfilename); | |
144 exit(1); | |
145 } | |
146 } else | |
147 outfile = stdout; | |
148 } |