diff options
author | Test_User <hax@andrewyu.org> | 2024-06-15 06:55:37 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-06-15 06:55:37 -0400 |
commit | 1238295ee3aaf63858ebb537020e84fefc1d1e63 (patch) | |
tree | 20fb8ec9b7a0d14b01a5510b66570878f6914f67 /table.c | |
parent | 4e820a26d221945b6277028f24c41393661e9124 (diff) | |
download | haxircd-1238295ee3aaf63858ebb537020e84fefc1d1e63.tar.gz haxircd-1238295ee3aaf63858ebb537020e84fefc1d1e63.zip |
Fixes and command improvements
Diffstat (limited to 'table.c')
-rw-r--r-- | table.c | 24 |
1 files changed, 6 insertions, 18 deletions
@@ -48,9 +48,9 @@ static inline int compare(struct string a, struct string b) { if (val == 0) { if (a.len < b.len) - return 1; - else if (a.len > b.len) return -1; + else if (a.len > b.len) + return 1; } return val; @@ -180,21 +180,9 @@ size_t get_table_offset(struct table tbl, struct string name, char *exists) { return search(tbl, name, exists); } +// TODO: Proper lookup void * get_table_prefix(struct table tbl, struct string name) { - char exists; - size_t index = search(tbl, name, &exists); - if (exists) - return tbl.array[index].ptr; - - if (index == 0) - return 0; - - size_t len = tbl.array[index - 1].name.len; - if (len > name.len) - return 0; - - if (memcmp(tbl.array[index - 1].name.data, name.data, len) != 0) - return 0; - - return tbl.array[index - 1].ptr; + for (size_t i = 0; i < tbl.len; i++) + if (tbl.array[i].name.len <= name.len && memcmp(tbl.array[i].name.data, name.data, tbl.array[i].name.len) == 0) + return tbl.array[i].ptr; } |