Beispiel #1
0
static void
config_parse_line(calipso_config_t *config , char *line, int nline)
{
	char option[MAXOPTLEN]= {0}, value[MAXOPTLEN] = {0};
	char *s, *delim = NULL;

    if(strlen(line) > MAXOPTLEN ) 
		parser_error(nline, PERR_LINE);

	//printf("line '%s' %d\n", line, nline); 
	if(block_begin(line)) {

		if(!strlen(_block)) {
			s = strtok(line, BLOCK_BEGIN);
			if(s) { 
				strncpy(_block, s, MAXOPTLEN);
				trim(_block);
				//mark context begin 
				config_mark_ctx(config, CTX_BLOCK_BEGIN);
			} else 	parser_error(nline, PERR_BLOCK);
		}
		else parser_error(nline, PERR_BEGIN);
		//printf("begin '%s'\n", _block);
		return;
	}

	if(block_end(line)) {
	
		if(strlen(_block) > 0) {
			//mark context end 
			config_mark_ctx(config, CTX_BLOCK_END);
			memset(_block, 0 , MAXOPTLEN);
		}
		else parser_error(nline, PERR_END);
		//printf("end '%s'\n", _block);
		return;
	}

	if(strstr(line , DELIM_EQU)) 
		delim = DELIM_EQU;
	else if(strstr(line , DELIM_SPACE))
		delim = DELIM_SPACE;
	else if(strstr(line, DELIM_TAB))
		delim = DELIM_TAB;
	else 
		parser_error(nline, PERR_DELIM);

	s = strtok (line, delim); 

	if (s) {
		strncpy (option, s, MAXOPTLEN);
	}

	s = strtok (NULL, delim);

    if (s) {
		strncpy (value, s, MAXOPTLEN);
	}

    if ( strlen(option) && strlen(value)) {
		trim(option);
		trim(value);
		config_set_option(config, option, value, strlen(_block) ? _block : NULL );
	} else {
		parser_error(nline, PERR_PAIR);
	}
}
Beispiel #2
0
void
open_if_block (const char *c_cond)
{
	output ("if (%s)", c_cond);
	block_begin ();
}