FreeCalypso > hg > ueda-linux
changeset 146:7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Nov 2020 03:32:48 +0000 |
parents | 5e91200bf609 |
children | 295b1e4534bf |
files | .hgignore netdiff/flip2pin/Makefile netdiff/flip2pin/main.c netdiff/flip2pin/mainproc.c netdiff/flip2pin/readlist.c netdiff/flip2pin/struct.h |
diffstat | 6 files changed, 227 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sun Nov 15 01:17:10 2020 +0000 +++ b/.hgignore Sun Nov 15 03:32:48 2020 +0000 @@ -23,6 +23,7 @@ ^netdiff/convert/pads2donl$ ^netdiff/convert/protel2donl$ ^netdiff/convert/tedax2donl$ +^netdiff/flip2pin/donl-flip2pin$ ^netdiff/match/donl-netmatch$ ^netdiff/match/donl-pinreport$ ^netdiff/renpart/donl-rename-parts$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netdiff/flip2pin/Makefile Sun Nov 15 03:32:48 2020 +0000 @@ -0,0 +1,16 @@ +CC= gcc +CFLAGS= -O2 +PROG= donl-flip2pin +OBJS= main.o mainproc.o readlist.o +BINDIR= /usr/local/bin + +all: ${PROG} + +${PROG}: ${OBJS} + ${CC} ${CFLAGS} -o $@ ${OBJS} + +install: + install -c -o bin -g bin -m 755 ${PROG} ${BINDIR} + +clean: + rm -f *.[ao] a.out core errs ${PROG}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netdiff/flip2pin/main.c Sun Nov 15 03:32:48 2020 +0000 @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> +#include "struct.h" + +struct flip_list *flip_list; + +main(argc, argv) + char **argv; +{ + int i; + + if (argc != 3) { + fprintf(stderr, "usage: %s input-donl flip-list-file\n", + argv[0]); + exit(1); + } + read_flip_list(argv[2]); + main_process(argv[1]); + exit(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netdiff/flip2pin/mainproc.c Sun Nov 15 03:32:48 2020 +0000 @@ -0,0 +1,115 @@ +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "struct.h" + +extern struct flip_list *flip_list; + +#define MAX_FIELDS 2 + +static char *infname; +static FILE *inf; +static char linebuf[512]; +static int lineno; +static char *fields[MAX_FIELDS]; +static unsigned nfields; + +static +get_line() +{ + if (!fgets(linebuf, sizeof linebuf, inf)) + return(0); + lineno++; + if (!index(linebuf, '\n')) { + fprintf(stderr, "%s line %d: missing newline\n", + infname, lineno); + exit(1); + } + return(1); +} + +static void +parse_into_fields() +{ + char *cp; + + nfields = 0; + for (cp = linebuf; ; ) { + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + break; + if (nfields >= MAX_FIELDS) { + fprintf(stderr, "%s line %d: too many fields\n", + infname, lineno); + exit(1); + } + fields[nfields++] = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + } +} + +static void +process_netpoint() +{ + char *cp, *refdes, *pin; + struct flip_list *rp; + + cp = index(fields[1], '.'); + if (!cp) { + fprintf(stderr, "%s line %d: expected '.' not found\n", + infname, lineno); + exit(1); + } + *cp++ = '\0'; + refdes = fields[1]; + pin = cp; + for (rp = flip_list; rp; rp = rp->next) { + if (!strcmp(refdes, rp->refdes)) + break; + } + if (rp) { + if (!strcmp(pin, "1")) + pin = "2"; + else if (!strcmp(pin, "2")) + pin = "1"; + else { + fprintf(stderr, + "%s line %d: flip pin number is not 1 or 2\n", + infname, lineno); + exit(1); + } + } + printf("%s\t%s.%s\n", fields[0], refdes, pin); +} + +main_process(input_filename) + char *input_filename; +{ + infname = input_filename; + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + for (;;) { + if (!get_line()) + break; + parse_into_fields(); + if (!nfields) + continue; + if (nfields != 2) { + fprintf(stderr, "%s line %d: expected 2 fields\n", + infname, lineno); + exit(1); + } + process_netpoint(); + } + fclose(inf); + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netdiff/flip2pin/readlist.c Sun Nov 15 03:32:48 2020 +0000 @@ -0,0 +1,71 @@ +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "struct.h" + +extern struct flip_list *flip_list; + +static char *infname; +static FILE *inf; +static char linebuf[256]; +static int lineno; + +static void +refdes_entry(entry) + char *entry; +{ + struct flip_list *rp, **rpp; + char *dp; + + for (rpp = &flip_list; rp = *rpp; rpp = &rp->next) { + if (!strcmp(rp->refdes, entry)) { + fprintf(stderr, "%s line %d: refdes %s given twice\n", + infname, lineno, entry); + exit(1); + } + } + rp = malloc(sizeof(struct flip_list) + strlen(entry) + 1); + dp = (char *)(rp + 1); + rp->refdes = dp; + strcpy(dp, entry); + rp->next = 0; + *rpp = rp; +} + +static void +process_line() +{ + char *cp, *np; + + for (cp = linebuf; ; ) { + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + break; + np = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + refdes_entry(np); + } +} + +read_flip_list(input_filename) + char *input_filename; +{ + infname = input_filename; + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + while (fgets(linebuf, sizeof linebuf, inf)) { + lineno++; + process_line(); + } + fclose(inf); + return(0); +}