trigger.c 30 KB

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