diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2016-03-12 17:48:57 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2016-03-12 17:48:57 +0000 |
commit | 534db770dbe8c358ea267df20145e9793fb0275a (patch) | |
tree | 66989fb4e5511b4efe5652cf5312ac4f160bfd01 /protocols/Telegram/src/tgl/auto-static-autocomplete.c | |
parent | 461f53bf697335fabdc82c6c9143e6020de4f022 (diff) |
tgl inside telegram
git-svn-id: http://svn.miranda-ng.org/main/trunk@16471 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Telegram/src/tgl/auto-static-autocomplete.c')
-rw-r--r-- | protocols/Telegram/src/tgl/auto-static-autocomplete.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/protocols/Telegram/src/tgl/auto-static-autocomplete.c b/protocols/Telegram/src/tgl/auto-static-autocomplete.c new file mode 100644 index 0000000000..43ec4cc02e --- /dev/null +++ b/protocols/Telegram/src/tgl/auto-static-autocomplete.c @@ -0,0 +1,63 @@ +#define IN_AUTOCOMPLETE_H +#include "auto-static-store.c" +#undef IN_AUTOCOMPLETE_H + +static int autocomplete_mode; +static char *autocomplete_string; +static int (*autocomplete_fun)(const char *, int, int, char **); + +static void set_autocomplete_string (const char *s) { + if (autocomplete_string) { free (autocomplete_string); } + autocomplete_string = strdup (s); + assert (autocomplete_string); + autocomplete_mode = 1; +} + +static void set_autocomplete_type (int (*f)(const char *, int, int, char **)) { + autocomplete_fun = f; + autocomplete_mode = 2; +} + +#define MAX_FVARS 100 +static struct paramed_type *fvars[MAX_FVARS]; +static int fvars_pos; + +static void add_var_to_be_freed (struct paramed_type *P) { + assert (fvars_pos < MAX_FVARS); + fvars[fvars_pos ++] = P; +} + +static void free_vars_to_be_freed (void) { + int i; + for (i = 0; i < fvars_pos; i++) { + tgl_paramed_type_free (fvars[i]); + } + fvars_pos = 0; +} + +int tglf_extf_autocomplete (struct tgl_state *TLS, const char *text, int text_len, int index, char **R, char *data, int data_len) { + if (index == -1) { + buffer_pos = data; + buffer_end = data + data_len; + autocomplete_mode = 0; + local_next_token (); + struct paramed_type *P = autocomplete_function_any (); + free_vars_to_be_freed (); + if (P) { tgl_paramed_type_free (P); } + } + if (autocomplete_mode == 0) { return -1; } + int len = strlen (text); + if (autocomplete_mode == 1) { + if (index >= 0) { return -1; } + index = 0; + if (!strncmp (text, autocomplete_string, len)) { + *R = strdup (autocomplete_string); + assert (*R); + return index; + } else { + return -1; + } + } else { + return autocomplete_fun (text, len, index, R); + } +} |