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