config.c 22 KB

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