diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-debug.c | 2 | ||||
-rw-r--r-- | src/core/wee-infolist.c | 50 | ||||
-rw-r--r-- | src/core/wee-infolist.h | 2 |
3 files changed, 20 insertions, 34 deletions
diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c index abf39e278..d9bdec6eb 100644 --- a/src/core/wee-debug.c +++ b/src/core/wee-debug.c @@ -611,6 +611,8 @@ debug_infolists () case INFOLIST_TIME: size_data += sizeof (time_t); break; + case INFOLIST_NUM_TYPES: + break; } } } diff --git a/src/core/wee-infolist.c b/src/core/wee-infolist.c index ea86ac2ab..091faa4c0 100644 --- a/src/core/wee-infolist.c +++ b/src/core/wee-infolist.c @@ -35,6 +35,10 @@ struct t_infolist *weechat_infolists = NULL; struct t_infolist *last_weechat_infolist = NULL; +char *infolist_type_char_string[INFOLIST_NUM_TYPES] = { + "i", "s", "p", "b", "t", +}; + /* * Creates a new infolist. @@ -391,7 +395,7 @@ const char * infolist_fields (struct t_infolist *infolist) { struct t_infolist_var *ptr_var; - int length; + char **fields; if (!infolist || !infolist->ptr_item) return NULL; @@ -400,44 +404,20 @@ infolist_fields (struct t_infolist *infolist) if (infolist->ptr_item->fields) return infolist->ptr_item->fields; - length = 0; - for (ptr_var = infolist->ptr_item->vars; - ptr_var; ptr_var = ptr_var->next_var) - { - length += strlen (ptr_var->name) + 3; - } - - infolist->ptr_item->fields = malloc (length + 1); - if (!infolist->ptr_item->fields) + fields = string_dyn_alloc (256); + if (!fields) return NULL; - infolist->ptr_item->fields[0] = '\0'; - for (ptr_var = infolist->ptr_item->vars; ptr_var; - ptr_var = ptr_var->next_var) + for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { - switch (ptr_var->type) - { - case INFOLIST_INTEGER: - strcat (infolist->ptr_item->fields, "i:"); - break; - case INFOLIST_STRING: - strcat (infolist->ptr_item->fields, "s:"); - break; - case INFOLIST_POINTER: - strcat (infolist->ptr_item->fields, "p:"); - break; - case INFOLIST_BUFFER: - strcat (infolist->ptr_item->fields, "b:"); - break; - case INFOLIST_TIME: - strcat (infolist->ptr_item->fields, "t:"); - break; - } - strcat (infolist->ptr_item->fields, ptr_var->name); - if (ptr_var->next_var) - strcat (infolist->ptr_item->fields, ","); + if (*fields[0]) + string_dyn_concat (fields, ",", -1); + string_dyn_concat (fields, infolist_type_char_string[ptr_var->type], -1); + string_dyn_concat (fields, ":", -1); + string_dyn_concat (fields, ptr_var->name, -1); } + infolist->ptr_item->fields = string_dyn_free (fields, 0); return infolist->ptr_item->fields; } @@ -785,6 +765,8 @@ infolist_print_log () case INFOLIST_TIME: log_printf (" value (time) . . . . : %lld", (long long)(*((time_t *)ptr_var->value))); break; + case INFOLIST_NUM_TYPES: + break; } log_printf (" prev_var . . . . . . : 0x%lx", ptr_var->prev_var); log_printf (" next_var . . . . . . : 0x%lx", ptr_var->next_var); diff --git a/src/core/wee-infolist.h b/src/core/wee-infolist.h index 43ac43ccb..b4d2589a6 100644 --- a/src/core/wee-infolist.h +++ b/src/core/wee-infolist.h @@ -33,6 +33,8 @@ enum t_infolist_type INFOLIST_POINTER, INFOLIST_BUFFER, INFOLIST_TIME, + /* number of infolist types */ + INFOLIST_NUM_TYPES, }; struct t_infolist_var |