Browse Source

Move query_dump to the separate file.

git-svn-id: https://klish.googlecode.com/svn/trunk@228 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
78e05e1934
6 changed files with 151 additions and 116 deletions
  1. 10 4
      Makefile.in
  2. 2 0
      konf/buf/buf.c
  3. 9 8
      konf/query.h
  4. 4 2
      konf/query/module.am
  5. 79 102
      konf/query/query.c
  6. 47 0
      konf/query/query_dump.c

+ 10 - 4
Makefile.in

@@ -246,7 +246,8 @@ am_libclish_la_OBJECTS = clish/libclish_la-clish_access_callback.lo \
 libclish_la_OBJECTS = $(am_libclish_la_OBJECTS)
 libkonf_la_DEPENDENCIES =
 am_libkonf_la_OBJECTS = konf/tree/tree.lo konf/tree/tree_dump.lo \
-	konf/query/query.lo konf/buf/buf.lo konf/net/net.lo
+	konf/query/query.lo konf/query/query_dump.lo konf/buf/buf.lo \
+	konf/net/net.lo
 libkonf_la_OBJECTS = $(am_libkonf_la_OBJECTS)
 liblub_la_DEPENDENCIES =
 am__liblub_la_SOURCES_DIST = lub/argv/argv__get_arg.c \
@@ -886,9 +887,9 @@ test_string_LDADD = \
     @BFD_LIBS@
 
 libkonf_la_SOURCES = konf/tree/tree.c konf/tree/tree_dump.c \
-	konf/tree/private.h konf/query/query.c konf/query/private.h \
-	konf/buf/buf.c konf/buf/private.h konf/net/net.c \
-	konf/net/private.h
+	konf/tree/private.h konf/query/query.c konf/query/query_dump.c \
+	konf/query/private.h konf/buf/buf.c konf/buf/private.h \
+	konf/net/net.c konf/net/private.h
 libkonf_la_LIBADD = 
 all: config.h
 	$(MAKE) $(AM_MAKEFLAGS) all-am
@@ -1202,6 +1203,8 @@ konf/query/$(DEPDIR)/$(am__dirstamp):
 	@: > konf/query/$(DEPDIR)/$(am__dirstamp)
 konf/query/query.lo: konf/query/$(am__dirstamp) \
 	konf/query/$(DEPDIR)/$(am__dirstamp)
+konf/query/query_dump.lo: konf/query/$(am__dirstamp) \
+	konf/query/$(DEPDIR)/$(am__dirstamp)
 konf/buf/$(am__dirstamp):
 	@$(MKDIR_P) konf/buf
 	@: > konf/buf/$(am__dirstamp)
@@ -1799,6 +1802,8 @@ mostlyclean-compile:
 	-rm -f konf/net/net.lo
 	-rm -f konf/query/query.$(OBJEXT)
 	-rm -f konf/query/query.lo
+	-rm -f konf/query/query_dump.$(OBJEXT)
+	-rm -f konf/query/query_dump.lo
 	-rm -f konf/tree/tree.$(OBJEXT)
 	-rm -f konf/tree/tree.lo
 	-rm -f konf/tree/tree_dump.$(OBJEXT)
@@ -2106,6 +2111,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@konf/buf/$(DEPDIR)/buf.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@konf/net/$(DEPDIR)/net.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@konf/query/$(DEPDIR)/query.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@konf/query/$(DEPDIR)/query_dump.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@konf/tree/$(DEPDIR)/tree.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@konf/tree/$(DEPDIR)/tree_dump.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv__get_arg.Plo@am__quote@

+ 2 - 0
konf/buf/buf.c

@@ -232,6 +232,7 @@ char * konf_buf_parse(konf_buf_t *buf)
 	return str;
 }
 
+/*--------------------------------------------------------- */
 char * konf_buf_preparse(konf_buf_t *buf)
 {
 	char * str = NULL;
@@ -243,6 +244,7 @@ char * konf_buf_preparse(konf_buf_t *buf)
 	return str;
 }
 
+/*--------------------------------------------------------- */
 int konf_buf_lseek(konf_buf_t *buf, int newpos)
 {
 	if (newpos > buf->pos)

+ 9 - 8
konf/query.h

@@ -16,15 +16,16 @@ typedef enum
 
 typedef struct konf_query_s konf_query_t;
 
-int konf_query_parse(konf_query_t *query, int argc, char **argv);
-int konf_query_parse_str(konf_query_t *query, char *str);
 konf_query_t *konf_query_new(void);
-void konf_query_free(konf_query_t *query);
-char *konf_query__get_pwd(konf_query_t *query, unsigned index);
-int konf_query__get_pwdc(konf_query_t *query);
-void konf_query_dump(konf_query_t *query);
-konf_query_op_t konf_query__get_op(konf_query_t *query);
-char * konf_query__get_path(konf_query_t *query);
+void konf_query_free(konf_query_t *instance);
+int konf_query_parse(konf_query_t *instance, int argc, char **argv);
+int konf_query_parse_str(konf_query_t *instance, char *str);
+void konf_query_dump(konf_query_t *instance);
+
+char *konf_query__get_pwd(konf_query_t *instance, unsigned index);
+int konf_query__get_pwdc(konf_query_t *instance);
+konf_query_op_t konf_query__get_op(konf_query_t *instance);
+char * konf_query__get_path(konf_query_t *instance);
 const char * konf_query__get_pattern(konf_query_t *instance);
 const char * konf_query__get_line(konf_query_t *instance);
 unsigned short konf_query__get_priority(konf_query_t *instance);

+ 4 - 2
konf/query/module.am

@@ -1,2 +1,4 @@
-libkonf_la_SOURCES +=	konf/query/query.c   \
-			konf/query/private.h
+libkonf_la_SOURCES += \
+	konf/query/query.c \
+	konf/query/query_dump.c \
+	konf/query/private.h

+ 79 - 102
konf/query/query.c

@@ -6,107 +6,73 @@
 #include <errno.h>
 #include <assert.h>
 
-#include "clish/private.h"
-#include "private.h"
 #include "lub/types.h"
 #include "lub/argv.h"
 #include "lub/string.h"
+#include "private.h"
 
+/*-------------------------------------------------------- */
 konf_query_t *konf_query_new(void)
 {
-	konf_query_t *query;
+	konf_query_t *this;
 
-	if (!(query = malloc(sizeof(*query))))
+	if (!(this = malloc(sizeof(*this))))
 		return NULL;
 
-	query->op = KONF_QUERY_OP_NONE;
-	query->pattern = NULL;
-	query->priority = 0;
-	query->seq = BOOL_FALSE;
-	query->seq_num = 0;
-	query->pwdc = 0;
-	query->pwd = NULL;
-	query->line = NULL;
-	query->path = NULL;
-	query->splitter = BOOL_TRUE;
-	query->unique = BOOL_TRUE;
-
-	return query;
-}
-
-void konf_query_dump(konf_query_t *query)
-{
-	switch (query->op) {
-	case KONF_QUERY_OP_SET:
-		printf("op=SET\n");
-		break;
-	case KONF_QUERY_OP_UNSET:
-		printf("op=UNSET\n");
-		break;
-	case KONF_QUERY_OP_DUMP:
-		printf("op=DUMP\n");
-		break;
-	case KONF_QUERY_OP_OK:
-		printf("op=OK\n");
-		break;
-	case KONF_QUERY_OP_ERROR:
-		printf("op=ERROR\n");
-		break;
-	case KONF_QUERY_OP_STREAM:
-		printf("op=STREAM\n");
-		break;
-	default:
-		printf("op=UNKNOWN\n");
-		break;
-	}
-	printf("pattern=%s\n", query->pattern);
-	printf("priority=%u\n", query->priority);
-	printf("sequence=%u\n", query->seq);
-	printf("seq_num=%u\n", query->seq_num);
-	printf("line=%s\n", query->line);
-	printf("path=%s\n", query->path);
-	printf("pwdc=%u\n", query->pwdc);
-	printf("splitter : %s\n", query->splitter ? "true" : "false");
-	printf("unique   : %s\n", query->unique ? "true" : "false");
+	this->op = KONF_QUERY_OP_NONE;
+	this->pattern = NULL;
+	this->priority = 0;
+	this->seq = BOOL_FALSE;
+	this->seq_num = 0;
+	this->pwdc = 0;
+	this->pwd = NULL;
+	this->line = NULL;
+	this->path = NULL;
+	this->splitter = BOOL_TRUE;
+	this->unique = BOOL_TRUE;
+
+	return this;
 }
 
-void konf_query_add_pwd(konf_query_t *query, char *str)
+/*-------------------------------------------------------- */
+void konf_query_add_pwd(konf_query_t *this, char *str)
 {
 	size_t new_size;
 	char **tmp;
 
-	if (!query)
+	if (!this)
 		return;
 
-	new_size = ((query->pwdc + 1) * sizeof(char *));
+	new_size = ((this->pwdc + 1) * sizeof(char *));
 
 	/* resize the pwd vector */
-	tmp = realloc(query->pwd, new_size);
+	tmp = realloc(this->pwd, new_size);
 	assert(tmp);
-	query->pwd = tmp;
+	this->pwd = tmp;
 	/* insert reference to the pwd component */
-	query->pwd[query->pwdc++] = lub_string_dup(str);
+	this->pwd[this->pwdc++] = lub_string_dup(str);
 }
 
-
-void konf_query_free(konf_query_t *query)
+/*-------------------------------------------------------- */
+void konf_query_free(konf_query_t *this)
 {
 	unsigned i;
 
-	lub_string_free(query->pattern);
-	lub_string_free(query->line);
-	lub_string_free(query->path);
-	if (query->pwdc > 0) {
-		for (i = 0; i < query->pwdc; i++)
-			lub_string_free(query->pwd[i]);
-		free(query->pwd);
+	lub_string_free(this->pattern);
+	lub_string_free(this->line);
+	lub_string_free(this->path);
+	if (this->pwdc > 0) {
+		for (i = 0; i < this->pwdc; i++)
+			lub_string_free(this->pwd[i]);
+		free(this->pwd);
 	}
 
-	free(query);
+	free(this);
 }
 
+/*-------------------------------------------------------- */
 /* Parse query */
-int konf_query_parse(konf_query_t *query, int argc, char **argv)
+int konf_query_parse(konf_query_t *this, int argc, char **argv)
 {
 	unsigned i = 0;
 	int pwdc = 0;
@@ -139,22 +105,22 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 			break;
 		switch (opt) {
 		case 'o':
-			query->op = KONF_QUERY_OP_OK;
+			this->op = KONF_QUERY_OP_OK;
 			break;
 		case 'e':
-			query->op = KONF_QUERY_OP_ERROR;
+			this->op = KONF_QUERY_OP_ERROR;
 			break;
 		case 's':
-			query->op = KONF_QUERY_OP_SET;
+			this->op = KONF_QUERY_OP_SET;
 			break;
 		case 'u':
-			query->op = KONF_QUERY_OP_UNSET;
+			this->op = KONF_QUERY_OP_UNSET;
 			break;
 		case 'd':
-			query->op = KONF_QUERY_OP_DUMP;
+			this->op = KONF_QUERY_OP_DUMP;
 			break;
 		case 't':
-			query->op = KONF_QUERY_OP_STREAM;
+			this->op = KONF_QUERY_OP_STREAM;
 			break;
 		case 'p':
 			{
@@ -166,7 +132,7 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 				break;
 			if ((val > 0xffff) || (val < 0))
 				break;
-			query->priority = (unsigned short)val;
+			this->priority = (unsigned short)val;
 			break;
 			}
 		case 'q':
@@ -174,29 +140,29 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 			long val = 0;
 			char *endptr;
 
-			query->seq = BOOL_TRUE;
+			this->seq = BOOL_TRUE;
 			val = strtol(optarg, &endptr, 0);
 			if (endptr == optarg)
 				break;
 			if ((val > 0xffff) || (val < 0))
 				break;
-			query->seq_num = (unsigned short)val;
+			this->seq_num = (unsigned short)val;
 			break;
 			}
 		case 'r':
-			query->pattern = lub_string_dup(optarg);
+			this->pattern = lub_string_dup(optarg);
 			break;
 		case 'l':
-			query->line = lub_string_dup(optarg);
+			this->line = lub_string_dup(optarg);
 			break;
 		case 'f':
-			query->path = lub_string_dup(optarg);
+			this->path = lub_string_dup(optarg);
 			break;
 		case 'i':
-			query->splitter = BOOL_FALSE;
+			this->splitter = BOOL_FALSE;
 			break;
 		case 'n':
-			query->unique = BOOL_FALSE;
+			this->unique = BOOL_FALSE;
 			break;
 		default:
 			break;
@@ -204,12 +170,12 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 	}
 
 	/* Check options */
-	if (KONF_QUERY_OP_NONE == query->op)
+	if (KONF_QUERY_OP_NONE == this->op)
 		return -1;
-	if (KONF_QUERY_OP_SET == query->op) {
-		if (NULL == query->pattern)
+	if (KONF_QUERY_OP_SET == this->op) {
+		if (NULL == this->pattern)
 			return -1;
-		if (NULL == query->line)
+		if (NULL == this->line)
 			return -1;
 	}
 
@@ -217,13 +183,14 @@ int konf_query_parse(konf_query_t *query, int argc, char **argv)
 		return -1;
 
 	for (i = 0; i < pwdc; i ++)
-		konf_query_add_pwd(query, argv[optind + i]);
+		konf_query_add_pwd(this, argv[optind + i]);
 
 	return 0;
 }
 
+/*-------------------------------------------------------- */
 /* Parse query string */
-int konf_query_parse_str(konf_query_t *query, char *str)
+int konf_query_parse_str(konf_query_t *this, char *str)
 {
 	int res;
 	lub_argv_t *lub_argv;
@@ -236,69 +203,79 @@ int konf_query_parse_str(konf_query_t *query, char *str)
 	str_argc = lub_argv__get_count(lub_argv) + 1;
 
 	/* Parse query */
-	res = konf_query_parse(query, str_argc, str_argv);
+	res = konf_query_parse(this, str_argc, str_argv);
 	free(str_argv);
 	lub_argv_delete(lub_argv);
 
 	return res;
 }
 
-char * konf_query__get_pwd(konf_query_t *query, unsigned index)
+/*-------------------------------------------------------- */
+char * konf_query__get_pwd(konf_query_t *this, unsigned index)
 {
-	if (!query)
+	if (!this)
 		return NULL;
-	if (index >= query->pwdc)
+	if (index >= this->pwdc)
 		return NULL;
 
-	return query->pwd[index];
+	return this->pwd[index];
 }
 
-int konf_query__get_pwdc(konf_query_t *query)
+/*-------------------------------------------------------- */
+int konf_query__get_pwdc(konf_query_t *this)
 {
-	return query->pwdc;
+	return this->pwdc;
 }
 
-konf_query_op_t konf_query__get_op(konf_query_t *query)
+/*-------------------------------------------------------- */
+konf_query_op_t konf_query__get_op(konf_query_t *this)
 {
-	return query->op;
+	return this->op;
 }
 
-char * konf_query__get_path(konf_query_t *query)
+/*-------------------------------------------------------- */
+char * konf_query__get_path(konf_query_t *this)
 {
-	return query->path;
+	return this->path;
 }
 
-
+/*-------------------------------------------------------- */
 const char * konf_query__get_pattern(konf_query_t *this)
 {
 	return this->pattern;
 }
 
+/*-------------------------------------------------------- */
 const char * konf_query__get_line(konf_query_t *this)
 {
 	return this->line;
 }
 
+/*-------------------------------------------------------- */
 unsigned short konf_query__get_priority(konf_query_t *this)
 {
 	return this->priority;
 }
 
+/*-------------------------------------------------------- */
 bool_t konf_query__get_splitter(konf_query_t *this)
 {
 	return this->splitter;
 }
 
+/*-------------------------------------------------------- */
 bool_t konf_query__get_seq(konf_query_t *this)
 {
 	return this->seq;
 }
 
+/*-------------------------------------------------------- */
 unsigned short konf_query__get_seq_num(konf_query_t *this)
 {
 	return this->seq_num;
 }
 
+/*-------------------------------------------------------- */
 bool_t konf_query__get_unique(konf_query_t *this)
 {
 	return this->unique;

+ 47 - 0
konf/query/query_dump.c

@@ -0,0 +1,47 @@
+#include "private.h"
+#include "lub/dump.h"
+
+/*-------------------------------------------------------- */
+void konf_query_dump(konf_query_t *this)
+{
+	const char *op;
+
+	lub_dump_printf("query(%p)\n", this);
+	lub_dump_indent();
+
+	switch (this->op) {
+	case KONF_QUERY_OP_SET:
+		op = "SET";
+		break;
+	case KONF_QUERY_OP_UNSET:
+		op = "UNSET";
+		break;
+	case KONF_QUERY_OP_DUMP:
+		op = "DUMP";
+		break;
+	case KONF_QUERY_OP_OK:
+		op = "OK";
+		break;
+	case KONF_QUERY_OP_ERROR:
+		op = "ERROR";
+		break;
+	case KONF_QUERY_OP_STREAM:
+		op = "STREAM";
+		break;
+	default:
+		op = "UNKNOWN";
+		break;
+	}
+	lub_dump_printf("operation : %s\n", op);
+	lub_dump_printf("pattern   : %s\n", this->pattern);
+	lub_dump_printf("priority  : %u\n", this->priority);
+	lub_dump_printf("sequence  : %u\n", this->seq);
+	lub_dump_printf("seq_num   : %u\n", this->seq_num);
+	lub_dump_printf("line      : %s\n", this->line);
+	lub_dump_printf("path      : %s\n", this->path);
+	lub_dump_printf("pwdc      : %u\n", this->pwdc);
+	lub_dump_printf("splitter  : %s\n", this->splitter ? "true" : "false");
+	lub_dump_printf("unique    : %s\n", this->unique ? "true" : "false");
+
+	lub_dump_undent();
+}