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
2cc75016
Commit
2cc75016
authored
Jul 30, 2015
by
vvaltman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated tgl
parent
224160d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
12 deletions
+110
-12
interface.c
interface.c
+3
-2
loop.c
loop.c
+106
-9
tgl
tgl
+1
-1
No files found.
interface.c
View file @
2cc75016
...
...
@@ -2858,13 +2858,14 @@ void user_status_upd (struct tgl_state *TLS, struct tgl_user *U) {
void
on_login
(
struct
tgl_state
*
TLS
);
void
on_started
(
struct
tgl_state
*
TLS
);
void
do_get_string
(
struct
tgl_state
*
TLS
,
const
char
*
prompt
,
int
flags
,
void
(
*
cb
)(
struct
tgl_state
*
,
const
char
*
,
void
*
),
void
*
arg
);
void
do_get_values
(
struct
tgl_state
*
TLS
,
enum
tgl_value_type
type
,
const
char
*
prompt
,
int
num_values
,
void
(
*
callback
)(
struct
tgl_state
*
TLS
,
const
char
*
string
[],
void
*
arg
),
void
*
arg
);
struct
tgl_update_callback
upd_cb
=
{
.
new_msg
=
print_message_gw
,
.
marked_read
=
mark_read_upd
,
.
logprintf
=
logprintf
,
.
get_
string
=
do_get_string
,
.
get_
values
=
do_get_values
,
.
logged_in
=
on_login
,
.
started
=
on_started
,
.
type_notification
=
type_notification_upd
,
...
...
loop.c
View file @
2cc75016
...
...
@@ -114,7 +114,12 @@ int read_one_string;
#define MAX_ONE_STRING_LEN 511
char
one_string
[
MAX_ONE_STRING_LEN
+
1
];
int
one_string_len
;
void
(
*
on_string_cb
)(
struct
tgl_state
*
TLS
,
char
*
str
,
void
*
arg
);
void
(
*
one_string_cb
)(
struct
tgl_state
*
TLS
,
const
char
*
string
[],
void
*
arg
);
enum
tgl_value_type
one_string_type
;
int
one_string_num
;
int
one_string_total_args
;
char
*
one_string_results
[
10
];
void
*
string_cb_arg
;
char
*
one_string_prompt
;
int
one_string_flags
;
...
...
@@ -123,29 +128,121 @@ extern int disable_link_preview;
void
deactivate_readline
(
void
);
void
reactivate_readline
(
void
);
void
do_get_string
(
struct
tgl_state
*
TLS
);
static
void
one_string_read_end
(
void
)
{
printf
(
"
\n
"
);
fflush
(
stdout
);
read_one_string
=
0
;
free
(
one_string_prompt
);
tfree_str
(
one_string_prompt
);
one_string_prompt
=
NULL
;
reactivate_readline
();
on_string_cb
(
TLS
,
one_string
,
string_cb_arg
);
one_string_results
[
one_string_num
]
=
tstrdup
(
one_string
);
++
one_string_num
;
if
(
one_string_num
<
one_string_total_args
)
{
do_get_string
(
TLS
);
}
else
{
one_string_cb
(
TLS
,
(
void
*
)
one_string_results
,
string_cb_arg
);
int
i
;
for
(
i
=
0
;
i
<
one_string_total_args
;
i
++
)
{
tfree_str
(
one_string_results
[
i
]);
}
}
}
void
do_get_string
(
struct
tgl_state
*
TLS
,
const
char
*
prompt
,
int
flags
,
void
(
*
cb
)(
struct
tgl_state
*
,
char
*
,
void
*
),
void
*
arg
)
{
void
generate_prompt
(
enum
tgl_value_type
type
,
int
num
)
{
switch
(
type
)
{
case
tgl_phone_number
:
assert
(
!
num
);
one_string_prompt
=
tstrdup
(
"phone number: "
);
one_string_flags
=
0
;
return
;
case
tgl_code
:
assert
(
!
num
);
one_string_prompt
=
tstrdup
(
"code ('CALL' for phone code): "
);
one_string_flags
=
0
;
return
;
case
tgl_register_info
:
one_string_flags
=
0
;
switch
(
num
)
{
case
0
:
one_string_prompt
=
tstrdup
(
"register (Y/n): "
);
return
;
case
1
:
one_string_prompt
=
tstrdup
(
"first name: "
);
return
;
case
2
:
one_string_prompt
=
tstrdup
(
"last name: "
);
return
;
default:
assert
(
0
);
}
return
;
case
tgl_new_password
:
one_string_flags
=
1
;
switch
(
num
)
{
case
0
:
one_string_prompt
=
tstrdup
(
"new password: "
);
return
;
case
1
:
one_string_prompt
=
tstrdup
(
"retype new password: "
);
return
;
default:
assert
(
0
);
}
return
;
case
tgl_cur_and_new_password
:
one_string_flags
=
1
;
switch
(
num
)
{
case
0
:
one_string_prompt
=
tstrdup
(
"old password: "
);
return
;
case
1
:
one_string_prompt
=
tstrdup
(
"new password: "
);
return
;
case
2
:
one_string_prompt
=
tstrdup
(
"retype new password: "
);
return
;
default:
assert
(
0
);
}
return
;
case
tgl_cur_password
:
one_string_flags
=
1
;
assert
(
!
num
);
one_string_prompt
=
tstrdup
(
"password: "
);
return
;
case
tgl_bot_hash
:
one_string_flags
=
0
;
assert
(
!
num
);
one_string_prompt
=
tstrdup
(
"hash: "
);
return
;
default:
assert
(
0
);
}
}
void
do_get_string
(
struct
tgl_state
*
TLS
)
{
deactivate_readline
();
printf
(
"%s "
,
prompt
);
generate_prompt
(
one_string_type
,
one_string_num
);
printf
(
"%s"
,
one_string_prompt
);
fflush
(
stdout
);
one_string_prompt
=
strdup
(
prompt
);
one_string_flags
=
flags
;
read_one_string
=
1
;
on_string_cb
=
cb
;
string_cb_arg
=
arg
;
one_string_len
=
0
;
}
void
do_get_values
(
struct
tgl_state
*
TLS
,
enum
tgl_value_type
type
,
const
char
*
prompt
,
int
num_values
,
void
(
*
callback
)(
struct
tgl_state
*
TLS
,
const
char
*
string
[],
void
*
arg
),
void
*
arg
)
{
one_string_cb
=
callback
;
one_string_num
=
0
;
one_string_total_args
=
num_values
;
one_string_type
=
type
;
string_cb_arg
=
arg
;
do_get_string
(
TLS
);
}
static
void
stdin_read_callback
(
evutil_socket_t
fd
,
short
what
,
void
*
arg
)
{
if
(
!
readline_disabled
&&
!
read_one_string
)
{
rl_callback_read_char
();
...
...
tgl
@
e279fef0
Subproject commit
7bfaae149a08d1e205e5188d548c3d54e5a1ce64
Subproject commit
e279fef0dc34c12d02e88f82a2fbde5917bc9c56
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