Exemple #1
0
int conf_parse(uint8_t * buf, struct conf_entry * root)
{
	struct conf_entry * section;
	struct conf_entry * entry;
	uint8_t * cp = buf;
	char token[512];
	int skip_section = 0;
	int count = 0;;
	int line = 0;
	int pos;
	int c;

	section = root;

	for (;;) {
		/* ---------------------------------------------------------
		   locate the next section, ignoring empty and comment lines */
		line++;
		DBG(DBG_MSG, "line %3d", line);

		/* skip spaces */
		do { c = *cp++; } while ((c == ' ') || (c == '\t'));

		if (c == '\0')
			break;

		if (c == '\n') {
			DBG(DBG_MSG, "empty line");
			continue;
		}

		if (c == '#') {
			DBG(DBG_MSG, "comment");
			do {
				c = *cp++;
				if (c == '\0')
					goto end;
			} while (c != '\n');
			continue;	
		}

		if (c == '[') {
			skip_section = 0;

			/* skip spaces */
			do { c = *cp++; } while ((c == ' ') || (c == '\t'));

			/* section name must start with a letter */
			if (!isalpha(c)) {
				DBG(DBG_ERROR, "line %d: expecting alphabetic character", 
					line);
				return -1;
			}

			/* read the section name */
			pos = 0;
			do { 
				token[pos++] = c;	
				c = *cp++; 
			} while (isalnum(c) || (c == '_') || (c == '/'));
			token[pos] = '\0';	

			/* skip spaces, if any */
			while ((c == ' ') || (c == '\t')) { c = *cp++; };

			if (c != ']') {
				DBG(DBG_ERROR, "line %d: expecting ]", line);
				return -1;
			}

			/* skip spaces */
			do { c = *cp++; } while ((c == ' ') || (c == '\t'));

			if (c == '#') {
				/* ignore to the end of line */
				DBG(DBG_MSG, "comment");
				do {
					c = *cp++;
					if (c == '\0')
						goto end;
				} while (c != '\n');
			} 

			if (c != '\n') {
				DBG(DBG_ERROR, "line %d: expecting EOL", line);
				return -1;
			}

			DBG(DBG_MSG, "section_lookup: '%s'", token);

			if ((section = section_lookup(root, token)) == NULL) {
				DBG(DBG_WARNING, "invalid section: '%s'", token);
				skip_section = 1;
			}
			continue;
		}

		if (skip_section) {
			DBG(DBG_MSG, "skiping");
			do {
				c = *cp++;
				if (c == '\0')
					goto end;
			} while (c != '\n');
			continue;	
		}
			
		/* ---------------------------------------------------------
		   read the section content 
		   -------------------------------------------------------- */

		/* entry name must start with a letter */
		if (!isalpha(c)) {
			DBG(DBG_ERROR, "line %d: expecting alphabetic character", line);
			return -1;
		}

		/* read the entry name */
		pos = 0;
		do { 
			token[pos++] = c;	
			c = *cp++; 
		} while (isalnum(c) || (c == '.') || (c == '-') || (c == '_'));
		token[pos] = '\0';	

		/* skip spaces, if any */
		while ((c == ' ') || (c == '\t')) { c = *cp++; };

		if (c != '=') {
			DBG(DBG_ERROR, "line %d: expecting =", line);
			return -1;
		}

		if ((entry = entry_lookup(section, token)) == NULL) {
			DBG(DBG_WARNING, "invalid entry: '%s.%s'", section->name, token);
			/* ignore to the end of line */
			do {
				c = *cp++;
				if (c == '\0')
					goto end;
			} while (c != '\n');
			continue;
		}

		/* skip spaces */
		do { c = *cp++; } while ((c == ' ') || (c == '\t'));

		/* read the entry value */
		pos = 0;
		do { 
			token[pos++] = c;	
			c = *cp++; 
		} while ((c != '\n') && (c != '\0'));
		token[pos] = '\0';	

		/* set the variable */
		if (entry->type->t_set(entry, token))
			count++;
		else
			DBG(DBG_WARNING, "line %d: '%s': decode error.", line, entry->name);
	}
end:
	return 0;
}
eight_bits
#line 317 "./cwebdir/ctang-w2c.ch"
 get_next P1H(void)
#line 903 "./cwebdir/ctangle.w"
{
static int preprocessing= 0;
eight_bits c;
while(1){
if(loc> limit){
if(preprocessing&&*(limit-1)!='\\')preprocessing= 0;
if(get_line()==0)return(new_section);
else if(print_where&&!no_where){
print_where= 0;
/*76:*/
#line 1225 "./cwebdir/ctangle.w"

store_two_bytes(0150000);
if(changing)id_first= change_file_name;
else id_first= cur_file_name;
id_loc= id_first+strlen(id_first);
if(changing)store_two_bytes((sixteen_bits)change_line);
else store_two_bytes((sixteen_bits)cur_line);
{int a= id_lookup(id_first,id_loc,0)-name_dir;app_repl((a/0400)+0200);
app_repl(a%0400);}

/*:76*/
#line 912 "./cwebdir/ctangle.w"
;
}
else return('\n');
}
c= *loc;
if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){
skip_comment(comment_continues||*(loc+1)=='*');

if(comment_continues)return('\n');
else continue;
}
loc++;
if(xisdigit(c)||c=='.')/*65:*/
#line 978 "./cwebdir/ctangle.w"
{
id_first= loc-1;
if(*id_first=='.'&&!xisdigit(*loc))goto mistake;
if(*id_first=='0'){
if(*loc=='x'||*loc=='X'){
loc++;while(xisxdigit(*loc))loc++;goto found;
}
}
while(xisdigit(*loc))loc++;
if(*loc=='.'){
loc++;
while(xisdigit(*loc))loc++;
}
if(*loc=='e'||*loc=='E'){
if(*++loc=='+'||*loc=='-')loc++;
while(xisdigit(*loc))loc++;
}
found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
||*loc=='f'||*loc=='F')loc++;
id_loc= loc;
return(constant);
}

/*:65*/
#line 924 "./cwebdir/ctangle.w"

else if(c=='\''||c=='"'||(c=='L'&&(*loc=='\''||*loc=='"')))
/*66:*/
#line 1006 "./cwebdir/ctangle.w"
{
char delim= c;
id_first= section_text+1;
id_loc= section_text;*++id_loc= delim;
if(delim=='L'){
delim= *loc++;*++id_loc= delim;
}
while(1){
if(loc>=limit){
if(*(limit-1)!='\\'){
err_print("! String didn't end");loc= limit;break;

}
if(get_line()==0){
err_print("! Input ended in middle of string");loc= buffer;break;

}
else if(++id_loc<=section_text_end)*id_loc= '\n';

}
if((c= *loc++)==delim){
if(++id_loc<=section_text_end)*id_loc= c;
break;
}
if(c=='\\'){
if(loc>=limit)continue;
if(++id_loc<=section_text_end)*id_loc= '\\';
c= *loc++;
}
if(++id_loc<=section_text_end)*id_loc= c;
}
if(id_loc>=section_text_end){
printf("\n! String too long: ");

term_write(section_text+1,25);
err_print("...");
}
id_loc++;
return(string);
}

/*:66*/
#line 926 "./cwebdir/ctangle.w"

else if(isalpha(c)||isxalpha(c)||ishigh(c))
/*64:*/
#line 972 "./cwebdir/ctangle.w"
{
id_first= --loc;
while(isalpha(*++loc)||isdigit(*loc)||isxalpha(*loc)||ishigh(*loc));
id_loc= loc;return(identifier);
}

/*:64*/
#line 928 "./cwebdir/ctangle.w"

else if(c=='@')/*67:*/
#line 1050 "./cwebdir/ctangle.w"
{
c= ccode[(eight_bits)*loc++];
switch(c){
case ignore:continue;
case translit_code:err_print("! Use @l in limbo only");continue;

case control_text:while((c= skip_ahead())=='@');

if(*(loc-1)!='>')
err_print("! Double @ should be used in control text");

continue;
case section_name:
cur_section_name_char= *(loc-1);
/*69:*/
#line 1098 "./cwebdir/ctangle.w"
{
char*k;
/*71:*/
#line 1118 "./cwebdir/ctangle.w"

k= section_text;
while(1){
if(loc> limit&&get_line()==0){
err_print("! Input ended in section name");

loc= buffer+1;break;
}
c= *loc;
/*72:*/
#line 1142 "./cwebdir/ctangle.w"

if(c=='@'){
c= *(loc+1);
if(c=='>'){
loc+= 2;break;
}
if(ccode[(eight_bits)c]==new_section){
err_print("! Section name didn't end");break;

}
if(ccode[(eight_bits)c]==section_name){
err_print("! Nesting of section names not allowed");break;

}
*(++k)= '@';loc++;
}

/*:72*/
#line 1127 "./cwebdir/ctangle.w"
;
loc++;if(k<section_text_end)k++;
if(xisspace(c)){
c= ' ';if(*(k-1)==' ')k--;
}
*k= c;
}
if(k>=section_text_end){
printf("\n! Section name too long: ");

term_write(section_text+1,25);
printf("...");mark_harmless;
}
if(*k==' '&&k> section_text)k--;

/*:71*/
#line 1100 "./cwebdir/ctangle.w"
;
if(k-section_text> 3&&strncmp(k-2,"...",3)==0)
cur_section_name= section_lookup(section_text+1,k-3,1);
else cur_section_name= section_lookup(section_text+1,k,0);
if(cur_section_name_char=='(')
/*39:*/
#line 516 "./cwebdir/ctangle.w"

{
for(an_output_file= cur_out_file;
an_output_file<end_output_files;an_output_file++)
if(*an_output_file==cur_section_name)break;
if(an_output_file==end_output_files){
if(cur_out_file> output_files)
*--cur_out_file= cur_section_name;
else{
overflow("output files");
}
}
}

/*:39*/
#line 1106 "./cwebdir/ctangle.w"
;
return(section_name);
}

/*:69*/
#line 1064 "./cwebdir/ctangle.w"
;
case string:/*73:*/
#line 1164 "./cwebdir/ctangle.w"
{
id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
while(*loc!='@'||*(loc+1)!='>')loc++;
if(loc>=limit)err_print("! Verbatim string didn't end");

id_loc= loc;loc+= 2;
return(string);
}

/*:73*/
#line 1065 "./cwebdir/ctangle.w"
;
case ord:/*68:*/
#line 1077 "./cwebdir/ctangle.w"

id_first= loc;
if(*loc=='\\'){
if(*++loc=='\'')loc++;
}
while(*loc!='\''){
if(*loc=='@'){
if(*(loc+1)!='@')
err_print("! Double @ should be used in ASCII constant");

else loc++;
}
loc++;
if(loc> limit){
err_print("! String didn't end");loc= limit-1;break;

}
}
loc++;
return(ord);

/*:68*/
#line 1066 "./cwebdir/ctangle.w"
;
default:return(c);
}
}

/*:67*/
#line 929 "./cwebdir/ctangle.w"

else if(xisspace(c)){
if(!preprocessing||loc> limit)continue;

else return(' ');
}
else if(c=='#'&&loc==buffer+1)preprocessing= 1;
mistake:/*63:*/
#line 950 "./cwebdir/ctangle.w"

switch(c){
case'+':if(*loc=='+')compress(plus_plus);break;
case'-':if(*loc=='-'){compress(minus_minus);}
else if(*loc=='>')if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
else compress(minus_gt);break;
case'.':if(*loc=='*'){compress(period_ast);}
else if(*loc=='.'&&*(loc+1)=='.'){
loc++;compress(dot_dot_dot);
}
break;
case':':if(*loc==':')compress(colon_colon);break;
case'=':if(*loc=='=')compress(eq_eq);break;
case'>':if(*loc=='='){compress(gt_eq);}
else if(*loc=='>')compress(gt_gt);break;
case'<':if(*loc=='='){compress(lt_eq);}
else if(*loc=='<')compress(lt_lt);break;
case'&':if(*loc=='&')compress(and_and);break;
case'|':if(*loc=='|')compress(or_or);break;
case'!':if(*loc=='=')compress(not_eq);break;
}

/*:63*/
#line 936 "./cwebdir/ctangle.w"

return(c);
}
}