瀏覽代碼

Fix pattern check while konfd dump operation.

git-svn-id: https://klish.googlecode.com/svn/trunk@215 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 年之前
父節點
當前提交
f32cd94f15
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      konf/tree/tree.c

+ 8 - 2
konf/tree/tree.c

@@ -143,6 +143,7 @@ void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
 	konf_tree_t *conf;
 	lub_bintree_iterator_t iter;
 	unsigned char pri = 0;
+	regex_t regexp;
 
 	if (this->line && *(this->line) != '\0') {
 		char *space = NULL;
@@ -163,18 +164,23 @@ void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
 		free(space);
 	}
 
+	/* regexp compilation */
+	if (pattern)
+		regcomp(&regexp, pattern, REG_EXTENDED | REG_ICASE);
+
 	/* iterate child elements */
 	if (!(conf = lub_bintree_findfirst(&this->tree)))
 		return;
 
 	for(lub_bintree_iterator_init(&iter, &this->tree, conf);
 		conf; conf = lub_bintree_iterator_next(&iter)) {
-		if (pattern &&
-			(lub_string_nocasestr(conf->line, pattern) != conf->line))
+		if (pattern && (0 != regexec(&regexp, conf->line, 0, NULL, 0)))
 			continue;
 		konf_tree_fprintf(conf, stream, NULL, depth + 1, seq, pri);
 		pri = konf_tree__get_priority_hi(conf);
 	}
+	if (pattern)
+		regfree(&regexp);
 }
 
 static int normalize_seq(konf_tree_t * this, unsigned short priority)