|
@@ -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 *));
|
|
|
|
|
|
|
|
|
- tmp = realloc(query->pwd, new_size);
|
|
|
+ tmp = realloc(this->pwd, new_size);
|
|
|
assert(tmp);
|
|
|
- query->pwd = tmp;
|
|
|
+ this->pwd = tmp;
|
|
|
|
|
|
- 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);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
|
|
|
-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)
|
|
|
}
|
|
|
|
|
|
|
|
|
- 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;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
|
|
|
-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;
|
|
|
|
|
|
|
|
|
- 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;
|