view librftab/rdcommon.c @ 995:74024eb17e04

fc-loadtool help: improve language regarding 16 MiB flash chips In FC project history, 16 MiB flash originally meant Pirelli DP-L10. Then we got FCDEV3B with the same flash (our own design), but now we are discovering more Calypso devices that used such large flash, both late Calypso era (Sony Ericsson K2x0) as well as much earlier ones (FIC FLUID devices.txt file with 2004 dates, Leonardo+ rev 5). Hence we need to migrate to more generic or neutral language in associated documentation, without giving elevated status to specific examples that drove our early project history.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 21:11:12 +0000
parents a0f79bba0ad8
children
line wrap: on
line source

/*
 * This C file is not a compilation unit in itself, but is the common piece
 * (a set of static variables and functions) included in the librftab modules
 * responsible for reading different kinds of ASCII tables.
 */

#define	MAX_FIELDS_PER_LINE	64

static char *filename;
static FILE *rdfile;
static unsigned lineno;
static char linebuf[256], *line_fields[MAX_FIELDS_PER_LINE];
static unsigned line_nfields, line_field_ptr;

static int
read_line()
{
	char *cp;

	if (!fgets(linebuf, sizeof linebuf, rdfile))
		return(0);
	lineno++;
	cp = linebuf;
	for (line_nfields = 0; ; ) {
		while (isspace(*cp))
			cp++;
		if (*cp == '\0' || *cp == '#')
			break;
		if (line_nfields >= MAX_FIELDS_PER_LINE) {
			printf("%s line %d: too many fields on one line\n",
				filename, lineno);
			return(-1);
		}
		line_fields[line_nfields++] = cp;
		while (*cp && !isspace(*cp))
			cp++;
		if (*cp)
			*cp++ = '\0';
	}
	return(1);
}

static
get_field(retp)
	char **retp;
{
	int rc;

	if (line_field_ptr < line_nfields) {
		*retp = line_fields[line_field_ptr++];
		return(1);
	}
	do {
		rc = read_line();
		if (rc <= 0)
			return(rc);
	} while (!line_nfields);
	*retp = line_fields[0];
	line_field_ptr = 1;
	return(1);
}