| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
#include "angband.h" |
|---|
| 19 |
#include "randname.h" |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
static char hexify(int i) |
|---|
| 27 |
{ |
|---|
| 28 |
return (hexsym[i % 16]); |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
static int dehex(char c) |
|---|
| 35 |
{ |
|---|
| 36 |
if (isdigit((unsigned char)c)) return (D2I(c)); |
|---|
| 37 |
if (isalpha((unsigned char)c)) return (A2I(tolower((unsigned char)c)) + 10); |
|---|
| 38 |
return (0); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
static size_t trigger_text_to_ascii(char *buf, size_t max, cptr *strptr) |
|---|
| 47 |
{ |
|---|
| 48 |
cptr str = *strptr; |
|---|
| 49 |
bool mod_status[MAX_MACRO_MOD]; |
|---|
| 50 |
|
|---|
| 51 |
int i, len = 0; |
|---|
| 52 |
int shiftstatus = 0; |
|---|
| 53 |
cptr key_code; |
|---|
| 54 |
|
|---|
| 55 |
size_t current_len = strlen(buf); |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
if (macro_template == NULL) return 0; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
for (i = 0; macro_modifier_chr[i]; i++) |
|---|
| 62 |
mod_status[i] = FALSE; |
|---|
| 63 |
|
|---|
| 64 |
str++; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
while (1) |
|---|
| 68 |
{ |
|---|
| 69 |
|
|---|
| 70 |
for (i = 0; macro_modifier_chr[i]; i++) |
|---|
| 71 |
{ |
|---|
| 72 |
len = strlen(macro_modifier_name[i]); |
|---|
| 73 |
|
|---|
| 74 |
if (!my_strnicmp(str, macro_modifier_name[i], len)) |
|---|
| 75 |
break; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
if (!macro_modifier_chr[i]) break; |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
str += len; |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
mod_status[i] = TRUE; |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
if (macro_modifier_chr[i] == 'S') |
|---|
| 89 |
shiftstatus = 1; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
for (i = 0; i < max_macrotrigger; i++) |
|---|
| 94 |
{ |
|---|
| 95 |
len = strlen(macro_trigger_name[i]); |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
if (!my_strnicmp(str, macro_trigger_name[i], len) && (']' == str[len])) |
|---|
| 99 |
break; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
if (i == max_macrotrigger) |
|---|
| 104 |
{ |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
str = strchr(str, ']'); |
|---|
| 110 |
|
|---|
| 111 |
if (str) |
|---|
| 112 |
{ |
|---|
| 113 |
strnfcat(buf, max, ¤t_len, "\x1F\r"); |
|---|
| 114 |
|
|---|
| 115 |
*strptr = str; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
return current_len; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
key_code = macro_trigger_keycode[shiftstatus][i]; |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
str += len; |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
strnfcat(buf, max, ¤t_len, "\x1F"); |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
for (i = 0; macro_template[i]; i++) |
|---|
| 132 |
{ |
|---|
| 133 |
char ch = macro_template[i]; |
|---|
| 134 |
|
|---|
| 135 |
switch (ch) |
|---|
| 136 |
{ |
|---|
| 137 |
|
|---|
| 138 |
case '&': |
|---|
| 139 |
{ |
|---|
| 140 |
size_t j; |
|---|
| 141 |
for (j = 0; macro_modifier_chr[j]; j++) |
|---|
| 142 |
{ |
|---|
| 143 |
if (mod_status[j]) |
|---|
| 144 |
strnfcat(buf, max, ¤t_len, "%c", macro_modifier_chr[j]); |
|---|
| 145 |
} |
|---|
| 146 |
break; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
case '#': |
|---|
| 151 |
{ |
|---|
| 152 |
strnfcat(buf, max, ¤t_len, "%s", key_code); |
|---|
| 153 |
break; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
default: |
|---|
| 158 |
{ |
|---|
| 159 |
strnfcat(buf, max, ¤t_len, "%c", ch); |
|---|
| 160 |
break; |
|---|
| 161 |
} |
|---|
| 162 |
} |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
strnfcat(buf, max, ¤t_len, "\r"); |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
*strptr = str; |
|---|
| 170 |
|
|---|
| 171 |
return current_len; |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
void text_to_ascii(char *buf, size_t len, cptr str) |
|---|
| 183 |
{ |
|---|
| 184 |
char *s = buf; |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
while (*str) |
|---|
| 188 |
{ |
|---|
| 189 |
|
|---|
| 190 |
if (s >= buf + len - 1) break; |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
if (*str == '\\') |
|---|
| 194 |
{ |
|---|
| 195 |
str++; |
|---|
| 196 |
if (*str == '\0') break; |
|---|
| 197 |
|
|---|
| 198 |
switch (*str) |
|---|
| 199 |
{ |
|---|
| 200 |
|
|---|
| 201 |
case '[': |
|---|
| 202 |
{ |
|---|
| 203 |
|
|---|
| 204 |
*s = '\0'; |
|---|
| 205 |
s += trigger_text_to_ascii(buf, len, &str); |
|---|
| 206 |
break; |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
case 'x': |
|---|
| 211 |
{ |
|---|
| 212 |
if (isxdigit((unsigned char)(*(str + 1))) && |
|---|
| 213 |
isxdigit((unsigned char)(*(str + 2)))) |
|---|
| 214 |
{ |
|---|
| 215 |
*s = 16 * dehex(*++str); |
|---|
| 216 |
*s++ += dehex(*++str); |
|---|
| 217 |
} |
|---|
| 218 |
else |
|---|
| 219 |
{ |
|---|
| 220 |
|
|---|
| 221 |
*s++ = '?'; |
|---|
| 222 |
} |
|---|
| 223 |
break; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
case 'e': |
|---|
| 227 |
*s++ = ESCAPE; |
|---|
| 228 |
break; |
|---|
| 229 |
case 's': |
|---|
| 230 |
*s++ = ' '; |
|---|
| 231 |
break; |
|---|
| 232 |
case 'b': |
|---|
| 233 |
*s++ = '\b'; |
|---|
| 234 |
break; |
|---|
| 235 |
case 'n': |
|---|
| 236 |
*s++ = '\n'; |
|---|
| 237 |
break; |
|---|
| 238 |
case 'r': |
|---|
| 239 |
*s++ = '\r'; |
|---|
| 240 |
break; |
|---|
| 241 |
case 't': |
|---|
| 242 |
*s++ = '\t'; |
|---|
| 243 |
break; |
|---|
| 244 |
case 'a': |
|---|
| 245 |
*s++ = '\a'; |
|---|
| 246 |
break; |
|---|
| 247 |
case '\\': |
|---|
| 248 |
*s++ = '\\'; |
|---|
| 249 |
break; |
|---|
| 250 |
case '^': |
|---|
| 251 |
*s++ = '^'; |
|---|
| 252 |
break; |
|---|
| 253 |
|
|---|
| 254 |
default: |
|---|
| 255 |
*s = *str; |
|---|
| 256 |
break; |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
str++; |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
else if (*str == '^') |
|---|
| 265 |
{ |
|---|
| 266 |
str++; |
|---|
| 267 |
if (*str == '\0') break; |
|---|
| 268 |
|
|---|
| 269 |
*s++ = KTRL(*str); |
|---|
| 270 |
str++; |
|---|
| 271 |
} |
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
else |
|---|
| 275 |
{ |
|---|
| 276 |
*s++ = *str++; |
|---|
| 277 |
} |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
*s = '\0'; |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
static size_t trigger_ascii_to_text(char *buf, size_t max, cptr *strptr) |
|---|
| 290 |
{ |
|---|
| 291 |
cptr str = *strptr; |
|---|
| 292 |
char key_code[100]; |
|---|
| 293 |
int i; |
|---|
| 294 |
cptr tmp; |
|---|
| 295 |
size_t current_len = strlen(buf); |
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
if (macro_template == NULL) return 0; |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
strnfcat(buf, max, ¤t_len, "\\["); |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
for (i = 0; macro_template[i]; i++) |
|---|
| 306 |
{ |
|---|
| 307 |
char ch = macro_template[i]; |
|---|
| 308 |
|
|---|
| 309 |
switch (ch) |
|---|
| 310 |
{ |
|---|
| 311 |
|
|---|
| 312 |
case '&': |
|---|
| 313 |
{ |
|---|
| 314 |
size_t j; |
|---|
| 315 |
while ((tmp = strchr(macro_modifier_chr, *str)) != 0) |
|---|
| 316 |
{ |
|---|
| 317 |
j = tmp - macro_modifier_chr; |
|---|
| 318 |
strnfcat(buf, max, ¤t_len, "%s", macro_modifier_name[j]); |
|---|
| 319 |
str++; |
|---|
| 320 |
} |
|---|
| 321 |
break; |
|---|
| 322 |
} |
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
case '#': |
|---|
| 326 |
{ |
|---|
| 327 |
size_t j; |
|---|
| 328 |
for (j = 0; *str && (*str != '\r') && (j < sizeof(key_code) - 1); j++) |
|---|
| 329 |
key_code[j] = *str++; |
|---|
| 330 |
key_code[j] = '\0'; |
|---|
| 331 |
break; |
|---|
| 332 |
} |
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
default: |
|---|
| 336 |
{ |
|---|
| 337 |
if (ch != *str) return 0; |
|---|
| 338 |
str++; |
|---|
| 339 |
} |
|---|
| 340 |
} |
|---|
| 341 |
} |
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
if (*str++ != '\r') return 0; |
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
for (i = 0; i < max_macrotrigger; i++) |
|---|
| 348 |
{ |
|---|
| 349 |
if (!my_stricmp(key_code, macro_trigger_keycode[0][i]) || |
|---|
| 350 |
!my_stricmp(key_code, macro_trigger_keycode[1][i])) |
|---|
| 351 |
break; |
|---|
| 352 |
} |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
if (i == max_macrotrigger) return 0; |
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
strnfcat(buf, max, ¤t_len, "%s]", macro_trigger_name[i]); |
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
*strptr = str; |
|---|
| 362 |
return current_len; |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
void ascii_to_text(char *buf, size_t len, cptr str) |
|---|
| 372 |
{ |
|---|
| 373 |
char *s = buf; |
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
while (*str) |
|---|
| 377 |
{ |
|---|
| 378 |
byte i = (byte)(*str++); |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
if (s >= buf + len - 5) break; |
|---|
| 383 |
|
|---|
| 384 |
if (i == ESCAPE) |
|---|
| 385 |
{ |
|---|
| 386 |
*s++ = '\\'; |
|---|
| 387 |
*s++ = 'e'; |
|---|
| 388 |
} |
|---|
| 389 |
else if (i == ' ') |
|---|
| 390 |
{ |
|---|
| 391 |
*s++ = '\\'; |
|---|
| 392 |
*s++ = 's'; |
|---|
| 393 |
} |
|---|
| 394 |
else if (i == '\b') |
|---|
| 395 |
{ |
|---|
| 396 |
*s++ = '\\'; |
|---|
| 397 |
*s++ = 'b'; |
|---|
| 398 |
} |
|---|
| 399 |
else if (i == '\t') |
|---|
| 400 |
{ |
|---|
| 401 |
*s++ = '\\'; |
|---|
| 402 |
*s++ = 't'; |
|---|
| 403 |
} |
|---|
| 404 |
else if (i == '\a') |
|---|
| 405 |
{ |
|---|
| 406 |
*s++ = '\\'; |
|---|
| 407 |
*s++ = 'a'; |
|---|
| 408 |
} |
|---|
| 409 |
else if (i == '\n') |
|---|
| 410 |
{ |
|---|
| 411 |
*s++ = '\\'; |
|---|
| 412 |
*s++ = 'n'; |
|---|
| 413 |
} |
|---|
| 414 |
else if (i == '\r') |
|---|
| 415 |
{ |
|---|
| 416 |
*s++ = '\\'; |
|---|
| 417 |
*s++ = 'r'; |
|---|
| 418 |
} |
|---|
| 419 |
else if (i == '\\') |
|---|
| 420 |
{ |
|---|
| 421 |
*s++ = '\\'; |
|---|
| 422 |
*s++ = '\\'; |
|---|
| 423 |
} |
|---|
| 424 |
else if (i == '^') |
|---|
| 425 |
{ |
|---|
| 426 |
*s++ = '\\'; |
|---|
| 427 |
*s++ = '^'; |
|---|
| 428 |
} |
|---|
| 429 |
|
|---|
| 430 |
else if (i == 31) |
|---|
| 431 |
{ |
|---|
| 432 |
size_t offset; |
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
*s = '\0'; |
|---|
| 436 |
|
|---|
| 437 |
offset = trigger_ascii_to_text(buf, len, &str); |
|---|
| 438 |
|
|---|
| 439 |
if (offset == 0) |
|---|
| 440 |
{ |
|---|
| 441 |
|
|---|
| 442 |
*s++ = '^'; |
|---|
| 443 |
*s++ = '_'; |
|---|
| 444 |
} |
|---|
| 445 |
else |
|---|
| 446 |
s += offset; |
|---|
| 447 |
} |
|---|
| 448 |
else if (i < 32) |
|---|
| 449 |
{ |
|---|
| 450 |
*s++ = '^'; |
|---|
| 451 |
*s++ = UN_KTRL(i); |
|---|
| 452 |
} |
|---|
| 453 |
else if (i < 127) |
|---|
| 454 |
{ |
|---|
| 455 |
*s++ = i; |
|---|
| 456 |
} |
|---|
| 457 |
else |
|---|
| 458 |
{ |
|---|
| 459 |
*s++ = '\\'; |
|---|
| 460 |
*s++ = 'x'; |
|---|
| 461 |
*s++ = hexify((int)i / 16); |
|---|
| 462 |
*s++ = hexify((int)i % 16); |
|---|
| 463 |
} |
|---|
| 464 |
} |
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
*s = '\0'; |
|---|
| 468 |
} |
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
static bool macro__use[256]; |
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
int macro_find_exact(cptr pat) |
|---|
| 492 |
{ |
|---|
| 493 |
int i; |
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
if (!macro__use[(byte)(pat[0])]) |
|---|
| 497 |
return -1; |
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
for (i = 0; i < macro__num; ++i) |
|---|
| 501 |
{ |
|---|
| 502 |
if (streq(macro__pat[i], pat)) |
|---|
| 503 |
return i; |
|---|
| 504 |
} |
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
return -1; |
|---|
| 508 |
} |
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
static int macro_find_check(cptr pat) |
|---|
| 515 |
{ |
|---|
| 516 |
int i; |
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
if (!macro__use[(byte)(pat[0])]) |
|---|
| 520 |
return -1; |
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
for (i = 0; i < macro__num; ++i) |
|---|
| 524 |
{ |
|---|
| 525 |
if (prefix(macro__pat[i], pat)) |
|---|
| 526 |
return i; |
|---|
| 527 |
} |
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
return -1; |
|---|
| 531 |
} |
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
static int macro_find_maybe(cptr pat) |
|---|
| 538 |
{ |
|---|
| 539 |
int i; |
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
if (!macro__use[(byte)(pat[0])]) |
|---|
| 543 |
return -1; |
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
for (i = 0; i < macro__num; ++i) |
|---|
| 547 |
{ |
|---|
| 548 |
if (prefix(macro__pat[i], pat) && !streq(macro__pat[i], pat)) |
|---|
| 549 |
return i; |
|---|
| 550 |
} |
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
return -1; |
|---|
| 554 |
} |
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
static int macro_find_ready(cptr pat) |
|---|
| 562 |
{ |
|---|
| 563 |
int i, t, n = -1, s = -1; |
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
if (!macro__use[(byte)(pat[0])]) |
|---|
| 567 |
return -1; |
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
for (i = 0; i < macro__num; ++i) |
|---|
| 571 |
{ |
|---|
| 572 |
|
|---|
| 573 |
if (!prefix(pat, macro__pat[i])) continue; |
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
t = strlen(macro__pat[i]); |
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
if ((n >= 0) && (s > t)) continue; |
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
n = i; |
|---|
| 583 |
s = t; |
|---|
| 584 |
} |
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
return n; |
|---|
| 588 |
} |
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
|
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
errr macro_add(cptr pat, cptr act) |
|---|
| 606 |
{ |
|---|
| 607 |
int n; |
|---|
| 608 |
|
|---|
| 609 |
if (!pat || !act) return (-1); |
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
n = macro_find_exact(pat); |
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 |
if (n >= 0) |
|---|
| 617 |
{ |
|---|
| 618 |
string_free(macro__act[n]); |
|---|
| 619 |
} |
|---|
| 620 |
|
|---|
| 621 |
|
|---|
| 622 |
else |
|---|
| 623 |
{ |
|---|
| 624 |
|
|---|
| 625 |
n = macro__num++; |
|---|
| 626 |
if (macro__num >= MACRO_MAX) quit("Too many macros!"); |
|---|
| 627 |
|
|---|
| 628 |
|
|---|
| 629 |
macro__pat[n] = string_make(pat); |
|---|
| 630 |
} |
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
macro__act[n] = string_make(act); |
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
macro__use[(byte)(pat[0])] = TRUE; |
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
return (0); |
|---|
| 640 |
} |
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
|
|---|
| 645 |
|
|---|
| 646 |
|
|---|
| 647 |
errr macro_init(void) |
|---|
| 648 |
{ |
|---|
| 649 |
|
|---|
| 650 |
macro__pat = C_ZNEW(MACRO_MAX, cptr); |
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
macro__act = C_ZNEW(MACRO_MAX, cptr); |
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
return (0); |
|---|
| 657 |
} |
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
errr macro_free(void) |
|---|
| 664 |
{ |
|---|
| 665 |
int i; |
|---|
| 666 |
size_t j; |
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
for (i = 0; i < macro__num; ++i) |
|---|
| 670 |
{ |
|---|
| 671 |
string_free(macro__pat[i]); |
|---|
| 672 |
string_free(macro__act[i]); |
|---|
| 673 |
} |
|---|
| 674 |
|
|---|
| 675 |
FREE(macro__pat); |
|---|
| 676 |
FREE(macro__act); |
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
for (i = 0; i < KEYMAP_MODES; ++i) |
|---|
| 680 |
{ |
|---|
| 681 |
for (j = 0; j < N_ELEMENTS(keymap_act[i]); ++j) |
|---|
| 682 |
{ |
|---|
| 683 |
string_free(keymap_act[i][j]); |
|---|
| 684 |
keymap_act[i][j] = NULL; |
|---|
| 685 |
} |
|---|
| 686 |
} |
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
return (0); |
|---|
| 690 |
} |
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
errr macro_trigger_free(void) |
|---|
| 697 |
{ |
|---|
| 698 |
int i; |
|---|
| 699 |
int num; |
|---|
| 700 |
|
|---|
| 701 |
if (macro_template != NULL) |
|---|
| 702 |
{ |
|---|
| 703 |
|
|---|
| 704 |
string_free(macro_template); |
|---|
| 705 |
macro_template = NULL; |
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
for (i = 0; i < max_macrotrigger; i++) |
|---|
| 709 |
{ |
|---|
| 710 |
string_free(macro_trigger_name[i]); |
|---|
| 711 |
|
|---|
| 712 |
string_free(macro_trigger_keycode[0][i]); |
|---|
| 713 |
string_free(macro_trigger_keycode[1][i]); |
|---|
| 714 |
} |
|---|
| 715 |
|
|---|
| 716 |
|
|---|
| 717 |
max_macrotrigger = 0; |
|---|
| 718 |
|
|---|
| 719 |
|
|---|
| 720 |
num = strlen(macro_modifier_chr); |
|---|
| 721 |
|
|---|
| 722 |
|
|---|
| 723 |
for (i = 0; i < num; i++) |
|---|
| 724 |
string_free(macro_modifier_name[i]); |
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 |
string_free(macro_modifier_chr); |
|---|
| 728 |
} |
|---|
| 729 |
|
|---|
| 730 |
|
|---|
| 731 |
return (0); |
|---|
| 732 |
} |
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
void flush(void) |
|---|
| 743 |
{ |
|---|
| 744 |
|
|---|
| 745 |
inkey_xtra = TRUE; |
|---|
| 746 |
} |
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
void flush_fail(void) |
|---|
| 753 |
{ |
|---|
| 754 |
if (flush_failure) flush(); |
|---|
| 755 |
} |
|---|
| 756 |
|
|---|
| 757 |
|
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 |
|
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
static bool parse_macro = FALSE; |
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 |
|
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
static bool parse_under = FALSE; |
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
|
|---|
| 777 |
|
|---|
| 778 |
|
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 |
|
|---|
| 782 |
|
|---|
| 783 |
|
|---|
| 784 |
|
|---|
| 785 |
|
|---|
| 786 |
|
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
|
|---|
| 790 |
|
|---|
| 791 |
|
|---|
| 792 |
static ui_event_data inkey_aux(int scan_cutoff) |
|---|
| 793 |
{ |
|---|
| 794 |
int k = 0, n, p = 0, w = 0; |
|---|
| 795 |
|
|---|
| 796 |
ui_event_data ke, ke0; |
|---|
| 797 |
char ch; |
|---|
| 798 |
|
|---|
| 799 |
cptr pat, act; |
|---|
| 800 |
|
|---|
| 801 |
char buf[1024]; |
|---|
| 802 |
|
|---|
| 803 |
|
|---|
| 804 |
ke0.type = EVT_NONE; |
|---|
| 805 |
ke0.key = 0; |
|---|
| 806 |
ke0.index = 0; |
|---|
| 807 |
ke0.mousey = 0; |
|---|
| 808 |
ke0.mousex = 0; |
|---|
| 809 |
|
|---|
| 810 |
|
|---|
| 811 |
if (scan_cutoff == SCAN_OFF) |
|---|
| 812 |
{ |
|---|
| 813 |
(void)(Term_inkey(&ke, TRUE, TRUE)); |
|---|
| 814 |
ch = ke.key; |
|---|
| 815 |
} |
|---|
| 816 |
else |
|---|
| 817 |
{ |
|---|
| 818 |
w = 0; |
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 |
while (Term_inkey(&ke, FALSE, TRUE) != 0) |
|---|
| 822 |
{ |
|---|
| 823 |
|
|---|
| 824 |
w++; |
|---|
| 825 |
|
|---|
| 826 |
|
|---|
| 827 |
if (w >= scan_cutoff) |
|---|
| 828 |
{ |
|---|
| 829 |
ke0.type = EVT_KBRD; |
|---|
| 830 |
return ke0; |
|---|
| 831 |
} |
|---|
| 832 |
|
|---|
| 833 |
|
|---|
| 834 |
Term_xtra(TERM_XTRA_DELAY, 10); |
|---|
| 835 |
} |
|---|
| 836 |
ch = ke.key; |
|---|
| 837 |
} |
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
if ((ch == 30) || (ch == '\xff')) |
|---|
| 842 |
{ |
|---|
| 843 |
parse_macro = FALSE; |
|---|
| 844 |
return (ke); |
|---|
| 845 |
} |
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
if (parse_macro) return (ke); |
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
if (parse_under) return (ke); |
|---|
| 852 |
|
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
buf[p++] = ch; |
|---|
| 856 |
buf[p] = '\0'; |
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
k = macro_find_check(buf); |
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 |
if (k < 0) return (ke); |
|---|
| 864 |
|
|---|
| 865 |
|
|---|
| 866 |
|
|---|
| 867 |
while (TRUE) |
|---|
| 868 |
{ |
|---|
| 869 |
|
|---|
| 870 |
k = macro_find_maybe(buf); |
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 |
if (k < 0) break; |
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
if (0 == Term_inkey(&ke, FALSE, TRUE)) |
|---|
| 877 |
{ |
|---|
| 878 |
|
|---|
| 879 |
buf[p++] = ke.key; |
|---|
| 880 |
buf[p] = '\0'; |
|---|
| 881 |
|
|---|
| 882 |
|
|---|