view pads2gpcb/readpads.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 aa0539cc3d41
children
line wrap: on
line source

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

char *input_filename;
int input_lineno;
char input_line_buf[1024], input_line_starkw[64];

#define	MAX_FIELDS	63
char *input_line_fields[MAX_FIELDS+1];
int input_line_nfields;

static FILE *inf;

open_input_file()
{
	inf = fopen(input_filename, "r");
	if (!inf) {
		perror(input_filename);
		exit(1);
	}
	return(0);
}

get_input_line()
{
	char *cp;

	if (!fgets(input_line_buf, sizeof input_line_buf, inf))
		return(0);
	input_lineno++;
	cp = index(input_line_buf, '\n');
	if (!cp) {
		fprintf(stderr, "%s line %d: missing newline\n",
			input_filename, input_lineno);
		exit(1);
	}
	*cp = '\0';
	if (cp > input_line_buf && cp[-1] == '\r')
		*--cp = '\0';
	return(1);
}

parse_starline()
{
	char *cp, *srcstr;

	srcstr = input_line_buf + 1;
	cp = index(srcstr, '*');
	if (!cp) {
		fprintf(stderr, "%s line %d: opening '*' but no closing '*'\n",
			input_filename, input_lineno);
		exit(1);
	}
	*cp = '\0';
	if (strlen(srcstr) + 1 > sizeof input_line_starkw) {
		fprintf(stderr, "%s line %d: star keyword is too long\n",
			input_filename, input_lineno);
		exit(1);
	}
	strcpy(input_line_starkw, srcstr);
	*cp = '*';
}

parse_input_line_fields()
{
	char *cp;
	int n;

	cp = input_line_buf;
	for (n = 0; ; ) {
		while (isspace(*cp))
			cp++;
		if (!*cp)
			break;
		if (n >= MAX_FIELDS) {
			fprintf(stderr,
				"%s line %d: number of fields exceeds limit\n",
				input_filename, input_lineno);
			exit(1);
		}
		input_line_fields[n++] = cp;
		while (*cp && !isspace(*cp))
			cp++;
		if (*cp)
			*cp++ = '\0';
	}
	input_line_fields[n] = 0;
	input_line_nfields = n;
}