コード例 #1
0
ファイル: parser.cpp プロジェクト: docbrown/3dml
bool
verify_line(char *expected_line)
{
	if (!line_is(expected_line)) {
		bad_line(expected_line);
		return(false);
	}
	return(true);
}
コード例 #2
0
ファイル: init.c プロジェクト: nori6001/FUZIX
/*
 *	Squash an init line in situ from
 *
 *	id:runlevels:type:args
 *	into
 *
 *	uint8 length
 *	char id[2]
 *	uint8 runlevel bit mask
 *	uint8 optype
 *	arguments with \0 separation
 */
static void parse_initline(void)
{
	uint8_t bit = 0;
	uint8_t *linelen;

	if (*sdata == '#') {
		sdata = strchr(sdata, '\n');
		if (sdata)
			sdata++;
		return;
	}
	/* We start with a line length then the id: bits. Don't write
	 * the length yet - we may still be using that byte for input */
	linelen = idata++;
	*idata++ = *sdata++;
	*idata++ = *sdata++;	/* Copy the init string */
	if (*sdata++ != ':') {
		bad_line();
		return;
	}
	while (*sdata != ':') {
		if (*sdata == '\n' || sdata > sdata_end) {
			bad_line();
			return;
		}
		bit = to_runlevel(*sdata++);
		if (bit == 0xFF) {
			bad_line();
			return;
		}
		/* Add the run level to the bitmask */
		*idata |= 1 << bit;
	}

	idata++;
	sdata++;
	if (memcmp(sdata, "respawn:", 8) == 0) {
		*idata++ = INIT_RESPAWN;
		sdata += 8;
	} else if (memcmp(sdata, "wait:", 5) == 0) {
		*idata++ = INIT_ONCE | INIT_WAIT;
		sdata += 5;
	} else if (memcmp(sdata, "once:", 5) == 0) {
		*idata++ = INIT_ONCE;
		sdata += 5;
	} else if (memcmp(sdata, "boot:", 5) == 0) {
		idata[-1] = MASK_BOOT;
		*idata++ = INIT_BOOT;
		sdata += 5;
	} else if (memcmp(sdata, "bootwait:", 9) == 0) {
		idata[-1] = MASK_BOOT;
		*idata++ = INIT_BOOT | INIT_WAIT;
		sdata += 9;
	} else if (memcmp(sdata, "off:", 4) == 0) {
		*idata++ = INIT_OFF;
		sdata += 4;
	} else if (memcmp(sdata, "initdefault:", 12) == 0) {
		*idata++ = INIT_DEFAULT;
		default_rl = bit;
		sdata += 12;
	} else if (memcmp(sdata, "sysinit:", 8) == 0) {
		idata[-1] = MASK_BOOT;
		*idata++ = INIT_SYS | INIT_WAIT;
		sdata += 8;
	} else {
		/* We don't yet spport power* methods */
		bad_line();
		return;
	}
	while (*sdata && *sdata != '\n' && sdata < sdata_end) {
		if (*sdata != ' ')
			*idata++ = *sdata;
		else
			*idata++ = 0;
		sdata++;
	}
	/* Terminate the final argument */
	*idata++ = 0;
	*linelen = idata - linelen;
	sdata++;
	initcount++;
}