Example #1
0
static char *
nextfld(char **str, const char *sep)
{
	char *ret;

	_DIAGASSERT(str != NULL);
	_DIAGASSERT(sep != NULL);

	while ((ret = stresep(str, sep, '\\')) != NULL && *ret == '\0')
		continue;
	return ret;
}
Example #2
0
/*
 * Process a file to set standard arp entries
 */
static int
file(const char *name)
{
	char *line, *argv[5];
	int i, retval;
	FILE *fp;

	if (!strcmp(name, "-")) {
		fp = stdin;
	} else {
		fp = fopen(name, "r");
		if (fp == NULL) {
			err(1, "Cannot open %s", name);
		}
	}
	retval = 0;
	for (; (line = fparseln(fp, NULL, NULL, NULL, 0)) != NULL; free(line)) {
		char **ap, *inputstring;

		inputstring = line;
		for (ap = argv; ap < &argv[sizeof(argv) / sizeof(argv[0])] &&
		    (*ap = stresep(&inputstring, " \t", '\\')) != NULL;) {
		       if (**ap != '\0')
				ap++;
		}
		i = ap - argv;
		if (i < 2) {
			warnx("bad line: %s", line);
			retval = 1;
			continue;
		}
		if (set(i, argv))
			retval = 1;
	}
	if (fp != stdin)
		(void)fclose(fp);
	return retval;
}