trunk: changeset 43

Mon, 27 May 2002 00:27:30 +0200

author
tuomov
date
Mon, 27 May 2002 00:27:30 +0200
changeset 40
0a050a9536a1
parent 39
ebea551c80dc
child 41
28628406763e

trunk: changeset 43
Added check_args_loose

include/libtu/parser.h file | annotate | diff | comparison | revisions
parser.c file | annotate | diff | comparison | revisions
--- a/include/libtu/parser.h	Tue Jan 22 01:24:03 2002 +0100
+++ b/include/libtu/parser.h	Mon May 27 00:27:30 2002 +0200
@@ -43,5 +43,7 @@
 extern bool parse_config_file(FILE *file, const ConfOpt *options, int flags);
 extern bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
 					   const char *fmt);
+extern bool check_args_loose(const Tokenizer *tokz, Token *tokens, int ntokens,
+							 const char *fmt);
 
 #endif /* LIBTU_PARSER_H */
--- a/parser.c	Tue Jan 22 01:24:03 2002 +0100
+++ b/parser.c	Mon May 27 00:27:30 2002 +0200
@@ -444,7 +444,7 @@
  */
 
 
-static int arg_match(Token *tok, char c)
+static int arg_match(Token *tok, char c, bool si)
 {
 	char c2=tok->type;
 	
@@ -454,6 +454,18 @@
 	if(c2==c)
 		return 0;
 	
+	if(si){
+		if(c2=='i' && c=='s'){
+			TOK_SET_IDENT(tok, TOK_STRING_VAL(tok));
+			return 0;
+		}
+		
+		if(c2=='s' && c=='i'){
+			TOK_SET_STRING(tok, TOK_IDENT_VAL(tok));
+			return 0;
+		}
+	}
+	
 	if(c2=='c' && c=='l'){
 		TOK_SET_LONG(tok, TOK_CHAR_VAL(tok));
 		return 0;
@@ -490,7 +502,8 @@
 }
 
 
-static int check_argument(const char **pret, Token *tok, const char *p)
+static int check_argument(const char **pret, Token *tok, const char *p,
+						  bool si)
 {
 	int mode;
 	int e=E_TOKZ_TOO_MANY_ARGS;
@@ -509,11 +522,11 @@
 		p++;
 	}else if(*p=='+'){
 		*pret=p;
-		return arg_match(tok, *(p-1));
+		return arg_match(tok, *(p-1), si);
 	}
 	
 	while(*p!='\0'){
-		e=arg_match(tok, *p);
+		e=arg_match(tok, *p, si);
 		if(e==0){
 			p++;
 			while(mode==2 && *p==':'){
@@ -564,8 +577,8 @@
 }
 
 
-bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
-				const char *fmt)
+bool do_check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
+				   const char *fmt, bool si)
 {
 	int i;
 	int e;
@@ -577,7 +590,7 @@
 	}
 
 	for(i=1; i<ntokens; i++){
-		e=check_argument(&fmt, &tokens[i], fmt);
+		e=check_argument(&fmt, &tokens[i], fmt, si);
 		if(e!=0){
 			tokz_warn_error(tokz, tokens[i].line, e);
 			return FALSE;
@@ -593,6 +606,20 @@
 }
 
 
+bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
+				const char *fmt)
+{
+	return do_check_args(tokz, tokens, ntokens, fmt, FALSE);
+}
+
+
+bool check_args_loose(const Tokenizer *tokz, Token *tokens, int ntokens,
+				const char *fmt)
+{
+	return do_check_args(tokz, tokens, ntokens, fmt, TRUE);
+}
+
+
 /* */
 
 

mercurial