# HG changeset patch # User Mychaela Falconia # Date 1589001114 0 # Node ID 36a6ba7f30ca3c9833f5ee0b4a6b125e2b0e4e85 # Parent afdf0315ad84cf58e58c391c22aa0a851895a5a4 lunakpd1 placetool written diff -r afdf0315ad84 -r 36a6ba7f30ca .hgignore --- 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\. diff -r afdf0315ad84 -r 36a6ba7f30ca lunakpd1/placetool/Makefile --- /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} diff -r afdf0315ad84 -r 36a6ba7f30ca lunakpd1/placetool/placetool.c --- /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 +#include +#include +#include +#include + +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); +}