view netdiff/convert/pads2donl.c @ 138:77acb816727b

netdiff: donl-rename-parts put together
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 04:02:14 +0000
parents ab7b9f01ac6a
children
line wrap: on
line source

/*
 * This program converts a PADS ASCII netlist into our
 * Diff-Oriented Netlist (DONL) format.
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#define	MAX_NETNAME	127

static char *infname;
static FILE *inf;
static char linebuf[512], netname[MAX_NETNAME+1];
static int lineno;

static void
process_signal_line()
{
	char *cp, *np;

	cp = linebuf + 1;
	while (*cp != '*')
		cp++;
	cp++;
	if (!isspace(*cp)) {
badsig:		fprintf(stderr, "%s line %d: malformed SIGNAL line\n",
			infname, lineno);
		exit(1);
	}
	while (isspace(*cp))
		cp++;
	if (!*cp)
		goto badsig;
	for (np = cp; *cp && !isspace(*cp); cp++)
		;
	if (*cp)
		*cp = '\0';
	if (strlen(np) > MAX_NETNAME) {
		fprintf(stderr, "%s line %d: signal name too long\n",
			infname, lineno);
		exit(1);
	}
	strcpy(netname, np);
}

static void
process_data_line()
{
	char *cp, *np;

	for (cp = linebuf; ; ) {
		while (isspace(*cp))
			cp++;
		if (!*cp)
			break;
		for (np = cp; *cp && !isspace(*cp); cp++)
			;
		if (*cp)
			*cp++ = '\0';
		printf("%s\t%s\n", netname, np);
	}
}

main(argc, argv)
	char **argv;
{
	if (argc != 2) {
		fprintf(stderr, "usage: %s pads-netlist-file\n", argv[0]);
		exit(1);
	}
	infname = argv[1];
	inf = fopen(infname, "r");
	if (!inf) {
		perror(infname);
		exit(1);
	}
	for (;;) {
		if (!fgets(linebuf, sizeof linebuf, inf))
			break;
		lineno++;
		if (!index(linebuf, '\n')) {
			fprintf(stderr, "%s line %d: missing newline\n",
				infname, lineno);
			exit(1);
		}
		if (linebuf[0] == '*') {
			if (!strncmp(linebuf, "*END*", 5))
				break;
			if (!strncmp(linebuf, "*SIG*", 5) ||
			    !strncmp(linebuf, "*SIGNAL*", 8))
				process_signal_line();
			else
				netname[0] = '\0';
			continue;
		}
		if (netname[0])
			process_data_line();
	}
	exit(0);
}