FreeCalypso > hg > fc-small-hw
annotate lunakpd1/placetool/placetool.c @ 18:8d93467a4260
lunakpd1.pcb complete
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 May 2020 08:08:42 +0000 |
parents | 7e564c546dde |
children |
rev | line source |
---|---|
15
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <ctype.h> |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <string.h> |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <strings.h> |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 char *infname; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 FILE *inf; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 int xstart, xstep, ystart, ystep; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 char linebuf[512], parsebuf[512], *fields[11]; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 int lineno; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 parse_element_line() |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int count; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char *cp; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 cp = parsebuf; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 for (count = 0; ; ) { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (!isdigit(*cp) && *cp != '-' && *cp != '\"') { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 inv: fprintf(stderr, "%s line %d: invalid Element line\n", |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 infname, lineno); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 exit(1); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (count >= 11) |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 goto inv; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fields[count++] = cp; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 while (*cp && *cp != ' ' && *cp != ']') |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 cp++; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (!*cp) |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 goto inv; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (*cp == ']') { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 *cp++ = '\0'; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 break; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 *cp++ = '\0'; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (count != 11 || *cp != '\n') |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 goto inv; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 emit_new_element_line() |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 int row, col; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 row = fields[2][2] - '0'; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 col = fields[2][3] - '0'; |
16
7e564c546dde
lunakpd1: beginning of sensible layout
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
48 printf("Element[%s %s %s %s %dmm %dmm %s %s %s %s %s]\n", |
15
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fields[0], fields[1], fields[2], fields[3], |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 xstart + col * xstep, ystart + row * ystep, |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fields[6], fields[7], fields[8], fields[9], fields[10]); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 main(argc, argv) |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 char **argv; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (argc != 6) { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 fprintf(stderr, |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 "usage: %s input-file x-start x-step y-start y-step\n", |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 argv[0]); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(1); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 infname = argv[1]; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 xstart = atoi(argv[2]); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 xstep = atoi(argv[3]); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 ystart = atoi(argv[4]); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 ystep = atoi(argv[5]); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 inf = fopen(infname, "r"); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (!inf) { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 perror(infname); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 exit(1); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (!index(linebuf, '\n')) { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 fprintf(stderr, "%s line %d: missing newline\n", |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 infname, lineno); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(1); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (strncmp(linebuf, "Element[", 8)) { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 fputs(linebuf, stdout); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 continue; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 strcpy(parsebuf, linebuf + 8); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 parse_element_line(); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (fields[2][0] != '\"' || fields[2][1] != 'S' || |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 !isdigit(fields[2][2]) || !isdigit(fields[2][3]) || |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 fields[2][4] != '\"' || fields[2][5]) { |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 fputs(linebuf, stdout); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 continue; |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 emit_new_element_line(); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 exit(0); |
36a6ba7f30ca
lunakpd1 placetool written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |