Browse Source

konf dump can use -i to don't show splitter

Serj Kalichev 8 years ago
parent
commit
56da1f31fe
3 changed files with 9 additions and 6 deletions
  1. 2 1
      bin/konfd.c
  2. 1 1
      konf/tree.h
  3. 6 4
      konf/tree/tree.c

+ 2 - 1
bin/konfd.c

@@ -486,7 +486,7 @@ static char * process_query(konf_buf_t *tbuf, konf_tree_t * conf, char *str)
 
 #ifdef DEBUG
 	/* Print whole tree */
-	konf_tree_fprintf(conf, stderr, NULL, -1, -1, BOOL_TRUE, 0);
+	konf_tree_fprintf(conf, stderr, NULL, -1, -1, BOOL_TRUE, BOOL_TRUE, 0);
 #endif
 
 	/* Free resources */
@@ -559,6 +559,7 @@ static int dump_running_config(int sock, konf_tree_t *conf, konf_query_t *query)
 		konf_query__get_pwdc(query) - 1,
 		konf_query__get_depth(query),
 		konf_query__get_seq(query),
+		konf_query__get_splitter(query),
 		0);
 	if (!filename) {
 		fprintf(fd, "\n");

+ 1 - 1
konf/tree.h

@@ -39,7 +39,7 @@ konf_tree_t *konf_tree_new(const char *line, unsigned short priority);
 void konf_tree_delete(konf_tree_t * instance);
 void konf_tree_fprintf(konf_tree_t * instance, FILE * stream,
 	const char *pattern, int top_depth, int depth,
-	bool_t seq, unsigned char prev_pri_hi);
+	bool_t seq, bool_t splitter, unsigned char prev_pri_hi);
 konf_tree_t *konf_tree_new_conf(konf_tree_t * instance,
 	const char *line, unsigned short priority,
 	bool_t seq, unsigned short seq_num);

+ 6 - 4
konf/tree/tree.c

@@ -103,7 +103,7 @@ void konf_tree_delete(konf_tree_t * this)
 /*--------------------------------------------------------- */
 void konf_tree_fprintf(konf_tree_t *this, FILE *stream,
 	const char *pattern, int top_depth, int depth,
-	bool_t seq, unsigned char prev_pri_hi)
+	bool_t seq, bool_t splitter, unsigned char prev_pri_hi)
 {
 	konf_tree_t *conf;
 	lub_list_node_t *iter;
@@ -114,13 +114,13 @@ void konf_tree_fprintf(konf_tree_t *this, FILE *stream,
 		(this->depth > top_depth) &&
 		((depth < 0 ) || (this->depth <= (top_depth + depth)))) {
 		char *space = NULL;
-		unsigned space_num = this->depth - top_depth - 1;
+		unsigned int space_num = this->depth - top_depth - 1;
 		if (space_num > 0) {
 			space = malloc(space_num + 1);
 			memset(space, ' ', space_num);
 			space[space_num] = '\0';
 		}
-		if ((0 == this->depth) &&
+		if (splitter && (0 == this->depth) &&
 			(this->splitter ||
 			(konf_tree__get_priority_hi(this) != prev_pri_hi)))
 			fprintf(stream, "!\n");
@@ -142,7 +142,9 @@ void konf_tree_fprintf(konf_tree_t *this, FILE *stream,
 		conf = (konf_tree_t *)lub_list_node__get_data(iter);
 		if (pattern && (0 != regexec(&regexp, conf->line, 0, NULL, 0)))
 			continue;
-		konf_tree_fprintf(conf, stream, NULL, top_depth, depth, seq, pri);
+		/* Don't check pattern for child elements */
+		konf_tree_fprintf(conf, stream, NULL, top_depth, depth,
+			seq, splitter, pri);
 		pri = konf_tree__get_priority_hi(conf);
 	}
 	if (pattern)