diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-06-13 12:31:19 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-06-13 12:31:19 +0200 |
commit | 756252b95cb1b1988891c7a7525378c8feaa5f8e (patch) | |
tree | c05f80e6919907e5b69f072d3bf9f21d446506bf | |
parent | 41261875743002bbaad8fe90fb2bb9c657a0fb41 (diff) | |
download | weechat-756252b95cb1b1988891c7a7525378c8feaa5f8e.zip |
core: add string representation for types pointer, buffer and time in properties "keys", "values" and "keys_values"
-rw-r--r-- | src/core/wee-hashtable.c | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c index 6fc09a00d..57c9c510f 100644 --- a/src/core/wee-hashtable.c +++ b/src/core/wee-hashtable.c @@ -480,7 +480,7 @@ hashtable_compute_length_keys_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { - char str_int[64]; + char str_value[128]; int *length; /* make C compiler happy */ @@ -491,15 +491,21 @@ hashtable_compute_length_keys_cb (void *data, switch (hashtable->type_keys) { case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)key)); - *length += strlen (str_int) + 1; + snprintf (str_value, sizeof (str_value), "%d", *((int *)key)); + *length += strlen (str_value) + 1; break; case HASHTABLE_STRING: *length += strlen ((char *)key) + 1; break; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: + snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)key); + *length += strlen (str_value) + 1; + break; case HASHTABLE_TIME: + snprintf (str_value, sizeof (str_value), "%ld", (long)(*((time_t *)key))); + *length += strlen (str_value) + 1; + break; case HASHTABLE_NUM_TYPES: break; } @@ -514,7 +520,7 @@ hashtable_compute_length_values_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { - char str_int[64]; + char str_value[128]; int *length; /* make C compiler happy */ @@ -527,15 +533,21 @@ hashtable_compute_length_values_cb (void *data, switch (hashtable->type_values) { case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); - *length += strlen (str_int) + 1; + snprintf (str_value, sizeof (str_value), "%d", *((int *)value)); + *length += strlen (str_value) + 1; break; case HASHTABLE_STRING: *length += strlen ((char *)value) + 1; break; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: + snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)value); + *length += strlen (str_value) + 1; + break; case HASHTABLE_TIME: + snprintf (str_value, sizeof (str_value), "%ld", (long)(*((time_t *)value))); + *length += strlen (str_value) + 1; + break; case HASHTABLE_NUM_TYPES: break; } @@ -568,7 +580,7 @@ hashtable_build_string_keys_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { - char str_int[64]; + char str_value[128]; char *str; /* make C compiler happy */ @@ -582,15 +594,21 @@ hashtable_build_string_keys_cb (void *data, switch (hashtable->type_keys) { case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)key)); - strcat (str, str_int); + snprintf (str_value, sizeof (str_value), "%d", *((int *)key)); + strcat (str, str_value); break; case HASHTABLE_STRING: strcat (str, (char *)key); break; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: + snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)key); + strcat (str, str_value); + break; case HASHTABLE_TIME: + snprintf (str_value, sizeof (str_value), "%ld", (long)(*((time_t *)key))); + strcat (str, str_value); + break; case HASHTABLE_NUM_TYPES: break; } @@ -605,7 +623,7 @@ hashtable_build_string_values_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { - char str_int[64]; + char str_value[128]; char *str; /* make C compiler happy */ @@ -621,15 +639,21 @@ hashtable_build_string_values_cb (void *data, switch (hashtable->type_values) { case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); - strcat (str, str_int); + snprintf (str_value, sizeof (str_value), "%d", *((int *)value)); + strcat (str, str_value); break; case HASHTABLE_STRING: strcat (str, (char *)value); break; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: + snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)value); + strcat (str, str_value); + break; case HASHTABLE_TIME: + snprintf (str_value, sizeof (str_value), "%ld", (long)(*((time_t *)value))); + strcat (str, str_value); + break; case HASHTABLE_NUM_TYPES: break; } @@ -649,12 +673,9 @@ hashtable_build_string_keys_values_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { - char str_int[64]; + char str_value[128]; char *str; - /* make C compiler happy */ - (void) key; - str = (char *)data; if (str[0]) @@ -663,15 +684,21 @@ hashtable_build_string_keys_values_cb (void *data, switch (hashtable->type_keys) { case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)key)); - strcat (str, str_int); + snprintf (str_value, sizeof (str_value), "%d", *((int *)key)); + strcat (str, str_value); break; case HASHTABLE_STRING: strcat (str, (char *)key); break; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: + snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)key); + strcat (str, str_value); + break; case HASHTABLE_TIME: + snprintf (str_value, sizeof (str_value), "%ld", (long)(*((time_t *)key))); + strcat (str, str_value); + break; case HASHTABLE_NUM_TYPES: break; } @@ -683,15 +710,21 @@ hashtable_build_string_keys_values_cb (void *data, switch (hashtable->type_values) { case HASHTABLE_INTEGER: - snprintf (str_int, sizeof (str_int), "%d", *((int *)value)); - strcat (str, str_int); + snprintf (str_value, sizeof (str_value), "%d", *((int *)value)); + strcat (str, str_value); break; case HASHTABLE_STRING: strcat (str, (char *)value); break; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: + snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)value); + strcat (str, str_value); + break; case HASHTABLE_TIME: + snprintf (str_value, sizeof (str_value), "%ld", (long)(*((time_t *)value))); + strcat (str, str_value); + break; case HASHTABLE_NUM_TYPES: break; } |