FreeCalypso > hg > ueda-linux
view netdiff/match/rdpass.c @ 145:5e91200bf609
netdiff: donl-pinreport utility written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Nov 2020 01:17:10 +0000 |
parents | d3eb3790386d |
children |
line wrap: on
line source
#include <ctype.h> #include <string.h> #include <strings.h> #include <stdio.h> #include <stdlib.h> #include "struct.h" extern char *infnames[2]; extern struct pin_info *database; #define MAX_FIELDS 2 static int pass; static FILE *inf; static char linebuf[512]; static int lineno; static char *fields[MAX_FIELDS]; static unsigned nfields; 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", infnames[pass], lineno); exit(1); } fields[nfields++] = cp; while (*cp && !isspace(*cp)) cp++; if (*cp) *cp++ = '\0'; } } static void existing_pin(p, netname) struct pin_info *p; char *netname; { char *dp; if (p->netnames[pass]) { fprintf(stderr, "%s line %d: multiple nets to pin %s\n", infnames[pass], lineno, p->pin_name); exit(1); } dp = malloc(strlen(netname) + 1); if (!dp) { perror("malloc"); exit(1); } strcpy(dp, netname); p->netnames[pass] = dp; } static void process_connect(netname, pinname) char *netname, *pinname; { struct pin_info *p, **pp; char *dp; for (pp = &database; p = *pp; pp = &p->next) { if (!strcmp(p->pin_name, pinname)) { existing_pin(p, netname); return; } } p = malloc(sizeof(struct pin_info) + strlen(netname) + strlen(pinname) + 2); if (!p) { perror("malloc"); exit(1); } bzero(p, sizeof(struct pin_info)); dp = (char *)(p + 1); p->pin_name = dp; strcpy(dp, pinname); dp += strlen(pinname) + 1; p->netnames[pass] = dp; strcpy(dp, netname); *pp = p; } static void process_line() { parse_into_fields(); if (!nfields) return; if (nfields != 2) { fprintf(stderr, "%s line %d: expected 2 fields\n", infnames[pass], lineno); exit(1); } process_connect(fields[0], fields[1]); } read_pass(pass_no) { pass = pass_no; inf = fopen(infnames[pass], "r"); if (!inf) { perror(infnames[pass]); exit(1); } lineno = 0; while (fgets(linebuf, sizeof linebuf, inf)) { lineno++; process_line(); } fclose(inf); return 0; }