const struct ec_node *node;
char *str;
char *display;
+ /* XXX add a keyval (attrs) */
/* reverse order: [0] = last, [len-1] = root */
const struct ec_node **path;
#include <ecoli_test.h>
#include <ecoli_keyval.h>
+EC_LOG_TYPE_REGISTER(keyval);
+
struct ec_keyval_elt {
char *key;
void *val;
keyval = ec_keyval();
if (keyval == NULL) {
- ec_log(EC_LOG_ERR, "cannot create keyval\n");
+ EC_LOG(EC_LOG_ERR, "cannot create keyval\n");
return -1;
}
#include <string.h>
#include <errno.h>
+#include <ecoli_malloc.h>
#include <ecoli_log.h>
static ec_log_t ec_log_fct = ec_log_default;
static void *ec_log_opaque;
-int ec_log_default(unsigned int level, void *opaque, const char *str)
+struct ec_log_type {
+ char *name;
+ unsigned int level;
+};
+
+static struct ec_log_type *log_types;
+static size_t log_types_len;
+
+int ec_log_default(int type, unsigned int level, void *opaque, const char *str)
{
(void)opaque;
- (void)level;
- return printf("%s", str);
+ return printf("[%d] %-12s %s", level, ec_log_name(type), str);
}
-int ec_log_register(ec_log_t usr_log, void *opaque)
+int ec_log_fct_register(ec_log_t usr_log, void *opaque)
{
if (usr_log == NULL)
return -1;
return 0;
}
-void ec_log_unregister(void)
+void ec_log_fct_unregister(void)
{
ec_log_fct = NULL;
}
-int ec_vlog(unsigned int level, const char *format, va_list ap)
+static int
+ec_log_lookup(const char *name)
+{
+ size_t i;
+
+ for (i = 0; i < log_types_len; i++) {
+ if (log_types[i].name == NULL)
+ continue;
+ if (strcmp(name, log_types[i].name) == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+const char *
+ec_log_name(int type)
+{
+ if (type < 0 || (unsigned int)type >= log_types_len)
+ return "unknown";
+ return log_types[type].name;
+}
+
+int
+ec_log_type_register(const char *name)
+{
+ struct ec_log_type *new_types;
+ char *copy;
+ int id;
+
+ id = ec_log_lookup(name);
+ if (id >= 0)
+ return id;
+
+ new_types = ec_realloc(log_types,
+ sizeof(*new_types) * (log_types_len + 1));
+ if (new_types == NULL)
+ return -ENOMEM;
+ log_types = new_types;
+
+ copy = ec_strdup(name);
+ if (copy == NULL)
+ return -ENOMEM;
+
+ id = log_types_len++;
+ log_types[id].name = copy;
+ log_types[id].level = EC_LOG_DEBUG;
+
+ return id;
+}
+
+int ec_vlog(int type, unsigned int level, const char *format, va_list ap)
{
char *s;
int ret;
if (ret < 0)
return ret;
- ret = ec_log_fct(level, ec_log_opaque, s);
+ ret = ec_log_fct(type, level, ec_log_opaque, s);
free(s);
return ret;
}
-int ec_log(unsigned int level, const char *format, ...)
+int ec_log(int type, unsigned int level, const char *format, ...)
{
va_list ap;
int ret;
va_start(ap, format);
- ret = ec_vlog(level, format, ap);
+ ret = ec_vlog(type, level, format, ap);
va_end(ap);
return ret;
#include <stdarg.h>
+#define EC_LOG_TYPE_REGISTER(name) \
+ static int name##_log_type; \
+ static int local_log_type; \
+ __attribute__((constructor, used)) \
+ static void ec_log_register_##name(void) \
+ { \
+ local_log_type = ec_log_type_register(#name); \
+ name##_log_type = local_log_type; \
+ }
+
+
/* return -1 on error, len(s) on success */
-typedef int (*ec_log_t)(unsigned int level, void *opaque, const char *str);
+typedef int (*ec_log_t)(int type, unsigned int level, void *opaque,
+ const char *str);
+
+int ec_log_fct_register(ec_log_t usr_log, void *opaque);
+void ec_log_fct_unregister(void);
-int ec_log_register(ec_log_t usr_log, void *opaque);
-void ec_log_unregister(void);
+int ec_log_type_register(const char *name);
+
+const char *ec_log_name(int type);
/* same api than printf */
-int ec_log(unsigned int level, const char *format, ...)
- __attribute__((format(__printf__, 2, 3)));
+int ec_log(int type, unsigned int level, const char *format, ...)
+ __attribute__((format(__printf__, 3, 4)));
+
+int ec_vlog(int type, unsigned int level, const char *format, va_list ap);
-int ec_vlog(unsigned int level, const char *format, va_list ap);
+/* to use the macros, the user must have called EC_LOG_TYPE_REGISTER */
+#define EC_LOG(level, args...) ec_log(local_log_type, level, args)
+#define EC_VLOG(level, fmt, ap) ec_vlog(local_log_type, level, fmt, ap)
/* default log handler for the library, use printf */
-int ec_log_default(unsigned int level, void *opaque, const char *str);
+int ec_log_default(int type, unsigned int level, void *opaque, const char *str);
#endif
#include <ecoli_log.h>
#include <ecoli_node.h>
+EC_LOG_TYPE_REGISTER(node);
+
static struct ec_node_type_list node_type_list =
TAILQ_HEAD_INITIALIZER(node_type_list);
struct ec_node *node = NULL;
char buf[256]; // XXX
- ec_log(EC_LOG_DEBUG, "create node type=%s id=%s\n",
+ EC_LOG(EC_LOG_DEBUG, "create node type=%s id=%s\n",
type->name, id);
node = ec_calloc(1, type->size);
type = ec_node_type_lookup(typename);
if (type == NULL) {
- ec_log(EC_LOG_ERR, "type=%s does not exist\n", typename);
+ EC_LOG(EC_LOG_ERR, "type=%s does not exist\n",
+ typename);
return NULL;
}
#include <ecoli_node_re_lex.h>
#include <ecoli_node_cmd.h>
+EC_LOG_TYPE_REGISTER(node_cmd);
+
struct ec_node_cmd {
struct ec_node gen;
char *cmd_str; /* the command string. */
ec_node_int("y", 20, 30, 10)
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 2, "command", "1");
node = EC_NODE_CMD(NULL, "good morning [count] bob|bobby|michael",
ec_node_int("count", 0, 10, 10));
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 4, "good", "morning", "1", "bob");
#include <ecoli_completed.h>
#include <ecoli_node_empty.h>
+EC_LOG_TYPE_REGISTER(node_empty);
+
struct ec_node_empty {
struct ec_node gen;
};
node = ec_node("empty", NULL);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 0, "foo");
/* never completes */
node = ec_node("empty", NULL);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_weakref.h>
#include <ecoli_node_expr.h>
+EC_LOG_TYPE_REGISTER(node_expr);
+
struct ec_node_expr {
struct ec_node gen;
struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
unsigned int i;
- ec_log(EC_LOG_DEBUG, "free %p %p %p\n", node, node->child, node->val_node);
+ EC_LOG(EC_LOG_DEBUG, "free %p %p %p\n", node, node->child, node->val_node);
ec_node_free(node->val_node);
for (i = 0; i < node->bin_ops_len; i++)
#include <ecoli_node_re_lex.h>
#include <ecoli_node_expr.h>
+EC_LOG_TYPE_REGISTER(node_expr);
+
struct my_eval_result {
int val;
};
#include <ecoli_completed.h>
#include <ecoli_node_file.h>
+EC_LOG_TYPE_REGISTER(node_file);
+
struct ec_node_file {
struct ec_node gen;
};
node = ec_node("file", NULL);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
/* any string matches */
#include <ecoli_node_int.h>
#include <ecoli_test.h>
+EC_LOG_TYPE_REGISTER(node_int);
+
struct ec_node_int {
struct ec_node gen;
bool check_min;
node = ec_node_int(NULL, 0, 256, 0);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "0");
node = ec_node_int(NULL, -1, LLONG_MAX, 16);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "0");
node = ec_node_int(NULL, LLONG_MIN, 0, 10);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "0");
/* test completion */
node = ec_node_int(NULL, 0, 10, 0);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_option.h>
#include <ecoli_node_many.h>
+EC_LOG_TYPE_REGISTER(node_many);
+
struct ec_node_many {
struct ec_node gen;
unsigned int min;
node = ec_node_many(NULL, ec_node_str(NULL, "foo"), 0, 0);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 0);
node = ec_node_many(NULL, ec_node_str(NULL, "foo"), 1, 0);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, -1, "bar");
node = ec_node_many(NULL, ec_node_str(NULL, "foo"), 1, 2);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, -1, "bar");
/* test completion */
node = ec_node_many(NULL, ec_node_str(NULL, "foo"), 2, 4);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_many.h>
#include <ecoli_node_once.h>
+EC_LOG_TYPE_REGISTER(node_once);
+
struct ec_node_once {
struct ec_node gen;
struct ec_node *child;
), 0, 0
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 0);
ec_node_str(NULL, "titi")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_str.h>
#include <ecoli_test.h>
+EC_LOG_TYPE_REGISTER(node_option);
+
struct ec_node_option {
struct ec_node gen;
struct ec_node *child;
node = ec_node_option(NULL, ec_node_str(NULL, "foo"));
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
/* test completion */
node = ec_node_option(NULL, ec_node_str(NULL, "foo"));
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_str.h>
#include <ecoli_test.h>
+EC_LOG_TYPE_REGISTER(node_or);
+
struct ec_node_or {
struct ec_node gen;
struct ec_node **table;
ec_node_str(NULL, "bar")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
ec_node_str(NULL, "titi")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_completed.h>
#include <ecoli_node_re.h>
+EC_LOG_TYPE_REGISTER(node_re);
+
struct ec_node_re {
struct ec_node gen;
char *re_str;
node = ec_node_re(NULL, "fo+|bar");
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
#include <ecoli_node_int.h>
#include <ecoli_node_re_lex.h>
+EC_LOG_TYPE_REGISTER(node_re_lex);
+
struct regexp_pattern {
char *pattern;
regex_t r;
c = dup[pos.rm_eo + off];
dup[pos.rm_eo + off] = '\0';
- ec_log(EC_LOG_DEBUG, "re_lex match <%s>\n", &dup[off]);
+ EC_LOG(EC_LOG_DEBUG, "re_lex match <%s>\n", &dup[off]);
if (ec_strvec_add(strvec, &dup[off]) < 0)
goto fail;
ret = regcomp(&table[node->len].r, pattern, REG_EXTENDED);
if (ret != 0) {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"Regular expression <%s> compilation failed: %d\n",
pattern, ret);
if (ret == REG_ESPACE)
)
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= ec_node_re_lex_add(node, "\\+", 1);
ret |= ec_node_re_lex_add(node, "[ ]+", 0);
if (ret != 0) {
- ec_log(EC_LOG_ERR, "cannot add regexp to node\n");
+ EC_LOG(EC_LOG_ERR, "cannot add regexp to node\n");
ec_node_free(node);
return -1;
}
#include <ecoli_node_many.h>
#include <ecoli_node_seq.h>
+EC_LOG_TYPE_REGISTER(node_seq);
+
struct ec_node_seq {
struct ec_node gen;
struct ec_node **table;
ec_node_str(NULL, "bar")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
ec_node_str(NULL, "bar")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_option.h>
#include <ecoli_node_sh_lex.h>
+EC_LOG_TYPE_REGISTER(node_sh_lex);
+
struct ec_node_sh_lex {
struct ec_node gen;
struct ec_node *child;
char *word = NULL, *concat = NULL, *tmp;
int last_is_space = 1;
-// printf("str=%s\n", str);
-
strvec = ec_strvec();
if (strvec == NULL)
goto fail;
len = eat_spaces(&str[off]);
if (len > 0)
last_is_space = 1;
-// printf("space=%zd\n", len);
off += len;
len = 0;
last_is_space = 0;
if (str[suboff] == '"' || str[suboff] == '\'') {
sublen = eat_quoted_str(&str[suboff]);
-// printf("sublen=%zd\n", sublen);
word = unquote_str(&str[suboff], sublen,
allow_missing_quote, missing_quote);
} else {
sublen = eat_str(&str[suboff]);
-// printf("sublen=%zd\n", sublen);
if (sublen == 0)
break;
word = ec_strndup(&str[suboff], sublen);
if (word == NULL)
goto fail;
-// printf("word=%s\n", word);
len += sublen;
suboff += sublen;
goto fail;
// printf("new:%s\n", ec_strvec_val(new_vec, 0));
- // XXX: complete should add the quotes for !EC_PARTIAL: use another
- // completed object
+ // XXX: complete should add the quotes for !EC_PARTIAL
+ // XXX: if no quotes, replace " " by "\ "
ret = ec_node_complete_child(node->child, completed, parsed, new_vec);
if (ret < 0)
goto fail;
)
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "foo bar");
)
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_completed.h>
#include <ecoli_node_space.h>
+EC_LOG_TYPE_REGISTER(node_space);
+
struct ec_node_space {
struct ec_node gen;
};
node = ec_node("space", NULL);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, " ");
/* test completion */
node = ec_node("space", NULL);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
/* never completes whatever the input */
#include <ecoli_completed.h>
#include <ecoli_node_str.h>
+EC_LOG_TYPE_REGISTER(node_str);
+
struct ec_node_str {
struct ec_node gen;
char *string;
/* XXX use EC_NO_ID instead of NULL */
node = ec_node_str(NULL, "foo");
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
node = ec_node_str(NULL, "Здравствуйте");
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "Здравствуйте");
/* an empty string node always matches */
node = ec_node_str(NULL, "");
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 1, "");
/* test completion */
node = ec_node_str(NULL, "foo");
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_or.h>
#include <ecoli_test.h>
+EC_LOG_TYPE_REGISTER(node_subset);
+
struct ec_node_subset {
struct ec_node gen;
struct ec_node **table;
ec_node_str(NULL, "toto")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 0);
ec_node_str(NULL, "titi")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
#include <ecoli_node_option.h>
#include <ecoli_node_weakref.h>
+EC_LOG_TYPE_REGISTER(node_weakref);
+
struct ec_node_weakref {
struct ec_node gen;
struct ec_node *child;
/*
node == NULL + empty children list means "no match"
+ XXX still valid?
*/
struct ec_parsed {
TAILQ_ENTRY(ec_parsed) next;
struct ec_parsed *parent;
const struct ec_node *node;
struct ec_strvec *strvec;
+ /* XXX add a keyval (attrs) */
};
struct ec_parsed *ec_parsed(void);
/* XXX we could use a cache to store possible completions or match: the
* cache would be per-node, and would be reset for each call to parse()
- * or complete() ? */
+ * or complete() ? ... not sure, since parse result can depend on state
+ */
/* a NULL return value is an error, with errno set
ENOTSUP: no ->parse() operation
*/
static struct ec_test_list test_list = TAILQ_HEAD_INITIALIZER(test_list);
+EC_LOG_TYPE_REGISTER(test);
+
/* register a driver */
void ec_test_register(struct ec_test *test)
{
p = ec_node_parse_strvec(tk, vec);
ec_parsed_dump(stdout, p); /* XXX only for debug */
if (p == NULL) {
- ec_log(EC_LOG_ERR, "parsed is NULL\n");
+ EC_LOG(EC_LOG_ERR, "parsed is NULL\n");
}
if (ec_parsed_matches(p))
match = ec_parsed_len(p);
if (expected == match) {
ret = 0;
} else {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"tk parsed len (%d) does not match expected (%d)\n",
match, expected);
}
}
if (item == NULL) {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"completion <%s> not in list\n", s);
ret = -1;
}
/* check if we have more completions (or less) than expected */
if (count != ec_completed_count(c, EC_MATCH)) {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"nb_completion (%d) does not match (%d)\n",
count, ec_completed_count(c, EC_MATCH));
ec_completed_dump(stdout, c);
if (name != NULL && strcmp(name, test->name))
continue;
- ec_log(EC_LOG_INFO, "== starting test %-20s\n", test->name);
+ EC_LOG(EC_LOG_INFO, "== starting test %-20s\n",
+ test->name);
count++;
if (test->test() == 0) {
- ec_log(EC_LOG_INFO, "== test %-20s success\n",
+ EC_LOG(EC_LOG_INFO,
+ "== test %-20s success\n",
test->name);
} else {
- ec_log(EC_LOG_INFO, "== test %-20s failed\n",
+ EC_LOG(EC_LOG_INFO,
+ "== test %-20s failed\n",
test->name);
ret = -1;
}
}
if (name != NULL && count == 0) {
- ec_log(EC_LOG_WARNING, "== test %s not found\n", name);
+ EC_LOG(EC_LOG_WARNING,
+ "== test %s not found\n", name);
ret = -1;
}
int ec_test_check_parse(struct ec_node *node, int expected, ...);
#define EC_TEST_ERR(fmt, ...) \
- ec_log(EC_LOG_ERR, "%s:%d: error: " fmt "\n", \
+ EC_LOG(EC_LOG_ERR, "%s:%d: error: " fmt "\n", \
__FILE__, __LINE__, ##__VA_ARGS__); \
-#define EC_TEST_ASSERT(cond, args...) \
+#define EC_TEST_ASSERT(cond) \
do { \
if (!(cond)) \
EC_TEST_ERR("assertion failure: " #cond); \
#include <ecoli_test.h>
#include <ecoli_vec.h>
+EC_LOG_TYPE_REGISTER(vec);
+
struct ec_vec {
size_t len;
size_t size;
}
#define GOTO_FAIL do { \
- ec_log(EC_LOG_ERR, "%s:%d: test failed\n", \
+ EC_LOG(EC_LOG_ERR, "%s:%d: test failed\n", \
__FILE__, __LINE__); \
goto fail; \
} while(0)
helps[i++] = get_node_help(compnode);
}
- ec_completed_dump(stdout, c);
ec_completed_free(c);
rl_display_match_list(helps, count + match, 1000); /* XXX 1000 */
#include <ecoli_test.h>
#include <ecoli_malloc.h>
+EC_LOG_TYPE_REGISTER(main);
+
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / \
((size_t)(!(sizeof(x) % sizeof(0[x])))))
ftr->cookie = 0x87654321;
}
- ec_log(EC_LOG_DEBUG, "%s:%d: info: malloc(%zd) -> %p\n",
+ EC_LOG(EC_LOG_DEBUG, "%s:%d: info: malloc(%zd) -> %p\n",
file, line, size, ret);
if (ret)
(void)file;
(void)line;
- ec_log(EC_LOG_DEBUG, "%s:%d: info: free(%p)\n", file, line, ptr);
+ EC_LOG(EC_LOG_DEBUG, "%s:%d: info: free(%p)\n", file, line, ptr);
if (ptr == NULL)
return;
hdr = (ptr - sizeof(*hdr));
if (hdr->cookie != 0x12345678) {
- ec_log(EC_LOG_ERR, "%s:%d: error: free(%p): bad start cookie\n",
+ EC_LOG(EC_LOG_ERR, "%s:%d: error: free(%p): bad start cookie\n",
file, line, ptr);
abort();
}
ftr = (ptr + hdr->size);
if (ftr->cookie != 0x87654321) {
- ec_log(EC_LOG_ERR, "%s:%d: error: free(%p): bad end cookie\n",
+ EC_LOG(EC_LOG_ERR, "%s:%d: error: free(%p): bad end cookie\n",
file, line, ptr);
abort();
}
}
if (h == NULL) {
- ec_log(EC_LOG_ERR, "%s:%d: error: free(%p): bad ptr\n",
+ EC_LOG(EC_LOG_ERR, "%s:%d: error: free(%p): bad ptr\n",
file, line, ptr);
abort();
}
if (ptr != NULL) {
hdr = (ptr - sizeof(*hdr));
if (hdr->cookie != 0x12345678) {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"%s:%d: error: realloc(%p): bad start cookie\n",
file, line, ptr);
abort();
ftr = (ptr + hdr->size);
if (ftr->cookie != 0x87654321) {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"%s:%d: error: realloc(%p): bad end cookie\n",
file, line, ptr);
abort();
}
if (h == NULL) {
- ec_log(EC_LOG_ERR, "%s:%d: error: realloc(%p): bad ptr\n",
+ EC_LOG(EC_LOG_ERR, "%s:%d: error: realloc(%p): bad ptr\n",
file, line, ptr);
abort();
}
ftr->cookie = 0x87654321;
}
- ec_log(EC_LOG_DEBUG, "%s:%d: info: realloc(%p, %zd) -> %p\n",
+ EC_LOG(EC_LOG_DEBUG, "%s:%d: info: realloc(%p, %zd) -> %p\n",
file, line, ptr, size, ret);
if (ret)
int i;
char **buffer;
- ec_log(EC_LOG_INFO, "%zd successful allocations\n", alloc_success);
+ EC_LOG(EC_LOG_INFO, "%zd successful allocations\n", alloc_success);
if (TAILQ_EMPTY(&debug_alloc_hdr_list))
return 0;
TAILQ_FOREACH(hdr, &debug_alloc_hdr_list, next) {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"%s:%d: error: memory leak size=%zd ptr=%p\n",
hdr->file, hdr->line, hdr->size, hdr + 1);
buffer = backtrace_symbols(hdr->stack, hdr->stacklen);
if (buffer == NULL) {
for (i = 0; i < hdr->stacklen; i++)
- ec_log(EC_LOG_ERR, " %p\n", hdr->stack[i]);
+ EC_LOG(EC_LOG_ERR, " %p\n", hdr->stack[i]);
} else {
for (i = 0; i < hdr->stacklen; i++)
- ec_log(EC_LOG_ERR, " %s\n",
+ EC_LOG(EC_LOG_ERR, " %s\n",
buffer ? buffer[i] : "unknown");
}
free(buffer);
}
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
" missing static syms, use: addr2line -f -e <prog> <addr>\n");
return -1;
}
-static int debug_log(unsigned int level, void *opaque, const char *str)
+static int debug_log(int type, unsigned int level, void *opaque,
+ const char *str)
{
+ (void)type;
(void)opaque;
if (level > (unsigned int)log_level)
srandom(seed);
- ec_log_register(debug_log, NULL);
+ if (0) ec_log_fct_register(debug_log, NULL);
/* register a new malloc to track memleaks */
TAILQ_INIT(&debug_alloc_hdr_list);
if (ec_malloc_register(debug_malloc, debug_free, debug_realloc) < 0) {
- ec_log(EC_LOG_ERR, "cannot register new malloc\n");
+ EC_LOG(EC_LOG_ERR, "cannot register new malloc\n");
return -1;
}
cleanup / rework
================
-- ec_completed_item_update()
-- ec_completed_item_set_display_value()
-
- add_no_match
- add_partial_match
- check XXX in code