view netdiff/flip2pin/readlist.c @ 148:64d4abf63e1e

netdiff: donl-pindiff factored out of donl-netmatch
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Nov 2020 04:11:01 +0000
parents 7ddfb9a67b0c
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 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);
}