diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-02-26 07:33:12 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-03-12 20:37:11 +0100 |
commit | 9e0dd1815278e189b6fd84046fc78e883cf85704 (patch) | |
tree | a7d8c6ed636ca02227cd140889d2bcc45aa2676e /src/core | |
parent | c85b57b8b399b980c5d6725fc33bef83d9727bfb (diff) | |
download | weechat-9e0dd1815278e189b6fd84046fc78e883cf85704.zip |
api: add function "hdata_longlong" (issue #2081)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-eval.c | 5 | ||||
-rw-r--r-- | src/core/wee-hdata.c | 61 | ||||
-rw-r--r-- | src/core/wee-hdata.h | 2 |
3 files changed, 64 insertions, 4 deletions
diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index 7909f05d0..fef8a8949 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -1230,6 +1230,11 @@ eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path, "%ld", hdata_long (hdata, pointer, var_name)); value = strdup (str_value); break; + case WEECHAT_HDATA_LONGLONG: + snprintf (str_value, sizeof (str_value), + "%lld", hdata_longlong (hdata, pointer, var_name)); + value = strdup (str_value); + break; case WEECHAT_HDATA_STRING: case WEECHAT_HDATA_SHARED_STRING: ptr_value = hdata_string (hdata, pointer, var_name); diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c index 933d92d64..0a3dc6a30 100644 --- a/src/core/wee-hdata.c +++ b/src/core/wee-hdata.c @@ -38,8 +38,8 @@ struct t_hashtable *weechat_hdata = NULL; -char *hdata_type_string[9] = -{ "other", "char", "integer", "long", "string", "pointer", "time", +char *hdata_type_string[WEECHAT_NUM_HDATA_TYPES] = +{ "other", "char", "integer", "long", "longlong", "string", "pointer", "time", "hashtable", "shared_string" }; @@ -331,6 +331,8 @@ hdata_get_var_array_size (struct t_hdata *hdata, void *pointer, return *((int *)(pointer + offset)); case WEECHAT_HDATA_LONG: return (int)(*((long *)(pointer + offset))); + case WEECHAT_HDATA_LONGLONG: + return (int)(*((long long *)(pointer + offset))); default: break; } @@ -799,7 +801,41 @@ hdata_long (struct t_hdata *hdata, void *pointer, const char *name) } } - return 0; + return 0L; +} + +/* + * Gets "long long" value of a variable in hdata. + */ + +long long +hdata_longlong (struct t_hdata *hdata, void *pointer, const char *name) +{ + int index; + const char *ptr_name; + struct t_hdata_var *var; + + if (!hdata || !pointer || !name) + return 0; + + hdata_get_index_and_name (name, &index, &ptr_name); + var = hashtable_get (hdata->hash_var, ptr_name); + if (var && (var->offset >= 0)) + { + if (var->array_size && (index >= 0)) + { + if (var->array_pointer) + return (*((long long **)(pointer + var->offset)))[index]; + else + return ((long long *)(pointer + var->offset))[index]; + } + else + { + return *((long long *)(pointer + var->offset)); + } + } + + return 0LL; } /* @@ -904,7 +940,7 @@ hdata_time (struct t_hdata *hdata, void *pointer, const char *name) } } - return 0; + return (time_t)0; } /* @@ -958,6 +994,7 @@ hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, { int rc, type, type1, type2, int_value1, int_value2; long long_value1, long_value2; + long long longlong_value1, longlong_value2; char *var_name, *property, char_value1, char_value2; const char *ptr_var_name, *pos, *pos_open_paren, *hdata_name; const char *str_value1, *str_value2; @@ -1013,6 +1050,12 @@ hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, rc = (long_value1 < long_value2) ? -1 : ((long_value1 > long_value2) ? 1 : 0); break; + case WEECHAT_HDATA_LONGLONG: + longlong_value1 = hdata_longlong (hdata, pointer1, var_name); + longlong_value2 = hdata_longlong (hdata, pointer2, var_name); + rc = (longlong_value1 < longlong_value2) ? + -1 : ((longlong_value1 > longlong_value2) ? 1 : 0); + break; case WEECHAT_HDATA_STRING: case WEECHAT_HDATA_SHARED_STRING: str_value1 = hdata_string (hdata, pointer1, var_name); @@ -1181,6 +1224,7 @@ hdata_set (struct t_hdata *hdata, void *pointer, const char *name, struct t_hdata_var *var; char **ptr_string, *error; long number; + long long number_longlong; unsigned long ptr; int rc; @@ -1220,6 +1264,15 @@ hdata_set (struct t_hdata *hdata, void *pointer, const char *name, return 1; } break; + case WEECHAT_HDATA_LONGLONG: + error = NULL; + number_longlong = strtoll (value, &error, 10); + if (error && !error[0]) + { + *((long long *)(pointer + var->offset)) = number_longlong; + return 1; + } + break; case WEECHAT_HDATA_STRING: ptr_string = (char **)(pointer + var->offset); if (*ptr_string) diff --git a/src/core/wee-hdata.h b/src/core/wee-hdata.h index d70d24b9f..078c06f47 100644 --- a/src/core/wee-hdata.h +++ b/src/core/wee-hdata.h @@ -122,6 +122,8 @@ extern int hdata_integer (struct t_hdata *hdata, void *pointer, const char *name); extern long hdata_long (struct t_hdata *hdata, void *pointer, const char *name); +extern long long hdata_longlong (struct t_hdata *hdata, void *pointer, + const char *name); extern const char *hdata_string (struct t_hdata *hdata, void *pointer, const char *name); extern void *hdata_pointer (struct t_hdata *hdata, void *pointer, |