FreeCalypso > hg > fc-small-hw
changeset 15:36a6ba7f30ca
lunakpd1 placetool written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 May 2020 05:11:54 +0000 |
parents | afdf0315ad84 |
children | 7e564c546dde |
files | .hgignore lunakpd1/placetool/Makefile lunakpd1/placetool/placetool.c |
diffstat | 3 files changed, 106 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sat May 09 04:00:24 2020 +0000 +++ b/.hgignore Sat May 09 05:11:54 2020 +0000 @@ -15,6 +15,7 @@ ^lcdtest1/pcb/gerbers\. ^lcdtest1/schem\+bom/elements\.pcb$ +^lunakpd1/placetool/placetool$ ^lunakpd1/src/elements\.pcb$ ^lunalcd1/pcb/gerbers\.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lunakpd1/placetool/Makefile Sat May 09 05:11:54 2020 +0000 @@ -0,0 +1,11 @@ +CC= gcc +CFLAGS= -O2 +PROG= placetool + +all: ${PROG} + +${PROG}: ${PROG}.c + ${CC} ${CFLAGS} -o $@ $@.c + +clean: + rm -f ${PROG}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lunakpd1/placetool/placetool.c Sat May 09 05:11:54 2020 +0000 @@ -0,0 +1,94 @@ +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> + +char *infname; +FILE *inf; +int xstart, xstep, ystart, ystep; +char linebuf[512], parsebuf[512], *fields[11]; +int lineno; + +parse_element_line() +{ + int count; + char *cp; + + cp = parsebuf; + for (count = 0; ; ) { + if (!isdigit(*cp) && *cp != '-' && *cp != '\"') { +inv: fprintf(stderr, "%s line %d: invalid Element line\n", + infname, lineno); + exit(1); + } + if (count >= 11) + goto inv; + fields[count++] = cp; + while (*cp && *cp != ' ' && *cp != ']') + cp++; + if (!*cp) + goto inv; + if (*cp == ']') { + *cp++ = '\0'; + break; + } + *cp++ = '\0'; + } + if (count != 11 || *cp != '\n') + goto inv; +} + +emit_new_element_line() +{ + int row, col; + + row = fields[2][2] - '0'; + col = fields[2][3] - '0'; + printf("Element[%s %s %s %s %dmm %dmm %s %s %s %s %s]", + fields[0], fields[1], fields[2], fields[3], + xstart + col * xstep, ystart + row * ystep, + fields[6], fields[7], fields[8], fields[9], fields[10]); +} + +main(argc, argv) + char **argv; +{ + if (argc != 6) { + fprintf(stderr, + "usage: %s input-file x-start x-step y-start y-step\n", + argv[0]); + exit(1); + } + infname = argv[1]; + xstart = atoi(argv[2]); + xstep = atoi(argv[3]); + ystart = atoi(argv[4]); + ystep = atoi(argv[5]); + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { + if (!index(linebuf, '\n')) { + fprintf(stderr, "%s line %d: missing newline\n", + infname, lineno); + exit(1); + } + if (strncmp(linebuf, "Element[", 8)) { + fputs(linebuf, stdout); + continue; + } + strcpy(parsebuf, linebuf + 8); + parse_element_line(); + if (fields[2][0] != '\"' || fields[2][1] != 'S' || + !isdigit(fields[2][2]) || !isdigit(fields[2][3]) || + fields[2][4] != '\"' || fields[2][5]) { + fputs(linebuf, stdout); + continue; + } + emit_new_element_line(); + } + exit(0); +}