Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
a00f67c3
Commit
a00f67c3
authored
Aug 26, 2014
by
vvaltman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added disable_readline. Do not try read stdin, after end of stdin reached
parent
4fe883b9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
24 deletions
+101
-24
interface.c
interface.c
+17
-3
loop.c
loop.c
+78
-9
main.c
main.c
+6
-12
No files found.
interface.c
View file @
a00f67c3
...
@@ -85,7 +85,7 @@ char *line_ptr;
...
@@ -85,7 +85,7 @@ char *line_ptr;
int
in_chat_mode
;
int
in_chat_mode
;
tgl_peer_id_t
chat_mode_id
;
tgl_peer_id_t
chat_mode_id
;
extern
int
readline_disabled
;
int
is_same_word
(
const
char
*
s
,
size_t
l
,
const
char
*
word
)
{
int
is_same_word
(
const
char
*
s
,
size_t
l
,
const
char
*
word
)
{
return
s
&&
word
&&
strlen
(
word
)
==
l
&&
!
memcmp
(
s
,
word
,
l
);
return
s
&&
word
&&
strlen
(
word
)
==
l
&&
!
memcmp
(
s
,
word
,
l
);
...
@@ -276,10 +276,12 @@ char *complete_none (const char *text UU, int state UU) {
...
@@ -276,10 +276,12 @@ char *complete_none (const char *text UU, int state UU) {
void
set_prompt
(
const
char
*
s
)
{
void
set_prompt
(
const
char
*
s
)
{
if
(
readline_disabled
)
{
return
;
}
rl_set_prompt
(
s
);
rl_set_prompt
(
s
);
}
}
void
update_prompt
(
void
)
{
void
update_prompt
(
void
)
{
if
(
readline_disabled
)
{
return
;
}
print_start
();
print_start
();
set_prompt
(
get_default_prompt
());
set_prompt
(
get_default_prompt
());
if
(
readline_active
)
{
if
(
readline_active
)
{
...
@@ -1065,6 +1067,7 @@ void interpreter (char *line UU) {
...
@@ -1065,6 +1067,7 @@ void interpreter (char *line UU) {
static
char
stat_buf
[
1
<<
15
];
static
char
stat_buf
[
1
<<
15
];
tgl_print_stat
(
stat_buf
,
(
1
<<
15
)
-
1
);
tgl_print_stat
(
stat_buf
,
(
1
<<
15
)
-
1
);
printf
(
"%s
\n
"
,
stat_buf
);
printf
(
"%s
\n
"
,
stat_buf
);
fflush
(
stdout
);
}
else
if
(
IS_WORD
(
"msg"
))
{
}
else
if
(
IS_WORD
(
"msg"
))
{
GET_PEER
;
GET_PEER
;
int
t
;
int
t
;
...
@@ -1578,6 +1581,7 @@ char *saved_line;
...
@@ -1578,6 +1581,7 @@ char *saved_line;
int
prompt_was
;
int
prompt_was
;
void
print_start
(
void
)
{
void
print_start
(
void
)
{
if
(
in_readline
)
{
return
;
}
if
(
in_readline
)
{
return
;
}
if
(
readline_disabled
)
{
return
;
}
assert
(
!
prompt_was
);
assert
(
!
prompt_was
);
if
(
readline_active
)
{
if
(
readline_active
)
{
saved_point
=
rl_point
;
saved_point
=
rl_point
;
...
@@ -1602,6 +1606,10 @@ void print_start (void) {
...
@@ -1602,6 +1606,10 @@ void print_start (void) {
void
print_end
(
void
)
{
void
print_end
(
void
)
{
if
(
in_readline
)
{
return
;
}
if
(
in_readline
)
{
return
;
}
if
(
readline_disabled
)
{
fflush
(
stdout
);
return
;
}
assert
(
prompt_was
);
assert
(
prompt_was
);
if
(
readline_active
)
{
if
(
readline_active
)
{
set_prompt
(
get_default_prompt
());
set_prompt
(
get_default_prompt
());
...
@@ -1631,12 +1639,17 @@ void logprintf (const char *format, ...) {
...
@@ -1631,12 +1639,17 @@ void logprintf (const char *format, ...) {
x
=
1
;
x
=
1
;
print_start
();
print_start
();
}
}
printf
(
COLOR_GREY
" *** "
);
if
(
!
disable_colors
)
{
printf
(
COLOR_GREY
);
}
printf
(
" *** "
);
va_list
ap
;
va_list
ap
;
va_start
(
ap
,
format
);
va_start
(
ap
,
format
);
vfprintf
(
stdout
,
format
,
ap
);
vfprintf
(
stdout
,
format
,
ap
);
va_end
(
ap
);
va_end
(
ap
);
if
(
!
disable_colors
)
{
printf
(
COLOR_NORMAL
);
printf
(
COLOR_NORMAL
);
}
if
(
x
)
{
if
(
x
)
{
print_end
();
print_end
();
}
}
...
@@ -2051,6 +2064,7 @@ void play_sound (void) {
...
@@ -2051,6 +2064,7 @@ void play_sound (void) {
}
}
void
set_interface_callbacks
(
void
)
{
void
set_interface_callbacks
(
void
)
{
if
(
readline_disabled
)
{
return
;
}
readline_active
=
1
;
readline_active
=
1
;
rl_callback_handler_install
(
get_default_prompt
(),
interpreter
);
rl_callback_handler_install
(
get_default_prompt
(),
interpreter
);
//rl_attempted_completion_function = (void *) complete_text;
//rl_attempted_completion_function = (void *) complete_text;
...
...
loop.c
View file @
a00f67c3
...
@@ -53,6 +53,7 @@
...
@@ -53,6 +53,7 @@
#include "binlog.h"
#include "binlog.h"
int
verbosity
;
int
verbosity
;
extern
int
readline_disabled
;
int
binlog_read
;
int
binlog_read
;
extern
char
*
default_username
;
extern
char
*
default_username
;
...
@@ -69,7 +70,13 @@ extern int sync_from_start;
...
@@ -69,7 +70,13 @@ extern int sync_from_start;
void
got_it
(
char
*
line
,
int
len
);
void
got_it
(
char
*
line
,
int
len
);
void
write_state_file
(
void
);
void
write_state_file
(
void
);
static
void
stdin_read_callback
(
evutil_socket_t
fd
,
short
what
,
void
*
arg
)
{
static
char
*
line_buffer
;
static
int
line_buffer_size
;
static
int
line_buffer_pos
;
static
int
delete_stdin_event
;
static
void
stdin_read_callback_all
(
int
arg
,
short
what
,
struct
event
*
self
)
{
if
(
!
readline_disabled
)
{
if
(((
long
)
arg
)
&
1
)
{
if
(((
long
)
arg
)
&
1
)
{
rl_callback_read_char
();
rl_callback_read_char
();
}
else
{
}
else
{
...
@@ -78,26 +85,88 @@ static void stdin_read_callback (evutil_socket_t fd, short what, void *arg) {
...
@@ -78,26 +85,88 @@ static void stdin_read_callback (evutil_socket_t fd, short what, void *arg) {
assert
(
getline
(
&
line
,
&
len
,
stdin
)
>=
0
);
assert
(
getline
(
&
line
,
&
len
,
stdin
)
>=
0
);
got_it
(
line
,
strlen
(
line
));
got_it
(
line
,
strlen
(
line
));
}
}
}
else
{
while
(
1
)
{
if
(
line_buffer_pos
==
line_buffer_size
)
{
line_buffer
=
realloc
(
line_buffer
,
line_buffer_size
*
2
+
100
);
line_buffer_size
=
line_buffer_size
*
2
+
100
;
assert
(
line_buffer
);
}
int
r
=
read
(
0
,
line_buffer
+
line_buffer_pos
,
line_buffer_size
-
line_buffer_pos
);
//logprintf ("r = %d, size = %d, pos = %d, what = 0x%x, fd = %d\n", r, line_buffer_size, line_buffer_pos, (int)what, fd);
if
(
r
<
0
)
{
perror
(
"read"
);
break
;
}
if
(
r
==
0
)
{
//struct event *ev = event_base_get_running_event (tgl_state.ev_base);
//event_del (ev);
//event_del (self);
delete_stdin_event
=
1
;
break
;
}
line_buffer_pos
+=
r
;
while
(
1
)
{
int
p
=
0
;
while
(
p
<
line_buffer_pos
&&
line_buffer
[
p
]
!=
'\n'
)
{
p
++
;
}
if
(
p
<
line_buffer_pos
)
{
if
(((
long
)
arg
)
&
1
)
{
line_buffer
[
p
]
=
0
;
interpreter
(
line_buffer
);
}
else
{
got_it
(
line_buffer
,
p
+
1
);
}
memmove
(
line_buffer
,
line_buffer
+
p
+
1
,
line_buffer_pos
-
p
-
1
);
line_buffer_pos
-=
(
p
+
1
);
}
else
{
break
;
}
}
}
}
}
static
void
stdin_read_callback_char
(
evutil_socket_t
fd
,
short
what
,
void
*
arg
)
{
stdin_read_callback_all
(
1
,
what
,
arg
);
}
static
void
stdin_read_callback_line
(
evutil_socket_t
fd
,
short
what
,
void
*
arg
)
{
stdin_read_callback_all
(
2
,
what
,
arg
);
}
}
void
net_loop
(
int
flags
,
int
(
*
is_end
)(
void
))
{
void
net_loop
(
int
flags
,
int
(
*
is_end
)(
void
))
{
delete_stdin_event
=
0
;
if
(
verbosity
)
{
if
(
verbosity
)
{
logprintf
(
"Starting netloop
\n
"
);
logprintf
(
"Starting netloop
\n
"
);
}
}
struct
event
*
ev
=
0
;
struct
event
*
ev
=
0
;
if
(
flags
&
3
)
{
if
(
flags
&
3
)
{
ev
=
event_new
(
tgl_state
.
ev_base
,
0
,
EV_READ
|
EV_PERSIST
,
stdin_read_callback
,
(
void
*
)(
long
)
flags
);
if
(
flags
&
1
)
{
ev
=
event_new
(
tgl_state
.
ev_base
,
0
,
EV_READ
|
EV_PERSIST
,
stdin_read_callback_char
,
0
);
}
else
{
ev
=
event_new
(
tgl_state
.
ev_base
,
0
,
EV_READ
|
EV_PERSIST
,
stdin_read_callback_line
,
0
);
}
event_add
(
ev
,
0
);
event_add
(
ev
,
0
);
}
}
while
(
!
is_end
||
!
is_end
())
{
while
(
!
is_end
||
!
is_end
())
{
event_base_loop
(
tgl_state
.
ev_base
,
EVLOOP_ONCE
);
event_base_loop
(
tgl_state
.
ev_base
,
EVLOOP_ONCE
);
if
(
ev
&&
delete_stdin_event
)
{
event_free
(
ev
);
ev
=
0
;
}
#ifdef USE_LUA
#ifdef USE_LUA
lua_do_all
();
lua_do_all
();
#endif
#endif
if
(
safe_quit
&&
!
tgl_state
.
active_queries
)
{
if
(
safe_quit
&&
!
tgl_state
.
active_queries
)
{
printf
(
"All done. Exit
\n
"
);
printf
(
"All done. Exit
\n
"
);
if
(
!
readline_disabled
)
{
rl_callback_handler_remove
();
rl_callback_handler_remove
();
}
exit
(
0
);
exit
(
0
);
}
}
write_state_file
();
write_state_file
();
...
...
main.c
View file @
a00f67c3
...
@@ -93,6 +93,7 @@ int sync_from_start;
...
@@ -93,6 +93,7 @@ int sync_from_start;
int
allow_weak_random
;
int
allow_weak_random
;
char
*
lua_file
;
char
*
lua_file
;
int
disable_colors
;
int
disable_colors
;
int
readline_disabled
;
void
set_default_username
(
const
char
*
s
)
{
void
set_default_username
(
const
char
*
s
)
{
if
(
default_username
)
{
if
(
default_username
)
{
...
@@ -394,6 +395,7 @@ void usage (void) {
...
@@ -394,6 +395,7 @@ void usage (void) {
#endif
#endif
printf
(
" -W send dialog_list query and wait for answer before reading input
\n
"
);
printf
(
" -W send dialog_list query and wait for answer before reading input
\n
"
);
printf
(
" -C disable color output
\n
"
);
printf
(
" -C disable color output
\n
"
);
printf
(
" -R disable readline
\n
"
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -411,7 +413,7 @@ int wait_dialog_list;
...
@@ -411,7 +413,7 @@ int wait_dialog_list;
void
args_parse
(
int
argc
,
char
**
argv
)
{
void
args_parse
(
int
argc
,
char
**
argv
)
{
int
opt
=
0
;
int
opt
=
0
;
while
((
opt
=
getopt
(
argc
,
argv
,
"u:hk:vNl:fEwWC"
while
((
opt
=
getopt
(
argc
,
argv
,
"u:hk:vNl:fEwWC
R
"
#ifdef HAVE_LIBCONFIG
#ifdef HAVE_LIBCONFIG
"c:p:"
"c:p:"
#else
#else
...
@@ -453,20 +455,9 @@ void args_parse (int argc, char **argv) {
...
@@ -453,20 +455,9 @@ void args_parse (int argc, char **argv) {
case
'l'
:
case
'l'
:
log_level
=
atoi
(
optarg
);
log_level
=
atoi
(
optarg
);
break
;
break
;
//case 'R':
// register_mode = 1;
// break;
case
'f'
:
case
'f'
:
sync_from_start
=
1
;
sync_from_start
=
1
;
break
;
break
;
//case 'L':
// if (log_net_file) {
// usage ();
// }
// log_net_file = tstrdup (optarg);
// log_net_f = fopen (log_net_file, "a");
// assert (log_net_f);
// break;
case
'E'
:
case
'E'
:
disable_auto_accept
=
1
;
disable_auto_accept
=
1
;
break
;
break
;
...
@@ -484,6 +475,9 @@ void args_parse (int argc, char **argv) {
...
@@ -484,6 +475,9 @@ void args_parse (int argc, char **argv) {
case
'C'
:
case
'C'
:
disable_colors
++
;
disable_colors
++
;
break
;
break
;
case
'R'
:
readline_disabled
++
;
break
;
case
'h'
:
case
'h'
:
default:
default:
usage
();
usage
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment