trigger.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  30. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  31. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  32. if (*arg1 == 0)
  33. {
  34. show_list(ses->list[LIST_ACTION], 0);
  35. }
  36. else if (*arg1 && *arg2 == 0)
  37. {
  38. if (show_node_with_wild(ses, arg1, ses->list[LIST_ACTION]) == FALSE)
  39. {
  40. show_message(ses, LIST_ACTION, "#ACTION: NO MATCHES FOUND FOR {%s}.", arg1);
  41. }
  42. }
  43. else
  44. {
  45. if (*arg3 && (atof(arg3) < 1 || atof(arg3) >= 10))
  46. {
  47. show_error(ses, LIST_ACTION, "#WARNING: #ACTION {%s} {..} {%s} SHOULD HAVE A PRIORITY BETWEEN 1.000 and 9.999.", arg1, arg3);
  48. }
  49. update_node_list(ses->list[LIST_ACTION], arg1, arg2, arg3, "");
  50. show_message(ses, LIST_ACTION, "#OK: #ACTION {%s} NOW TRIGGERS {%s} @ {%s}.", arg1, arg2, arg3);
  51. }
  52. return ses;
  53. }
  54. DO_COMMAND(do_unaction)
  55. {
  56. delete_node_with_wild(ses, LIST_ACTION, arg);
  57. return ses;
  58. }
  59. void check_all_actions(struct session *ses, char *original, char *line, char *buf)
  60. {
  61. struct listroot *root = ses->list[LIST_ACTION];
  62. struct listnode *node;
  63. for (root->update = 0 ; root->update < root->used ; root->update++)
  64. {
  65. node = root->list[root->update];
  66. if (HAS_BIT(node->flags, NODE_FLAG_MULTI))
  67. {
  68. continue;
  69. }
  70. if (check_one_regexp(ses, node, line, original, 0))
  71. {
  72. show_debug(ses, LIST_ACTION, COLOR_DEBUG "#DEBUG ACTION " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1);
  73. substitute(ses, node->arg2, buf, SUB_ARG|SUB_SEC);
  74. if (node->shots && --node->shots == 0)
  75. {
  76. delete_node_list(ses, LIST_ACTION, node);
  77. }
  78. script_driver(ses, LIST_ACTION, buf);
  79. if (HAS_BIT(ses->config_flags, CONFIG_FLAG_MULTI_TRIGGER))
  80. {
  81. DEL_BIT(ses->config_flags, CONFIG_FLAG_MULTI_TRIGGER);
  82. continue;
  83. }
  84. return;
  85. }
  86. }
  87. }
  88. void check_all_actions_multi(struct session *ses, char *original, char *stripped, char *buf)
  89. {
  90. struct listroot *root = ses->list[LIST_ACTION];
  91. struct listnode *node;
  92. char *pto, *pts, *ptm;
  93. for (root->multi_update = 0 ; root->multi_update < root->used ; root->multi_update++)
  94. {
  95. node = root->list[root->multi_update];
  96. if (!HAS_BIT(node->flags, NODE_FLAG_MULTI))
  97. {
  98. continue;
  99. }
  100. pto = original;
  101. pts = stripped;
  102. while (pto && pts)
  103. {
  104. if (!check_one_regexp(ses, node, pts, pto, 0))
  105. {
  106. break;
  107. }
  108. show_debug(ses, LIST_ACTION, COLOR_DEBUG "#DEBUG MULTI ACTION " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1);
  109. substitute(ses, node->arg2, buf, SUB_ARG|SUB_SEC);
  110. if (node->shots && --node->shots == 0)
  111. {
  112. delete_node_list(ses, LIST_ACTION, node);
  113. pto = pts = NULL;
  114. }
  115. else
  116. {
  117. if (*gtd->vars[0])
  118. {
  119. pto += gtd->match[1];
  120. pts += gtd->match[1];
  121. if (pts[-1] != '\n')
  122. {
  123. pto = strchr(pto, '\n'); if (pto) pto++;
  124. pts = strchr(pts, '\n'); if (pts) pts++;
  125. }
  126. }
  127. else
  128. {
  129. pto = pts = NULL;
  130. }
  131. }
  132. script_driver(ses, LIST_ACTION, buf);
  133. ptm = node->arg1 + (*node->arg1 == '~');
  134. if (ptm[0] == '\\' && ptm[1] == 'A')
  135. {
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. /******************************************************************************
  142. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  143. * *
  144. * coded by Peter Unold 1992 *
  145. * recoded by Igor van den Hoven 2009 *
  146. ******************************************************************************/
  147. DO_COMMAND(do_alias)
  148. {
  149. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  150. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  151. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  152. if (*arg1 == 0)
  153. {
  154. show_list(ses->list[LIST_ALIAS], 0);
  155. }
  156. else if (*arg2 == 0)
  157. {
  158. if (show_node_with_wild(ses, arg1, ses->list[LIST_ALIAS]) == FALSE)
  159. {
  160. show_message(ses, LIST_ALIAS, "#ALIAS: NO MATCHES FOUND FOR {%s}.", arg1);
  161. }
  162. }
  163. else
  164. {
  165. update_node_list(ses->list[LIST_ALIAS], arg1, arg2, arg3, "");
  166. show_message(ses, LIST_ALIAS, "#ALIAS {%s} NOW TRIGGERS {%s} @ {%s}.", arg1, arg2, arg3);
  167. }
  168. return ses;
  169. }
  170. DO_COMMAND(do_unalias)
  171. {
  172. delete_node_with_wild(ses, LIST_ALIAS, arg);
  173. return ses;
  174. }
  175. int check_all_aliases(struct session *ses, char *input)
  176. {
  177. struct listnode *node;
  178. struct listroot *root;
  179. char *buf, *line, *arg;
  180. int i;
  181. root = ses->list[LIST_ALIAS];
  182. if (gtd->level->ignore || HAS_BIT(root->flags, LIST_FLAG_IGNORE))
  183. {
  184. return FALSE;
  185. }
  186. if (push_call_printf("check_all_aliases(%s,%s)",ses->name,input) == 0)
  187. {
  188. pop_call();
  189. return FALSE;
  190. }
  191. buf = str_alloc_stack(0);
  192. line = str_alloc_stack(0);
  193. substitute(ses, input, line, SUB_VAR|SUB_FUN);
  194. for (root->update = 0 ; root->update < root->used ; root->update++)
  195. {
  196. node = root->list[root->update];
  197. if (check_one_regexp(ses, node, line, line, PCRE_ANCHORED))
  198. {
  199. i = strlen(node->arg1);
  200. if (!strncmp(node->arg1, line, i))
  201. {
  202. if (line[i])
  203. {
  204. if (line[i] != ' ')
  205. {
  206. continue;
  207. }
  208. arg = &line[i + 1];
  209. }
  210. else
  211. {
  212. arg = &line[i];
  213. }
  214. RESTRING(gtd->vars[0], arg)
  215. for (i = 1 ; i < 100 ; i++)
  216. {
  217. gtd->varc = i;
  218. if (*arg == 0)
  219. {
  220. while (i < 100)
  221. {
  222. *gtd->vars[i++] = 0;
  223. }
  224. break;
  225. }
  226. arg = get_arg_in_braces(ses, arg, buf, GET_ONE);
  227. RESTRING(gtd->vars[i], buf);
  228. }
  229. }
  230. substitute(ses, node->arg2, buf, SUB_ARG);
  231. if (!strncmp(node->arg1, line, strlen(node->arg1)) && !strcmp(node->arg2, buf) && *gtd->vars[0])
  232. {
  233. sprintf(input, "%s %s", buf, gtd->vars[0]);
  234. }
  235. else
  236. {
  237. sprintf(input, "%s", buf);
  238. }
  239. show_debug(ses, LIST_ALIAS, COLOR_DEBUG "#DEBUG ALIAS " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1, gtd->vars[0]);
  240. if (node->shots && --node->shots == 0)
  241. {
  242. delete_node_list(ses, LIST_ALIAS, node);
  243. }
  244. pop_call();
  245. return TRUE;
  246. }
  247. }
  248. pop_call();
  249. return FALSE;
  250. }
  251. /******************************************************************************
  252. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  253. * *
  254. * coded by Igor van den Hoven 2019 *
  255. ******************************************************************************/
  256. DO_COMMAND(do_button)
  257. {
  258. struct listnode *node;
  259. int index;
  260. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  261. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  262. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  263. if (*arg1 == 0)
  264. {
  265. show_list(ses->list[LIST_BUTTON], 0);
  266. }
  267. else if (*arg1 && *arg2 == 0)
  268. {
  269. if (show_node_with_wild(ses, arg1, ses->list[LIST_BUTTON]) == FALSE)
  270. {
  271. show_message(ses, LIST_BUTTON, "#BUTTON: NO MATCHES FOUND FOR {%s}.", arg1);
  272. }
  273. }
  274. else
  275. {
  276. SET_BIT(gtd->event_flags, EVENT_FLAG_MOUSE);
  277. SET_BIT(ses->event_flags, EVENT_FLAG_MOUSE);
  278. node = update_node_list(ses->list[LIST_BUTTON], arg1, arg2, arg3, "");
  279. show_message(ses, LIST_BUTTON, "#OK: BUTTON {%s} NOW TRIGGERS {%s} @ {%s}.", arg1, arg2, arg3);
  280. arg = arg1;
  281. for (index = 0 ; index < 4 ; index++)
  282. {
  283. arg = sub_arg_in_braces(ses, arg, arg2, GET_ONE, SUB_VAR|SUB_FUN);
  284. node->val16[index] = (short) get_number(ses, arg2);
  285. if (node->val16[index] == 0)
  286. {
  287. show_error(ses, LIST_BUTTON, "#ERROR: #BUTTON {%s} IS NOT A VALID SQUARE COORDINATE.", arg1);
  288. delete_node_list(ses, LIST_BUTTON, node);
  289. return ses;
  290. }
  291. if (*arg == COMMAND_SEPARATOR)
  292. {
  293. arg++;
  294. }
  295. }
  296. if (*arg)
  297. {
  298. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  299. str_cpy(&node->arg4, arg2);
  300. }
  301. else
  302. {
  303. str_cpy(&node->arg4, "PRESSED MOUSE BUTTON ONE");
  304. }
  305. }
  306. return ses;
  307. }
  308. DO_COMMAND(do_unbutton)
  309. {
  310. delete_node_with_wild(ses, LIST_BUTTON, arg);
  311. return ses;
  312. }
  313. void check_all_buttons(struct session *ses, short row, short col, char *arg1, char *arg2, char *word, char *line)
  314. {
  315. char *buf, *arg4;
  316. struct listnode *node;
  317. struct listroot *root;
  318. short val[4];
  319. root = ses->list[LIST_BUTTON];
  320. if (HAS_BIT(root->flags, LIST_FLAG_IGNORE))
  321. {
  322. return;
  323. }
  324. push_call("check_all_buttons(%p,%d,%d,%p,%p,%p,%p)",ses,row,col,arg1,arg2,word,line);
  325. buf = str_alloc_stack(0);
  326. arg4 = str_alloc_stack(0);
  327. sprintf(arg4, "%s %s", arg1, arg2);
  328. 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);
  329. for (root->update = 0 ; root->update < root->used ; root->update++)
  330. {
  331. node = root->list[root->update];;
  332. val[0] = node->val16[0] < 0 ? 1 + gtd->screen->rows + node->val16[0] : node->val16[0];
  333. val[1] = node->val16[1] < 0 ? 1 + gtd->screen->cols + node->val16[1] : node->val16[1];
  334. if (row < val[0] || col < val[1])
  335. {
  336. continue;
  337. }
  338. val[2] = node->val16[2] < 0 ? 1 + gtd->screen->rows + node->val16[2] : node->val16[2];
  339. val[3] = node->val16[3] < 0 ? 1 + gtd->screen->cols + node->val16[3] : node->val16[3];
  340. if (row > val[2] || col > val[3])
  341. {
  342. continue;
  343. }
  344. if (!strcmp(arg4, node->arg4))
  345. {
  346. show_debug(ses, LIST_BUTTON, COLOR_DEBUG "#DEBUG BUTTON " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1);
  347. RESTRING(gtd->vars[0], ntos(row));
  348. RESTRING(gtd->vars[1], ntos(col));
  349. RESTRING(gtd->vars[2], ntos(-1 - (gtd->screen->rows - row)));
  350. RESTRING(gtd->vars[3], ntos(-1 - (gtd->screen->cols - col)));
  351. RESTRING(gtd->vars[4], word);
  352. RESTRING(gtd->vars[5], line);
  353. substitute(ses, node->arg2, buf, SUB_ARG|SUB_SEC);
  354. if (node->shots && --node->shots == 0)
  355. {
  356. delete_node_list(ses, LIST_BUTTON, node);
  357. }
  358. script_driver(ses, LIST_BUTTON, buf);
  359. break;
  360. }
  361. }
  362. pop_call();
  363. return;
  364. }
  365. /******************************************************************************
  366. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  367. * *
  368. * coded by Igor van den Hoven 2004 *
  369. ******************************************************************************/
  370. DO_COMMAND(do_delay)
  371. {
  372. char time[NUMBER_SIZE];
  373. long double number;
  374. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  375. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  376. arg = sub_arg_in_braces(ses, arg, arg3, GET_ALL, SUB_VAR|SUB_FUN);
  377. if (*arg1 == 0)
  378. {
  379. show_list(ses->list[LIST_DELAY], 0);
  380. }
  381. else if (*arg2 == 0)
  382. {
  383. if (show_node_with_wild(ses, arg1, ses->list[LIST_DELAY]) == FALSE)
  384. {
  385. show_message(ses, LIST_DELAY, "#DELAY: NO MATCHES FOUND FOR {%s}.", arg1);
  386. }
  387. }
  388. else
  389. {
  390. if (*arg3 == 0)
  391. {
  392. number = get_number(ses, arg1);
  393. sprintf(arg3, "%lld", gtd->utime);
  394. sprintf(time, "%llu.%010llu", gtd->utime + (unsigned long long) (number * 1000000), (unsigned long long) (number * 10000000000) % 10000000000);
  395. create_node_list(ses->list[LIST_DELAY], time, arg2, arg1, arg3);
  396. show_message(ses, LIST_DELAY, "#DELAY: IN {%s} SECONDS {%s} IS EXECUTED.", arg1, arg2);
  397. }
  398. else
  399. {
  400. struct listnode *node;
  401. get_number_string(ses, arg3, time);
  402. sprintf(arg3, "%lld", gtd->utime);
  403. node = update_node_list(ses->list[LIST_TICKER], arg1, arg2, time, arg3);
  404. node->shots = 1;
  405. show_message(ses, LIST_TICKER, "#ONESHOT: #TICKER {%s} WILL EXECUTE {%s} IN {%s} SECONDS.", arg1, arg2, time);
  406. }
  407. }
  408. return ses;
  409. }
  410. DO_COMMAND(do_undelay)
  411. {
  412. sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  413. if (is_alpha(*arg1))
  414. {
  415. delete_node_with_wild(ses, LIST_TICKER, arg);
  416. }
  417. else
  418. {
  419. delete_node_with_wild(ses, LIST_DELAY, arg);
  420. }
  421. return ses;
  422. }
  423. // checked in update.c
  424. /******************************************************************************
  425. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  426. * *
  427. * coded by Sverre Normann 1999 *
  428. * recoded by Igor van den Hoven 2004 *
  429. ******************************************************************************/
  430. DO_COMMAND(do_function)
  431. {
  432. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  433. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  434. if (*arg1 == 0)
  435. {
  436. show_list(ses->list[LIST_FUNCTION], 0);
  437. }
  438. else if (*arg1 && *arg2 == 0)
  439. {
  440. if (show_node_with_wild(ses, arg1, ses->list[LIST_FUNCTION]) == FALSE)
  441. {
  442. show_message(ses, LIST_FUNCTION, "#FUNCTION: NO MATCHES FOUND FOR {%s}.", arg1);
  443. }
  444. }
  445. else
  446. {
  447. update_node_list(ses->list[LIST_FUNCTION], arg1, arg2, "", "");
  448. show_message(ses, LIST_FUNCTION, "#OK: FUNCTION {%s} NOW TRIGGERS {%s}.", arg1, arg2);
  449. }
  450. return ses;
  451. }
  452. DO_COMMAND(do_unfunction)
  453. {
  454. delete_node_with_wild(ses, LIST_FUNCTION, arg);
  455. return ses;
  456. }
  457. // checked in tinexp.c
  458. /******************************************************************************
  459. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  460. * *
  461. * coded by Igor van den Hoven 2007 *
  462. ******************************************************************************/
  463. DO_COMMAND(do_gag)
  464. {
  465. arg = sub_arg_in_braces(ses, arg, arg1, GET_ALL, SUB_VAR|SUB_FUN);
  466. if (*arg1 == 0)
  467. {
  468. show_list(ses->list[LIST_GAG], 0);
  469. }
  470. else
  471. {
  472. update_node_list(ses->list[LIST_GAG], arg1, "", "", "");
  473. show_message(ses, LIST_GAG, "#OK: {%s} IS NOW GAGGED.", arg1);
  474. }
  475. return ses;
  476. }
  477. DO_COMMAND(do_ungag)
  478. {
  479. delete_node_with_wild(ses, LIST_GAG, arg);
  480. return ses;
  481. }
  482. void check_all_gags(struct session *ses, char *original, char *line)
  483. {
  484. struct listroot *root = ses->list[LIST_GAG];
  485. struct listnode *node;
  486. for (root->update = 0 ; root->update < root->used ; root->update++)
  487. {
  488. node = root->list[root->update];
  489. if (check_one_regexp(ses, node, line, original, 0))
  490. {
  491. // show_debug(ses, LIST_GAG, "#DEBUG GAG {%s}", node->arg1);
  492. if (node->shots && --node->shots == 0)
  493. {
  494. delete_node_list(ses, LIST_GAG, node);
  495. }
  496. if (ses->gagline == 0)
  497. {
  498. ses->gagline = 1;
  499. }
  500. return;
  501. }
  502. }
  503. }
  504. /******************************************************************************
  505. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  506. * *
  507. * coded by Bill Reiss 1993 *
  508. * recoded by Igor van den Hoven 2004 *
  509. ******************************************************************************/
  510. DO_COMMAND(do_highlight)
  511. {
  512. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  513. arg = sub_arg_in_braces(ses, arg, arg2, GET_ALL, SUB_VAR|SUB_FUN);
  514. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  515. if (*arg1 == 0)
  516. {
  517. show_list(ses->list[LIST_HIGHLIGHT], 0);
  518. }
  519. else if (*arg1 && *arg2 == 0)
  520. {
  521. if (show_node_with_wild(ses, arg1, ses->list[LIST_HIGHLIGHT]) == FALSE)
  522. {
  523. show_message(ses, LIST_HIGHLIGHT, "#HIGHLIGHT: NO MATCHES FOUND FOR {%s}.", arg1);
  524. }
  525. }
  526. else
  527. {
  528. if (!is_color_name(arg2))
  529. {
  530. tintin_printf2(ses, "#HIGHLIGHT: INVALID COLOR {%s}. VALID COLORS ARE:\n", arg2);
  531. tintin_printf2(ses, "reset, light, 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.");
  532. }
  533. else
  534. {
  535. update_node_list(ses->list[LIST_HIGHLIGHT], arg1, arg2, arg3, "");
  536. show_message(ses, LIST_HIGHLIGHT, "#OK: {%s} NOW HIGHLIGHTS {%s} @ {%s}.", arg1, arg2, arg3);
  537. }
  538. }
  539. return ses;
  540. }
  541. DO_COMMAND(do_unhighlight)
  542. {
  543. delete_node_with_wild(ses, LIST_HIGHLIGHT, arg);
  544. return ses;
  545. }
  546. void check_all_highlights(struct session *ses, char *original, char *line)
  547. {
  548. struct listroot *root = ses->list[LIST_HIGHLIGHT];
  549. struct listnode *node;
  550. char *pto, *ptl, *ptm;
  551. char *match, *color, *output, *plain;
  552. int len;
  553. push_call("check_all_highlights(%p,%p,%p)",ses,original,line);
  554. match = str_alloc_stack(0);
  555. color = str_alloc_stack(0);
  556. output = str_alloc_stack(0);
  557. plain = str_alloc_stack(0);
  558. for (root->update = 0 ; root->update < root->used ; root->update++)
  559. {
  560. node = root->list[root->update];
  561. if (check_one_regexp(ses, node, line, original, 0))
  562. {
  563. get_color_names(ses, node->arg2, color);
  564. *output = *gtd->color_reset = 0;
  565. pto = original;
  566. ptl = line;
  567. do
  568. {
  569. if (*gtd->vars[0] == 0)
  570. {
  571. break;
  572. }
  573. strcpy(match, gtd->vars[0]);
  574. strip_vt102_codes(match, plain);
  575. if (*node->arg1 == '~')
  576. {
  577. ptm = strstr(pto, match);
  578. len = strlen(match);
  579. }
  580. else
  581. {
  582. ptm = strip_vt102_strstr(pto, match, &len);
  583. ptl = strstr(ptl, match) + strlen(match);
  584. }
  585. *ptm = 0;
  586. get_color_codes(gtd->color_reset, pto, gtd->color_reset, GET_ALL);
  587. cat_sprintf(output, "%s%s%s\e[0m%s", pto, color, plain, gtd->color_reset);
  588. pto = ptm + len;
  589. show_debug(ses, LIST_HIGHLIGHT, COLOR_DEBUG "#DEBUG HIGHLIGHT " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1);
  590. }
  591. while (check_one_regexp(ses, node, ptl, pto, 0));
  592. if (node->shots && --node->shots == 0)
  593. {
  594. delete_node_list(ses, LIST_HIGHLIGHT, node);
  595. }
  596. strcat(output, pto);
  597. strcpy(original, output);
  598. }
  599. }
  600. pop_call();
  601. return;
  602. }
  603. /******************************************************************************
  604. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  605. * *
  606. * coded by Igor van den Hoven 2006 *
  607. ******************************************************************************/
  608. DO_COMMAND(do_macro)
  609. {
  610. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  611. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  612. if (*arg1 == 0)
  613. {
  614. show_list(ses->list[LIST_MACRO], 0);
  615. }
  616. else if (*arg1 && *arg2 == 0)
  617. {
  618. if (show_node_with_wild(ses, arg1, ses->list[LIST_MACRO]) == FALSE)
  619. {
  620. show_message(ses, LIST_MACRO, "#MACRO: NO MATCHES FOUND FOR {%s}.", arg1);
  621. }
  622. }
  623. else
  624. {
  625. tintin_macro_compile(arg1, arg3);
  626. update_node_list(ses->list[LIST_MACRO], arg1, arg2, "", arg3);
  627. show_message(ses, LIST_MACRO, "#OK: MACRO {%s} NOW TRIGGERS {%s}.", arg1, arg2);
  628. }
  629. return ses;
  630. }
  631. DO_COMMAND(do_unmacro)
  632. {
  633. delete_node_with_wild(ses, LIST_MACRO, arg);
  634. return ses;
  635. }
  636. // checked in input.c
  637. /******************************************************************************
  638. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  639. * *
  640. * coded by Igor van den Hoven 2004 *
  641. ******************************************************************************/
  642. DO_COMMAND(do_prompt)
  643. {
  644. arg = get_arg_in_braces(ses, arg, arg1, GET_ALL);
  645. arg = get_arg_in_braces(ses, arg, arg2, GET_ALL);
  646. if (*arg1 == 0)
  647. {
  648. show_list(ses->list[LIST_PROMPT], 0);
  649. }
  650. else if (*arg1 && *arg2 == 0 && *arg == 0)
  651. {
  652. if (show_node_with_wild(ses, arg1, ses->list[LIST_PROMPT]) == FALSE)
  653. {
  654. show_message(ses, LIST_PROMPT, "#PROMPT: NO MATCHES FOUND FOR {%s}.", arg1);
  655. }
  656. }
  657. else
  658. {
  659. arg3 = str_alloc_stack(0);
  660. arg4 = str_alloc_stack(0);
  661. arg = sub_arg_in_braces(ses, arg, arg3, GET_ONE, SUB_VAR|SUB_FUN);
  662. arg = sub_arg_in_braces(ses, arg, arg4, GET_ONE, SUB_VAR|SUB_FUN);
  663. update_node_list(ses->list[LIST_PROMPT], arg1, arg2, arg3, arg4);
  664. show_message(ses, LIST_PROMPT, "#OK: {%s} NOW PROMPTS {%s} @ {%s} {%s}.", arg1, arg2, arg3, arg4);
  665. }
  666. return ses;
  667. }
  668. DO_COMMAND(do_unprompt)
  669. {
  670. delete_node_with_wild(ses, LIST_PROMPT, arg);
  671. return ses;
  672. }
  673. int check_all_prompts(struct session *ses, char *original, char *line)
  674. {
  675. struct listroot *root = ses->list[LIST_PROMPT];
  676. struct listnode *node;
  677. if (!HAS_BIT(ses->flags, SES_FLAG_SPLIT))
  678. {
  679. return 0;
  680. }
  681. for (root->update = 0 ; root->update < root->used ; root->update++)
  682. {
  683. node = root->list[root->update];
  684. if (check_one_regexp(ses, node, line, original, 0))
  685. {
  686. if (*node->arg2)
  687. {
  688. substitute(ses, node->arg2, line, SUB_ARG);
  689. substitute(ses, line, original, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC);
  690. strip_vt102_codes(original, line);
  691. }
  692. show_debug(ses, LIST_PROMPT, COLOR_DEBUG "#DEBUG PROMPT " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1);
  693. if (strcmp(node->arg3, "0"))
  694. {
  695. split_show(ses, original, node->arg3, node->arg4);
  696. if (ses->gagline == 0)
  697. {
  698. ses->gagline = 1;
  699. }
  700. }
  701. if (node->shots && --node->shots == 0)
  702. {
  703. delete_node_list(ses, LIST_PROMPT, node);
  704. }
  705. }
  706. }
  707. return 0;
  708. }
  709. /******************************************************************************
  710. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  711. * *
  712. * coded by Peter Unold 1992 *
  713. * recoded by Igor van den Hoven 2004 *
  714. ******************************************************************************/
  715. DO_COMMAND(do_substitute)
  716. {
  717. char *str;
  718. str = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  719. arg = get_arg_in_braces(ses, str, arg2, GET_ALL);
  720. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  721. if (*arg1 == 0)
  722. {
  723. show_list(ses->list[LIST_SUBSTITUTE], 0);
  724. }
  725. else if (*str == 0)
  726. {
  727. if (show_node_with_wild(ses, arg1, ses->list[LIST_SUBSTITUTE]) == FALSE)
  728. {
  729. show_message(ses, LIST_SUBSTITUTE, "#SUBSTITUTE: NO MATCHES FOUND FOR {%s}.", arg1);
  730. }
  731. }
  732. else
  733. {
  734. update_node_list(ses->list[LIST_SUBSTITUTE], arg1, arg2, arg3, "");
  735. show_message(ses, LIST_SUBSTITUTE, "#OK: {%s} IS NOW SUBSTITUTED AS {%s} @ {%s}.", arg1, arg2, arg3);
  736. }
  737. return ses;
  738. }
  739. DO_COMMAND(do_unsubstitute)
  740. {
  741. delete_node_with_wild(ses, LIST_SUBSTITUTE, arg);
  742. return ses;
  743. }
  744. void check_all_substitutions(struct session *ses, char *original, char *line)
  745. {
  746. char *match, *subst, *result, *temp, *ptl, *ptm, *pto, *ptr;
  747. struct listroot *root = ses->list[LIST_SUBSTITUTE];
  748. struct listnode *node;
  749. int len;
  750. push_call("check_all_substitutions(%p,%p,%p)",ses,original,line);
  751. match = str_alloc_stack(0);
  752. subst = str_alloc_stack(0);
  753. result = str_alloc_stack(0);
  754. temp = str_alloc_stack(0);
  755. for (root->update = 0 ; root->update < root->used ; root->update++)
  756. {
  757. node = root->list[root->update];
  758. if (HAS_BIT(node->flags, NODE_FLAG_MULTI))
  759. {
  760. continue;
  761. }
  762. if (check_one_regexp(ses, node, line, original, 0))
  763. {
  764. pto = original;
  765. ptl = line;
  766. ptr = result;
  767. *result = *gtd->color_reset = 0;
  768. do
  769. {
  770. if (*gtd->vars[0] == 0)
  771. {
  772. break;
  773. }
  774. strcpy(match, gtd->vars[0]);
  775. substitute(ses, node->arg2, temp, SUB_ARG);
  776. if (*node->arg1 == '~')
  777. {
  778. ptm = strstr(pto, match);
  779. len = strlen(match);
  780. }
  781. else
  782. {
  783. ptm = strip_vt102_strstr(pto, match, &len);
  784. ptl = strstr(ptl, match) + strlen(match);
  785. }
  786. *ptm = 0;
  787. get_color_codes(gtd->color_reset, pto, gtd->color_reset, GET_ALL);
  788. substitute(ses, temp, subst, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC);
  789. ptr += sprintf(ptr, "%s%s", pto, subst);
  790. pto = ptm + len;
  791. show_debug(ses, LIST_SUBSTITUTE, COLOR_DEBUG "#DEBUG SUBSTITUTE " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1, match);
  792. ptm = node->arg1 + (*node->arg1 == '~');
  793. if (ptm[0] == '\\' && ptm[1] == 'A')
  794. {
  795. break;
  796. }
  797. }
  798. while (*pto && check_one_regexp(ses, node, ptl, pto, PCRE_NOTBOL));
  799. if (node->shots && --node->shots == 0)
  800. {
  801. delete_node_list(ses, LIST_SUBSTITUTE, node);
  802. }
  803. strcpy(ptr, pto);
  804. strcpy(original, result);
  805. strip_vt102_codes(original, line);
  806. }
  807. }
  808. pop_call();
  809. return;
  810. }
  811. void check_all_substitutions_multi(struct session *ses, char *original, char *line)
  812. {
  813. char *match, *subst, *result, *temp, *ptl, *ptm, *pto, *ptr;
  814. struct listroot *root = ses->list[LIST_SUBSTITUTE];
  815. struct listnode *node;
  816. int len;
  817. push_call("check_all_substitutions(%p,%p,%p)",ses,original,line);
  818. match = str_alloc_stack(0);
  819. subst = str_alloc_stack(0);
  820. result = str_alloc_stack(0);
  821. temp = str_alloc_stack(0);
  822. for (root->multi_update = 0 ; root->multi_update < root->used ; root->multi_update++)
  823. {
  824. node = root->list[root->multi_update];
  825. if (!HAS_BIT(node->flags, NODE_FLAG_MULTI))
  826. {
  827. continue;
  828. }
  829. if (check_one_regexp(ses, node, line, original, 0))
  830. {
  831. pto = original;
  832. ptl = line;
  833. ptr = result;
  834. *result = *gtd->color_reset = 0;
  835. do
  836. {
  837. if (*gtd->vars[0] == 0)
  838. {
  839. break;
  840. }
  841. strcpy(match, gtd->vars[0]);
  842. substitute(ses, node->arg2, temp, SUB_ARG);
  843. if (*node->arg1 == '~')
  844. {
  845. ptm = strstr(pto, match);
  846. len = strlen(match);
  847. }
  848. else
  849. {
  850. ptm = strip_vt102_strstr(pto, match, &len);
  851. ptl = strstr(ptl, match) + strlen(match);
  852. }
  853. *ptm = 0;
  854. get_color_codes(gtd->color_reset, pto, gtd->color_reset, GET_ALL);
  855. substitute(ses, temp, subst, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC);
  856. ptr += sprintf(ptr, "%s%s", pto, subst);
  857. pto = ptm + len;
  858. show_debug(ses, LIST_SUBSTITUTE, COLOR_DEBUG "#DEBUG SUBSTITUTE " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", node->arg1, match);
  859. ptm = node->arg1 + (*node->arg1 == '~');
  860. if (ptm[0] == '\\' && ptm[1] == 'A')
  861. {
  862. break;
  863. }
  864. }
  865. while (*pto && check_one_regexp(ses, node, ptl, pto, PCRE_NOTBOL));
  866. if (node->shots && --node->shots == 0)
  867. {
  868. delete_node_list(ses, LIST_SUBSTITUTE, node);
  869. }
  870. strcpy(ptr, pto);
  871. strcpy(original, result);
  872. strip_vt102_codes(original, line);
  873. }
  874. }
  875. pop_call();
  876. return;
  877. }
  878. /******************************************************************************
  879. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  880. * *
  881. * coded by Igor van den Hoven 2006 *
  882. ******************************************************************************/
  883. DO_COMMAND(do_tab)
  884. {
  885. sub_arg_in_braces(ses, arg, arg1, GET_ALL, SUB_VAR|SUB_FUN);
  886. if (*arg1 == 0)
  887. {
  888. show_list(ses->list[LIST_TAB], 0);
  889. }
  890. else
  891. {
  892. update_node_list(ses->list[LIST_TAB], arg1, "", "", "");
  893. show_message(ses, LIST_TAB, "#OK: {%s} IS NOW A TAB.", arg1);
  894. }
  895. return ses;
  896. }
  897. DO_COMMAND(do_untab)
  898. {
  899. delete_node_with_wild(ses, LIST_TAB, arg);
  900. return ses;
  901. }
  902. // checked in cursor.c
  903. /******************************************************************************
  904. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  905. * *
  906. * coded by Peter Unold 1992 *
  907. * recoded by Igor van den Hoven 2004 *
  908. ******************************************************************************/
  909. DO_COMMAND(do_tick)
  910. {
  911. char time[NUMBER_SIZE];
  912. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  913. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  914. arg = get_arg_in_braces(ses, arg, arg3, GET_ALL);
  915. if (*arg3 == 0)
  916. {
  917. strcpy(time, "60");
  918. }
  919. else
  920. {
  921. get_number_string(ses, arg3, time);
  922. }
  923. // store creation time for #info tickers save
  924. sprintf(arg3, "%lld", ++gtd->utime);
  925. if (*arg1 == 0)
  926. {
  927. show_list(ses->list[LIST_TICKER], 0);
  928. }
  929. else if (*arg1 && *arg2 == 0)
  930. {
  931. if (show_node_with_wild(ses, arg1, ses->list[LIST_TICKER]) == FALSE)
  932. {
  933. show_message(ses, LIST_TICKER, "#TICKER: NO MATCHES FOUND FOR {%s}.", arg1);
  934. }
  935. }
  936. else
  937. {
  938. update_node_list(ses->list[LIST_TICKER], arg1, arg2, time, arg3);
  939. show_message(ses, LIST_TICKER, "#OK: #TICKER {%s} NOW EXECUTES {%s} EVERY {%s} SECONDS.", arg1, arg2, time);
  940. }
  941. return ses;
  942. }
  943. DO_COMMAND(do_untick)
  944. {
  945. delete_node_with_wild(ses, LIST_TICKER, arg);
  946. return ses;
  947. }
  948. // checked in update.c