data.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. /******************************************************************************
  2. * This file is part of TinTin++ *
  3. * *
  4. * Copyright 2004-2019 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. * *
  17. * You should have received a copy of the GNU General Public License *
  18. * along with TinTin++. If not, see https://www.gnu.org/licenses. *
  19. ******************************************************************************/
  20. /******************************************************************************
  21. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  22. * *
  23. * coded by Igor van den Hoven 2004 *
  24. ******************************************************************************/
  25. #include "tintin.h"
  26. struct listroot *init_list(struct session *ses, int type, int size)
  27. {
  28. struct listroot *listhead;
  29. if ((listhead = (struct listroot *) calloc(1, sizeof(struct listroot))) == NULL)
  30. {
  31. syserr_fatal(-1, "init_list: calloc");
  32. }
  33. listhead->ses = ses;
  34. listhead->list = (struct listnode **) calloc(size, sizeof(struct listnode *));
  35. listhead->size = size;
  36. listhead->type = type;
  37. listhead->flags = list_table[type].flags;
  38. return listhead;
  39. }
  40. void kill_list(struct listroot *root)
  41. {
  42. while (root->used)
  43. {
  44. delete_index_list(root, root->used - 1);
  45. }
  46. }
  47. void free_list(struct listroot *root)
  48. {
  49. kill_list(root);
  50. free(root->list);
  51. free(root);
  52. }
  53. struct listroot *copy_list(struct session *ses, struct listroot *sourcelist, int type)
  54. {
  55. int i;
  56. struct listnode *node;
  57. push_call("copy_list(%p,%p,%p)",ses,sourcelist,type);
  58. ses->list[type] = init_list(ses, type, sourcelist->size);
  59. if (HAS_BIT(sourcelist->flags, LIST_FLAG_INHERIT))
  60. {
  61. for (i = 0 ; i < sourcelist->used ; i++)
  62. {
  63. node = (struct listnode *) calloc(1, sizeof(struct listnode));
  64. node->arg1 = strdup(sourcelist->list[i]->arg1);
  65. node->arg2 = strdup(sourcelist->list[i]->arg2);
  66. node->arg3 = strdup(sourcelist->list[i]->arg3);
  67. node->arg4 = strdup(sourcelist->list[i]->arg4);
  68. node->group = strdup(sourcelist->list[i]->group);
  69. switch (type)
  70. {
  71. case LIST_ALIAS:
  72. node->regex = tintin_regexp_compile(ses, node, node->arg1, PCRE_ANCHORED);
  73. break;
  74. case LIST_ACTION:
  75. case LIST_GAG:
  76. case LIST_HIGHLIGHT:
  77. case LIST_PROMPT:
  78. case LIST_SUBSTITUTE:
  79. node->regex = tintin_regexp_compile(ses, node, node->arg1, 0);
  80. break;
  81. case LIST_VARIABLE:
  82. copy_nest_node(ses->list[type], node, sourcelist->list[i]);
  83. break;
  84. }
  85. ses->list[type]->list[i] = node;
  86. }
  87. ses->list[type]->used = sourcelist->used;
  88. }
  89. ses->list[type]->flags = sourcelist->flags;
  90. pop_call();
  91. return ses->list[type];
  92. }
  93. struct listnode *insert_node_list(struct listroot *root, char *arg1, char *arg2, char *arg3, char *arg4)
  94. {
  95. int index;
  96. struct listnode *node;
  97. node = (struct listnode *) calloc(1, sizeof(struct listnode));
  98. if (HAS_BIT(root->flags, LIST_FLAG_PRIORITY) && *arg3 == 0)
  99. {
  100. strcpy(arg3, "5");
  101. }
  102. node->arg1 = strdup(arg1);
  103. node->arg2 = strdup(arg2);
  104. node->arg3 = strdup(arg3);
  105. node->arg4 = strdup(arg4);
  106. node->group = HAS_BIT(root->flags, LIST_FLAG_CLASS) ? strdup(root->ses->group) : strdup("");
  107. switch (root->type)
  108. {
  109. case LIST_ALIAS:
  110. node->regex = tintin_regexp_compile(root->ses, node, node->arg1, PCRE_ANCHORED);
  111. break;
  112. case LIST_ACTION:
  113. case LIST_GAG:
  114. case LIST_HIGHLIGHT:
  115. case LIST_PROMPT:
  116. case LIST_SUBSTITUTE:
  117. node->regex = tintin_regexp_compile(root->ses, node, node->arg1, 0);
  118. break;
  119. }
  120. index = locate_index_list(root, arg1, arg3);
  121. return insert_index_list(root, node, index);
  122. }
  123. struct listnode *update_node_list(struct listroot *root, char *arg1, char *arg2, char *arg3, char *arg4)
  124. {
  125. int index;
  126. struct listnode *node;
  127. index = search_index_list(root, arg1, NULL);
  128. if (index != -1)
  129. {
  130. if (list_table[root->type].mode == SORT_DELAY && is_number(arg1))
  131. {
  132. return insert_node_list(root, arg1, arg2, arg3, arg4);
  133. }
  134. node = root->list[index];
  135. if (strcmp(node->arg2, arg2) != 0)
  136. {
  137. free(node->arg2);
  138. node->arg2 = strdup(arg2);
  139. }
  140. switch (root->type)
  141. {
  142. case LIST_DELAY:
  143. case LIST_TICKER:
  144. node->data = 0;
  145. break;
  146. }
  147. if (HAS_BIT(root->flags, LIST_FLAG_PRIORITY) && *arg3 == 0)
  148. {
  149. strcpy(arg3, "5");
  150. }
  151. switch (list_table[root->type].mode)
  152. {
  153. case SORT_PRIORITY:
  154. if (atof(node->arg3) != atof(arg3))
  155. {
  156. delete_index_list(root, index);
  157. return insert_node_list(root, arg1, arg2, arg3, arg4);
  158. }
  159. break;
  160. case SORT_APPEND:
  161. delete_index_list(root, index);
  162. return insert_node_list(root, arg1, arg2, arg3, arg4);
  163. break;
  164. case SORT_ALPHA:
  165. case SORT_DELAY:
  166. if (strcmp(node->arg3, arg3) != 0)
  167. {
  168. free(node->arg3);
  169. node->arg3 = strdup(arg3);
  170. }
  171. break;
  172. default:
  173. tintin_printf2(root->ses, "#BUG: update_node_list: unknown mode: %d", list_table[root->type].mode);
  174. break;
  175. }
  176. return node;
  177. }
  178. else
  179. {
  180. return insert_node_list(root, arg1, arg2, arg3, arg4);
  181. }
  182. }
  183. struct listnode *insert_index_list(struct listroot *root, struct listnode *node, int index)
  184. {
  185. root->used++;
  186. if (root->used == root->size)
  187. {
  188. root->size *= 2;
  189. root->list = (struct listnode **) realloc(root->list, (root->size) * sizeof(struct listnode *));
  190. }
  191. memmove(&root->list[index + 1], &root->list[index], (root->used - index) * sizeof(struct listnode *));
  192. root->list[index] = node;
  193. return node;
  194. }
  195. void delete_node_list(struct session *ses, int type, struct listnode *node)
  196. {
  197. int index = search_index_list(ses->list[type], node->arg1, node->arg3);
  198. delete_index_list(ses->list[type], index);
  199. }
  200. void delete_index_list(struct listroot *root, int index)
  201. {
  202. struct listnode *node = root->list[index];
  203. if (node->root)
  204. {
  205. free_list(node->root);
  206. }
  207. if (index <= root->update)
  208. {
  209. root->update--;
  210. }
  211. free(node->arg1);
  212. free(node->arg2);
  213. free(node->arg3);
  214. free(node->arg4);
  215. free(node->group);
  216. if (HAS_BIT(list_table[root->type].flags, LIST_FLAG_REGEX))
  217. {
  218. if (node->regex)
  219. {
  220. free(node->regex);
  221. }
  222. }
  223. free(node);
  224. memmove(&root->list[index], &root->list[index + 1], (root->used - index) * sizeof(struct listnode *));
  225. root->used--;
  226. return;
  227. }
  228. struct listnode *search_node_list(struct listroot *root, char *text)
  229. {
  230. int index;
  231. push_call("search_node_list(%p,%p)",root,text);
  232. switch (list_table[root->type].mode)
  233. {
  234. case SORT_ALPHA:
  235. case SORT_DELAY:
  236. index = bsearch_alpha_list(root, text, 0);
  237. break;
  238. default:
  239. index = nsearch_list(root, text);
  240. break;
  241. }
  242. if (index != -1)
  243. {
  244. pop_call();
  245. return root->list[index];
  246. }
  247. pop_call();
  248. return NULL;
  249. }
  250. int search_index_list(struct listroot *root, char *text, char *priority)
  251. {
  252. if (list_table[root->type].mode == SORT_ALPHA || list_table[root->type].mode == SORT_DELAY)
  253. {
  254. return bsearch_alpha_list(root, text, 0);
  255. }
  256. if (list_table[root->type].mode == SORT_PRIORITY && priority)
  257. {
  258. return bsearch_priority_list(root, text, priority, 0);
  259. }
  260. return nsearch_list(root, text);
  261. }
  262. /*
  263. Return insertion index.
  264. */
  265. int locate_index_list(struct listroot *root, char *text, char *priority)
  266. {
  267. switch (list_table[root->type].mode)
  268. {
  269. case SORT_ALPHA:
  270. case SORT_DELAY:
  271. return bsearch_alpha_list(root, text, 1);
  272. case SORT_PRIORITY:
  273. return bsearch_priority_list(root, text, priority, 1);
  274. default:
  275. return root->used;
  276. }
  277. }
  278. /*
  279. binary search on alphabetically sorted list
  280. */
  281. int bsearch_alpha_list(struct listroot *root, char *text, int seek)
  282. {
  283. long long bot, top, val;
  284. long double toi, toj, srt;
  285. push_call("bsearch_alpha_list(%p,%p,%d)",root,text,seek);
  286. bot = 0;
  287. top = root->used - 1;
  288. val = top;
  289. // toi = get_number(root->ses, text);
  290. if (seek == 0 && (*text == '+' || *text == '-') && is_math(root->ses, text) && HAS_BIT(root->flags, LIST_FLAG_NEST))
  291. {
  292. toi = get_number(root->ses, text);
  293. if (toi > 0 && toi <= root->used)
  294. {
  295. pop_call();
  296. return toi - 1;
  297. }
  298. if (toi < 0 && toi + root->used >= 0)
  299. {
  300. pop_call();
  301. return root->used + toi;
  302. }
  303. else
  304. {
  305. pop_call();
  306. return -1;
  307. }
  308. }
  309. toi = is_number(text) ? tintoi(text) : 0;
  310. while (bot <= top)
  311. {
  312. toj = is_number(root->list[val]->arg1) ? tintoi(root->list[val]->arg1) : 0;
  313. if (toi)
  314. {
  315. srt = toi - toj;
  316. }
  317. else if (toj)
  318. {
  319. srt = -1;
  320. }
  321. else
  322. {
  323. srt = strcmp(text, root->list[val]->arg1);
  324. }
  325. if (srt == 0)
  326. {
  327. pop_call();
  328. return val;
  329. }
  330. if (srt < 0)
  331. {
  332. top = val - 1;
  333. }
  334. else
  335. {
  336. bot = val + 1;
  337. }
  338. val = bot + (top - bot) / 2;
  339. }
  340. if (seek)
  341. {
  342. pop_call();
  343. return UMAX(0, val);
  344. }
  345. pop_call();
  346. return -1;
  347. }
  348. /*
  349. Binary search on priorially and alphabetically sorted list
  350. */
  351. int bsearch_priority_list(struct listroot *root, char *text, char *priority, int seek)
  352. {
  353. int bot, top, val;
  354. double srt;
  355. bot = 0;
  356. top = root->used - 1;
  357. val = top;
  358. while (bot <= top)
  359. {
  360. srt = atof(priority) - atof(root->list[val]->arg3);
  361. if (!srt)
  362. {
  363. srt = strcmp(text, root->list[val]->arg1);
  364. }
  365. if (srt == 0)
  366. {
  367. return val;
  368. }
  369. if (srt < 0)
  370. {
  371. top = val - 1;
  372. }
  373. else
  374. {
  375. bot = val + 1;
  376. }
  377. val = bot + (top - bot) / 2;
  378. }
  379. if (seek)
  380. {
  381. return UMAX(0, val);
  382. }
  383. else
  384. {
  385. return -1;
  386. }
  387. }
  388. /*
  389. Linear search
  390. */
  391. int nsearch_list(struct listroot *root, char *text)
  392. {
  393. int i;
  394. for (i = 0 ; i < root->used ; i++)
  395. {
  396. if (!strcmp(text, root->list[i]->arg1))
  397. {
  398. return i;
  399. }
  400. }
  401. return -1;
  402. }
  403. /*
  404. show content of a node on screen
  405. */
  406. void show_node(struct listroot *root, struct listnode *node, int level)
  407. {
  408. char *str_arg2 = str_dup("");
  409. show_nest_node(node, &str_arg2, TRUE);
  410. switch (list_table[root->type].args)
  411. {
  412. case 4:
  413. tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2, node->arg3, node->arg4);
  414. break;
  415. case 3:
  416. if (HAS_BIT(list_table[root->type].flags, LIST_FLAG_PRIORITY) && !strcmp(node->arg3, "5"))
  417. {
  418. tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2);
  419. }
  420. else
  421. {
  422. tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2, node->arg3);
  423. }
  424. break;
  425. case 2:
  426. tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2);
  427. break;
  428. case 1:
  429. tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1);
  430. break;
  431. }
  432. str_free(str_arg2);
  433. }
  434. /*
  435. list content of a list on screen
  436. */
  437. void show_list(struct listroot *root, int level)
  438. {
  439. int i;
  440. if (root == root->ses->list[root->type])
  441. {
  442. tintin_header(root->ses, " %s ", list_table[root->type].name_multi);
  443. }
  444. for (i = 0 ; i < root->used ; i++)
  445. {
  446. show_node(root, root->list[i], level);
  447. }
  448. }
  449. int show_node_with_wild(struct session *ses, char *text, struct listroot *root)
  450. {
  451. struct listnode *node;
  452. int i, found = FALSE;
  453. push_call("show_node_with_wild(%p,%p,%p)",ses,text,root);
  454. node = search_node_list(root, text);
  455. if (node)
  456. {
  457. switch(root->type)
  458. {
  459. case LIST_EVENT:
  460. case LIST_FUNCTION:
  461. case LIST_MACRO:
  462. tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2));
  463. break;
  464. case LIST_ACTION:
  465. case LIST_ALIAS:
  466. case LIST_BUTTON:
  467. if (!strcmp(node->arg3, "5"))
  468. {
  469. tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2));
  470. }
  471. else
  472. {
  473. tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n{" COLOR_STRING "%s" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2), node->arg3);
  474. }
  475. break;
  476. case LIST_DELAY:
  477. case LIST_TICKER:
  478. tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n{" COLOR_STRING "%s" COLOR_BRACE "}\n\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2), node->arg3);
  479. break;
  480. default:
  481. show_node(root, node, 0);
  482. break;
  483. }
  484. pop_call();
  485. return TRUE;
  486. }
  487. for (i = 0 ; i < root->used ; i++)
  488. {
  489. if (match(ses, root->list[i]->arg1, text, SUB_VAR|SUB_FUN))
  490. {
  491. show_node(root, root->list[i], 0);
  492. found = TRUE;
  493. }
  494. }
  495. pop_call();
  496. return found;
  497. }
  498. void delete_node_with_wild(struct session *ses, int type, char *text)
  499. {
  500. struct listroot *root = ses->list[type];
  501. struct listnode *node;
  502. char arg1[BUFFER_SIZE];
  503. int i, found = FALSE;
  504. sub_arg_in_braces(ses, text, arg1, GET_ALL, SUB_VAR|SUB_FUN);
  505. node = search_node_list(root, arg1);
  506. if (node)
  507. {
  508. show_message(ses, type, "#OK. {%s} IS NO LONGER %s %s.", node->arg1, (*list_table[type].name == 'A' || *list_table[type].name == 'E') ? "AN" : "A", list_table[type].name);
  509. delete_node_list(ses, type, node);
  510. return;
  511. }
  512. for (i = root->used - 1 ; i >= 0 ; i--)
  513. {
  514. if (match(ses, root->list[i]->arg1, arg1, SUB_VAR|SUB_FUN))
  515. {
  516. show_message(ses, type, "#OK. {%s} IS NO LONGER %s %s.", root->list[i]->arg1, (*list_table[type].name == 'A' || *list_table[type].name == 'E') ? "AN" : "A", list_table[type].name);
  517. delete_index_list(root, i);
  518. found = TRUE;
  519. }
  520. }
  521. if (found == 0)
  522. {
  523. show_message(ses, type, "#KILL: NO MATCHES FOUND FOR %s {%s}.", list_table[type].name, arg1);
  524. }
  525. }
  526. DO_COMMAND(do_kill)
  527. {
  528. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
  529. int index;
  530. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  531. get_arg_in_braces(ses, arg, arg2, GET_ALL);
  532. if (*arg1 == 0 || !strcasecmp(arg1, "ALL"))
  533. {
  534. for (index = 0 ; index < LIST_MAX ; index++)
  535. {
  536. kill_list(ses->list[index]);
  537. }
  538. show_message(ses, LIST_COMMAND, "#KILL - ALL LISTS CLEARED.");
  539. return ses;
  540. }
  541. for (index = 0 ; index < LIST_MAX ; index++)
  542. {
  543. if (!is_abbrev(arg1, list_table[index].name) && !is_abbrev(arg1, list_table[index].name_multi))
  544. {
  545. continue;
  546. }
  547. if (*arg2 == 0 || !strcasecmp(arg2, "ALL"))
  548. {
  549. kill_list(ses->list[index]);
  550. show_message(ses, LIST_COMMAND, "#OK: #%s LIST CLEARED.", list_table[index].name);
  551. }
  552. else
  553. {
  554. delete_node_with_wild(ses, index, arg);
  555. }
  556. break;
  557. }
  558. if (index == LIST_MAX)
  559. {
  560. show_error(ses, LIST_COMMAND, "#ERROR: #KILL {%s} {%s} - NO MATCH FOUND.", arg1, arg2);
  561. }
  562. return ses;
  563. }
  564. DO_COMMAND(do_message)
  565. {
  566. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
  567. int index, found = FALSE;
  568. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  569. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  570. if (*arg1 == 0)
  571. {
  572. tintin_header(ses, " MESSAGES ");
  573. for (index = 0 ; index < LIST_MAX ; index++)
  574. {
  575. if (!HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
  576. {
  577. tintin_printf2(ses, " %-20s %3s", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE) ? "ON" : "OFF");
  578. }
  579. }
  580. tintin_header(ses, "");
  581. }
  582. else
  583. {
  584. for (index = found = 0 ; index < LIST_MAX ; index++)
  585. {
  586. if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
  587. {
  588. continue;
  589. }
  590. if (!is_abbrev(arg1, list_table[index].name) && !is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
  591. {
  592. continue;
  593. }
  594. if (*arg2 == 0)
  595. {
  596. TOG_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE);
  597. }
  598. else if (is_abbrev(arg2, "ON"))
  599. {
  600. SET_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE);
  601. }
  602. else if (is_abbrev(arg2, "OFF"))
  603. {
  604. DEL_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE);
  605. }
  606. else
  607. {
  608. show_error(ses, LIST_COMMAND, "#SYNTAX: #MESSAGE {%s} [ON|OFF]", arg1);
  609. return ses;
  610. }
  611. show_message(ses, LIST_COMMAND, "#OK: #%s MESSAGES HAVE BEEN SET TO: %s.", list_table[index].name, HAS_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE) ? "ON" : "OFF");
  612. found = TRUE;
  613. }
  614. if (found == FALSE)
  615. {
  616. show_error(ses, LIST_COMMAND, "#ERROR: #MESSAGE {%s} - NO MATCH FOUND.", arg1);
  617. }
  618. }
  619. return ses;
  620. }
  621. DO_COMMAND(do_ignore)
  622. {
  623. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
  624. int index, found = FALSE;
  625. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  626. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  627. if (*arg1 == 0)
  628. {
  629. tintin_header(ses, " IGNORES ");
  630. for (index = 0 ; index < LIST_MAX ; index++)
  631. {
  632. if (!HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
  633. {
  634. tintin_printf2(ses, " %-20s %3s", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE) ? "ON" : "OFF");
  635. }
  636. }
  637. tintin_header(ses, "");
  638. }
  639. else
  640. {
  641. for (index = found = 0 ; index < LIST_MAX ; index++)
  642. {
  643. if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
  644. {
  645. continue;
  646. }
  647. if (!is_abbrev(arg1, list_table[index].name) && !is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
  648. {
  649. continue;
  650. }
  651. if (*arg2 == 0)
  652. {
  653. TOG_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE);
  654. }
  655. else if (is_abbrev(arg2, "ON"))
  656. {
  657. SET_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE);
  658. }
  659. else if (is_abbrev(arg2, "OFF"))
  660. {
  661. DEL_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE);
  662. }
  663. else
  664. {
  665. show_error(ses, LIST_COMMAND, "#SYNTAX: #IGNORE {%s} [ON|OFF]", arg1);
  666. return ses;
  667. }
  668. show_message(ses, LIST_COMMAND, "#OK: #%s IGNORE STATUS HAS BEEN SET TO: %s.", list_table[index].name, HAS_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE) ? "ON" : "OFF");
  669. found = TRUE;
  670. }
  671. if (found == FALSE)
  672. {
  673. show_error(ses, LIST_COMMAND, "#ERROR: #IGNORE {%s} - NO MATCH FOUND.", arg1);
  674. }
  675. }
  676. return ses;
  677. }
  678. DO_COMMAND(do_debug)
  679. {
  680. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
  681. int index, found = FALSE;
  682. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  683. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  684. if (*arg1 == 0)
  685. {
  686. tintin_header(ses, " DEBUGS ");
  687. for (index = 0 ; index < LIST_MAX ; index++)
  688. {
  689. if (!HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
  690. {
  691. tintin_printf2(ses, " %-20s %3s", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG) ? "ON" : "OFF");
  692. }
  693. }
  694. tintin_header(ses, "");
  695. }
  696. else
  697. {
  698. for (index = found = 0 ; index < LIST_MAX ; index++)
  699. {
  700. if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
  701. {
  702. continue;
  703. }
  704. if (!is_abbrev(arg1, list_table[index].name) && !is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
  705. {
  706. continue;
  707. }
  708. if (*arg2 == 0)
  709. {
  710. TOG_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG);
  711. }
  712. else if (is_abbrev(arg2, "ON"))
  713. {
  714. SET_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG);
  715. }
  716. else if (is_abbrev(arg2, "OFF"))
  717. {
  718. DEL_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG);
  719. DEL_BIT(ses->list[index]->flags, LIST_FLAG_LOG);
  720. }
  721. else if (is_abbrev(arg2, "LOG"))
  722. {
  723. SET_BIT(ses->list[index]->flags, LIST_FLAG_LOG);
  724. }
  725. else
  726. {
  727. show_error(ses, LIST_COMMAND, "#SYNTAX: #DEBUG {%s} [ON|OFF|LOG]", arg1);
  728. return ses;
  729. }
  730. show_message(ses, LIST_COMMAND, "#OK: #%s DEBUG STATUS HAS BEEN SET TO: %s.", list_table[index].name, is_abbrev(arg2, "LOG") ? "LOG" : HAS_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG) ? "ON" : "OFF");
  731. found = TRUE;
  732. }
  733. if (found == FALSE)
  734. {
  735. show_error(ses, LIST_COMMAND, "#DEBUG {%s} - NO MATCH FOUND.", arg1);
  736. }
  737. }
  738. return ses;
  739. }
  740. DO_COMMAND(do_info)
  741. {
  742. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], name[BUFFER_SIZE];
  743. int cnt, index, found = FALSE;
  744. struct listroot *root;
  745. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  746. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  747. if (*arg1 == 0)
  748. {
  749. tintin_header(ses, " INFORMATION ");
  750. for (index = 0 ; index < LIST_MAX ; index++)
  751. {
  752. if (!HAS_BIT(ses->list[index]->flags, LIST_FLAG_HIDE))
  753. {
  754. tintin_printf2(ses, "%-15s %5d IGNORE %3s MESSAGE %3s INFO %3s DEBUG %3s %3s",
  755. list_table[index].name_multi,
  756. ses->list[index]->used,
  757. HAS_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE) ? "ON" : "OFF",
  758. HAS_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE) ? "ON" : "OFF",
  759. HAS_BIT(ses->list[index]->flags, LIST_FLAG_INFO) ? "ON" : "OFF",
  760. HAS_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG) ? "ON" : "OFF",
  761. HAS_BIT(ses->list[index]->flags, LIST_FLAG_LOG) ? "LOG" : " ");
  762. }
  763. }
  764. tintin_header(ses, "");
  765. }
  766. else
  767. {
  768. for (index = found = 0 ; index < LIST_MAX ; index++)
  769. {
  770. if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
  771. {
  772. continue;
  773. }
  774. if (!is_abbrev(arg1, list_table[index].name) && !is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
  775. {
  776. continue;
  777. }
  778. if (*arg2 == 0)
  779. {
  780. TOG_BIT(ses->list[index]->flags, LIST_FLAG_INFO);
  781. }
  782. else if (is_abbrev(arg2, "ON"))
  783. {
  784. SET_BIT(ses->list[index]->flags, LIST_FLAG_INFO);
  785. }
  786. else if (is_abbrev(arg2, "OFF"))
  787. {
  788. DEL_BIT(ses->list[index]->flags, LIST_FLAG_INFO);
  789. }
  790. else
  791. {
  792. root = ses->list[index];
  793. if (is_abbrev(arg2, "LIST"))
  794. {
  795. for (cnt = 0 ; cnt < root->used ; cnt++)
  796. {
  797. tintin_printf2(ses, "#INFO %s %4d {arg1}{%s} {arg2}{%s} {arg3}{%s} {class}{%s}", list_table[index].name, cnt, root->list[cnt]->arg1, root->list[cnt]->arg2, root->list[cnt]->arg3, root->list[cnt]->group);
  798. }
  799. }
  800. else if (is_abbrev(arg2, "SAVE"))
  801. {
  802. sprintf(name, "info[%s]", list_table[index].name);
  803. delete_nest_node(ses->list[LIST_VARIABLE], name);
  804. for (cnt = 0 ; cnt < root->used ; cnt++)
  805. {
  806. sprintf(name, "info[%s][%d]", list_table[index].name, cnt);
  807. set_nest_node(ses->list[LIST_VARIABLE], name, "{arg1}{%s}{arg2}{%s}{arg3}{%s}{class}{%s}", root->list[cnt]->arg1, root->list[cnt]->arg2, root->list[cnt]->arg3, root->list[cnt]->group);
  808. }
  809. show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[%s]}", list_table[index].name);
  810. }
  811. else
  812. {
  813. show_error(ses, LIST_COMMAND, "#SYNTAX: #INFO {%s} [ON|OFF|LIST|SAVE|SYSTEM]", arg1);
  814. return ses;
  815. }
  816. found = TRUE;
  817. show_error(ses, LIST_COMMAND, "#SYNTAX: #INFO {%s} [ON|OFF]", arg1);
  818. return ses;
  819. }
  820. show_message(ses, LIST_COMMAND, "#OK: #%s INFO STATUS HAS BEEN SET TO: %s.", list_table[index].name, HAS_BIT(ses->list[index]->flags, LIST_FLAG_INFO) ? "ON" : "OFF");
  821. found = TRUE;
  822. }
  823. if (found == FALSE)
  824. {
  825. if (is_abbrev(arg1, "CPU"))
  826. {
  827. show_cpu(ses);
  828. }
  829. else if (is_abbrev(arg1, "STACK"))
  830. {
  831. dump_stack();
  832. }
  833. else if (is_abbrev(arg1, "SYSTEM"))
  834. {
  835. if (is_abbrev(arg2, "SAVE"))
  836. {
  837. sprintf(name, "info[SYSTEM]");
  838. set_nest_node(ses->list[LIST_VARIABLE], name, "{CLIENT_NAME}{%s}{CLIENT_VERSION}{%-3s}", CLIENT_NAME, CLIENT_VERSION);
  839. add_nest_node(ses->list[LIST_VARIABLE], name, "{CLIENT}{{NAME}{%s}{VERSION}{%-3s}}", CLIENT_NAME, CLIENT_VERSION);
  840. add_nest_node(ses->list[LIST_VARIABLE], name, "{HOME}{%s}{LANG}{%s}{OS}{%s}{TERM}{%s}", gtd->home, gtd->lang, gtd->os, gtd->term);
  841. show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[SYSTEM]}");
  842. }
  843. else
  844. {
  845. tintin_printf2(ses, "#INFO SYSTEM: CLIENT_NAME = %s", CLIENT_NAME);
  846. tintin_printf2(ses, "#INFO SYSTEM: CLIENT_VERSION = %s", CLIENT_VERSION);
  847. tintin_printf2(ses, "#INFO SYSTEM: HOME = %s", gtd->home);
  848. tintin_printf2(ses, "#INFO SYSTEM: LANG = %s", gtd->lang);
  849. tintin_printf2(ses, "#INFO SYSTEM: OS = %s", gtd->os);
  850. tintin_printf2(ses, "#INFO SYSTEM: TERM = %s", gtd->term);
  851. }
  852. }
  853. else
  854. {
  855. show_error(ses, LIST_COMMAND, "#INFO {%s} - NO MATCH FOUND.", arg1);
  856. }
  857. }
  858. }
  859. return ses;
  860. }