trigger.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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. #include "tintin.h"
  21. /******************************************************************************
  22. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  23. * *
  24. * coded by Peter Unold 1992 *
  25. * recoded by Igor van den Hoven 2009 *
  26. ******************************************************************************/
  27. DO_COMMAND(do_action)
  28. {
  29. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE];
  30. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  31. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  32. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  33. if (*arg1 == 0)
  34. {
  35. show_list(ses->list[LIST_ACTION], 0);
  36. }
  37. else if (*arg1 && *arg2 == 0)
  38. {
  39. if (show_node_with_wild(ses, arg1, ses->list[LIST_ACTION]) == FALSE)
  40. {
  41. show_message(ses, LIST_ACTION, "#ACTION: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  42. }
  43. }
  44. else
  45. {
  46. update_node_list(ses->list[LIST_ACTION], arg1, arg2, arg3, "");
  47. show_message(ses, LIST_ACTION, "#OK. #ACTION {%s} NOW TRIGGERS {%s} @ {%s}.", arg1, arg2, arg3);
  48. }
  49. return ses;
  50. }
  51. DO_COMMAND(do_unaction)
  52. {
  53. delete_node_with_wild(ses, LIST_ACTION, arg);
  54. return ses;
  55. }
  56. void check_all_actions(struct session *ses, char *original, char *line)
  57. {
  58. struct listroot *root = ses->list[LIST_ACTION];
  59. struct listnode *node;
  60. char buf[BUFFER_SIZE];
  61. for (root->update = 0 ; root->update < root->used ; root->update++)
  62. {
  63. node = root->list[root->update];
  64. if (check_one_regexp(ses, node, line, original, 0))
  65. {
  66. show_debug(ses, LIST_ACTION, "#DEBUG ACTION {%s}", node->arg1);
  67. substitute(ses, node->arg2, buf, SUB_ARG|SUB_SEC);
  68. if (HAS_BIT(node->flags, NODE_FLAG_ONESHOT))
  69. {
  70. delete_node_list(ses, LIST_ACTION, node);
  71. }
  72. script_driver(ses, LIST_ACTION, buf);
  73. return;
  74. }
  75. }
  76. }
  77. /******************************************************************************
  78. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  79. * *
  80. * coded by Peter Unold 1992 *
  81. * recoded by Igor van den Hoven 2009 *
  82. ******************************************************************************/
  83. DO_COMMAND(do_alias)
  84. {
  85. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE];
  86. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  87. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  88. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  89. if (*arg1 == 0)
  90. {
  91. show_list(ses->list[LIST_ALIAS], 0);
  92. }
  93. else if (*arg2 == 0)
  94. {
  95. if (show_node_with_wild(ses, arg1, ses->list[LIST_ALIAS]) == FALSE)
  96. {
  97. show_message(ses, LIST_ALIAS, "#ALIAS: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  98. }
  99. }
  100. else
  101. {
  102. update_node_list(ses->list[LIST_ALIAS], arg1, arg2, arg3, "");
  103. show_message(ses, LIST_ALIAS, "#ALIAS {%s} NOW TRIGGERS {%s} @ {%s}.", arg1, arg2, arg3);
  104. }
  105. return ses;
  106. }
  107. DO_COMMAND(do_unalias)
  108. {
  109. delete_node_with_wild(ses, LIST_ALIAS, arg);
  110. return ses;
  111. }
  112. int check_all_aliases(struct session *ses, char *input)
  113. {
  114. struct listnode *node;
  115. struct listroot *root;
  116. char tmp[BUFFER_SIZE], line[BUFFER_SIZE], *arg;
  117. int i;
  118. root = ses->list[LIST_ALIAS];
  119. if (HAS_BIT(root->flags, LIST_FLAG_IGNORE))
  120. {
  121. return FALSE;
  122. }
  123. substitute(ses, input, line, SUB_VAR|SUB_FUN);
  124. for (root->update = 0 ; root->update < root->used ; root->update++)
  125. {
  126. node = root->list[root->update];
  127. if (check_one_regexp(ses, node, line, line, PCRE_ANCHORED))
  128. {
  129. i = strlen(node->arg1);
  130. if (!strncmp(node->arg1, line, i))
  131. {
  132. if (line[i])
  133. {
  134. if (line[i] != ' ')
  135. {
  136. continue;
  137. }
  138. arg = &line[i + 1];
  139. }
  140. else
  141. {
  142. arg = &line[i];
  143. }
  144. RESTRING(gtd->vars[0], arg)
  145. for (i = 1 ; i < 100 ; i++)
  146. {
  147. arg = get_arg_in_braces(ses, arg, tmp, GET_ONE);
  148. RESTRING(gtd->vars[i], tmp);
  149. if (*arg == 0)
  150. {
  151. while (++i < 100)
  152. {
  153. if (*gtd->vars[i])
  154. {
  155. RESTRING(gtd->vars[i], "");
  156. }
  157. }
  158. break;
  159. }
  160. }
  161. }
  162. substitute(ses, node->arg2, tmp, SUB_ARG);
  163. if (!strncmp(node->arg1, line, strlen(node->arg1)) && !strcmp(node->arg2, tmp) && *gtd->vars[0])
  164. {
  165. sprintf(input, "%s %s", tmp, gtd->vars[0]);
  166. }
  167. else
  168. {
  169. sprintf(input, "%s", tmp);
  170. }
  171. show_debug(ses, LIST_ALIAS, "#DEBUG ALIAS {%s} {%s}", node->arg1, gtd->vars[0]);
  172. if (HAS_BIT(node->flags, NODE_FLAG_ONESHOT))
  173. {
  174. delete_node_list(ses, LIST_ALIAS, node);
  175. }
  176. return TRUE;
  177. }
  178. }
  179. return FALSE;
  180. }
  181. /******************************************************************************
  182. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  183. * *
  184. * coded by Igor van den Hoven 2019 *
  185. ******************************************************************************/
  186. DO_COMMAND(do_button)
  187. {
  188. struct listnode *node;
  189. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE];
  190. int index;
  191. arg = sub_arg_in_braces(ses, arg, arg1, GET_ALL, SUB_VAR|SUB_FUN);
  192. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  193. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  194. if (*arg1 == 0)
  195. {
  196. show_list(ses->list[LIST_BUTTON], 0);
  197. }
  198. else if (*arg1 && *arg2 == 0)
  199. {
  200. if (show_node_with_wild(ses, arg1, ses->list[LIST_BUTTON]) == FALSE)
  201. {
  202. show_message(ses, LIST_BUTTON, "#BUTTON: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  203. }
  204. }
  205. else
  206. {
  207. node = update_node_list(ses->list[LIST_BUTTON], arg1, arg2, arg3, "");
  208. show_message(ses, LIST_BUTTON, "#OK. BUTTON {%s} NOW TRIGGERS {%s} @ {%s}.", arg1, arg2, arg3);
  209. arg = arg1;
  210. for (index = 0 ; index < 4 ; index++)
  211. {
  212. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  213. node->val16[index] = (short) get_number(ses, arg2);
  214. if (*arg == COMMAND_SEPARATOR)
  215. {
  216. arg++;
  217. }
  218. }
  219. if (*arg)
  220. {
  221. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  222. RESTRING(node->arg4, arg2);
  223. }
  224. else
  225. {
  226. RESTRING(node->arg4, "PRESSED MOUSE BUTTON ONE");
  227. }
  228. }
  229. return ses;
  230. }
  231. DO_COMMAND(do_unbutton)
  232. {
  233. delete_node_with_wild(ses, LIST_BUTTON, arg);
  234. return ses;
  235. }
  236. void check_all_buttons(struct session *ses, short row, short col, char *arg1, char *arg2, char *word, char *line)
  237. {
  238. char buf[BUFFER_SIZE], arg4[BUFFER_SIZE];
  239. struct listnode *node;
  240. struct listroot *root;
  241. short val[4];
  242. root = ses->list[LIST_BUTTON];
  243. if (HAS_BIT(root->flags, LIST_FLAG_IGNORE))
  244. {
  245. return;
  246. }
  247. sprintf(arg4, "%s %s", arg1, arg2);
  248. show_info(ses, LIST_BUTTON, "#INFO BUTTON {%d;%d;%d;%d;%s}", row, col, -1 - (gtd->screen->rows - row), -1 - (gtd->screen->cols - col), arg4);
  249. for (root->update = 0 ; root->update < root->used ; root->update++)
  250. {
  251. node = root->list[root->update];;
  252. val[0] = node->val16[0] < 0 ? 1 + gtd->screen->rows + node->val16[0] : node->val16[0];
  253. val[1] = node->val16[1] < 0 ? 1 + gtd->screen->cols + node->val16[1] : node->val16[1];
  254. if (row < val[0] || col < val[1])
  255. {
  256. continue;
  257. }
  258. val[2] = node->val16[2] < 0 ? 1 + gtd->screen->rows + node->val16[2] : node->val16[2];
  259. val[3] = node->val16[3] < 0 ? 1 + gtd->screen->cols + node->val16[3] : node->val16[3];
  260. if (row > val[2] || col > val[3])
  261. {
  262. continue;
  263. }
  264. if (!strcmp(arg4, node->arg4))
  265. {
  266. show_debug(ses, LIST_BUTTON, "#DEBUG BUTTON {%s}", node->arg1);
  267. RESTRING(gtd->vars[0], ntos(row));
  268. RESTRING(gtd->vars[1], ntos(col));
  269. RESTRING(gtd->vars[2], ntos(-1 - (gtd->screen->rows - row)));
  270. RESTRING(gtd->vars[3], ntos(-1 - (gtd->screen->cols - col)));
  271. RESTRING(gtd->vars[4], word);
  272. RESTRING(gtd->vars[5], line);
  273. substitute(ses, node->arg2, buf, SUB_ARG|SUB_SEC);
  274. if (HAS_BIT(node->flags, NODE_FLAG_ONESHOT))
  275. {
  276. delete_node_list(ses, LIST_BUTTON, node);
  277. }
  278. script_driver(ses, LIST_BUTTON, buf);
  279. return;
  280. }
  281. }
  282. }
  283. /******************************************************************************
  284. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  285. * *
  286. * coded by Igor van den Hoven 2004 *
  287. ******************************************************************************/
  288. DO_COMMAND(do_delay)
  289. {
  290. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE], time[BUFFER_SIZE];
  291. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  292. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  293. arg = sub_arg_in_braces(ses, arg, arg3, GET_ALL, SUB_VAR|SUB_FUN);
  294. if (*arg1 == 0)
  295. {
  296. show_list(ses->list[LIST_DELAY], 0);
  297. }
  298. else if (*arg2 == 0)
  299. {
  300. if (show_node_with_wild(ses, arg1, ses->list[LIST_DELAY]) == FALSE)
  301. {
  302. show_message(ses, LIST_DELAY, "#DELAY: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  303. }
  304. }
  305. else
  306. {
  307. if (*arg3 == 0)
  308. {
  309. sprintf(arg3, "%lld", utime() + (long long) (1000000 * get_number(ses, arg1)));
  310. get_number_string(ses, arg1, time);
  311. update_node_list(ses->list[LIST_DELAY], arg3, arg2, time, "");
  312. show_message(ses, LIST_DELAY, "#OK, IN {%s} SECONDS {%s} IS EXECUTED.", time, arg2);
  313. }
  314. else
  315. {
  316. get_number_string(ses, arg3, time);
  317. gtd->level->oneshot++;
  318. update_node_list(ses->list[LIST_TICKER], arg1, arg2, time, "");
  319. gtd->level->oneshot--;
  320. show_message(ses, LIST_TICKER, "#OK. #TICK {%s} WILL EXECUTE {%s} IN {%s} SECONDS.", arg1, arg2, time);
  321. }
  322. }
  323. return ses;
  324. }
  325. DO_COMMAND(do_undelay)
  326. {
  327. if (isalpha(*arg))
  328. {
  329. delete_node_with_wild(ses, LIST_TICKER, arg);
  330. }
  331. else
  332. {
  333. delete_node_with_wild(ses, LIST_DELAY, arg);
  334. }
  335. return ses;
  336. }
  337. // checked in update.c
  338. /******************************************************************************
  339. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  340. * *
  341. * coded by Sverre Normann 1999 *
  342. * recoded by Igor van den Hoven 2004 *
  343. ******************************************************************************/
  344. DO_COMMAND(do_function)
  345. {
  346. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
  347. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  348. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  349. if (*arg1 == 0)
  350. {
  351. show_list(ses->list[LIST_FUNCTION], 0);
  352. }
  353. else if (*arg1 && *arg2 == 0)
  354. {
  355. if (show_node_with_wild(ses, arg1, ses->list[LIST_FUNCTION]) == FALSE)
  356. {
  357. show_message(ses, LIST_FUNCTION, "#FUNCTION: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  358. }
  359. }
  360. else
  361. {
  362. update_node_list(ses->list[LIST_FUNCTION], arg1, arg2, "", "");
  363. show_message(ses, LIST_FUNCTION, "#OK. FUNCTION {%s} HAS BEEN SET TO {%s}.", arg1, arg2);
  364. }
  365. return ses;
  366. }
  367. DO_COMMAND(do_unfunction)
  368. {
  369. delete_node_with_wild(ses, LIST_FUNCTION, arg);
  370. return ses;
  371. }
  372. // checked in tinexp.c
  373. /******************************************************************************
  374. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  375. * *
  376. * coded by Igor van den Hoven 2007 *
  377. ******************************************************************************/
  378. DO_COMMAND(do_gag)
  379. {
  380. char arg1[BUFFER_SIZE];
  381. arg = sub_arg_in_braces(ses, arg, arg1, GET_ALL, SUB_VAR|SUB_FUN);
  382. if (*arg1 == 0)
  383. {
  384. show_list(ses->list[LIST_GAG], 0);
  385. }
  386. else
  387. {
  388. update_node_list(ses->list[LIST_GAG], arg1, "", "", "");
  389. show_message(ses, LIST_GAG, "#OK. {%s} IS NOW GAGGED.", arg1);
  390. }
  391. return ses;
  392. }
  393. DO_COMMAND(do_ungag)
  394. {
  395. delete_node_with_wild(ses, LIST_GAG, arg);
  396. return ses;
  397. }
  398. void check_all_gags(struct session *ses, char *original, char *line)
  399. {
  400. struct listroot *root = ses->list[LIST_GAG];
  401. struct listnode *node;
  402. for (root->update = 0 ; root->update < root->used ; root->update++)
  403. {
  404. node = root->list[root->update];
  405. if (check_one_regexp(ses, node, line, original, 0))
  406. {
  407. show_debug(ses, LIST_GAG, "#DEBUG GAG {%s}", node->arg1);
  408. if (HAS_BIT(node->flags, NODE_FLAG_ONESHOT))
  409. {
  410. delete_node_list(ses, LIST_GAG, node);
  411. }
  412. SET_BIT(ses->flags, SES_FLAG_GAG);
  413. return;
  414. }
  415. }
  416. }
  417. /******************************************************************************
  418. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  419. * *
  420. * coded by Bill Reiss 1993 *
  421. * recoded by Igor van den Hoven 2004 *
  422. ******************************************************************************/
  423. DO_COMMAND(do_highlight)
  424. {
  425. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE], temp[BUFFER_SIZE];
  426. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  427. arg = sub_arg_in_braces(ses, arg, arg2, GET_ALL, SUB_VAR|SUB_FUN);
  428. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  429. if (*arg1 == 0)
  430. {
  431. show_list(ses->list[LIST_HIGHLIGHT], 0);
  432. }
  433. else if (*arg1 && *arg2 == 0)
  434. {
  435. if (show_node_with_wild(ses, arg1, ses->list[LIST_HIGHLIGHT]) == FALSE)
  436. {
  437. show_message(ses, LIST_HIGHLIGHT, "#HIGHLIGHT: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  438. }
  439. }
  440. else
  441. {
  442. if (get_color_names(ses, arg2, temp) == FALSE)
  443. {
  444. tintin_printf2(ses, "#HIGHLIGHT: VALID COLORS ARE:\n");
  445. tintin_printf2(ses, "reset, bold, light, faint, dim, dark, underscore, blink, reverse, black, red, green, yellow, blue, magenta, cyan, white, b black, b red, b green, b yellow, b blue, b magenta, b cyan, b white, azure, ebony, jade, lime, orange, pink, silver, tan, violet.");
  446. }
  447. else
  448. {
  449. update_node_list(ses->list[LIST_HIGHLIGHT], arg1, arg2, arg3, "");
  450. show_message(ses, LIST_HIGHLIGHT, "#OK. {%s} NOW HIGHLIGHTS {%s} @ {%s}.", arg1, arg2, arg3);
  451. }
  452. }
  453. return ses;
  454. }
  455. DO_COMMAND(do_unhighlight)
  456. {
  457. delete_node_with_wild(ses, LIST_HIGHLIGHT, arg);
  458. return ses;
  459. }
  460. void check_all_highlights(struct session *ses, char *original, char *line)
  461. {
  462. struct listroot *root = ses->list[LIST_HIGHLIGHT];
  463. struct listnode *node;
  464. char *pto, *ptl, *ptm;
  465. char match[BUFFER_SIZE], color[BUFFER_SIZE], reset[BUFFER_SIZE], output[BUFFER_SIZE], plain[BUFFER_SIZE];
  466. int len;
  467. push_call("check_all_highlights(%p,%p,%p)",ses,original,line);
  468. for (root->update = 0 ; root->update < root->used ; root->update++)
  469. {
  470. node = root->list[root->update];
  471. if (check_one_regexp(ses, node, line, original, 0))
  472. {
  473. get_color_names(ses, node->arg2, color);
  474. *output = *reset = 0;
  475. pto = original;
  476. ptl = line;
  477. do
  478. {
  479. if (*gtd->vars[0] == 0)
  480. {
  481. break;
  482. }
  483. strcpy(match, gtd->vars[0]);
  484. strip_vt102_codes(match, plain);
  485. if (*node->arg1 == '~')
  486. {
  487. ptm = strstr(pto, match);
  488. len = strlen(match);
  489. }
  490. else
  491. {
  492. ptm = strip_vt102_strstr(pto, match, &len);
  493. ptl = strstr(ptl, match) + strlen(match);
  494. }
  495. *ptm = 0;
  496. get_color_codes(reset, pto, reset, GET_ALL);
  497. cat_sprintf(output, "%s%s%s\e[0m%s", pto, color, plain, reset);
  498. pto = ptm + len;
  499. show_debug(ses, LIST_HIGHLIGHT, "#DEBUG HIGHLIGHT {%s}", node->arg1);
  500. }
  501. while (check_one_regexp(ses, node, ptl, pto, 0));
  502. if (HAS_BIT(node->flags, NODE_FLAG_ONESHOT))
  503. {
  504. delete_node_list(ses, LIST_HIGHLIGHT, node);
  505. }
  506. strcat(output, pto);
  507. strcpy(original, output);
  508. }
  509. }
  510. pop_call();
  511. return;
  512. }
  513. /******************************************************************************
  514. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  515. * *
  516. * coded by Igor van den Hoven 2006 *
  517. ******************************************************************************/
  518. DO_COMMAND(do_macro)
  519. {
  520. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE];
  521. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  522. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  523. if (*arg1 == 0)
  524. {
  525. show_list(ses->list[LIST_MACRO], 0);
  526. }
  527. else if (*arg1 && *arg2 == 0)
  528. {
  529. if (show_node_with_wild(ses, arg1, ses->list[LIST_MACRO]) == FALSE)
  530. {
  531. show_message(ses, LIST_MACRO, "#MACRO: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  532. }
  533. }
  534. else
  535. {
  536. tintin_macro_compile(arg1, arg3);
  537. update_node_list(ses->list[LIST_MACRO], arg1, arg2, arg3, "");
  538. show_message(ses, LIST_MACRO, "#OK. MACRO {%s} HAS BEEN SET TO {%s}.", arg1, arg2);
  539. }
  540. return ses;
  541. }
  542. DO_COMMAND(do_unmacro)
  543. {
  544. delete_node_with_wild(ses, LIST_MACRO, arg);
  545. return ses;
  546. }
  547. // checked in input.c
  548. /******************************************************************************
  549. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  550. * *
  551. * coded by Igor van den Hoven 2004 *
  552. ******************************************************************************/
  553. DO_COMMAND(do_prompt)
  554. {
  555. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE], arg4[BUFFER_SIZE];
  556. arg = get_arg_in_braces(ses, arg, arg1, GET_ALL);
  557. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  558. if (*arg1 == 0)
  559. {
  560. show_list(ses->list[LIST_PROMPT], 0);
  561. }
  562. else if (*arg1 && *arg2 == 0)
  563. {
  564. if (show_node_with_wild(ses, arg1, ses->list[LIST_PROMPT]) == FALSE)
  565. {
  566. show_message(ses, LIST_PROMPT, "#PROMPT: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  567. }
  568. }
  569. else
  570. {
  571. arg = sub_arg_in_braces(ses, arg, arg3, GET_ONE, SUB_VAR|SUB_FUN);
  572. arg = sub_arg_in_braces(ses, arg, arg4, GET_ONE, SUB_VAR|SUB_FUN);
  573. update_node_list(ses->list[LIST_PROMPT], arg1, arg2, arg3, arg4);
  574. show_message(ses, LIST_PROMPT, "#OK. {%s} NOW PROMPTS {%s} @ {%s} {%s}.", arg1, arg2, arg3, arg4);
  575. }
  576. return ses;
  577. }
  578. DO_COMMAND(do_unprompt)
  579. {
  580. delete_node_with_wild(ses, LIST_PROMPT, arg);
  581. return ses;
  582. }
  583. void check_all_prompts(struct session *ses, char *original, char *line)
  584. {
  585. struct listroot *root = ses->list[LIST_PROMPT];
  586. struct listnode *node;
  587. if (!HAS_BIT(ses->flags, SES_FLAG_SPLIT))
  588. {
  589. return;
  590. }
  591. for (root->update = 0 ; root->update < root->used ; root->update++)
  592. {
  593. node = root->list[root->update];
  594. if (check_one_regexp(ses, node, line, original, 0))
  595. {
  596. if (*node->arg2)
  597. {
  598. substitute(ses, node->arg2, original, SUB_ARG);
  599. substitute(ses, original, original, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC);
  600. }
  601. show_debug(ses, LIST_PROMPT, "#DEBUG PROMPT {%s}", node->arg1);
  602. show_debug(ses, LIST_GAG, "#DEBUG GAG {%s}", node->arg1);
  603. split_show(ses, original, atoi(node->arg3), atoi(node->arg4));
  604. if (HAS_BIT(node->flags, NODE_FLAG_ONESHOT))
  605. {
  606. delete_node_list(ses, LIST_GAG, node);
  607. }
  608. SET_BIT(ses->flags, SES_FLAG_GAG);
  609. }
  610. }
  611. }
  612. /******************************************************************************
  613. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  614. * *
  615. * coded by Peter Unold 1992 *
  616. * recoded by Igor van den Hoven 2004 *
  617. ******************************************************************************/
  618. DO_COMMAND(do_substitute)
  619. {
  620. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE], *str;
  621. str = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  622. arg = get_arg_in_braces(ses, str, arg2, GET_ALL);
  623. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  624. if (*arg1 == 0)
  625. {
  626. show_list(ses->list[LIST_SUBSTITUTE], 0);
  627. }
  628. else if (*str == 0)
  629. {
  630. if (show_node_with_wild(ses, arg1, ses->list[LIST_SUBSTITUTE]) == FALSE)
  631. {
  632. show_message(ses, LIST_SUBSTITUTE, "#SUBSTITUTE: NO MATCH(ES) FOUND FOR {%s}.", arg1);
  633. }
  634. }
  635. else
  636. {
  637. update_node_list(ses->list[LIST_SUBSTITUTE], arg1, arg2, arg3, "");
  638. show_message(ses, LIST_SUBSTITUTE, "#OK. {%s} IS NOW SUBSTITUTED AS {%s} @ {%s}.", arg1, arg2, arg3);
  639. }
  640. return ses;
  641. }
  642. DO_COMMAND(do_unsubstitute)
  643. {
  644. delete_node_with_wild(ses, LIST_SUBSTITUTE, arg);
  645. return ses;
  646. }
  647. void check_all_substitutions(struct session *ses, char *original, char *line)
  648. {
  649. char match[BUFFER_SIZE], subst[BUFFER_SIZE], output[BUFFER_SIZE], temp[BUFFER_SIZE], *ptl, *ptm, *pto;
  650. struct listroot *root = ses->list[LIST_SUBSTITUTE];
  651. struct listnode *node;
  652. int len;
  653. for (root->update = 0 ; root->update < root->used ; root->update++)
  654. {
  655. node = root->list[root->update];
  656. if (check_one_regexp(ses, node, line, original, 0))
  657. {
  658. pto = original;
  659. ptl = line;
  660. *output = 0;
  661. do
  662. {
  663. if (*gtd->vars[0] == 0)
  664. {
  665. break;
  666. }
  667. strcpy(match, gtd->vars[0]);
  668. substitute(ses, node->arg2, temp, SUB_ARG);
  669. substitute(ses, temp, subst, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC);
  670. if (*node->arg1 == '~')
  671. {
  672. ptm = strstr(pto, match);
  673. len = strlen(match);
  674. }
  675. else
  676. {
  677. ptm = strip_vt102_strstr(pto, match, &len);
  678. ptl = strstr(ptl, match) + strlen(match);
  679. }
  680. *ptm = 0;
  681. cat_sprintf(output, "%s%s", pto, subst);
  682. pto = ptm + len;
  683. show_debug(ses, LIST_SUBSTITUTE, "#DEBUG SUBSTITUTE {%s} {%s}", node->arg1, match);
  684. }
  685. while (check_one_regexp(ses, node, ptl, pto, 0));
  686. if (HAS_BIT(node->flags, NODE_FLAG_ONESHOT))
  687. {
  688. delete_node_list(ses, LIST_SUBSTITUTE, node);
  689. }
  690. strcat(output, pto);
  691. strcpy(original, output);
  692. strip_vt102_codes(original, line);
  693. }
  694. }
  695. }
  696. /******************************************************************************
  697. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  698. * *
  699. * coded by Igor van den Hoven 2006 *
  700. ******************************************************************************/
  701. DO_COMMAND(do_tab)
  702. {
  703. char arg1[BUFFER_SIZE];
  704. sub_arg_in_braces(ses, arg, arg1, GET_ALL, SUB_VAR|SUB_FUN);
  705. if (*arg1 == 0)
  706. {
  707. show_list(ses->list[LIST_TAB], 0);
  708. }
  709. else
  710. {
  711. update_node_list(ses->list[LIST_TAB], arg1, "", "", "");
  712. show_message(ses, LIST_TAB, "#OK. {%s} IS NOW A TAB.", arg1);
  713. }
  714. return ses;
  715. }
  716. DO_COMMAND(do_untab)
  717. {
  718. delete_node_with_wild(ses, LIST_TAB, arg);
  719. return ses;
  720. }
  721. // checked in cursor.c
  722. /******************************************************************************
  723. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  724. * *
  725. * coded by Peter Unold 1992 *
  726. * recoded by Igor van den Hoven 2004 *
  727. ******************************************************************************/
  728. DO_COMMAND(do_tick)
  729. {
  730. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], arg3[BUFFER_SIZE], arg4[BUFFER_SIZE];
  731. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  732. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  733. arg = get_arg_in_braces(ses, arg, arg4, GET_ALL);
  734. if (*arg4 == 0)
  735. {
  736. strcpy(arg3, "60");
  737. }
  738. else
  739. {
  740. get_number_string(ses, arg4, arg3);
  741. }
  742. if (*arg1 == 0)
  743. {
  744. show_list(ses->list[LIST_TICKER], 0);
  745. }
  746. else if (*arg1 && *arg2 == 0)
  747. {
  748. if (show_node_with_wild(ses, arg1, ses->list[LIST_TICKER]) == FALSE)
  749. {
  750. show_message(ses, LIST_TICKER, "#TICK, NO MATCH(ES) FOUND FOR {%s}.", arg1);
  751. }
  752. }
  753. else
  754. {
  755. update_node_list(ses->list[LIST_TICKER], arg1, arg2, arg3, "");
  756. show_message(ses, LIST_TICKER, "#OK. #TICK {%s} NOW EXECUTES {%s} EVERY {%s} SECONDS.", arg1, arg2, arg3);
  757. }
  758. return ses;
  759. }
  760. DO_COMMAND(do_untick)
  761. {
  762. delete_node_with_wild(ses, LIST_TICKER, arg);
  763. return ses;
  764. }
  765. // checked in update.c