config.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. /******************************************************************************
  2. * This file is part of TinTin++ *
  3. * *
  4. * Copyright 2004-2020 Igor van den Hoven *
  5. * *
  6. * TinTin++ is free software; you can redistribute it and/or modify *
  7. * it under the terms of the GNU General Public License as published by *
  8. * the Free Software Foundation; either version 3 of the License, or *
  9. * (at your option) any later version. *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with TinTin++. If not, see https://www.gnu.org/licenses. *
  18. ******************************************************************************/
  19. /******************************************************************************
  20. * T I N T I N + + *
  21. * *
  22. * coded by Igor van den Hoven 2004 *
  23. ******************************************************************************/
  24. #include "tintin.h"
  25. DO_COMMAND(do_configure)
  26. {
  27. struct listnode *node;
  28. int index;
  29. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  30. arg = sub_arg_in_braces(ses, arg, arg2, GET_ALL, SUB_VAR|SUB_FUN);
  31. if (*arg1 == 0)
  32. {
  33. tintin_header(ses, 80, " CONFIGURATIONS ");
  34. for (index = 0 ; *config_table[index].name != 0 ; index++)
  35. {
  36. node = search_node_list(ses->list[LIST_CONFIG], config_table[index].name);
  37. if (node)
  38. {
  39. strcpy(arg2, "");
  40. config_table[index].config(ses, arg1, arg2, index);
  41. tintin_printf2(ses, "[%-14s] [%12s] %s",
  42. node->arg1,
  43. arg2,
  44. strcmp(node->arg2, "OFF") ? config_table[index].msg_on : config_table[index].msg_off);
  45. }
  46. }
  47. tintin_header(ses, 80, "");
  48. }
  49. else
  50. {
  51. // fixing silly config name
  52. if (is_abbrev(arg1, "MOUSE TRACKING"))
  53. {
  54. str_cpy(&arg1, "MOUSE");
  55. }
  56. for (index = 0 ; *config_table[index].name != 0 ; index++)
  57. {
  58. if (is_abbrev(arg1, config_table[index].name))
  59. {
  60. if (*arg2)
  61. {
  62. if (config_table[index].config(ses, arg1, arg2, index) != NULL)
  63. {
  64. update_node_list(ses->list[LIST_CONFIG], config_table[index].name, arg2, "", "");
  65. node = search_node_list(ses->list[LIST_CONFIG], config_table[index].name);
  66. if (node)
  67. {
  68. show_message(ses, LIST_CONFIG, "#CONFIG {%s} HAS BEEN SET TO {%s}.", config_table[index].name, node->arg2);
  69. }
  70. }
  71. }
  72. else
  73. {
  74. config_table[index].config(ses, arg1, arg2, index);
  75. show_message(ses, LIST_CONFIG, "#CONFIG {%s} IS SET TO {%s}.", config_table[index].name, arg2);
  76. }
  77. return ses;
  78. }
  79. }
  80. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG {%s} IS NOT A VALID OPTION.", capitalize(arg1));
  81. }
  82. return ses;
  83. }
  84. DO_CONFIG(config_autotab)
  85. {
  86. if (*arg2)
  87. {
  88. if (!is_number(arg2))
  89. {
  90. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {AUTO TAB} <NUMBER>");
  91. return NULL;
  92. }
  93. if (atoi(arg2) < 1 || atoi(arg2) > 999999)
  94. {
  95. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG BUFFER: PROVIDE A NUMBER BETWEEN 1 and 999999");
  96. return NULL;
  97. }
  98. ses->scrollback_tab = atoi(arg2);
  99. }
  100. sprintf(arg2, "%d", ses->scrollback_tab);
  101. return ses;
  102. }
  103. DO_CONFIG(config_buffersize)
  104. {
  105. if (*arg2)
  106. {
  107. if (!is_number(arg2))
  108. {
  109. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {BUFFER SIZE} <NUMBER>");
  110. return NULL;
  111. }
  112. switch (atoi(arg2))
  113. {
  114. case 100:
  115. case 1000:
  116. case 10000:
  117. case 100000:
  118. case 1000000:
  119. break;
  120. default:
  121. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG BUFFER: SIZE MUST BE 100, 1000, 10000, 100000, or 1000000.");
  122. return NULL;
  123. }
  124. init_buffer(ses, atoi(arg2));
  125. }
  126. sprintf(arg2, "%d", ses->scroll->size);
  127. return ses;
  128. }
  129. DO_CONFIG(config_charset)
  130. {
  131. if (*arg2)
  132. {
  133. if (is_abbrev(arg2, "AUTO"))
  134. {
  135. if (strcasestr(gtd->system->lang, "UTF-8"))
  136. {
  137. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  138. SET_BIT(ses->charset, CHARSET_FLAG_UTF8);
  139. }
  140. else if (strcasestr(gtd->system->lang, "BIG-5"))
  141. {
  142. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  143. SET_BIT(ses->charset, CHARSET_FLAG_BIG5);
  144. }
  145. else if (strcasestr(gtd->system->term, "XTERM"))
  146. {
  147. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  148. SET_BIT(ses->charset, CHARSET_FLAG_UTF8);
  149. }
  150. else
  151. {
  152. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  153. }
  154. }
  155. else if (is_abbrev(arg2, "ASCII"))
  156. {
  157. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  158. }
  159. else if (is_abbrev(arg2, "BIG-5"))
  160. {
  161. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  162. SET_BIT(ses->charset, CHARSET_FLAG_BIG5);
  163. }
  164. else if (is_abbrev(arg2, "GBK-1"))
  165. {
  166. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  167. SET_BIT(ses->charset, CHARSET_FLAG_GBK1);
  168. }
  169. else if (is_abbrev(arg2, "UTF-8"))
  170. {
  171. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  172. SET_BIT(ses->charset, CHARSET_FLAG_UTF8);
  173. }
  174. else if (is_abbrev(arg2, "BIG5TOUTF8") || is_abbrev(arg2, "BIG2UTF"))
  175. {
  176. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  177. SET_BIT(ses->charset, CHARSET_FLAG_UTF8|CHARSET_FLAG_BIG5TOUTF8);
  178. }
  179. else if (is_abbrev(arg2, "CP1251TOUTF8"))
  180. {
  181. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  182. SET_BIT(ses->charset, CHARSET_FLAG_UTF8|CHARSET_FLAG_CP1251TOUTF8);
  183. }
  184. else if (is_abbrev(arg2, "FANSI"))
  185. {
  186. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  187. SET_BIT(ses->charset, CHARSET_FLAG_UTF8|CHARSET_FLAG_FANSITOUTF8);
  188. }
  189. else if (is_abbrev(arg2, "GBK1TOUTF8"))
  190. {
  191. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  192. SET_BIT(ses->charset, CHARSET_FLAG_UTF8|CHARSET_FLAG_GBK1TOUTF8);
  193. }
  194. else if (is_abbrev(arg2, "ISO1TOUTF8"))
  195. {
  196. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  197. SET_BIT(ses->charset, CHARSET_FLAG_UTF8|CHARSET_FLAG_ISO1TOUTF8);
  198. }
  199. else if (is_abbrev(arg2, "ISO2TOUTF8"))
  200. {
  201. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  202. SET_BIT(ses->charset, CHARSET_FLAG_UTF8|CHARSET_FLAG_ISO2TOUTF8);
  203. }
  204. else if (is_abbrev(arg2, "KOI8TOUTF8"))
  205. {
  206. DEL_BIT(ses->charset, CHARSET_FLAG_ALL);
  207. SET_BIT(ses->charset, CHARSET_FLAG_UTF8|CHARSET_FLAG_KOI8TOUTF8);
  208. }
  209. else
  210. {
  211. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <AUTO|ASCII|BIG-5|BIG5TOUTF8|CP1251TOUTF8|FANSI|GBK-1|GBK1TOUTF8|ISO1TOUTF8|ISO2TOUTF8|KOI8TOUTF8|UTF-8>", config_table[index].name);
  212. return NULL;
  213. }
  214. }
  215. switch (HAS_BIT(ses->charset, CHARSET_FLAG_ALL))
  216. {
  217. case CHARSET_FLAG_BIG5:
  218. strcpy(arg2, "BIG-5");
  219. break;
  220. case CHARSET_FLAG_GBK1:
  221. strcpy(arg2, "GBK-1");
  222. break;
  223. case CHARSET_FLAG_UTF8:
  224. strcpy(arg2, "UTF-8");
  225. break;
  226. case CHARSET_FLAG_UTF8|CHARSET_FLAG_BIG5TOUTF8:
  227. strcpy(arg2, "BIG5TOUTF8");
  228. break;
  229. case CHARSET_FLAG_UTF8|CHARSET_FLAG_CP1251TOUTF8:
  230. strcpy(arg2, "CP1251TOUTF8");
  231. break;
  232. case CHARSET_FLAG_UTF8|CHARSET_FLAG_FANSITOUTF8:
  233. strcpy(arg2, "FANSI");
  234. break;
  235. case CHARSET_FLAG_UTF8|CHARSET_FLAG_GBK1TOUTF8:
  236. strcpy(arg2, "GBK1TOUTF8");
  237. break;
  238. case CHARSET_FLAG_UTF8|CHARSET_FLAG_KOI8TOUTF8:
  239. strcpy(arg2, "KOI8TOUTF8");
  240. break;
  241. case CHARSET_FLAG_UTF8|CHARSET_FLAG_ISO1TOUTF8:
  242. strcpy(arg2, "ISO1TOUTF8");
  243. break;
  244. case CHARSET_FLAG_UTF8|CHARSET_FLAG_ISO2TOUTF8:
  245. strcpy(arg2, "ISO2TOUTF8");
  246. break;
  247. default:
  248. strcpy(arg2, "ASCII");
  249. break;
  250. }
  251. return ses;
  252. }
  253. DO_CONFIG(config_childlock)
  254. {
  255. if (*arg2)
  256. {
  257. if (is_abbrev(arg2, "ON"))
  258. {
  259. SET_BIT(gtd->flags, TINTIN_FLAG_CHILDLOCK);
  260. }
  261. else if (is_abbrev(arg2, "OFF"))
  262. {
  263. DEL_BIT(gtd->flags, TINTIN_FLAG_CHILDLOCK);
  264. }
  265. else
  266. {
  267. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  268. return NULL;
  269. }
  270. }
  271. strcpy(arg2, HAS_BIT(gtd->flags, TINTIN_FLAG_CHILDLOCK) ? "ON" : "OFF");
  272. return ses;
  273. }
  274. DO_CONFIG(config_colormode)
  275. {
  276. if (*arg2)
  277. {
  278. if (is_abbrev(arg2, "NONE") || is_abbrev(arg2, "OFF"))
  279. {
  280. ses->color = 0;
  281. }
  282. else if (is_abbrev(arg2, "ANSI"))
  283. {
  284. ses->color = 16;
  285. }
  286. else if (is_abbrev(arg2, "256"))
  287. {
  288. ses->color = 256;
  289. }
  290. else if (is_abbrev(arg2, "TRUE") || is_abbrev(arg2, "ON") || is_abbrev(arg2, "AUTO"))
  291. {
  292. ses->color = 4096;
  293. }
  294. else
  295. {
  296. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF|ANSI|256|TRUE>", config_table[index].name);
  297. return NULL;
  298. }
  299. }
  300. strcpy(arg2, ses->color == 0 ? "OFF" : ses->color == 16 ? "ANSI" : ses->color == 256 ? "256" : "TRUE");
  301. return ses;
  302. }
  303. DO_CONFIG(config_colorpatch)
  304. {
  305. if (*arg2)
  306. {
  307. if (is_abbrev(arg2, "ON"))
  308. {
  309. SET_BIT(ses->config_flags, CONFIG_FLAG_COLORPATCH);
  310. }
  311. else if (is_abbrev(arg2, "OFF"))
  312. {
  313. DEL_BIT(ses->config_flags, CONFIG_FLAG_COLORPATCH);
  314. }
  315. else
  316. {
  317. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  318. return NULL;
  319. }
  320. }
  321. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_COLORPATCH) ? "ON" : "OFF");
  322. return ses;
  323. }
  324. DO_CONFIG(config_commandcolor)
  325. {
  326. if (*arg2)
  327. {
  328. get_color_names(ses, arg2, arg1);
  329. RESTRING(ses->cmd_color, arg1);
  330. }
  331. convert_meta(ses->cmd_color, arg2, SUB_EOL);
  332. return ses;
  333. }
  334. DO_CONFIG(config_commandecho)
  335. {
  336. if (*arg2)
  337. {
  338. if (is_abbrev(arg2, "ON"))
  339. {
  340. SET_BIT(ses->config_flags, CONFIG_FLAG_ECHOCOMMAND);
  341. }
  342. else if (is_abbrev(arg2, "OFF"))
  343. {
  344. DEL_BIT(ses->config_flags, CONFIG_FLAG_ECHOCOMMAND);
  345. }
  346. else
  347. {
  348. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  349. return NULL;
  350. }
  351. }
  352. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_ECHOCOMMAND) ? "ON" : "OFF");
  353. return ses;
  354. }
  355. DO_CONFIG(config_connectretry)
  356. {
  357. if (*arg2)
  358. {
  359. if (!is_number(arg2))
  360. {
  361. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {CONNECT RETRY} <NUMBER>");
  362. return NULL;
  363. }
  364. else if (atof(arg2) < 0 || atof(arg2) > 10000)
  365. {
  366. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG CONNECT RETRY: PROVIDE A NUMBER BETWEEN 0.0 and 10000.0");
  367. return NULL;
  368. }
  369. gts->connect_retry = atoll(arg2) * 1000000LL;
  370. }
  371. sprintf(arg2, "%.1Lf", (long double) gts->connect_retry / 1000000);
  372. return ses;
  373. }
  374. DO_CONFIG(config_convertmeta)
  375. {
  376. if (*arg2)
  377. {
  378. if (is_abbrev(arg2, "ON"))
  379. {
  380. SET_BIT(ses->config_flags, CONFIG_FLAG_CONVERTMETA);
  381. }
  382. else if (is_abbrev(arg2, "OFF"))
  383. {
  384. DEL_BIT(ses->config_flags, CONFIG_FLAG_CONVERTMETA);
  385. }
  386. else
  387. {
  388. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  389. return NULL;
  390. }
  391. }
  392. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_CONVERTMETA) ? "ON" : "OFF");
  393. return ses;
  394. }
  395. DO_CONFIG(config_debugtelnet)
  396. {
  397. if (*arg2)
  398. {
  399. if (is_abbrev(arg2, "ON"))
  400. {
  401. SET_BIT(ses->telopts, TELOPT_FLAG_DEBUG);
  402. }
  403. else if (is_abbrev(arg2, "OFF"))
  404. {
  405. DEL_BIT(ses->telopts, TELOPT_FLAG_DEBUG);
  406. }
  407. else
  408. {
  409. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  410. return NULL;
  411. }
  412. }
  413. strcpy(arg2, HAS_BIT(ses->telopts, TELOPT_FLAG_DEBUG) ? "ON" : "OFF");
  414. return ses;
  415. }
  416. DO_CONFIG(config_historysize)
  417. {
  418. if (*arg2)
  419. {
  420. if (!is_number(arg2))
  421. {
  422. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {HISTORY SIZE} <NUMBER>");
  423. return NULL;
  424. }
  425. if (atoi(arg2) < 0 || atoi(arg2) > 9999)
  426. {
  427. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG HISTORY: PROVIDE A NUMBER BETWEEN 0 and 9999");
  428. return NULL;
  429. }
  430. gtd->history_size = atoi(arg2);
  431. }
  432. sprintf(arg2, "%d", gtd->history_size);
  433. return ses;
  434. }
  435. DO_CONFIG(config_inheritance)
  436. {
  437. if (*arg2)
  438. {
  439. if (is_abbrev(arg2, "ON"))
  440. {
  441. SET_BIT(gtd->flags, TINTIN_FLAG_INHERITANCE);
  442. }
  443. else if (is_abbrev(arg2, "OFF"))
  444. {
  445. DEL_BIT(gtd->flags, TINTIN_FLAG_INHERITANCE);
  446. }
  447. else
  448. {
  449. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  450. return NULL;
  451. }
  452. }
  453. strcpy(arg2, HAS_BIT(gtd->flags, TINTIN_FLAG_INHERITANCE) ? "ON" : "OFF");
  454. return ses;
  455. }
  456. DO_CONFIG(config_loglevel)
  457. {
  458. if (*arg2)
  459. {
  460. if (is_abbrev(arg2, "LOW"))
  461. {
  462. SET_BIT(ses->logmode, LOG_FLAG_LOW);
  463. }
  464. else if (is_abbrev(arg2, "HIGH"))
  465. {
  466. DEL_BIT(ses->logmode, LOG_FLAG_LOW);
  467. }
  468. else
  469. {
  470. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <LOW|HIGH>", config_table[index].name);
  471. return NULL;
  472. }
  473. }
  474. strcpy(arg2, HAS_BIT(ses->logmode, LOG_FLAG_LOW) ? "LOW" : "HIGH");
  475. return ses;
  476. }
  477. DO_CONFIG(config_logmode)
  478. {
  479. if (*arg2)
  480. {
  481. if (is_abbrev(arg2, "HTML"))
  482. {
  483. SET_BIT(ses->logmode, LOG_FLAG_HTML);
  484. DEL_BIT(ses->logmode, LOG_FLAG_PLAIN);
  485. DEL_BIT(ses->logmode, LOG_FLAG_RAW);
  486. }
  487. else if (is_abbrev(arg2, "PLAIN"))
  488. {
  489. DEL_BIT(ses->logmode, LOG_FLAG_HTML);
  490. SET_BIT(ses->logmode, LOG_FLAG_PLAIN);
  491. DEL_BIT(ses->logmode, LOG_FLAG_RAW);
  492. }
  493. else if (is_abbrev(arg2, "RAW"))
  494. {
  495. DEL_BIT(ses->logmode, LOG_FLAG_HTML);
  496. DEL_BIT(ses->logmode, LOG_FLAG_PLAIN);
  497. SET_BIT(ses->logmode, LOG_FLAG_RAW);
  498. }
  499. else
  500. {
  501. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG LOG <HTML|PLAIN|RAW>");
  502. return NULL;
  503. }
  504. }
  505. strcpy(arg2, HAS_BIT(ses->logmode, LOG_FLAG_HTML) ? "HTML" : HAS_BIT(ses->logmode, LOG_FLAG_PLAIN) ? "PLAIN" : "RAW");
  506. return ses;
  507. }
  508. DO_CONFIG(config_mccp)
  509. {
  510. if (*arg2)
  511. {
  512. if (is_abbrev(arg2, "ON"))
  513. {
  514. SET_BIT(ses->config_flags, CONFIG_FLAG_MCCP);
  515. }
  516. else if (is_abbrev(arg2, "OFF"))
  517. {
  518. DEL_BIT(ses->config_flags, CONFIG_FLAG_MCCP);
  519. }
  520. else
  521. {
  522. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  523. return NULL;
  524. }
  525. }
  526. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_MCCP) ? "ON" : "OFF");
  527. return ses;
  528. }
  529. DO_CONFIG(config_mousetracking)
  530. {
  531. if (*arg2)
  532. {
  533. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  534. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  535. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS);
  536. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS);
  537. DEL_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  538. if (is_member(arg2, "INFO"))
  539. {
  540. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  541. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  542. }
  543. if (is_member(arg2, "DEBUG"))
  544. {
  545. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  546. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  547. }
  548. if (is_member(arg2, "ON"))
  549. {
  550. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  551. }
  552. if (is_member(arg2, "PIXELS"))
  553. {
  554. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS);
  555. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  556. }
  557. if (is_abbrev(arg2, "OFF"))
  558. {
  559. if (HAS_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING))
  560. {
  561. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  562. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  563. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS);
  564. DEL_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  565. print_stdout(0, 0, "\e[?1000l\e[?1002l\e[?1004l\e[?1006l\e[?1016l");
  566. }
  567. }
  568. else
  569. {
  570. if (HAS_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING))
  571. {
  572. if (HAS_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS))
  573. {
  574. print_stdout(0, 0, "\e[?1000h\e[?1002h\e[?1004h\e[?1016h");
  575. }
  576. else
  577. {
  578. print_stdout(0, 0, "\e[?1000h\e[?1002h\e[?1004h\e[?1006h");
  579. }
  580. }
  581. else
  582. {
  583. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF|DEBUG|INFO|PIXELS>", config_table[index].name);
  584. return NULL;
  585. }
  586. }
  587. /*
  588. if (is_abbrev(arg2, "ON"))
  589. {
  590. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  591. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  592. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS);
  593. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  594. print_stdout(0, 0, "\e[?1000h\e[?1002h\e[?1004h\e[?1006h");
  595. }
  596. else if (is_abbrev(arg2, "PIXELS"))
  597. {
  598. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  599. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  600. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS);
  601. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  602. print_stdout(0, 0, "\e[?1000h\e[?1002h\e[?1004h\e[?1016h");
  603. }
  604. else if (is_abbrev(arg2, "OFF"))
  605. {
  606. if (HAS_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING))
  607. {
  608. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  609. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  610. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS);
  611. DEL_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  612. print_stdout(0, 0, "\e[?1000l\e[?1002l\e[?1004l\e[?1006l");
  613. }
  614. }
  615. else if (is_abbrev(arg2, "DEBUG"))
  616. {
  617. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  618. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  619. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  620. print_stdout(0, 0, "\e[?1000h\e[?1002h\e[?1004h\e[?1006h");
  621. }
  622. else if (is_abbrev(arg2, "DEBUG INFO"))
  623. {
  624. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  625. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  626. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  627. print_stdout(0, 0, "\e[?1000h\e[?1002h\e[?1004h\e[?1006h");
  628. }
  629. else if (is_abbrev(arg2, "INFO"))
  630. {
  631. DEL_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG);
  632. SET_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO);
  633. SET_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING);
  634. print_stdout(0, 0, "\e[?1000h\e[?1002h\e[?1004h\e[?1006h");
  635. }
  636. else
  637. {
  638. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF|DEBUG|INFO|DEBUG INFO>", config_table[index].name);
  639. return NULL;
  640. }
  641. */
  642. }
  643. if (HAS_BIT(gtd->flags, TINTIN_FLAG_MOUSETRACKING))
  644. {
  645. if (!HAS_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG|CONFIG_FLAG_MOUSEINFO|CONFIG_FLAG_MOUSEPIXELS))
  646. {
  647. strcpy(arg2, "ON");
  648. }
  649. else
  650. {
  651. strcpy(arg2, "");
  652. if (HAS_BIT(ses->config_flags, CONFIG_FLAG_MOUSEPIXELS))
  653. {
  654. strcpy(arg2, "PIXELS");
  655. }
  656. if (HAS_BIT(ses->config_flags, CONFIG_FLAG_MOUSEDEBUG))
  657. {
  658. strcat(arg2, *arg2 ? " DEBUG" : "DEBUG");
  659. }
  660. if (HAS_BIT(ses->config_flags, CONFIG_FLAG_MOUSEINFO))
  661. {
  662. strcat(arg2, *arg2 ? " INFO" : "INFO");
  663. }
  664. }
  665. }
  666. else
  667. {
  668. strcpy(arg2, "OFF");
  669. }
  670. return ses;
  671. }
  672. DO_CONFIG(config_packetpatch)
  673. {
  674. if (*arg2)
  675. {
  676. if (is_abbrev(arg2, "AUTO PROMPT") || is_abbrev(arg2, "AUTO TELNET") || is_abbrev(arg2, "AUTO OFF"))
  677. {
  678. ses->packet_patch = 0;
  679. SET_BIT(ses->config_flags, CONFIG_FLAG_AUTOPATCH);
  680. }
  681. else if (!is_number(arg2))
  682. {
  683. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {PACKET PATCH} <NUMBER>");
  684. return NULL;
  685. }
  686. else if (atof(arg2) < 0 || atof(arg2) > 10)
  687. {
  688. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG PACKET PATCH: PROVIDE A NUMBER BETWEEN 0.00 and 10.00");
  689. return NULL;
  690. }
  691. else
  692. {
  693. DEL_BIT(ses->config_flags, CONFIG_FLAG_AUTOPATCH);
  694. ses->packet_patch = (unsigned long long) (tintoi(arg2) * 1000000ULL);
  695. }
  696. }
  697. if (HAS_BIT(ses->config_flags, CONFIG_FLAG_AUTOPATCH))
  698. {
  699. if (ses->list[LIST_PROMPT]->list[0])
  700. {
  701. strcpy(arg2, "AUTO PROMPT");
  702. }
  703. else if (HAS_BIT(ses->config_flags, CONFIG_FLAG_AUTOPROMPT))
  704. {
  705. strcpy(arg2, "AUTO TELNET");
  706. }
  707. else
  708. {
  709. strcpy(arg2, "AUTO OFF");
  710. }
  711. }
  712. else
  713. {
  714. sprintf(arg2, "%4.2Lf", (long double) ses->packet_patch / 1000000);
  715. }
  716. return ses;
  717. }
  718. DO_CONFIG(config_randomseed)
  719. {
  720. if (*arg2)
  721. {
  722. if (is_abbrev(arg2, "AUTO"))
  723. {
  724. seed_rand(ses, utime());
  725. }
  726. else if (is_number(arg2))
  727. {
  728. seed_rand(ses, get_number(ses, arg2));
  729. }
  730. else
  731. {
  732. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <AUTO|NUMBER>", config_table[index].name);
  733. return NULL;
  734. }
  735. }
  736. sprintf(arg2, "%u", (unsigned int) ses->rand);
  737. return ses;
  738. }
  739. DO_CONFIG(config_repeatchar)
  740. {
  741. if (*arg2)
  742. {
  743. if (!ispunct((int) arg2[0]))
  744. {
  745. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG REPEAT CHAR: INVALID CHARACTER {%c}", arg2[0]);
  746. return NULL;
  747. }
  748. gtd->repeat_char = arg2[0];
  749. arg2[1] = 0;
  750. }
  751. sprintf(arg2, "%c", gtd->repeat_char);
  752. return ses;
  753. }
  754. DO_CONFIG(config_repeatenter)
  755. {
  756. if (*arg2)
  757. {
  758. if (is_abbrev(arg2, "ON"))
  759. {
  760. SET_BIT(ses->config_flags, CONFIG_FLAG_REPEATENTER);
  761. }
  762. else if (is_abbrev(arg2, "OFF"))
  763. {
  764. DEL_BIT(ses->config_flags, CONFIG_FLAG_REPEATENTER);
  765. }
  766. else
  767. {
  768. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  769. return NULL;
  770. }
  771. }
  772. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_REPEATENTER) ? "ON" : "OFF");
  773. return ses;
  774. }
  775. DO_CONFIG(config_screenreader)
  776. {
  777. if (*arg2)
  778. {
  779. if (is_abbrev(arg2, "ON"))
  780. {
  781. SET_BIT(ses->config_flags, CONFIG_FLAG_SCREENREADER);
  782. }
  783. else if (is_abbrev(arg2, "OFF"))
  784. {
  785. DEL_BIT(ses->config_flags, CONFIG_FLAG_SCREENREADER);
  786. }
  787. else
  788. {
  789. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  790. return NULL;
  791. }
  792. }
  793. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_SCREENREADER) ? "ON" : "OFF");
  794. return ses;
  795. }
  796. DO_CONFIG(config_scrolllock)
  797. {
  798. if (*arg2)
  799. {
  800. if (is_abbrev(arg2, "ON"))
  801. {
  802. SET_BIT(ses->config_flags, CONFIG_FLAG_SCROLLLOCK);
  803. }
  804. else if (is_abbrev(arg2, "OFF"))
  805. {
  806. DEL_BIT(ses->config_flags, CONFIG_FLAG_SCROLLLOCK);
  807. }
  808. else
  809. {
  810. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  811. return NULL;
  812. }
  813. }
  814. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_SCROLLLOCK) ? "ON" : "OFF");
  815. return ses;
  816. }
  817. DO_CONFIG(config_speedwalk)
  818. {
  819. if (*arg2)
  820. {
  821. if (is_abbrev(arg2, "ON"))
  822. {
  823. SET_BIT(ses->config_flags, CONFIG_FLAG_SPEEDWALK);
  824. }
  825. else if (is_abbrev(arg2, "OFF"))
  826. {
  827. DEL_BIT(ses->config_flags, CONFIG_FLAG_SPEEDWALK);
  828. }
  829. else
  830. {
  831. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  832. return NULL;
  833. }
  834. }
  835. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_SPEEDWALK) ? "ON" : "OFF");
  836. return ses;
  837. }
  838. DO_CONFIG(config_tabwidth)
  839. {
  840. if (*arg2)
  841. {
  842. if (is_abbrev(arg2, "AUTO"))
  843. {
  844. ses->tab_width = 8;
  845. }
  846. else if (!is_number(arg2))
  847. {
  848. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {TAB WIDTH} <NUMBER>");
  849. return NULL;
  850. }
  851. else if (atof(arg2) < 1 || atof(arg2) > 16)
  852. {
  853. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG TAB WIDTH: PROVIDE A NUMBER BETWEEN 1 and 16");
  854. return NULL;
  855. }
  856. else
  857. {
  858. ses->tab_width = (int) tintoi(arg2);
  859. }
  860. }
  861. sprintf(arg2, "%d", ses->tab_width);
  862. return ses;
  863. }
  864. DO_CONFIG(config_telnet)
  865. {
  866. if (*arg2)
  867. {
  868. if (is_abbrev(arg2, "ON"))
  869. {
  870. DEL_BIT(ses->telopts, TELOPT_FLAG_DEBUG);
  871. SET_BIT(ses->config_flags, CONFIG_FLAG_TELNET);
  872. }
  873. else if (is_abbrev(arg2, "OFF"))
  874. {
  875. DEL_BIT(ses->telopts, TELOPT_FLAG_DEBUG);
  876. DEL_BIT(ses->config_flags, CONFIG_FLAG_TELNET);
  877. }
  878. else if (is_abbrev(arg2, "DEBUG"))
  879. {
  880. SET_BIT(ses->telopts, TELOPT_FLAG_DEBUG);
  881. SET_BIT(ses->config_flags, CONFIG_FLAG_TELNET);
  882. }
  883. else if (is_abbrev(arg2, "INFO"))
  884. {
  885. SET_BIT(ses->telopts, TELOPT_FLAG_DEBUG);
  886. SET_BIT(ses->config_flags, CONFIG_FLAG_TELNET);
  887. }
  888. else
  889. {
  890. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF|DEBUG|INFO>", config_table[index].name);
  891. return NULL;
  892. }
  893. }
  894. strcpy(arg2, HAS_BIT(ses->telopts, TELOPT_FLAG_DEBUG) ? "DEBUG" : HAS_BIT(ses->config_flags, CONFIG_FLAG_TELNET) ? "ON" : "OFF");
  895. return ses;
  896. }
  897. DO_CONFIG(config_tintinchar)
  898. {
  899. if (*arg2)
  900. {
  901. if (!ispunct((int) arg2[0]))
  902. {
  903. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG TINTIN CHAR: INVALID CHARACTER {%c}", arg2[0]);
  904. return NULL;
  905. }
  906. gtd->tintin_char = arg2[0];
  907. }
  908. sprintf(arg2, "%c", gtd->tintin_char);
  909. return ses;
  910. }
  911. DO_CONFIG(config_verbatim)
  912. {
  913. if (*arg2)
  914. {
  915. if (is_abbrev(arg2, "ON"))
  916. {
  917. SET_BIT(ses->config_flags, CONFIG_FLAG_VERBATIM);
  918. }
  919. else if (is_abbrev(arg2, "OFF"))
  920. {
  921. DEL_BIT(ses->config_flags, CONFIG_FLAG_VERBATIM);
  922. }
  923. else
  924. {
  925. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  926. return NULL;
  927. }
  928. }
  929. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_VERBATIM) ? "ON" : "OFF");
  930. return ses;
  931. }
  932. DO_CONFIG(config_verbatimchar)
  933. {
  934. if (*arg2)
  935. {
  936. if (!ispunct((int) arg2[0]))
  937. {
  938. show_error(ses, LIST_CONFIG, "#ERROR: #CONFIG VERBATIM CHAR: INVALID CHARACTER {%c}", arg2[0]);
  939. return NULL;
  940. }
  941. gtd->verbatim_char = arg2[0];
  942. }
  943. sprintf(arg2, "%c", gtd->verbatim_char);
  944. return ses;
  945. }
  946. DO_CONFIG(config_verbose)
  947. {
  948. if (*arg2)
  949. {
  950. if (is_abbrev(arg2, "ON"))
  951. {
  952. SET_BIT(ses->config_flags, CONFIG_FLAG_VERBOSE);
  953. }
  954. else if (is_abbrev(arg2, "OFF"))
  955. {
  956. DEL_BIT(ses->config_flags, CONFIG_FLAG_VERBOSE);
  957. }
  958. else
  959. {
  960. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  961. return NULL;
  962. }
  963. }
  964. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_VERBOSE) ? "ON" : "OFF");
  965. return ses;
  966. }
  967. DO_CONFIG(config_wordwrap)
  968. {
  969. if (*arg2)
  970. {
  971. if (is_abbrev(arg2, "ON"))
  972. {
  973. SET_BIT(ses->config_flags, CONFIG_FLAG_WORDWRAP);
  974. }
  975. else if (is_abbrev(arg2, "OFF"))
  976. {
  977. DEL_BIT(ses->config_flags, CONFIG_FLAG_WORDWRAP);
  978. }
  979. else
  980. {
  981. show_error(ses, LIST_CONFIG, "#SYNTAX: #CONFIG {%s} <ON|OFF>", config_table[index].name);
  982. return NULL;
  983. }
  984. }
  985. strcpy(arg2, HAS_BIT(ses->config_flags, CONFIG_FLAG_WORDWRAP) ? "ON" : "OFF");
  986. return ses;
  987. }