Commit efc7673a authored by Vysheng's avatar Vysheng

Merge github.com:vysheng/tg

parents 1dcbce52 069fe471
## Telegram messenger CLI [![Build Status](https://travis-ci.org/lwhsu/tg.png)](https://travis-ci.org/lwhsu/tg) ## Telegram messenger CLI [![Build Status](https://travis-ci.org/vysheng/tg.png)](https://travis-ci.org/vysheng/tg)
Command-line interface for [Telegram](http://telegram.org). Uses readline interface. Command-line interface for [Telegram](http://telegram.org). Uses readline interface.
......
...@@ -22,7 +22,6 @@ AC_CHECK_FUNC([backtrace], ...@@ -22,7 +22,6 @@ AC_CHECK_FUNC([backtrace],
) )
if test "x$BT" = "x" ; then if test "x$BT" = "x" ; then
AC_MSG_RESULT([no])
AC_CHECK_LIB([execinfo], [backtrace]) AC_CHECK_LIB([execinfo], [backtrace])
[ EXTRA_LIBS="${EXTRA_LIBS} -lexecinfo" ; ] [ EXTRA_LIBS="${EXTRA_LIBS} -lexecinfo" ; ]
fi fi
......
...@@ -49,6 +49,8 @@ char *default_prompt = "> "; ...@@ -49,6 +49,8 @@ char *default_prompt = "> ";
int unread_messages; int unread_messages;
int msg_num_mode; int msg_num_mode;
int safe_quit;
int in_readline; int in_readline;
int readline_active; int readline_active;
...@@ -304,6 +306,7 @@ char *commands[] = { ...@@ -304,6 +306,7 @@ char *commands[] = {
"status_offline", "status_offline",
"contacts_search", "contacts_search",
"quit", "quit",
"safe_quit",
"send_audio", "send_audio",
"load_audio", "load_audio",
"view_audio", "view_audio",
...@@ -1062,6 +1065,8 @@ void interpreter (char *line UU) { ...@@ -1062,6 +1065,8 @@ void interpreter (char *line UU) {
chat_mode_id = id; chat_mode_id = id;
} else if (IS_WORD ("quit")) { } else if (IS_WORD ("quit")) {
exit (0); exit (0);
} else if (IS_WORD ("safe_quit")) {
safe_quit = 1;
} }
} }
#undef IS_WORD #undef IS_WORD
......
...@@ -59,6 +59,8 @@ extern int binlog_enabled; ...@@ -59,6 +59,8 @@ extern int binlog_enabled;
extern int unknown_user_list_pos; extern int unknown_user_list_pos;
extern int unknown_user_list[]; extern int unknown_user_list[];
int register_mode; int register_mode;
extern int safe_quit;
extern int queries_num;
int unread_messages; int unread_messages;
void got_it (char *line, int len); void got_it (char *line, int len);
...@@ -93,10 +95,15 @@ void net_loop (int flags, int (*is_end)(void)) { ...@@ -93,10 +95,15 @@ void net_loop (int flags, int (*is_end)(void)) {
} }
} }
connections_poll_result (fds + cc, x - cc); connections_poll_result (fds + cc, x - cc);
if (safe_quit && !queries_num) {
printf ("All done. Exit\n");
rl_callback_handler_remove ();
exit (0);
}
if (unknown_user_list_pos) { if (unknown_user_list_pos) {
do_get_user_list_info_silent (unknown_user_list_pos, unknown_user_list); do_get_user_list_info_silent (unknown_user_list_pos, unknown_user_list);
unknown_user_list_pos = 0; unknown_user_list_pos = 0;
} }
} }
} }
......
...@@ -66,6 +66,8 @@ long long cur_downloaded_bytes; ...@@ -66,6 +66,8 @@ long long cur_downloaded_bytes;
extern int binlog_enabled; extern int binlog_enabled;
extern int sync_from_start; extern int sync_from_start;
int queries_num;
void out_peer_id (peer_id_t id); void out_peer_id (peer_id_t id);
#define QUERY_TIMEOUT 6.0 #define QUERY_TIMEOUT 6.0
...@@ -150,6 +152,7 @@ struct query *send_query (struct dc *DC, int ints, void *data, struct query_meth ...@@ -150,6 +152,7 @@ struct query *send_query (struct dc *DC, int ints, void *data, struct query_meth
insert_event_timer (&q->ev); insert_event_timer (&q->ev);
q->extra = extra; q->extra = extra;
queries_num ++;
return q; return q;
} }
...@@ -188,6 +191,7 @@ void query_error (long long id) { ...@@ -188,6 +191,7 @@ void query_error (long long id) {
free (q->data); free (q->data);
free (q); free (q);
} }
queries_num --;
} }
#define MAX_PACKED_SIZE (1 << 24) #define MAX_PACKED_SIZE (1 << 24)
...@@ -255,6 +259,7 @@ void query_result (long long id UU) { ...@@ -255,6 +259,7 @@ void query_result (long long id UU) {
in_ptr = end; in_ptr = end;
in_end = eend; in_end = eend;
} }
queries_num --;
} }
#define event_timer_cmp(a,b) ((a)->timeout > (b)->timeout ? 1 : ((a)->timeout < (b)->timeout ? -1 : (memcmp (a, b, sizeof (struct event_timer))))) #define event_timer_cmp(a,b) ((a)->timeout > (b)->timeout ? 1 : ((a)->timeout < (b)->timeout ? -1 : (memcmp (a, b, sizeof (struct event_timer)))))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment