Added [-D] (disable output) key
This commit is contained in:
parent
98dfe80ca1
commit
4fe0014a66
10
interface.c
10
interface.c
@ -94,6 +94,8 @@ int in_chat_mode;
|
||||
tgl_peer_id_t chat_mode_id;
|
||||
extern int readline_disabled;
|
||||
|
||||
extern int disable_output;
|
||||
|
||||
int is_same_word (const char *s, size_t l, const char *word) {
|
||||
return s && word && strlen (word) == l && !memcmp (s, word, l);
|
||||
}
|
||||
@ -848,7 +850,7 @@ void mark_read_upd (int num, struct tgl_message *list[]) {
|
||||
}
|
||||
|
||||
void type_notification_upd (struct tgl_user *U) {
|
||||
if (log_level < 2) { return; }
|
||||
if (log_level < 2 || disable_output) { return; }
|
||||
print_start ();
|
||||
push_color (COLOR_YELLOW);
|
||||
printf ("User ");
|
||||
@ -859,7 +861,7 @@ void type_notification_upd (struct tgl_user *U) {
|
||||
}
|
||||
|
||||
void type_in_chat_notification_upd (struct tgl_user *U, struct tgl_chat *C) {
|
||||
if (log_level < 2) { return; }
|
||||
if (log_level < 2 || disable_output) { return; }
|
||||
print_start ();
|
||||
push_color (COLOR_YELLOW);
|
||||
printf ("User ");
|
||||
@ -876,6 +878,7 @@ void print_message_gw (struct tgl_message *M) {
|
||||
#ifdef USE_LUA
|
||||
lua_new_msg (M);
|
||||
#endif
|
||||
if (disable_output) { return; }
|
||||
if (!binlog_read) { return; }
|
||||
print_start ();
|
||||
print_message (M);
|
||||
@ -935,6 +938,7 @@ void user_update_gw (struct tgl_user *U, unsigned flags) {
|
||||
lua_user_update (U, flags);
|
||||
#endif
|
||||
|
||||
if (disable_output) { return; }
|
||||
if (!binlog_read) { return; }
|
||||
|
||||
if (!(flags & TGL_UPDATE_CREATED)) {
|
||||
@ -959,6 +963,7 @@ void chat_update_gw (struct tgl_chat *U, unsigned flags) {
|
||||
lua_chat_update (U, flags);
|
||||
#endif
|
||||
|
||||
if (disable_output) { return; }
|
||||
if (!binlog_read) { return; }
|
||||
|
||||
if (!(flags & TGL_UPDATE_CREATED)) {
|
||||
@ -983,6 +988,7 @@ void secret_chat_update_gw (struct tgl_secret_chat *U, unsigned flags) {
|
||||
lua_secret_chat_update (U, flags);
|
||||
#endif
|
||||
|
||||
if (disable_output) { return; }
|
||||
if (!binlog_read) { return; }
|
||||
|
||||
if ((flags & TGL_UPDATE_WORKING) || (flags & TGL_UPDATE_DELETED)) {
|
||||
|
6
loop.c
6
loop.c
@ -72,6 +72,8 @@ int register_mode;
|
||||
extern int safe_quit;
|
||||
extern int sync_from_start;
|
||||
|
||||
extern int disable_output;
|
||||
|
||||
void got_it (char *line, int len);
|
||||
void write_state_file (void);
|
||||
|
||||
@ -613,6 +615,10 @@ int loop (void) {
|
||||
}
|
||||
|
||||
if (!tgl_signed_dc (tgl_state.DC_working)) {
|
||||
if (disable_output) {
|
||||
fprintf (stderr, "Can not login without output\n");
|
||||
exit (2);
|
||||
}
|
||||
if (!default_username) {
|
||||
size_t size = 0;
|
||||
char *user = 0;
|
||||
|
37
main.c
37
main.c
@ -94,6 +94,7 @@ int allow_weak_random;
|
||||
char *lua_file;
|
||||
int disable_colors;
|
||||
int readline_disabled;
|
||||
int disable_output;
|
||||
|
||||
void set_default_username (const char *s) {
|
||||
if (default_username) {
|
||||
@ -218,7 +219,9 @@ void running_for_first_time (void) {
|
||||
//char *downloads_directory = get_downloads_directory ();
|
||||
|
||||
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
|
||||
printf ("[%s] created\n", config_directory);
|
||||
if (!disable_output) {
|
||||
printf ("[%s] created\n", config_directory);
|
||||
}
|
||||
}
|
||||
|
||||
tfree_str (config_directory);
|
||||
@ -351,15 +354,21 @@ void parse_config (void) {
|
||||
tgl_set_download_directory (downloads_directory);
|
||||
|
||||
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
|
||||
printf ("[%s] created\n", config_directory);
|
||||
if (!disable_output) {
|
||||
printf ("[%s] created\n", config_directory);
|
||||
}
|
||||
}
|
||||
if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) {
|
||||
printf ("[%s] created\n", downloads_directory);
|
||||
if (!disable_output) {
|
||||
printf ("[%s] created\n", downloads_directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
void parse_config (void) {
|
||||
printf ("libconfig not enabled\n");
|
||||
if (!disable_output) {
|
||||
printf ("libconfig not enabled\n");
|
||||
}
|
||||
tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
|
||||
|
||||
if (binlog_enabled) {
|
||||
@ -405,6 +414,7 @@ void usage (void) {
|
||||
printf (" -R disable readline\n");
|
||||
printf (" -d daemon mode\n");
|
||||
printf (" -L <log-name> log file name\n");
|
||||
printf (" -D disable output\n");
|
||||
|
||||
exit (1);
|
||||
}
|
||||
@ -462,7 +472,7 @@ static void sighup_handler (const int sig) {
|
||||
|
||||
void args_parse (int argc, char **argv) {
|
||||
int opt = 0;
|
||||
while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:"
|
||||
while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:D"
|
||||
#ifdef HAVE_LIBCONFIG
|
||||
"c:p:"
|
||||
#else
|
||||
@ -533,6 +543,9 @@ void args_parse (int argc, char **argv) {
|
||||
case 'L':
|
||||
logname = optarg;
|
||||
break;
|
||||
case 'D':
|
||||
disable_output ++;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage ();
|
||||
@ -586,12 +599,14 @@ int main (int argc, char **argv) {
|
||||
signal (SIGUSR1, sigusr1_handler);
|
||||
reopen_logs ();
|
||||
}
|
||||
printf (
|
||||
"Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n"
|
||||
"Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
|
||||
"This is free software, and you are welcome to redistribute it\n"
|
||||
"under certain conditions; type `show_license' for details.\n"
|
||||
);
|
||||
if (!disable_output) {
|
||||
printf (
|
||||
"Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n"
|
||||
"Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
|
||||
"This is free software, and you are welcome to redistribute it\n"
|
||||
"under certain conditions; type `show_license' for details.\n"
|
||||
);
|
||||
}
|
||||
running_for_first_time ();
|
||||
parse_config ();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user