diff --git a/Makefile b/Makefile index 6b83182..bdf94b2 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ EXE=telegram all: $(SRC) $(EXE) $(EXE): $(OBJ) - $(LD) $(LDFLAGS) $(OBJ) -o $@ + $(LD) $(OBJ) $(LDFLAGS) -o $@ .c.o: $(CC) $(CFLAGS) $< -o $@ diff --git a/interface.c b/interface.c index 61f6931..e060a00 100644 --- a/interface.c +++ b/interface.c @@ -27,7 +27,7 @@ int commands_flags[] = { 070, 072, }; - + char *a = 0; char **user_list = &a; char **chat_list = &a; @@ -36,7 +36,7 @@ int init_token (char **q) { char *r = *q; while (*r == ' ') { r ++; } if (!*r) { return 0; } - q = &r; + *q = r; return 1; } @@ -44,7 +44,7 @@ char *get_token (char **q, int *l) { char *r = *q; while (*r == ' ') { r ++; } if (!*r) { - q = &r; + *q = r; *l = 0; return 0; } @@ -56,8 +56,9 @@ char *get_token (char **q, int *l) { } else { neg = 0; } + r++; } - q = &r; + *q = r; *l = r - s; return s; } @@ -74,7 +75,7 @@ int get_complete_mode (void) { int n = 0; int flags = -1; while (*command) { - if ((int)strlen (*command) == l && !memcmp (r, *command, l)) { + if (!strncmp (r, *command, l)) { flags = commands_flags[n]; break; } @@ -95,12 +96,10 @@ int get_complete_mode (void) { int complete_string_list (char **list, int index, const char *text, int len, char **R) { index ++; - int cc = 0; - while (cc <= 1 && list[index] && strncmp (list[index], text, len)) { + while (list[index] && strncmp (list[index], text, len)) { index ++; - if (!list[index]) { index = 0; cc ++; } } - if (list[index] && cc <= 1) { + if (list[index]) { *R = strdup (list[index]); return index; } else { @@ -110,7 +109,7 @@ int complete_string_list (char **list, int index, const char *text, int len, cha } char *command_generator (const char *text, int state) { static int len, index, mode; - + if (!state) { len = strlen (text); index = -1; diff --git a/loop.c b/loop.c index 49be9ab..2c4a27a 100644 --- a/loop.c +++ b/loop.c @@ -8,6 +8,8 @@ #include #include +#include + #include "interface.h" extern char *default_username; extern char *auth_token; @@ -16,7 +18,36 @@ void set_default_username (const char *s); int main_loop (void) { - assert (0); + fd_set inp, outp; + struct timeval tv; + while (1) { + FD_ZERO (&inp); + FD_ZERO (&outp); + FD_SET (0, &inp); + tv.tv_sec = 1; + tv.tv_usec = 0; + + int lfd = 0; + + if (select (lfd + 1, &inp, &outp, NULL, &tv) < 0) { + if (errno == EINTR) { + /* resuming from interrupt, so not an error situation, + this generally happens when you suspend your + messenger with "C-z" and then "fg". This is allowed " + */ + rl_reset_line_state (); + rl_forced_update_display (); + continue; + } + perror ("select()"); + break; + } + + if (FD_ISSET (0, &inp)) { + rl_callback_read_char (); + } + } + return 0; } int loop (void) {