Browse Source

Fix konfd output when the pwd is given.

git-svn-id: https://klish.googlecode.com/svn/trunk@216 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 14 years ago
parent
commit
160dcdcd24
4 changed files with 26 additions and 10 deletions
  1. 1 0
      bin/konfd.c
  2. 2 1
      konf/tree.h
  3. 1 0
      konf/tree/private.h
  4. 22 9
      konf/tree/tree.c

+ 1 - 0
bin/konfd.c

@@ -239,6 +239,7 @@ static char * process_query(int sock, konf_tree_t * conf, char *str)
 			break;
 		}
 		konf_tree__set_splitter(tmpconf, konf_query__get_splitter(query));
+		konf_tree__set_depth(tmpconf, konf_query__get_pwdc(query));
 		ret = KONF_QUERY_OP_OK;
 		break;
 

+ 2 - 1
konf/tree.h

@@ -54,7 +54,6 @@ int konf_tree_del_pattern(konf_tree_t * instance,
 /*-----------------
  * attributes 
  *----------------- */
-unsigned konf_tree__get_depth(const konf_tree_t * instance);
 unsigned short konf_tree__get_priority(const konf_tree_t * instance);
 unsigned char konf_tree__get_priority_hi(const konf_tree_t * instance);
 unsigned char konf_tree__get_priority_lo(const konf_tree_t * instance);
@@ -65,6 +64,8 @@ void konf_tree__set_seq_num(konf_tree_t * instance, unsigned short seq_num);
 unsigned short konf_tree__get_sub_num(const konf_tree_t * instance);
 void konf_tree__set_sub_num(konf_tree_t * instance, unsigned short sub_num);
 const char * konf_tree__get_line(const konf_tree_t * instance);
+void konf_tree__set_depth(konf_tree_t * instance, int depth);
+int konf_tree__get_depth(const konf_tree_t * instance);
 
 #endif				/* _konf_tree_h */
 /** @} clish_conf */

+ 1 - 0
konf/tree/private.h

@@ -19,6 +19,7 @@ struct konf_tree_s {
 	unsigned short seq_num;
 	unsigned short sub_num;
 	bool_t splitter;
+	int depth;
 };
 
 #endif

+ 22 - 9
konf/tree/tree.c

@@ -78,6 +78,7 @@ konf_tree_init(konf_tree_t * this, const char *line, unsigned short priority)
 	this->seq_num = 0;
 	this->sub_num = KONF_ENTRY_OK;
 	this->splitter = BOOL_TRUE;
+	this->depth = -1;
 
 	/* Be a good binary tree citizen */
 	lub_bintree_node_init(&this->bt_node);
@@ -137,7 +138,7 @@ void konf_tree_delete(konf_tree_t * this)
 
 /*--------------------------------------------------------- */
 void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
-		const char *pattern, int depth,
+		const char *pattern, int top_depth,
 		bool_t seq, unsigned char prev_pri_hi)
 {
 	konf_tree_t *conf;
@@ -145,15 +146,16 @@ void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
 	unsigned char pri = 0;
 	regex_t regexp;
 
-	if (this->line && *(this->line) != '\0') {
+	if (this->line && (*(this->line) != '\0') &&
+		(this->depth > top_depth)) {
 		char *space = NULL;
-
-		if (depth > 0) {
-			space = malloc(depth + 1);
-			memset(space, ' ', depth);
-			space[depth] = '\0';
+		unsigned 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 == depth) &&
+		if ((0 == this->depth) &&
 			(this->splitter ||
 			(konf_tree__get_priority_hi(this) != prev_pri_hi)))
 			fprintf(stream, "!\n");
@@ -176,7 +178,7 @@ void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
 		conf; conf = lub_bintree_iterator_next(&iter)) {
 		if (pattern && (0 != regexec(&regexp, conf->line, 0, NULL, 0)))
 			continue;
-		konf_tree_fprintf(conf, stream, NULL, depth + 1, seq, pri);
+		konf_tree_fprintf(conf, stream, NULL, top_depth, seq, pri);
 		pri = konf_tree__get_priority_hi(conf);
 	}
 	if (pattern)
@@ -392,3 +394,14 @@ const char * konf_tree__get_line(const konf_tree_t * this)
 	return this->line;
 }
 
+/*--------------------------------------------------------- */
+void konf_tree__set_depth(konf_tree_t * this, int depth)
+{
+	this->depth = depth;
+}
+
+/*--------------------------------------------------------- */
+int konf_tree__get_depth(const konf_tree_t * this)
+{
+	return this->depth;
+}