misc.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /******************************************************************************
  2. * This file is part of TinTin++ *
  3. * *
  4. * Copyright 2004-2019 Igor van den Hoven *
  5. * *
  6. * TinTin++ is free software; you can redistribute it and/or modify *
  7. * it under the terms of the GNU General Public License as published by *
  8. * the Free Software Foundation; either version 3 of the License, or *
  9. * (at your option) any later version. *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * *
  17. * You should have received a copy of the GNU General Public License *
  18. * along with TinTin++. If not, see https://www.gnu.org/licenses. *
  19. ******************************************************************************/
  20. /******************************************************************************
  21. * (T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t *
  22. * *
  23. * coded by Peter Unold 1992 *
  24. ******************************************************************************/
  25. #include "tintin.h"
  26. DO_COMMAND(do_bell)
  27. {
  28. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  29. arg = sub_arg_in_braces(ses, arg, arg2, GET_ONE, SUB_VAR|SUB_FUN);
  30. if (*arg1 == 0)
  31. {
  32. print_stdout("\007");
  33. }
  34. else if (is_abbrev(arg1, "FLASH"))
  35. {
  36. if (is_abbrev(arg2, "ON"))
  37. {
  38. print_stdout("\e[?1042h");
  39. }
  40. else if (is_abbrev(arg2, "OFF"))
  41. {
  42. print_stdout("\e[?1042l");
  43. }
  44. else
  45. {
  46. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL FLASH {ON|OFF}");
  47. }
  48. }
  49. else if (is_abbrev(arg1, "FOCUS"))
  50. {
  51. if (is_abbrev(arg2, "ON"))
  52. {
  53. print_stdout("\e[?1043h");
  54. }
  55. else if (is_abbrev(arg2, "OFF"))
  56. {
  57. print_stdout("\e[?1043l");
  58. }
  59. else
  60. {
  61. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL FOCUS {ON|OFF}");
  62. }
  63. }
  64. else if (is_abbrev(arg1, "MARGIN"))
  65. {
  66. if (is_abbrev(arg2, "ON"))
  67. {
  68. print_stdout("\e[?44h");
  69. }
  70. else if (is_abbrev(arg2, "OFF"))
  71. {
  72. print_stdout("\e[?44l");
  73. }
  74. else
  75. {
  76. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL MARGIN {ON|OFF}");
  77. }
  78. }
  79. else if (is_abbrev(arg1, "RING"))
  80. {
  81. print_stdout("\007");
  82. }
  83. else if (is_abbrev(arg1, "VOLUME"))
  84. {
  85. if (is_math(ses, arg2))
  86. {
  87. print_stdout("\e[ %dt", (int) get_number(ses, arg2));
  88. }
  89. else
  90. {
  91. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL VOLUME {1-8}");
  92. }
  93. }
  94. else
  95. {
  96. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL {FLASH|FOCUS|MARGIN|RING|VOLUME} {ARGUMENT}");
  97. }
  98. return ses;
  99. }
  100. DO_COMMAND(do_commands)
  101. {
  102. char buf[BUFFER_SIZE] = { 0 };
  103. int cmd;
  104. tintin_header(ses, " %s ", "COMMANDS");
  105. for (cmd = 0 ; *command_table[cmd].name != 0 ; cmd++)
  106. {
  107. if (*arg && !is_abbrev(arg, command_table[cmd].name))
  108. {
  109. continue;
  110. }
  111. if (strip_vt102_strlen(ses, buf) + 20 > gtd->screen->cols)
  112. {
  113. tintin_puts2(ses, buf);
  114. buf[0] = 0;
  115. }
  116. if (command_table[cmd].type == TOKEN_TYPE_COMMAND)
  117. {
  118. cat_sprintf(buf, "%s%20s", COLOR_COMMAND, command_table[cmd].name);
  119. }
  120. else
  121. {
  122. cat_sprintf(buf, "%s%20s", COLOR_STATEMENT, command_table[cmd].name);
  123. }
  124. }
  125. if (buf[0])
  126. {
  127. tintin_puts2(ses, buf);
  128. }
  129. return ses;
  130. }
  131. DO_COMMAND(do_cr)
  132. {
  133. write_mud(ses, "", SUB_EOL);
  134. return ses;
  135. }
  136. DO_COMMAND(do_echo)
  137. {
  138. char format[BUFFER_SIZE], result[BUFFER_SIZE], temp[BUFFER_SIZE], *output, left[BUFFER_SIZE];
  139. int lnf;
  140. arg = sub_arg_in_braces(ses, arg, format, GET_ONE, SUB_VAR|SUB_FUN);
  141. format_string(ses, format, arg, result);
  142. arg = result;
  143. if (*arg == DEFAULT_OPEN)
  144. {
  145. arg = get_arg_in_braces(ses, arg, left, GET_ALL);
  146. get_arg_in_braces(ses, arg, temp, GET_ALL);
  147. if (*temp)
  148. {
  149. int row = (int) get_number(ses, temp);
  150. substitute(ses, left, temp, SUB_COL|SUB_ESC);
  151. split_show(ses, temp, row, 0);
  152. return ses;
  153. }
  154. }
  155. lnf = !str_suffix(arg, "\\");
  156. substitute(ses, arg, temp, SUB_COL|SUB_ESC);
  157. if (strip_vt102_strlen(ses, ses->more_output) != 0)
  158. {
  159. output = str_dup_printf("\n\e[0m%s\e[0m", temp);
  160. }
  161. else
  162. {
  163. output = str_dup_printf("\e[0m%s\e[0m", temp);
  164. }
  165. add_line_buffer(ses, output, lnf);
  166. if (ses == gtd->ses)
  167. {
  168. if (!HAS_BIT(ses->flags, SES_FLAG_READMUD) && IS_SPLIT(ses))
  169. {
  170. save_pos(ses);
  171. goto_pos(ses, ses->split->bot_row, 1);
  172. print_line(ses, &output, lnf);
  173. restore_pos(ses);
  174. }
  175. else
  176. {
  177. print_line(ses, &output, lnf);
  178. }
  179. }
  180. str_free(output);
  181. return ses;
  182. }
  183. DO_COMMAND(do_end)
  184. {
  185. if (*arg)
  186. {
  187. sub_arg_in_braces(ses, arg, arg1, GET_ALL, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC|SUB_LNF);
  188. quitmsg(arg1);
  189. }
  190. else
  191. {
  192. quitmsg(NULL);
  193. }
  194. return NULL;
  195. }
  196. DO_COMMAND(do_nop)
  197. {
  198. return ses;
  199. }
  200. DO_COMMAND(do_send)
  201. {
  202. push_call("do_send(%p,%p)",ses,arg);
  203. get_arg_in_braces(ses, arg, arg1, GET_ALL);
  204. write_mud(ses, arg1, SUB_VAR|SUB_FUN|SUB_ESC|SUB_EOL);
  205. pop_call();
  206. return ses;
  207. }
  208. DO_COMMAND(do_test)
  209. {
  210. if (!strcmp(arg, "string"))
  211. {
  212. char *test = str_dup("\e[32m0 2 4 6 8 A C E");
  213. test = str_ins_str(ses, &test, "\e[33mbli bli", 4, 11);
  214. printf("test: [%s]\n", test);
  215. str_free(test);
  216. return ses;
  217. }
  218. strcpy(arg2, "9");
  219. strcpy(arg3, "<f0b8>");
  220. strcpy(arg4, "1 9");
  221. if (isdigit((int) arg[0]))
  222. {
  223. sprintf(arg2, "%d", (arg[0] - '0') * (arg[0] - '0'));
  224. if ((isxdigit((int) arg[1]) && isxdigit((int) arg[2]) && isxdigit((int) arg[3])) || (arg[1] == '?' && arg[2] == '?' && arg[3] == '?'))
  225. {
  226. sprintf(arg3, "<f%c%c%c>", arg[1], arg[2], arg[3]);
  227. if (isdigit((int) arg[4]) && isdigit((int) arg[5]))
  228. {
  229. sprintf(arg4, "%f %d %s", (arg[4] - '0') * (arg[4] - '0') / 10.0, (arg[5] - '0') * (arg[5] - '0'), &arg[6]);
  230. tintin_printf2(ses, "do_test debug: %s", arg4);
  231. }
  232. }
  233. }
  234. sprintf(arg1, "#line quiet {#event {RECEIVED KEYPRESS} {#end \\};#screen cursor hide;#screen clear all;#event {SECOND} #loop 0 %s cnt #delay {$cnt / (1.0+%s)} #draw %s rain 1 1 -1 -1 rain %s}", arg2, arg2, arg3, arg4);
  235. script_driver(gtd->ses, LIST_COMMAND, arg1);
  236. return ses;
  237. }