misc.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
  29. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  30. arg = sub_arg_in_braces(ses, arg, arg2, GET_ONE, SUB_VAR|SUB_FUN);
  31. if (*arg1 == 0)
  32. {
  33. print_stdout("\007");
  34. return ses;
  35. }
  36. if (is_abbrev(arg1, "FLASH"))
  37. {
  38. if (is_abbrev(arg2, "ON"))
  39. {
  40. print_stdout("\e[?1042h");
  41. }
  42. else if (is_abbrev(arg2, "OFF"))
  43. {
  44. print_stdout("\e[?1042l");
  45. }
  46. else
  47. {
  48. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL FLASH {ON|OFF}");
  49. }
  50. }
  51. else if (is_abbrev(arg1, "FOCUS"))
  52. {
  53. if (is_abbrev(arg2, "ON"))
  54. {
  55. print_stdout("\e[?1043h");
  56. }
  57. else if (is_abbrev(arg2, "OFF"))
  58. {
  59. print_stdout("\e[?1043l");
  60. }
  61. else
  62. {
  63. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL POP {ON|OFF}");
  64. }
  65. }
  66. else if (is_abbrev(arg1, "MARGIN"))
  67. {
  68. if (is_abbrev(arg2, "ON"))
  69. {
  70. print_stdout("\e[?44h");
  71. }
  72. else if (is_abbrev(arg2, "OFF"))
  73. {
  74. print_stdout("\e[?44l");
  75. }
  76. else
  77. {
  78. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL MARGIN {ON|OFF}");
  79. }
  80. }
  81. else if (is_abbrev(arg1, "RING"))
  82. {
  83. print_stdout("\007");
  84. }
  85. else if (is_abbrev(arg1, "VOLUME"))
  86. {
  87. if (is_math(ses, arg2))
  88. {
  89. print_stdout("\e[ %dt", (int) get_number(ses, arg2));
  90. }
  91. else
  92. {
  93. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL VOLUME {1-8}");
  94. }
  95. }
  96. else
  97. {
  98. show_error(ses, LIST_COMMAND, "#SYNTAX: #BELL {FLASH|FOCUS|MARGIN|RING|VOLUME} {ARGUMENT}");
  99. }
  100. return ses;
  101. }
  102. DO_COMMAND(do_commands)
  103. {
  104. char buf[BUFFER_SIZE] = { 0 }, add[BUFFER_SIZE];
  105. int cmd;
  106. tintin_header(ses, " %s ", "COMMANDS");
  107. for (cmd = 0 ; *command_table[cmd].name != 0 ; cmd++)
  108. {
  109. if (*arg && !is_abbrev(arg, command_table[cmd].name))
  110. {
  111. continue;
  112. }
  113. if ((int) strlen(buf) + 20 > gtd->screen->cols)
  114. {
  115. tintin_puts2(ses, buf);
  116. buf[0] = 0;
  117. }
  118. sprintf(add, "%20s", command_table[cmd].name);
  119. strcat(buf, add);
  120. }
  121. if (buf[0])
  122. {
  123. tintin_puts2(ses, buf);
  124. }
  125. tintin_header(ses, "");
  126. return ses;
  127. }
  128. DO_COMMAND(do_cr)
  129. {
  130. write_mud(ses, "", SUB_EOL);
  131. return ses;
  132. }
  133. DO_COMMAND(do_echo)
  134. {
  135. char format[BUFFER_SIZE], result[BUFFER_SIZE], temp[BUFFER_SIZE], *output, left[BUFFER_SIZE];
  136. int lnf;
  137. arg = sub_arg_in_braces(ses, arg, format, GET_ONE, SUB_VAR|SUB_FUN);
  138. format_string(ses, format, arg, result);
  139. arg = result;
  140. if (*arg == DEFAULT_OPEN)
  141. {
  142. arg = get_arg_in_braces(ses, arg, left, GET_ALL);
  143. get_arg_in_braces(ses, arg, temp, GET_ALL);
  144. if (*temp)
  145. {
  146. int row = (int) get_number(ses, temp);
  147. substitute(ses, left, temp, SUB_COL|SUB_ESC);
  148. split_show(ses, temp, row, 0);
  149. return ses;
  150. }
  151. }
  152. lnf = !str_suffix(arg, "\\");
  153. substitute(ses, arg, temp, SUB_COL|SUB_ESC);
  154. if (strip_vt102_strlen(ses, ses->more_output) != 0)
  155. {
  156. output = str_dup_printf("\n\e[0m%s\e[0m", temp);
  157. }
  158. else
  159. {
  160. output = str_dup_printf("\e[0m%s\e[0m", temp);
  161. }
  162. add_line_buffer(ses, output, lnf);
  163. if (ses == gtd->ses)
  164. {
  165. if (!HAS_BIT(ses->flags, SES_FLAG_READMUD) && IS_SPLIT(ses))
  166. {
  167. save_pos(ses);
  168. goto_pos(ses, ses->split->bot_row, 1);
  169. print_line(ses, &output, lnf);
  170. restore_pos(ses);
  171. }
  172. else
  173. {
  174. print_line(ses, &output, lnf);
  175. }
  176. }
  177. str_free(output);
  178. return ses;
  179. }
  180. DO_COMMAND(do_end)
  181. {
  182. char arg1[BUFFER_SIZE];
  183. if (*arg)
  184. {
  185. sub_arg_in_braces(ses, arg, arg1, GET_ALL, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC|SUB_LNF);
  186. quitmsg(arg1);
  187. }
  188. else
  189. {
  190. quitmsg(NULL);
  191. }
  192. return NULL;
  193. }
  194. DO_COMMAND(do_nop)
  195. {
  196. return ses;
  197. }
  198. DO_COMMAND(do_send)
  199. {
  200. char arg1[BUFFER_SIZE];
  201. push_call("do_send(%p,%p)",ses,arg);
  202. get_arg_in_braces(ses, arg, arg1, GET_ALL);
  203. write_mud(ses, arg1, SUB_VAR|SUB_FUN|SUB_ESC|SUB_EOL);
  204. pop_call();
  205. return ses;
  206. }
  207. DO_COMMAND(do_test)
  208. {
  209. char arg1[BUFFER_SIZE], arg2[100], arg3[100], arg4[100];
  210. strcpy(arg2, "9");
  211. strcpy(arg3, "<f0b8>");
  212. strcpy(arg4, "3 9");
  213. if (isdigit(arg[0]))
  214. {
  215. sprintf(arg2, "%d", (arg[0] - '0') * (arg[0] - '0'));
  216. if (isxdigit(arg[1]) && isxdigit(arg[2]) && isxdigit(arg[3]))
  217. {
  218. sprintf(arg3, "<f%c%c%c>", arg[1], arg[2], arg[3]);
  219. if (isdigit(arg[4]) && isdigit(arg[5]))
  220. {
  221. sprintf(arg4, "%d %d %s", (arg[4] - '0') * (arg[4] - '0') / 10, (arg[5] - '0') * (arg[5] - '0'), &arg[6]);
  222. }
  223. }
  224. }
  225. 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);
  226. script_driver(gtd->ses, LIST_COMMAND, arg1);
  227. return ses;
  228. }