Added configure script. Some interface fixes
This commit is contained in:
parent
dee10a0af9
commit
6ce15fda97
45
Makefile
45
Makefile
@ -1,20 +1,35 @@
|
||||
CC=cc
|
||||
CFLAGS=-c -Wall -Wextra -Werror -fPIC -ggdb -O2 -fno-omit-frame-pointer -fno-strict-aliasing -rdynamic
|
||||
LDFLAGS=-lreadline -lssl -lcrypto -lrt -lz -lconfig -ggdb -rdynamic
|
||||
LD=cc
|
||||
srcdir=.
|
||||
|
||||
SRC=main.c loop.c interface.c net.c mtproto-common.c mtproto-client.c queries.c structures.c
|
||||
OBJ=$(SRC:.c=.o)
|
||||
EXE=telegram
|
||||
HDRS=include.h interface.h loop.h mtproto-client.h mtproto-common.h net.h queries.h structures.h telegram.h tree.h
|
||||
CFLAGS=-g -O2
|
||||
LDFLAGS=
|
||||
CPPFLAGS=
|
||||
DEFS=-DHAVE_CONFIG_H
|
||||
COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb
|
||||
|
||||
all: $(SRC) $(EXE)
|
||||
|
||||
$(EXE): $(OBJ)
|
||||
$(LD) $(OBJ) $(LDFLAGS) -o $@
|
||||
EXTRA_LIBS= -lreadline -lconfig
|
||||
LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -lrt ${EXTRA_LIBS}
|
||||
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS}
|
||||
|
||||
HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h
|
||||
INCLUDE=-I. -I${srcdir}
|
||||
CC=gcc
|
||||
OBJECTS=main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
.SUFFIXES: .c .h .o
|
||||
|
||||
all: telegram
|
||||
|
||||
${OBJECTS}: ${HEADERS}
|
||||
|
||||
telegram: ${OBJECTS}
|
||||
${CC} ${OBJECTS} ${LINK_FLAGS} -o $@
|
||||
|
||||
.c.o :
|
||||
${CC} ${COMPILE_FLAGS} ${INCLUDE} -c $< -o $@
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm *.o telegram || true
|
||||
rm -rf *.o telegram > /dev/null || echo "all clean"
|
||||
|
||||
|
35
Makefile.in
Normal file
35
Makefile.in
Normal file
@ -0,0 +1,35 @@
|
||||
srcdir=@srcdir@
|
||||
|
||||
CFLAGS=@CFLAGS@
|
||||
LDFLAGS=@LDFLAGS@
|
||||
CPPFLAGS=@CPPFLAGS@
|
||||
DEFS=@DEFS@
|
||||
COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb
|
||||
|
||||
EXTRA_LIBS=@EXTRA_LIBS@
|
||||
LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -lrt ${EXTRA_LIBS}
|
||||
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS}
|
||||
|
||||
HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h
|
||||
INCLUDE=-I. -I${srcdir}
|
||||
CC=@CC@
|
||||
OBJECTS=main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
.SUFFIXES: .c .h .o
|
||||
|
||||
all: telegram
|
||||
|
||||
${OBJECTS}: ${HEADERS}
|
||||
|
||||
telegram: ${OBJECTS}
|
||||
${CC} ${OBJECTS} ${LINK_FLAGS} -o $@
|
||||
|
||||
.c.o :
|
||||
${CC} ${COMPILE_FLAGS} ${INCLUDE} -c $< -o $@
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o telegram > /dev/null || echo "all clean"
|
||||
|
106
config.h
Normal file
106
config.h
Normal file
@ -0,0 +1,106 @@
|
||||
/* config.h. Generated from config.h.in by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* enable libconfig */
|
||||
#define ENABLE_LIBCONFIG 1
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#define HAVE_LIBCRYPTO 1
|
||||
|
||||
/* Define to 1 if you have the `edit' library (-ledit). */
|
||||
/* #undef HAVE_LIBEDIT */
|
||||
|
||||
/* Define to 1 if you have the `m' library (-lm). */
|
||||
#define HAVE_LIBM 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <malloc.h> header file. */
|
||||
#define HAVE_MALLOC_H 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
||||
and to 0 otherwise. */
|
||||
#define HAVE_REALLOC 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#define HAVE_SELECT 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strndup' function. */
|
||||
#define HAVE_STRNDUP 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "telegram"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "telegram 0.1"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "telegram"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "0.1"
|
||||
|
||||
/* Use libedit */
|
||||
/* #undef READLINE_EDIT */
|
||||
|
||||
/* Use gnu libreadline */
|
||||
#define READLINE_GNU 1
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to rpl_realloc if the replacement function should be used. */
|
||||
/* #undef realloc */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
105
config.h.in
Normal file
105
config.h.in
Normal file
@ -0,0 +1,105 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* enable libconfig */
|
||||
#undef ENABLE_LIBCONFIG
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#undef HAVE_LIBCRYPTO
|
||||
|
||||
/* Define to 1 if you have the `edit' library (-ledit). */
|
||||
#undef HAVE_LIBEDIT
|
||||
|
||||
/* Define to 1 if you have the `m' library (-lm). */
|
||||
#undef HAVE_LIBM
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#undef HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the <malloc.h> header file. */
|
||||
#undef HAVE_MALLOC_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#undef HAVE_MEMSET
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
||||
and to 0 otherwise. */
|
||||
#undef HAVE_REALLOC
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#undef HAVE_SELECT
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#undef HAVE_STRDUP
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strndup' function. */
|
||||
#undef HAVE_STRNDUP
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#undef PACKAGE_URL
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Use libedit */
|
||||
#undef READLINE_EDIT
|
||||
|
||||
/* Use gnu libreadline */
|
||||
#undef READLINE_GNU
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
#undef malloc
|
||||
|
||||
/* Define to rpl_realloc if the replacement function should be used. */
|
||||
#undef realloc
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
57
configure.ac
Normal file
57
configure.ac
Normal file
@ -0,0 +1,57 @@
|
||||
AC_PREREQ([2.68])
|
||||
AC_INIT([telegram], [0.1])
|
||||
AC_CONFIG_SRCDIR([config.h.in])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB([m], [sqrt])
|
||||
AC_CHECK_LIB([crypto], [AES_set_encrypt_key])
|
||||
|
||||
EXTRA_LIBS=""
|
||||
|
||||
AC_CHECK_LIB([readline], [rl_save_prompt],
|
||||
[
|
||||
AC_DEFINE([READLINE_GNU], [1], [Use gnu libreadline])
|
||||
[ EXTRA_LIBS+=" -lreadline" ; ]
|
||||
],
|
||||
[
|
||||
AC_CHECK_LIB([edit], [rl_set_prompt])
|
||||
AC_DEFINE([READLINE_EDIT], [1], [Use libedit])
|
||||
[ EXTRA_LIBS+=" -ledit" ; ]
|
||||
]
|
||||
)
|
||||
|
||||
AC_MSG_CHECKING([Checking for libconfig])
|
||||
AC_ARG_ENABLE(libconfig,[--enable-libconfig/--disable-libconfig],
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_MSG_RESULT([disabled])
|
||||
else
|
||||
AC_MSG_RESULT([enabled])
|
||||
AC_CHECK_LIB([config],[config_init],AC_DEFINE(ENABLE_LIBCONFIG,1,[enable libconfig]),AC_MSG_ERROR([No libconfig found. Try --disable-libconfig]))
|
||||
[EXTRA_LIBS+=" -lconfig" ; ]
|
||||
fi
|
||||
],[
|
||||
AC_MSG_RESULT([enabled])
|
||||
AC_CHECK_LIB([config],[config_init],AC_DEFINE(ENABLE_LIBCONFIG,1,[enable libconfig]),AC_MSG_ERROR([No libconfig found. Try --disable-libconfig]))
|
||||
[EXTRA_LIBS+=" -lconfig" ; ]
|
||||
])
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([fcntl.h malloc.h stdlib.h string.h sys/socket.h unistd.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_TYPE_SIZE_T
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_FUNC_REALLOC
|
||||
AC_CHECK_FUNCS([memset select strdup strndup])
|
||||
|
||||
AC_SUBST(EXTRA_LIBS)
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
66
interface.c
66
interface.c
@ -17,15 +17,22 @@
|
||||
Copyright Vitaly Valtman 2013
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef READLINE_GNU
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#else
|
||||
#include <editline/readline.h>
|
||||
#include <editline/history.h>
|
||||
#endif
|
||||
|
||||
#include "include.h"
|
||||
#include "queries.h"
|
||||
@ -51,6 +58,7 @@ char *line_ptr;
|
||||
extern peer_t *Peers[];
|
||||
extern int peer_num;
|
||||
|
||||
|
||||
int is_same_word (const char *s, size_t l, const char *word) {
|
||||
return s && word && strlen (word) == l && !memcmp (s, word, l);
|
||||
}
|
||||
@ -220,9 +228,14 @@ char *complete_none (const char *text UU, int state UU) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void set_prompt (const char *s) {
|
||||
rl_set_prompt (s);
|
||||
}
|
||||
|
||||
void update_prompt (void) {
|
||||
print_start ();
|
||||
rl_set_prompt (get_default_prompt ());
|
||||
set_prompt (get_default_prompt ());
|
||||
rl_redisplay ();
|
||||
print_end ();
|
||||
}
|
||||
@ -755,9 +768,6 @@ void interpreter (char *line UU) {
|
||||
"visualize_key <secret_chat> - prints visualization of encryption key. You should compare it to your partner's one\n"
|
||||
);
|
||||
pop_color ();
|
||||
rl_on_new_line ();
|
||||
//print_end ();
|
||||
printf ("\033[1K\033H");
|
||||
} else if (IS_WORD ("show_license")) {
|
||||
char *b =
|
||||
#include "LICENSE.h"
|
||||
@ -835,20 +845,32 @@ void print_start (void) {
|
||||
assert (!prompt_was);
|
||||
if (readline_active) {
|
||||
saved_point = rl_point;
|
||||
saved_line = rl_copy_text(0, rl_end);
|
||||
#ifdef READLINE_GNU
|
||||
saved_line = rl_copy_text(0, rl_end);
|
||||
rl_save_prompt();
|
||||
rl_replace_line("", 0);
|
||||
#else
|
||||
assert (rl_end >= 0);
|
||||
saved_line = malloc (rl_end + 1);
|
||||
memcpy (saved_line, rl_line_buffer, rl_end + 1);
|
||||
rl_line_buffer[0] = 0;
|
||||
set_prompt ("");
|
||||
#endif
|
||||
rl_redisplay();
|
||||
}
|
||||
prompt_was = 1;
|
||||
}
|
||||
|
||||
void print_end (void) {
|
||||
if (in_readline) { return; }
|
||||
assert (prompt_was);
|
||||
if (readline_active) {
|
||||
rl_set_prompt (get_default_prompt ());
|
||||
rl_redisplay();
|
||||
set_prompt (get_default_prompt ());
|
||||
#if READLINE_GNU
|
||||
rl_replace_line(saved_line, 0);
|
||||
#else
|
||||
memcpy (rl_line_buffer, saved_line, rl_end + 1); // not safe, but I hope this would work.
|
||||
#endif
|
||||
rl_point = saved_point;
|
||||
rl_redisplay();
|
||||
free(saved_line);
|
||||
@ -857,26 +879,11 @@ void print_end (void) {
|
||||
}
|
||||
|
||||
void hexdump (int *in_ptr, int *in_end) {
|
||||
int saved_point = 0;
|
||||
char *saved_line = 0;
|
||||
if (readline_active) {
|
||||
saved_point = rl_point;
|
||||
saved_line = rl_copy_text(0, rl_end);
|
||||
rl_save_prompt();
|
||||
rl_replace_line("", 0);
|
||||
rl_redisplay();
|
||||
}
|
||||
print_start ();
|
||||
int *ptr = in_ptr;
|
||||
while (ptr < in_end) { fprintf (stdout, " %08x", *(ptr ++)); }
|
||||
fprintf (stdout, "\n");
|
||||
|
||||
if (readline_active) {
|
||||
rl_restore_prompt();
|
||||
rl_replace_line(saved_line, 0);
|
||||
rl_point = saved_point;
|
||||
rl_redisplay();
|
||||
free(saved_line);
|
||||
}
|
||||
while (ptr < in_end) { printf (" %08x", *(ptr ++)); }
|
||||
printf ("\n");
|
||||
print_end ();
|
||||
}
|
||||
|
||||
void logprintf (const char *format, ...) {
|
||||
@ -1204,3 +1211,10 @@ void print_message (struct message *M) {
|
||||
printf ("\n");
|
||||
print_end();
|
||||
}
|
||||
|
||||
void set_interface_callbacks (void) {
|
||||
readline_active = 1;
|
||||
rl_callback_handler_install (get_default_prompt (), interpreter);
|
||||
rl_attempted_completion_function = (CPPFunction *) complete_text;
|
||||
rl_completion_entry_function = (void *)complete_none;
|
||||
}
|
||||
|
@ -59,4 +59,5 @@ void print_date_full (long t);
|
||||
void print_date (long t);
|
||||
|
||||
void update_prompt (void);
|
||||
void set_interface_callbacks (void);
|
||||
#endif
|
||||
|
44
loop.c
44
loop.c
@ -17,14 +17,20 @@
|
||||
Copyright Vitaly Valtman 2013
|
||||
*/
|
||||
#define READLINE_CALLBACKS
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef READLINE_GNU
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#else
|
||||
#include <editline/readline.h>
|
||||
#include <editline/history.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
@ -51,11 +57,12 @@ extern int unknown_user_list_pos;
|
||||
extern int unknown_user_list[];
|
||||
|
||||
int unread_messages;
|
||||
void got_it (char *line, int len);
|
||||
void net_loop (int flags, int (*is_end)(void)) {
|
||||
while (!is_end ()) {
|
||||
struct pollfd fds[101];
|
||||
int cc = 0;
|
||||
if (flags & 1) {
|
||||
if (flags & 3) {
|
||||
fds[0].fd = 0;
|
||||
fds[0].events = POLLIN;
|
||||
cc ++;
|
||||
@ -70,9 +77,16 @@ void net_loop (int flags, int (*is_end)(void)) {
|
||||
continue;
|
||||
}
|
||||
work_timers ();
|
||||
if ((flags & 1) && (fds[0].revents & POLLIN)) {
|
||||
if ((flags & 3) && (fds[0].revents & POLLIN)) {
|
||||
unread_messages = 0;
|
||||
rl_callback_read_char ();
|
||||
if (flags & 1) {
|
||||
rl_callback_read_char ();
|
||||
} else {
|
||||
char *line = 0;
|
||||
size_t len = 0;
|
||||
assert (getline (&line, &len, stdin) >= 0);
|
||||
got_it (line, strlen (line));
|
||||
}
|
||||
}
|
||||
connections_poll_result (fds + cc, x - cc);
|
||||
if (unknown_user_list_pos) {
|
||||
@ -86,9 +100,10 @@ char **_s;
|
||||
size_t *_l;
|
||||
int got_it_ok;
|
||||
|
||||
void got_it (char *line) {
|
||||
*_s = strdup (line);
|
||||
*_l = strlen (line);
|
||||
void got_it (char *line, int len) {
|
||||
line[-- len] = 0; // delete end of line
|
||||
*_s = line;
|
||||
*_l = len;
|
||||
got_it_ok = 1;
|
||||
}
|
||||
|
||||
@ -97,12 +112,13 @@ int is_got_it (void) {
|
||||
}
|
||||
|
||||
int net_getline (char **s, size_t *l) {
|
||||
rl_already_prompted = 1;
|
||||
fflush (stdout);
|
||||
// rl_already_prompted = 1;
|
||||
got_it_ok = 0;
|
||||
_s = s;
|
||||
_l = l;
|
||||
rl_callback_handler_install (0, got_it);
|
||||
net_loop (1, is_got_it);
|
||||
// rl_callback_handler_install (0, got_it);
|
||||
net_loop (2, is_got_it);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -411,8 +427,7 @@ int new_dc_num;
|
||||
int loop (void) {
|
||||
on_start ();
|
||||
read_auth_file ();
|
||||
readline_active = 1;
|
||||
rl_set_prompt ("");
|
||||
update_prompt ();
|
||||
|
||||
assert (DC_list[dc_working_num]);
|
||||
if (auth_state == 0) {
|
||||
@ -534,12 +549,11 @@ int loop (void) {
|
||||
fflush (stdout);
|
||||
fflush (stderr);
|
||||
|
||||
rl_callback_handler_install (get_default_prompt (), interpreter);
|
||||
rl_attempted_completion_function = (CPPFunction *) complete_text;
|
||||
rl_completion_entry_function = complete_none;
|
||||
|
||||
read_state_file ();
|
||||
read_secret_chat_file ();
|
||||
|
||||
set_interface_callbacks ();
|
||||
|
||||
do_get_difference ();
|
||||
net_loop (0, dgot);
|
||||
do_get_dialog_list ();
|
||||
|
14
main.c
14
main.c
@ -17,6 +17,7 @@
|
||||
Copyright Vitaly Valtman 2013
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -26,7 +27,12 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#if (READLINE == GNU)
|
||||
#include <readline/readline.h>
|
||||
#else
|
||||
#include <editline/readline.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
@ -195,6 +201,7 @@ void running_for_first_time (void) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LIBCONFIG
|
||||
void parse_config_val (config_t *conf, char **s, char *param_name, const char *default_name, const char *path) {
|
||||
static char buf[1000];
|
||||
int l = 0;
|
||||
@ -267,6 +274,11 @@ void parse_config (void) {
|
||||
printf ("[%s] created\n", downloads_directory);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void parse_config (void) {
|
||||
printf ("libconfig not enabled\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void inner_main (void) {
|
||||
loop ();
|
||||
@ -321,7 +333,7 @@ void print_backtrace (void) {
|
||||
|
||||
void sig_handler (int signum) {
|
||||
set_terminal_attributes ();
|
||||
printf ("signal %d received\n", signum);
|
||||
printf ("Signal %d received\n", signum);
|
||||
print_backtrace ();
|
||||
}
|
||||
|
||||
|
2
net.h
2
net.h
@ -26,7 +26,7 @@ struct dc;
|
||||
#define TG_SERVER_TEST "173.240.5.253"
|
||||
#define TG_APP_HASH "36722c72256a24c1225de00eb6a1ca74"
|
||||
#define TG_APP_ID 2899
|
||||
#define TG_BUILD "203"
|
||||
#define TG_BUILD "209"
|
||||
|
||||
#define TG_VERSION "0.01-beta"
|
||||
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
Copyright Vitaly Valtman 2013
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "structures.h"
|
||||
|
Loading…
Reference in New Issue
Block a user