view libpwon/readconf.c @ 926:6a0aa8d36d06

rvinterf backslash escape: introduce libprint The new helper function library named libprint is meant to replace the badly misnamed libg23, and will soon contain functions for printing all of the same kinds of GPF TST packets that are now handled in libg23. However, we are also moving safe_print_trace() from libasync to this new library, and changing it to emit our new backslash escape format.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 May 2023 03:47:46 +0000
parents 7d1df6d831e4
children ab54957dbe35
line wrap: on
line source

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

static char conf_file_pathname[] = "/opt/freecalypso/bootctrl.conf";

#define	MAX_BOOTCTRL_CONF_LINE	510

char bootctrl_pwon_cmd[MAX_BOOTCTRL_CONF_LINE+1];

find_bootctrl_entry(soughtname)
	char *soughtname;
{
	FILE *inf;
	char linebuf[MAX_BOOTCTRL_CONF_LINE+2];
	int lineno;
	char *cp, *np;

	if (bootctrl_check_duart28c(soughtname))
		return(0);
	inf = fopen(conf_file_pathname, "r");
	if (!inf) {
		perror(conf_file_pathname);
		return(-1);
	}
	for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
		cp = index(linebuf, '\n');
		if (!cp) {
			fprintf(stderr,
				"%s line %d: too long or missing newline\n",
				conf_file_pathname, lineno);
			fclose(inf);
			return(-1);
		}
		*cp = '\0';
		for (cp = linebuf; isspace(*cp); cp++)
			;
		if (*cp == '\0' || *cp == '#')
			continue;
		for (np = cp; *cp && !isspace(*cp); cp++)
			;
		if (!*cp) {
invalid_syntax:		fprintf(stderr, "%s line %d: invalid syntax\n",
				conf_file_pathname, lineno);
			fclose(inf);
			return(-1);
		}
		*cp++ = '\0';
		while (isspace(*cp))
			cp++;
		if (*cp == '\0' || *cp == '#')
			goto invalid_syntax;
		if (!strcmp(np, soughtname)) {
			strcpy(bootctrl_pwon_cmd, cp);
			fclose(inf);
			return(0);
		}
	}
	fclose(inf);
	fprintf(stderr, "error: no \"%s\" entry found in %s\n", soughtname,
		conf_file_pathname);
	return(-1);
}