parser.c

changeset 1
6e704fc09528
parent 0
86b7f6f9c5c0
child 2
e14a1aba4c56
--- a/parser.c	Tue Feb 15 18:57:52 2005 +0100
+++ b/parser.c	Sat Feb 19 23:23:29 2000 +0100
@@ -32,6 +32,17 @@
 
 /* */
 
+static bool opt_include(Tokenizer *tokz, int n, Token *toks);
+
+
+static ConfOpt common_opts[]={
+	{"include", "s", opt_include, NULL},
+	{NULL, NULL, NULL, NULL}
+};
+
+
+/* */
+
 
 static int read_statement(const ConfOpt **opt_ret, Token *tokens,
 						  int *ntok_ret, Tokenizer *tokz,
@@ -71,10 +82,17 @@
 						break;
 				}
 				
-				if(!opt->optname){
-					e=E_TOKZ_UNKNOWN_OPTION;
-					e_line=tok->line;
-					retval=P_ERROR;
+				if(opt->optname==NULL){
+					/* common opt? include, etc. */
+					for(opt=common_opts; opt->optname; opt++){
+						if(strcmp(opt->optname, TOK_IDENT_VAL(tok))==0)
+							break;
+					}
+					if(opt->optname==NULL){
+						e=E_TOKZ_UNKNOWN_OPTION;
+						e_line=tok->line;
+						retval=P_ERROR;
+					}
 				}
 
 				had_comma=2;
@@ -295,7 +313,10 @@
 			break;
 
 		case P_EOF:
-			if(tokz->nest_lvl>0){
+			if(tokz_popf(tokz)){
+				if(!had_error)
+					continue;
+			}else if(tokz->nest_lvl>0){
 				tokz_warn_error(tokz, 0, E_TOKZ_UNEXPECTED_EOF);
 				had_error=TRUE;
 			}else if(!had_error){
@@ -516,3 +537,39 @@
 	return TRUE;
 }
 
+
+/* */
+
+
+static bool opt_include(Tokenizer *tokz, int n, Token *toks)
+{
+	const char *fname=TOK_STRING_VAL(toks+1);
+	const char *lastndx;
+	char *tmpname;
+	bool retval;
+	
+	if(fname[0]=='/' || tokz->name==NULL)
+		goto thisdir;
+	
+	lastndx=strrchr(tokz->name, '/');
+	
+	if(lastndx==NULL)
+		goto thisdir;
+	
+	tmpname=scatn(tokz->name, lastndx-tokz->name+1, fname, -1);
+	
+	if(tmpname==NULL){
+		warn_err();
+		return FALSE;
+	}
+	
+	retval=tokz_pushf(tokz, tmpname);
+	
+	free(tmpname);
+	
+	return retval;
+
+thisdir:
+	return tokz_pushf(tokz, fname);
+}
+

mercurial