Skip to content

Commit 5308d0c

Browse files
author
Vysheng
committed
Added --disable-extf to configure script
1 parent 84795ec commit 5308d0c

File tree

7 files changed

+140
-80
lines changed

7 files changed

+140
-80
lines changed

‎auto-static.c

+3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
*/
2020

2121
#include "mtproto-common.h"
22+
#include "config.h"
2223
#include <string.h>
2324

25+
#ifndef DISABLE_EXTF
2426
static int cur_token_len;
2527
static char *cur_token;
2628
static int cur_token_real_len;
@@ -435,3 +437,4 @@ char *tglf_extf_fetch (struct paramed_type *T) {
435437
if (fetch_type_any (T) < 0) { return 0; }
436438
return out_buf;
437439
}
440+
#endif

‎config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/* config.h.in. Generated from configure.ac by autoheader. */
22

3+
/* disable extf queries */
4+
#undef DISABLE_EXTF
5+
36
/* Use libevent v1 */
47
#undef EVENT_V1
58

‎configure

+14
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ enable_option_checking
692692
with_openssl
693693
with_zlib
694694
enable_libconfig
695+
enable_extf
695696
enable_liblua
696697
with_progname
697698
'
@@ -1317,6 +1318,7 @@ Optional Features:
13171318
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
13181319
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
13191320
--enable-libconfig/--disable-libconfig
1321+
--enable-extf/--disable-extf
13201322
--enable-liblua/--disable-liblua
13211323
13221324
Optional Packages:
@@ -4502,6 +4504,18 @@ fi
45024504
fi
45034505

45044506

4507+
# Check whether --enable-extf was given.
4508+
if test "${enable_extf+set}" = set; then :
4509+
enableval=$enable_extf;
4510+
if test "x$enableval" = "xno" ; then
4511+
4512+
$as_echo "#define DISABLE_EXTF 1" >>confdefs.h
4513+
4514+
fi
4515+
4516+
fi
4517+
4518+
45054519
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for liblua" >&5
45064520
$as_echo_n "checking for liblua... " >&6; }
45074521
# Check whether --enable-liblua was given.

‎configure.ac

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ AC_ARG_ENABLE(libconfig,[--enable-libconfig/--disable-libconfig],
5252
AC_CHECK_LIB([config],[config_init],[],AC_MSG_ERROR([No libconfig found. Try --disable-libconfig]))
5353
])
5454

55+
AC_ARG_ENABLE(extf,[--enable-extf/--disable-extf],
56+
[
57+
if test "x$enableval" = "xno" ; then
58+
AC_DEFINE([DISABLE_EXTF],[1],[disable extf queries])
59+
fi
60+
],[
61+
])
62+
5563
AC_MSG_CHECKING([for liblua])
5664
AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua],
5765
[

‎generate.c

+96-79
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ static char buf[1 << 20];
8282
int buf_size;
8383
int *buf_ptr = (int *)buf;
8484
int *buf_end;
85+
#ifndef DISABLE_EXTF
86+
int skip_only = 0;
87+
#else
88+
int skip_only = 1;
89+
#endif
8590

8691
int verbosity;
8792

@@ -872,6 +877,7 @@ void gen_constructor_store (struct tl_combinator *c) {
872877
sprintf (s, "T");
873878

874879
int *vars = malloc0 (c->var_num * 4);;
880+
assert (c->var_num <= 10);
875881
gen_uni_skip (c->result, s, vars, 1, 0);
876882

877883
if (c->name == NAME_INT) {
@@ -937,6 +943,7 @@ void gen_constructor_autocomplete (struct tl_combinator *c) {
937943
sprintf (s, "T");
938944

939945
int *vars = malloc0 (c->var_num * 4);;
946+
assert (c->var_num <= 10);
940947
gen_uni_skip (c->result, s, vars, 1, 0);
941948

942949
if (c->name == NAME_INT) {
@@ -1145,6 +1152,7 @@ void gen_function_store (struct tl_combinator *f) {
11451152
int i;
11461153

11471154
int *vars = malloc0 (f->var_num * 4);;
1155+
assert (f->var_num <= 10);
11481156

11491157
for (i = 0; i < f->args_num; i++) if (!(f->args[i]->flags & FLAG_OPT_VAR)) {
11501158
if (f->args[i]->flags & FLAG_EXCL) {
@@ -1169,6 +1177,7 @@ void gen_function_autocomplete (struct tl_combinator *f) {
11691177
int i;
11701178

11711179
int *vars = malloc0 (f->var_num * 4);;
1180+
assert (f->var_num <= 10);
11721181

11731182
for (i = 0; i < f->args_num; i++) if (!(f->args[i]->flags & FLAG_OPT_VAR)) {
11741183
if (f->args[i]->flags & FLAG_EXCL) {
@@ -1561,7 +1570,8 @@ int parse_tlo_file (void) {
15611570
}
15621571

15631572
assert (buf_ptr == buf_end);
1564-
1573+
1574+
15651575
int j;
15661576
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type")) {
15671577
tps[i]->name = 0;
@@ -1579,21 +1589,27 @@ int parse_tlo_file (void) {
15791589
for (i = 0; i < tn; i++) {
15801590
for (j = 0; j < tps[i]->constructors_num; j ++) {
15811591
gen_constructor_skip (tps[i]->constructors[j]);
1582-
gen_constructor_store (tps[i]->constructors[j]);
1583-
gen_constructor_fetch (tps[i]->constructors[j]);
1584-
gen_constructor_autocomplete (tps[i]->constructors[j]);
1592+
if (!skip_only) {
1593+
gen_constructor_store (tps[i]->constructors[j]);
1594+
gen_constructor_fetch (tps[i]->constructors[j]);
1595+
gen_constructor_autocomplete (tps[i]->constructors[j]);
1596+
}
15851597
}
15861598
}
15871599
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type")) {
15881600
gen_type_skip (tps[i]);
1589-
gen_type_store (tps[i]);
1590-
gen_type_fetch (tps[i]);
1591-
gen_type_autocomplete (tps[i]);
1592-
gen_type_do_autocomplete (tps[i]);
1601+
if (!skip_only) {
1602+
gen_type_store (tps[i]);
1603+
gen_type_fetch (tps[i]);
1604+
gen_type_autocomplete (tps[i]);
1605+
gen_type_do_autocomplete (tps[i]);
1606+
}
15931607
}
1594-
for (i = 0; i < fn; i++) {
1595-
gen_function_store (fns[i]);
1596-
gen_function_autocomplete (fns[i]);
1608+
if (!skip_only) {
1609+
for (i = 0; i < fn; i++) {
1610+
gen_function_store (fns[i]);
1611+
gen_function_autocomplete (fns[i]);
1612+
}
15971613
}
15981614
printf ("int skip_type_any (struct paramed_type *T) {\n");
15991615
printf (" switch (T->type->name) {\n");
@@ -1603,76 +1619,78 @@ int parse_tlo_file (void) {
16031619
}
16041620
printf (" default: return -1; }\n");
16051621
printf ("}\n");
1606-
printf ("int store_type_any (struct paramed_type *T) {\n");
1607-
printf (" switch (T->type->name) {\n");
1608-
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type") && tps[i]->name) {
1609-
printf (" case 0x%08x: return store_type_%s (T);\n", tps[i]->name, tps[i]->print_id);
1610-
printf (" case 0x%08x: return store_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->print_id);
1611-
}
1612-
printf (" default: return -1; }\n");
1613-
printf ("}\n");
1614-
printf ("int fetch_type_any (struct paramed_type *T) {\n");
1615-
printf (" switch (T->type->name) {\n");
1616-
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type") && tps[i]->name) {
1617-
printf (" case 0x%08x: return fetch_type_%s (T);\n", tps[i]->name, tps[i]->print_id);
1618-
printf (" case 0x%08x: return fetch_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->print_id);
1619-
}
1620-
printf (" default: return -1; }\n");
1621-
printf ("}\n");
1622-
printf ("int autocomplete_type_any (struct paramed_type *T) {\n");
1623-
printf (" switch (T->type->name) {\n");
1624-
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type") && tps[i]->name) {
1625-
printf (" case 0x%08x: return autocomplete_type_%s (T);\n", tps[i]->name, tps[i]->print_id);
1626-
printf (" case 0x%08x: return autocomplete_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->print_id);
1627-
}
1628-
printf (" default: return -1; }\n");
1629-
printf ("}\n");
1630-
printf ("struct paramed_type *store_function_any (void) {\n");
1631-
printf (" if (cur_token_len != 1 || *cur_token != '(') { return 0; }\n");
1632-
printf (" local_next_token ();\n");
1633-
printf (" if (cur_token_len == 1 || *cur_token == '.') { \n");
1634-
printf (" local_next_token ();\n");
1635-
printf (" if (cur_token_len != 1 || *cur_token != '=') { return 0; }\n");
1636-
printf (" local_next_token ();\n");
1637-
printf (" };\n");
1638-
printf (" if (cur_token_len < 0) { return 0; }\n");
1639-
for (i = 0; i < fn; i++) {
1640-
printf (" if (cur_token_len == %d && !memcmp (cur_token, \"%s\", cur_token_len)) {\n", (int)strlen (fns[i]->id), fns[i]->id);
1641-
printf (" out_int (0x%08x);\n", fns[i]->name);
1642-
printf (" local_next_token ();\n");
1643-
printf (" struct paramed_type *P = store_function_%s ();\n", fns[i]->print_id);
1644-
printf (" if (!P) { return 0; }\n");
1645-
printf (" if (cur_token_len != 1 || *cur_token != ')') { return 0; }\n");
1622+
if (!skip_only) {
1623+
printf ("int store_type_any (struct paramed_type *T) {\n");
1624+
printf (" switch (T->type->name) {\n");
1625+
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type") && tps[i]->name) {
1626+
printf (" case 0x%08x: return store_type_%s (T);\n", tps[i]->name, tps[i]->print_id);
1627+
printf (" case 0x%08x: return store_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->print_id);
1628+
}
1629+
printf (" default: return -1; }\n");
1630+
printf ("}\n");
1631+
printf ("int fetch_type_any (struct paramed_type *T) {\n");
1632+
printf (" switch (T->type->name) {\n");
1633+
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type") && tps[i]->name) {
1634+
printf (" case 0x%08x: return fetch_type_%s (T);\n", tps[i]->name, tps[i]->print_id);
1635+
printf (" case 0x%08x: return fetch_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->print_id);
1636+
}
1637+
printf (" default: return -1; }\n");
1638+
printf ("}\n");
1639+
printf ("int autocomplete_type_any (struct paramed_type *T) {\n");
1640+
printf (" switch (T->type->name) {\n");
1641+
for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type") && tps[i]->name) {
1642+
printf (" case 0x%08x: return autocomplete_type_%s (T);\n", tps[i]->name, tps[i]->print_id);
1643+
printf (" case 0x%08x: return autocomplete_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->print_id);
1644+
}
1645+
printf (" default: return -1; }\n");
1646+
printf ("}\n");
1647+
printf ("struct paramed_type *store_function_any (void) {\n");
1648+
printf (" if (cur_token_len != 1 || *cur_token != '(') { return 0; }\n");
1649+
printf (" local_next_token ();\n");
1650+
printf (" if (cur_token_len == 1 || *cur_token == '.') { \n");
16461651
printf (" local_next_token ();\n");
1647-
printf (" return P;\n");
1648-
printf (" }\n");
1649-
}
1650-
printf (" return 0;\n");
1651-
printf ("}\n");
1652-
printf ("int do_autocomplete_function (const char *text, int text_len, int index, char **R) {\n");
1653-
printf (" index ++;\n");
1654-
int i;
1655-
for (i = 0; i < fn; i++) {
1656-
printf (" if (index == %d) { if (!strncmp (text, \"%s\", text_len)) { *R = tstrdup (\"%s\"); return index; } else { index ++; }}\n", i, fns[i]->id, fns[i]->id);
1657-
}
1658-
printf (" *R = 0;\n");
1659-
printf (" return 0;\n");
1660-
printf ("}\n");
1661-
printf ("struct paramed_type *autocomplete_function_any (void) {\n");
1662-
printf (" expect_token_ptr_autocomplete (\"(\", 1);\n");
1663-
printf (" if (cur_token_len == -3) { set_autocomplete_type (do_autocomplete_function); }\n");
1664-
printf (" if (cur_token_len < 0) { return 0; }\n");
1665-
for (i = 0; i < fn; i++) {
1666-
printf (" if (cur_token_len == %d && !memcmp (cur_token, \"%s\", cur_token_len)) {\n", (int)strlen (fns[i]->id), fns[i]->id);
1652+
printf (" if (cur_token_len != 1 || *cur_token != '=') { return 0; }\n");
16671653
printf (" local_next_token ();\n");
1668-
printf (" struct paramed_type *P = autocomplete_function_%s ();\n", fns[i]->print_id);
1669-
printf (" if (!P) { return 0; }\n");
1670-
printf (" expect_token_ptr_autocomplete (\")\", 1);\n");
1671-
printf (" return P;\n");
1672-
printf (" }\n");
1654+
printf (" };\n");
1655+
printf (" if (cur_token_len < 0) { return 0; }\n");
1656+
for (i = 0; i < fn; i++) {
1657+
printf (" if (cur_token_len == %d && !memcmp (cur_token, \"%s\", cur_token_len)) {\n", (int)strlen (fns[i]->id), fns[i]->id);
1658+
printf (" out_int (0x%08x);\n", fns[i]->name);
1659+
printf (" local_next_token ();\n");
1660+
printf (" struct paramed_type *P = store_function_%s ();\n", fns[i]->print_id);
1661+
printf (" if (!P) { return 0; }\n");
1662+
printf (" if (cur_token_len != 1 || *cur_token != ')') { return 0; }\n");
1663+
printf (" local_next_token ();\n");
1664+
printf (" return P;\n");
1665+
printf (" }\n");
1666+
}
1667+
printf (" return 0;\n");
1668+
printf ("}\n");
1669+
printf ("int do_autocomplete_function (const char *text, int text_len, int index, char **R) {\n");
1670+
printf (" index ++;\n");
1671+
int i;
1672+
for (i = 0; i < fn; i++) {
1673+
printf (" if (index == %d) { if (!strncmp (text, \"%s\", text_len)) { *R = tstrdup (\"%s\"); return index; } else { index ++; }}\n", i, fns[i]->id, fns[i]->id);
1674+
}
1675+
printf (" *R = 0;\n");
1676+
printf (" return 0;\n");
1677+
printf ("}\n");
1678+
printf ("struct paramed_type *autocomplete_function_any (void) {\n");
1679+
printf (" expect_token_ptr_autocomplete (\"(\", 1);\n");
1680+
printf (" if (cur_token_len == -3) { set_autocomplete_type (do_autocomplete_function); }\n");
1681+
printf (" if (cur_token_len < 0) { return 0; }\n");
1682+
for (i = 0; i < fn; i++) {
1683+
printf (" if (cur_token_len == %d && !memcmp (cur_token, \"%s\", cur_token_len)) {\n", (int)strlen (fns[i]->id), fns[i]->id);
1684+
printf (" local_next_token ();\n");
1685+
printf (" struct paramed_type *P = autocomplete_function_%s ();\n", fns[i]->print_id);
1686+
printf (" if (!P) { return 0; }\n");
1687+
printf (" expect_token_ptr_autocomplete (\")\", 1);\n");
1688+
printf (" return P;\n");
1689+
printf (" }\n");
1690+
}
1691+
printf (" return 0;\n");
1692+
printf ("}\n");
16731693
}
1674-
printf (" return 0;\n");
1675-
printf ("}\n");
16761694
} else {
16771695
for (i = 0; i < tn; i++) {
16781696
for (j = 0; j < tps[i]->constructors_num; j ++) {
@@ -1725,7 +1743,6 @@ int parse_tlo_file (void) {
17251743
}
17261744
}
17271745

1728-
17291746

17301747
return 0;
17311748
}

‎interface.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,10 @@ int complete_command_list (int index, const char *text, int len, char **R) {
12521252
}
12531253

12541254
char *command_generator (const char *text, int state) {
1255-
static int len, index;
1255+
#ifndef DISABLE_EXTF
1256+
static int len;
1257+
#endif
1258+
static int index;
12561259
static enum command_argument mode;
12571260
static char *command_pos;
12581261
static int command_len;
@@ -1267,7 +1270,9 @@ char *command_generator (const char *text, int state) {
12671270
c = rl_line_buffer[rl_point];
12681271
rl_line_buffer[rl_point] = 0;
12691272
if (!state) {
1273+
#ifndef DISABLE_EXTF
12701274
len = strlen (text);
1275+
#endif
12711276
index = -1;
12721277

12731278
mode = get_complete_mode ();
@@ -1314,10 +1319,12 @@ char *command_generator (const char *text, int state) {
13141319
index = complete_string_list (modifiers, index, command_pos, command_len, &R);
13151320
if (c) { rl_line_buffer[rl_point] = c; }
13161321
return R;
1322+
#ifndef DISABLE_EXTF
13171323
case ca_extf:
13181324
index = tglf_extf_autocomplete (text, len, index, &R, rl_line_buffer, rl_point);
13191325
if (c) { rl_line_buffer[rl_point] = c; }
13201326
return R;
1327+
#endif
13211328
default:
13221329
if (c) { rl_line_buffer[rl_point] = c; }
13231330
return 0;

‎queries.c

+8
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,7 @@ void tgl_do_import_card (int size, int *card, void (*callback)(void *callback_ex
38093809
}
38103810
/* }}} */
38113811

3812+
#ifndef DISABLE_EXTF
38123813
static int ext_query_on_answer (struct query *q UU) {
38133814
if (q->callback) {
38143815
char *buf = tglf_extf_fetch (q->type);
@@ -3831,6 +3832,13 @@ void tgl_do_send_extf (char *data, int data_len, void (*callback)(void *callback
38313832
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &ext_query_methods, 0, callback, callback_extra);
38323833
}
38333834
}
3835+
#else
3836+
void tgl_do_send_extf (char *data, int data_len, void (*callback)(void *callback_extra, int success, char *buf), void *callback_extra) {
3837+
if (callback) {
3838+
callback (callback_extra, 0, 0);
3839+
}
3840+
}
3841+
#endif
38343842

38353843
static void set_flag_4 (void *_D, int success) {
38363844
struct tgl_dc *D = _D;

0 commit comments

Comments
 (0)