変愚蛮怒のメインリポジトリです
修订版 | 7643737c7ad6cadd9195dcc986b4600ea387b5af (tree) |
---|---|
时间 | 2020-02-01 10:37:17 |
作者 | Hourier <hourier@user...> |
Commiter | Hourier |
[Refactor] #37353 util.c において、1行ごとに挟まれていたコメントを削除 / Removed many comments per 1 line in util.c
@@ -139,8 +139,6 @@ s16b command_wrk; /* See "object1.c" */ | ||
139 | 139 | TERM_LEN command_gap = 999; /* See "object1.c" */ |
140 | 140 | s16b command_new; /* Command chaining from inven/equip view */ |
141 | 141 | |
142 | - | |
143 | - | |
144 | 142 | #ifdef SET_UID |
145 | 143 | |
146 | 144 | # ifndef HAVE_USLEEP |
@@ -152,42 +150,28 @@ s16b command_new; /* Command chaining from inven/equip view */ | ||
152 | 150 | */ |
153 | 151 | int usleep(huge usecs) |
154 | 152 | { |
155 | - struct timeval Timer; | |
153 | + struct timeval timer; | |
156 | 154 | |
157 | - int nfds = 0; | |
155 | + int nfds = 0; | |
158 | 156 | |
159 | 157 | #ifdef FD_SET |
160 | 158 | fd_set *no_fds = NULL; |
161 | 159 | #else |
162 | 160 | int *no_fds = NULL; |
163 | 161 | #endif |
164 | - | |
165 | - | |
166 | - /* Was: int readfds, writefds, exceptfds; */ | |
167 | - /* Was: readfds = writefds = exceptfds = 0; */ | |
168 | - | |
169 | - | |
170 | - /* Paranoia -- No excessive sleeping */ | |
171 | 162 | if (usecs > 4000000L) core(_("不当な usleep() 呼び出し", "Illegal usleep() call")); |
172 | 163 | |
173 | - /* Wait for it */ | |
174 | - Timer.tv_sec = (usecs / 1000000L); | |
175 | - Timer.tv_usec = (usecs % 1000000L); | |
176 | - | |
177 | - /* Wait for it */ | |
178 | - if (select(nfds, no_fds, no_fds, no_fds, &Timer) < 0) | |
164 | + timer.tv_sec = (usecs / 1000000L); | |
165 | + timer.tv_usec = (usecs % 1000000L); | |
166 | + if (select(nfds, no_fds, no_fds, no_fds, &timer) < 0) | |
179 | 167 | { |
180 | - /* Hack -- ignore interrupts */ | |
181 | 168 | if (errno != EINTR) return -1; |
182 | 169 | } |
183 | 170 | |
184 | - /* Success */ | |
185 | 171 | return 0; |
186 | 172 | } |
187 | - | |
188 | 173 | # endif |
189 | 174 | |
190 | - | |
191 | 175 | /* |
192 | 176 | * Hack -- External functions |
193 | 177 | */ |
@@ -196,21 +180,17 @@ extern struct passwd *getpwuid(uid_t uid); | ||
196 | 180 | extern struct passwd *getpwnam(concptr name); |
197 | 181 | #endif |
198 | 182 | |
199 | - | |
200 | 183 | /* |
201 | 184 | * Find a default user name from the system. |
202 | 185 | */ |
203 | 186 | void user_name(char *buf, int id) |
204 | 187 | { |
205 | 188 | struct passwd *pw; |
206 | - | |
207 | - /* Look up the user name */ | |
208 | 189 | if ((pw = getpwuid(id))) |
209 | 190 | { |
210 | 191 | (void)strcpy(buf, pw->pw_name); |
211 | 192 | buf[16] = '\0'; |
212 | 193 | |
213 | - /* Hack -- capitalize the user name */ | |
214 | 194 | #ifdef JP |
215 | 195 | if (!iskanji(buf[0])) |
216 | 196 | #endif |
@@ -220,15 +200,12 @@ void user_name(char *buf, int id) | ||
220 | 200 | return; |
221 | 201 | } |
222 | 202 | |
223 | - /* Oops. Hack -- default to "PLAYER" */ | |
224 | 203 | strcpy(buf, "PLAYER"); |
225 | 204 | } |
226 | 205 | |
227 | 206 | #endif /* SET_UID */ |
228 | 207 | |
229 | 208 | |
230 | - | |
231 | - | |
232 | 209 | /* |
233 | 210 | * The concept of the "file" routines below (and elsewhere) is that all |
234 | 211 | * file handling should be done using as few routines as possible, since |
@@ -257,9 +234,7 @@ void user_name(char *buf, int id) | ||
257 | 234 | * We should probably parse a leading "~~/" as referring to "ANGBAND_DIR". (?) |
258 | 235 | */ |
259 | 236 | |
260 | - | |
261 | 237 | #ifdef SET_UID |
262 | - | |
263 | 238 | /* |
264 | 239 | * Extract a "parsed" path from an initial filename |
265 | 240 | * Normally, we simply copy the filename into the buffer |
@@ -269,34 +244,20 @@ void user_name(char *buf, int id) | ||
269 | 244 | */ |
270 | 245 | errr path_parse(char *buf, int max, concptr file) |
271 | 246 | { |
272 | - concptr u, s; | |
273 | - struct passwd *pw; | |
274 | - char user[128]; | |
275 | - | |
276 | - | |
277 | - /* Assume no result */ | |
278 | 247 | buf[0] = '\0'; |
279 | - | |
280 | - /* No file? */ | |
281 | 248 | if (!file) return -1; |
282 | 249 | |
283 | - /* File needs no parsing */ | |
284 | 250 | if (file[0] != '~') |
285 | 251 | { |
286 | 252 | (void)strnfmt(buf, max, "%s", file); |
287 | 253 | return 0; |
288 | 254 | } |
289 | 255 | |
290 | - /* Point at the user */ | |
291 | - u = file + 1; | |
292 | - | |
293 | - /* Look for non-user portion of the file */ | |
294 | - s = my_strstr(u, PATH_SEP); | |
295 | - | |
296 | - /* Hack -- no long user names */ | |
256 | + concptr u = file + 1; | |
257 | + concptr s = my_strstr(u, PATH_SEP); | |
258 | + char user[128]; | |
297 | 259 | if (s && (s >= u + sizeof(user))) return 1; |
298 | 260 | |
299 | - /* Extract a user name */ | |
300 | 261 | if (s) |
301 | 262 | { |
302 | 263 | int i; |
@@ -305,28 +266,20 @@ errr path_parse(char *buf, int max, concptr file) | ||
305 | 266 | u = user; |
306 | 267 | } |
307 | 268 | |
308 | - /* Look up the "current" user */ | |
309 | 269 | if (u[0] == '\0') u = getlogin(); |
310 | 270 | |
311 | - /* Look up a user (or "current" user) */ | |
271 | + struct passwd *pw; | |
312 | 272 | if (u) pw = getpwnam(u); |
313 | 273 | else pw = getpwuid(getuid()); |
314 | 274 | |
315 | - /* Nothing found? */ | |
316 | 275 | if (!pw) return 1; |
317 | 276 | |
318 | - /* Make use of the info */ | |
319 | 277 | if (s) strnfmt(buf, max, "%s%s", pw->pw_dir, s); |
320 | 278 | else strnfmt(buf, max, "%s", pw->pw_dir); |
321 | 279 | |
322 | - /* Success */ | |
323 | 280 | return 0; |
324 | 281 | } |
325 | - | |
326 | - | |
327 | 282 | #else /* SET_UID */ |
328 | - | |
329 | - | |
330 | 283 | /* |
331 | 284 | * Extract a "parsed" path from an initial filename |
332 | 285 | * |
@@ -335,12 +288,9 @@ errr path_parse(char *buf, int max, concptr file) | ||
335 | 288 | */ |
336 | 289 | errr path_parse(char *buf, int max, concptr file) |
337 | 290 | { |
338 | - /* Accept the filename */ | |
339 | 291 | (void)strnfmt(buf, max, "%s", file); |
340 | 292 | return 0; |
341 | 293 | } |
342 | - | |
343 | - | |
344 | 294 | #endif /* SET_UID */ |
345 | 295 | |
346 | 296 |
@@ -353,26 +303,20 @@ errr path_parse(char *buf, int max, concptr file) | ||
353 | 303 | */ |
354 | 304 | static errr path_temp(char *buf, int max) |
355 | 305 | { |
356 | - concptr s; | |
357 | - | |
358 | - /* Temp file */ | |
359 | - s = tmpnam(NULL); | |
360 | - | |
306 | + concptr s = tmpnam(NULL); | |
361 | 307 | if (!s) return -1; |
362 | 308 | |
363 | - /* Format to length */ | |
364 | 309 | #if !defined(WIN32) || (defined(_MSC_VER) && (_MSC_VER >= 1900)) |
365 | 310 | (void)strnfmt(buf, max, "%s", s); |
366 | 311 | #else |
367 | 312 | (void)strnfmt(buf, max, ".%s", s); |
368 | 313 | #endif |
369 | 314 | |
370 | - /* Success */ | |
371 | 315 | return 0; |
372 | 316 | } |
373 | - | |
374 | 317 | #endif |
375 | 318 | |
319 | + | |
376 | 320 | /*! |
377 | 321 | * @brief ファイル入出力のためのパス生成する。/ Create a new path by appending a file (or directory) to a path. |
378 | 322 | * @param buf ファイルのフルを返すバッファ |
@@ -393,35 +337,23 @@ static errr path_temp(char *buf, int max) | ||
393 | 337 | */ |
394 | 338 | errr path_build(char *buf, int max, concptr path, concptr file) |
395 | 339 | { |
396 | - /* Special file */ | |
397 | 340 | if (file[0] == '~') |
398 | 341 | { |
399 | - /* Use the file itself */ | |
400 | 342 | (void)strnfmt(buf, max, "%s", file); |
401 | 343 | } |
402 | - | |
403 | - /* Absolute file, on "normal" systems */ | |
404 | 344 | else if (prefix(file, PATH_SEP) && !streq(PATH_SEP, "")) |
405 | 345 | { |
406 | - /* Use the file itself */ | |
407 | 346 | (void)strnfmt(buf, max, "%s", file); |
408 | 347 | } |
409 | - | |
410 | - /* No path given */ | |
411 | 348 | else if (!path[0]) |
412 | 349 | { |
413 | - /* Use the file itself */ | |
414 | 350 | (void)strnfmt(buf, max, "%s", file); |
415 | 351 | } |
416 | - | |
417 | - /* Path and File */ | |
418 | 352 | else |
419 | 353 | { |
420 | - /* Build the new path */ | |
421 | 354 | (void)strnfmt(buf, max, "%s%s%s", path, PATH_SEP, file); |
422 | 355 | } |
423 | 356 | |
424 | - /* Success */ | |
425 | 357 | return 0; |
426 | 358 | } |
427 | 359 |
@@ -431,26 +363,20 @@ errr path_build(char *buf, int max, concptr path, concptr file) | ||
431 | 363 | */ |
432 | 364 | FILE *my_fopen(concptr file, concptr mode) |
433 | 365 | { |
434 | - char buf[1024]; | |
435 | - | |
436 | 366 | #if defined(MACH_O_CARBON) |
437 | 367 | FILE *tempfff; |
438 | 368 | #endif |
439 | - | |
440 | - /* Hack -- Try to parse the path */ | |
369 | + char buf[1024]; | |
441 | 370 | if (path_parse(buf, 1024, file)) return (NULL); |
442 | - | |
443 | 371 | #if defined(MACH_O_CARBON) |
444 | 372 | if (my_strchr(mode, 'w')) |
445 | 373 | { |
446 | - /* setting file type/creator */ | |
447 | 374 | tempfff = fopen(buf, mode); |
448 | 375 | fsetfileinfo(buf, _fcreator, _ftype); |
449 | 376 | fclose(tempfff); |
450 | 377 | } |
451 | 378 | #endif |
452 | 379 | |
453 | - /* Attempt to fopen the file anyway */ | |
454 | 380 | return (fopen(buf, mode)); |
455 | 381 | } |
456 | 382 |
@@ -460,45 +386,27 @@ FILE *my_fopen(concptr file, concptr mode) | ||
460 | 386 | */ |
461 | 387 | errr my_fclose(FILE *fff) |
462 | 388 | { |
463 | - /* Require a file */ | |
464 | 389 | if (!fff) return -1; |
465 | - | |
466 | - /* Close, check for error */ | |
467 | 390 | if (fclose(fff) == EOF) return 1; |
468 | - | |
469 | - /* Success */ | |
470 | 391 | return 0; |
471 | 392 | } |
472 | 393 | |
473 | 394 | |
474 | 395 | #ifdef HAVE_MKSTEMP |
475 | - | |
476 | 396 | FILE *my_fopen_temp(char *buf, int max) |
477 | 397 | { |
478 | - int fd; | |
479 | - | |
480 | - /* Prepare the buffer for mkstemp */ | |
481 | 398 | strncpy(buf, "/tmp/anXXXXXX", max); |
482 | - | |
483 | - /* Secure creation of a temporary file */ | |
484 | - fd = mkstemp(buf); | |
485 | - | |
486 | - /* Check the file-descriptor */ | |
399 | + int fd = mkstemp(buf); | |
487 | 400 | if (fd < 0) return (NULL); |
488 | 401 | |
489 | - /* Return a file stream */ | |
490 | 402 | return (fdopen(fd, "w")); |
491 | 403 | } |
492 | - | |
493 | 404 | #else /* HAVE_MKSTEMP */ |
494 | - | |
495 | 405 | FILE *my_fopen_temp(char *buf, int max) |
496 | 406 | { |
497 | - /* Generate a temporary filename */ | |
498 | 407 | if (path_temp(buf, max)) return (NULL); |
499 | 408 | return (my_fopen(buf, "w")); |
500 | 409 | } |
501 | - | |
502 | 410 | #endif /* HAVE_MKSTEMP */ |
503 | 411 | |
504 | 412 |
@@ -515,14 +423,11 @@ errr my_fgets(FILE *fff, char *buf, huge n) | ||
515 | 423 | char *s; |
516 | 424 | char tmp[1024]; |
517 | 425 | |
518 | - /* Read a line */ | |
519 | 426 | if (fgets(tmp, 1024, fff)) |
520 | 427 | { |
521 | 428 | #ifdef JP |
522 | 429 | guess_convert_to_system_encoding(tmp, sizeof(tmp)); |
523 | 430 | #endif |
524 | - | |
525 | - /* Convert weirdness */ | |
526 | 431 | for (s = tmp; *s; s++) |
527 | 432 | { |
528 | 433 | #if defined(MACH_O_CARBON) |
@@ -535,30 +440,19 @@ errr my_fgets(FILE *fff, char *buf, huge n) | ||
535 | 440 | if (*s == '\r') *s = '\n'; |
536 | 441 | |
537 | 442 | #endif /* MACH_O_CARBON */ |
538 | - | |
539 | - /* Handle newline */ | |
540 | 443 | if (*s == '\n') |
541 | 444 | { |
542 | - /* Terminate */ | |
543 | 445 | buf[i] = '\0'; |
544 | - | |
545 | - /* Success */ | |
546 | 446 | return 0; |
547 | 447 | } |
548 | - | |
549 | - /* Handle tabs */ | |
550 | 448 | else if (*s == '\t') |
551 | 449 | { |
552 | - /* Hack -- require room */ | |
553 | 450 | if (i + 8 >= n) break; |
554 | 451 | |
555 | - /* Append a space */ | |
556 | 452 | buf[i++] = ' '; |
557 | - | |
558 | - /* Append some more spaces */ | |
559 | - while (0 != (i % 8)) buf[i++] = ' '; | |
453 | + while (0 != (i % 8)) | |
454 | + buf[i++] = ' '; | |
560 | 455 | } |
561 | - | |
562 | 456 | #ifdef JP |
563 | 457 | else if (iskanji(*s)) |
564 | 458 | { |
@@ -566,35 +460,25 @@ errr my_fgets(FILE *fff, char *buf, huge n) | ||
566 | 460 | buf[i++] = *s++; |
567 | 461 | buf[i++] = *s; |
568 | 462 | } |
569 | - | |
570 | - /* 半角かなに対応 */ | |
571 | 463 | else if (iskana(*s)) |
572 | 464 | { |
465 | + /* 半角かなに対応 */ | |
573 | 466 | buf[i++] = *s; |
574 | 467 | if (i >= n) break; |
575 | 468 | } |
576 | 469 | #endif |
577 | - /* Handle printables */ | |
578 | 470 | else if (isprint((unsigned char)*s)) |
579 | 471 | { |
580 | - /* Copy */ | |
581 | 472 | buf[i++] = *s; |
582 | - | |
583 | - /* Check length */ | |
584 | 473 | if (i >= n) break; |
585 | 474 | } |
586 | 475 | } |
587 | - /* No newline character, but terminate */ | |
588 | - buf[i] = '\0'; | |
589 | 476 | |
590 | - /* Success */ | |
477 | + buf[i] = '\0'; | |
591 | 478 | return 0; |
592 | 479 | } |
593 | 480 | |
594 | - /* Nothing */ | |
595 | 481 | buf[0] = '\0'; |
596 | - | |
597 | - /* Failure */ | |
598 | 482 | return 1; |
599 | 483 | } |
600 | 484 |
@@ -606,13 +490,8 @@ errr my_fgets(FILE *fff, char *buf, huge n) | ||
606 | 490 | */ |
607 | 491 | errr my_fputs(FILE *fff, concptr buf, huge n) |
608 | 492 | { |
609 | - /* XXX XXX */ | |
610 | 493 | n = n ? n : 0; |
611 | - | |
612 | - /* Dump, ignore errors */ | |
613 | 494 | (void)fprintf(fff, "%s\n", buf); |
614 | - | |
615 | - /* Success */ | |
616 | 495 | return 0; |
617 | 496 | } |
618 | 497 |
@@ -625,19 +504,15 @@ errr my_fputs(FILE *fff, concptr buf, huge n) | ||
625 | 504 | #endif /* O_BINARY */ |
626 | 505 | |
627 | 506 | |
628 | - /* | |
629 | - * Hack -- attempt to delete a file | |
630 | - */ | |
507 | +/* | |
508 | + * Hack -- attempt to delete a file | |
509 | + */ | |
631 | 510 | errr fd_kill(concptr file) |
632 | 511 | { |
633 | 512 | char buf[1024]; |
634 | - | |
635 | - /* Hack -- Try to parse the path */ | |
636 | 513 | if (path_parse(buf, 1024, file)) return -1; |
637 | 514 | |
638 | - /* Remove */ | |
639 | 515 | (void)remove(buf); |
640 | - | |
641 | 516 | return 0; |
642 | 517 | } |
643 | 518 |
@@ -649,16 +524,10 @@ errr fd_move(concptr file, concptr what) | ||
649 | 524 | { |
650 | 525 | char buf[1024]; |
651 | 526 | char aux[1024]; |
652 | - | |
653 | - /* Hack -- Try to parse the path */ | |
654 | 527 | if (path_parse(buf, 1024, file)) return -1; |
655 | - | |
656 | - /* Hack -- Try to parse the path */ | |
657 | 528 | if (path_parse(aux, 1024, what)) return -1; |
658 | 529 | |
659 | - /* Rename */ | |
660 | 530 | (void)rename(buf, aux); |
661 | - | |
662 | 531 | return 0; |
663 | 532 | } |
664 | 533 |
@@ -673,45 +542,39 @@ errr fd_copy(concptr file, concptr what) | ||
673 | 542 | int read_num; |
674 | 543 | int src_fd, dst_fd; |
675 | 544 | |
676 | - /* Hack -- Try to parse the path */ | |
677 | 545 | if (path_parse(buf, 1024, file)) return -1; |
678 | - | |
679 | - /* Hack -- Try to parse the path */ | |
680 | 546 | if (path_parse(aux, 1024, what)) return -1; |
681 | 547 | |
682 | - /* Open source file */ | |
683 | 548 | src_fd = fd_open(buf, O_RDONLY); |
684 | 549 | if (src_fd < 0) return -1; |
685 | 550 | |
686 | - /* Open destination file */ | |
687 | 551 | dst_fd = fd_open(aux, O_WRONLY | O_TRUNC | O_CREAT); |
688 | 552 | if (dst_fd < 0) return -1; |
689 | 553 | |
690 | - /* Copy */ | |
691 | 554 | while ((read_num = read(src_fd, buf, 1024)) > 0) |
692 | 555 | { |
693 | 556 | int write_num = 0; |
694 | 557 | while (write_num < read_num) |
695 | 558 | { |
696 | 559 | int ret = write(dst_fd, buf + write_num, read_num - write_num); |
697 | - if (ret < 0) { | |
698 | - /* Close files */ | |
560 | + if (ret < 0) | |
561 | + { | |
699 | 562 | fd_close(src_fd); |
700 | 563 | fd_close(dst_fd); |
701 | 564 | |
702 | 565 | return ret; |
703 | 566 | } |
567 | + | |
704 | 568 | write_num += ret; |
705 | 569 | } |
706 | 570 | } |
707 | 571 | |
708 | - /* Close files */ | |
709 | 572 | fd_close(src_fd); |
710 | 573 | fd_close(dst_fd); |
711 | - | |
712 | 574 | return 0; |
713 | 575 | } |
714 | 576 | |
577 | + | |
715 | 578 | /* |
716 | 579 | * Hack -- attempt to open a file descriptor (create file) |
717 | 580 | * This function should fail if the file already exists |
@@ -720,25 +583,19 @@ errr fd_copy(concptr file, concptr what) | ||
720 | 583 | int fd_make(concptr file, BIT_FLAGS mode) |
721 | 584 | { |
722 | 585 | char buf[1024]; |
723 | - | |
724 | - /* Hack -- Try to parse the path */ | |
725 | 586 | if (path_parse(buf, 1024, file)) return -1; |
726 | 587 | |
727 | 588 | #if defined(MACH_O_CARBON) |
728 | 589 | { |
729 | 590 | int fdes; |
730 | - /* Create the file, fail if exists, write-only, binary */ | |
731 | 591 | fdes = open(buf, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, mode); |
732 | - /* Set creator and type if the file is successfully opened */ | |
733 | 592 | if (fdes >= 0) fsetfileinfo(buf, _fcreator, _ftype); |
734 | - /* Return the descriptor */ | |
735 | 593 | return (fdes); |
736 | 594 | } |
595 | + | |
737 | 596 | #else |
738 | - /* Create the file, fail if exists, write-only, binary */ | |
739 | 597 | return (open(buf, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, mode)); |
740 | 598 | #endif |
741 | - | |
742 | 599 | } |
743 | 600 | |
744 | 601 |
@@ -750,11 +607,8 @@ int fd_make(concptr file, BIT_FLAGS mode) | ||
750 | 607 | int fd_open(concptr file, int flags) |
751 | 608 | { |
752 | 609 | char buf[1024]; |
753 | - | |
754 | - /* Hack -- Try to parse the path */ | |
755 | 610 | if (path_parse(buf, 1024, file)) return -1; |
756 | 611 | |
757 | - /* Attempt to open the file */ | |
758 | 612 | return (open(buf, flags | O_BINARY, 0)); |
759 | 613 | } |
760 | 614 |
@@ -766,29 +620,20 @@ int fd_open(concptr file, int flags) | ||
766 | 620 | */ |
767 | 621 | errr fd_lock(int fd, int what) |
768 | 622 | { |
769 | - /* XXX XXX */ | |
770 | 623 | what = what ? what : 0; |
771 | - | |
772 | - /* Verify the fd */ | |
773 | 624 | if (fd < 0) return -1; |
774 | 625 | |
775 | 626 | #if defined(SET_UID) && defined(LOCK_UN) && defined(LOCK_EX) |
776 | - /* Un-Lock */ | |
777 | 627 | if (what == F_UNLCK) |
778 | 628 | { |
779 | - /* Unlock it, Ignore errors */ | |
780 | 629 | (void)flock(fd, LOCK_UN); |
781 | 630 | } |
782 | - | |
783 | - /* Lock */ | |
784 | 631 | else |
785 | 632 | { |
786 | - /* Lock the score file */ | |
787 | 633 | if (flock(fd, LOCK_EX) != 0) return 1; |
788 | 634 | } |
789 | 635 | #endif |
790 | 636 | |
791 | - /* Success */ | |
792 | 637 | return 0; |
793 | 638 | } |
794 | 639 |
@@ -798,18 +643,11 @@ errr fd_lock(int fd, int what) | ||
798 | 643 | */ |
799 | 644 | errr fd_seek(int fd, huge n) |
800 | 645 | { |
801 | - huge p; | |
802 | - | |
803 | - /* Verify fd */ | |
804 | 646 | if (fd < 0) return -1; |
805 | 647 | |
806 | - /* Seek to the given position */ | |
807 | - p = lseek(fd, n, SEEK_SET); | |
808 | - | |
809 | - /* Failure */ | |
648 | + huge p = lseek(fd, n, SEEK_SET); | |
810 | 649 | if (p != n) return 1; |
811 | 650 | |
812 | - /* Success */ | |
813 | 651 | return 0; |
814 | 652 | } |
815 | 653 |
@@ -819,18 +657,12 @@ errr fd_seek(int fd, huge n) | ||
819 | 657 | */ |
820 | 658 | errr fd_chop(int fd, huge n) |
821 | 659 | { |
822 | - /* XXX XXX */ | |
823 | 660 | n = n ? n : 0; |
824 | - | |
825 | - /* Verify the fd */ | |
826 | 661 | if (fd < 0) return -1; |
827 | 662 | |
828 | 663 | #if defined(NeXT) |
829 | - /* Truncate */ | |
830 | 664 | ftruncate(fd, n); |
831 | 665 | #endif |
832 | - | |
833 | - /* Success */ | |
834 | 666 | return 0; |
835 | 667 | } |
836 | 668 |
@@ -840,30 +672,19 @@ errr fd_chop(int fd, huge n) | ||
840 | 672 | */ |
841 | 673 | errr fd_read(int fd, char *buf, huge n) |
842 | 674 | { |
843 | - /* Verify the fd */ | |
844 | 675 | if (fd < 0) return -1; |
845 | - | |
846 | 676 | #ifndef SET_UID |
847 | - | |
848 | - /* Read pieces */ | |
849 | 677 | while (n >= 16384) |
850 | 678 | { |
851 | - /* Read a piece */ | |
852 | 679 | if (read(fd, buf, 16384) != 16384) return 1; |
853 | 680 | |
854 | - /* Shorten the task */ | |
855 | 681 | buf += 16384; |
856 | - | |
857 | - /* Shorten the task */ | |
858 | 682 | n -= 16384; |
859 | 683 | } |
860 | - | |
861 | 684 | #endif |
862 | 685 | |
863 | - /* Read the final piece */ | |
864 | 686 | if (read(fd, buf, n) != (int)n) return 1; |
865 | 687 | |
866 | - /* Success */ | |
867 | 688 | return 0; |
868 | 689 | } |
869 | 690 |
@@ -873,30 +694,20 @@ errr fd_read(int fd, char *buf, huge n) | ||
873 | 694 | */ |
874 | 695 | errr fd_write(int fd, concptr buf, huge n) |
875 | 696 | { |
876 | - /* Verify the fd */ | |
877 | 697 | if (fd < 0) return -1; |
878 | 698 | |
879 | 699 | #ifndef SET_UID |
880 | - | |
881 | - /* Write pieces */ | |
882 | 700 | while (n >= 16384) |
883 | 701 | { |
884 | - /* Write a piece */ | |
885 | 702 | if (write(fd, buf, 16384) != 16384) return 1; |
886 | 703 | |
887 | - /* Shorten the task */ | |
888 | 704 | buf += 16384; |
889 | - | |
890 | - /* Shorten the task */ | |
891 | 705 | n -= 16384; |
892 | 706 | } |
893 | - | |
894 | 707 | #endif |
895 | 708 | |
896 | - /* Write the final piece */ | |
897 | 709 | if (write(fd, buf, n) != (int)n) return 1; |
898 | 710 | |
899 | - /* Success */ | |
900 | 711 | return 0; |
901 | 712 | } |
902 | 713 |
@@ -906,12 +717,9 @@ errr fd_write(int fd, concptr buf, huge n) | ||
906 | 717 | */ |
907 | 718 | errr fd_close(int fd) |
908 | 719 | { |
909 | - /* Verify the fd */ | |
910 | 720 | if (fd < 0) return -1; |
911 | 721 | |
912 | - /* Close */ | |
913 | 722 | (void)close(fd); |
914 | - | |
915 | 723 | return 0; |
916 | 724 | } |
917 | 725 |
@@ -971,7 +779,6 @@ void move_cursor(int row, int col) | ||
971 | 779 | } |
972 | 780 | |
973 | 781 | |
974 | - | |
975 | 782 | /* |
976 | 783 | * Convert a decimal to a single digit octal number |
977 | 784 | */ |
@@ -980,6 +787,7 @@ static char octify(uint i) | ||
980 | 787 | return (hexsym[i % 8]); |
981 | 788 | } |
982 | 789 | |
790 | + | |
983 | 791 | /* |
984 | 792 | * Convert a decimal to a single digit hex number |
985 | 793 | */ |
@@ -998,6 +806,7 @@ static int deoct(char c) | ||
998 | 806 | return 0; |
999 | 807 | } |
1000 | 808 | |
809 | + | |
1001 | 810 | /* |
1002 | 811 | * Convert a hexidecimal-digit into a decimal |
1003 | 812 | */ |
@@ -1012,14 +821,10 @@ static int dehex(char c) | ||
1012 | 821 | |
1013 | 822 | static int my_stricmp(concptr a, concptr b) |
1014 | 823 | { |
1015 | - concptr s1, s2; | |
1016 | - char z1, z2; | |
1017 | - | |
1018 | - /* Scan the strings */ | |
1019 | - for (s1 = a, s2 = b; TRUE; s1++, s2++) | |
824 | + for (concptr s1 = a, s2 = b; TRUE; s1++, s2++) | |
1020 | 825 | { |
1021 | - z1 = FORCEUPPER(*s1); | |
1022 | - z2 = FORCEUPPER(*s2); | |
826 | + char z1 = FORCEUPPER(*s1); | |
827 | + char z2 = FORCEUPPER(*s2); | |
1023 | 828 | if (z1 < z2) return -1; |
1024 | 829 | if (z1 > z2) return 1; |
1025 | 830 | if (!z1) return 0; |
@@ -1028,18 +833,15 @@ static int my_stricmp(concptr a, concptr b) | ||
1028 | 833 | |
1029 | 834 | static int my_strnicmp(concptr a, concptr b, int n) |
1030 | 835 | { |
1031 | - concptr s1, s2; | |
1032 | - char z1, z2; | |
1033 | - | |
1034 | - /* Scan the strings */ | |
1035 | - for (s1 = a, s2 = b; n > 0; s1++, s2++, n--) | |
836 | + for (concptr s1 = a, s2 = b; n > 0; s1++, s2++, n--) | |
1036 | 837 | { |
1037 | - z1 = FORCEUPPER(*s1); | |
1038 | - z2 = FORCEUPPER(*s2); | |
838 | + char z1 = FORCEUPPER(*s1); | |
839 | + char z2 = FORCEUPPER(*s2); | |
1039 | 840 | if (z1 < z2) return -1; |
1040 | 841 | if (z1 > z2) return 1; |
1041 | 842 | if (!z1) return 0; |
1042 | 843 | } |
844 | + | |
1043 | 845 | return 0; |
1044 | 846 | } |
1045 | 847 |
@@ -1071,23 +873,23 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr) | ||
1071 | 873 | if (!my_strnicmp(str, macro_modifier_name[i], len)) |
1072 | 874 | break; |
1073 | 875 | } |
876 | + | |
1074 | 877 | if (!macro_modifier_chr[i]) break; |
1075 | 878 | str += len; |
1076 | 879 | mod_status[i] = TRUE; |
1077 | 880 | if ('S' == macro_modifier_chr[i]) |
1078 | 881 | shiftstatus = 1; |
1079 | 882 | } |
883 | + | |
1080 | 884 | for (i = 0; i < max_macrotrigger; i++) |
1081 | 885 | { |
1082 | 886 | len = strlen(macro_trigger_name[i]); |
1083 | 887 | if (!my_strnicmp(str, macro_trigger_name[i], len) && ']' == str[len]) |
1084 | 888 | { |
1085 | - /* a trigger name found */ | |
1086 | 889 | break; |
1087 | 890 | } |
1088 | 891 | } |
1089 | 892 | |
1090 | - /* Invalid trigger name? */ | |
1091 | 893 | if (i == max_macrotrigger) |
1092 | 894 | { |
1093 | 895 | str = my_strchr(str, ']'); |
@@ -1098,8 +900,10 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr) | ||
1098 | 900 | *bufptr = s; |
1099 | 901 | *strptr = str; /* where **strptr == ']' */ |
1100 | 902 | } |
903 | + | |
1101 | 904 | return; |
1102 | 905 | } |
906 | + | |
1103 | 907 | key_code = macro_trigger_keycode[shiftstatus][i]; |
1104 | 908 | str += len; |
1105 | 909 |
@@ -1107,15 +911,15 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr) | ||
1107 | 911 | for (i = 0; macro_template[i]; i++) |
1108 | 912 | { |
1109 | 913 | char ch = macro_template[i]; |
1110 | - int j; | |
1111 | - | |
1112 | 914 | switch (ch) |
1113 | 915 | { |
1114 | 916 | case '&': |
1115 | - for (j = 0; macro_modifier_chr[j]; j++) { | |
917 | + for (int j = 0; macro_modifier_chr[j]; j++) | |
918 | + { | |
1116 | 919 | if (mod_status[j]) |
1117 | 920 | *s++ = macro_modifier_chr[j]; |
1118 | 921 | } |
922 | + | |
1119 | 923 | break; |
1120 | 924 | case '#': |
1121 | 925 | strcpy(s, key_code); |
@@ -1126,6 +930,7 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr) | ||
1126 | 930 | break; |
1127 | 931 | } |
1128 | 932 | } |
933 | + | |
1129 | 934 | *s++ = '\r'; |
1130 | 935 | |
1131 | 936 | *bufptr = s; |
@@ -1144,126 +949,91 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr) | ||
1144 | 949 | void text_to_ascii(char *buf, concptr str) |
1145 | 950 | { |
1146 | 951 | char *s = buf; |
1147 | - | |
1148 | - /* Analyze the "ascii" string */ | |
1149 | 952 | while (*str) |
1150 | 953 | { |
1151 | - /* Backslash codes */ | |
1152 | 954 | if (*str == '\\') |
1153 | 955 | { |
1154 | - /* Skip the backslash */ | |
1155 | 956 | str++; |
1156 | 957 | if (!(*str)) break; |
1157 | 958 | |
1158 | - /* Macro Trigger */ | |
1159 | 959 | if (*str == '[') |
1160 | 960 | { |
1161 | 961 | trigger_text_to_ascii(&s, &str); |
1162 | 962 | } |
1163 | 963 | else |
1164 | - | |
1165 | - /* Hex-mode XXX */ | |
964 | + { | |
1166 | 965 | if (*str == 'x') |
1167 | 966 | { |
1168 | 967 | *s = 16 * (char)dehex(*++str); |
1169 | 968 | *s++ += (char)dehex(*++str); |
1170 | 969 | } |
1171 | - | |
1172 | - /* Hack -- simple way to specify "backslash" */ | |
1173 | 970 | else if (*str == '\\') |
1174 | 971 | { |
1175 | 972 | *s++ = '\\'; |
1176 | 973 | } |
1177 | - | |
1178 | - /* Hack -- simple way to specify "caret" */ | |
1179 | 974 | else if (*str == '^') |
1180 | 975 | { |
1181 | 976 | *s++ = '^'; |
1182 | 977 | } |
1183 | - | |
1184 | - /* Hack -- simple way to specify "space" */ | |
1185 | 978 | else if (*str == 's') |
1186 | 979 | { |
1187 | 980 | *s++ = ' '; |
1188 | 981 | } |
1189 | - | |
1190 | - /* Hack -- simple way to specify Escape */ | |
1191 | 982 | else if (*str == 'e') |
1192 | 983 | { |
1193 | 984 | *s++ = ESCAPE; |
1194 | 985 | } |
1195 | - | |
1196 | - /* Backspace */ | |
1197 | 986 | else if (*str == 'b') |
1198 | 987 | { |
1199 | 988 | *s++ = '\b'; |
1200 | 989 | } |
1201 | - | |
1202 | - /* Newline */ | |
1203 | 990 | else if (*str == 'n') |
1204 | 991 | { |
1205 | 992 | *s++ = '\n'; |
1206 | 993 | } |
1207 | - | |
1208 | - /* Return */ | |
1209 | 994 | else if (*str == 'r') |
1210 | 995 | { |
1211 | 996 | *s++ = '\r'; |
1212 | 997 | } |
1213 | - | |
1214 | - /* Tab */ | |
1215 | 998 | else if (*str == 't') |
1216 | 999 | { |
1217 | 1000 | *s++ = '\t'; |
1218 | 1001 | } |
1219 | - | |
1220 | - /* Octal-mode */ | |
1221 | 1002 | else if (*str == '0') |
1222 | 1003 | { |
1223 | 1004 | *s = 8 * (char)deoct(*++str); |
1224 | 1005 | *s++ += (char)deoct(*++str); |
1225 | 1006 | } |
1226 | - | |
1227 | - /* Octal-mode */ | |
1228 | 1007 | else if (*str == '1') |
1229 | 1008 | { |
1230 | 1009 | *s = 64 + 8 * (char)deoct(*++str); |
1231 | 1010 | *s++ += (char)deoct(*++str); |
1232 | 1011 | } |
1233 | - | |
1234 | - /* Octal-mode */ | |
1235 | 1012 | else if (*str == '2') |
1236 | 1013 | { |
1237 | 1014 | *s = 64 * 2 + 8 * (char)deoct(*++str); |
1238 | 1015 | *s++ += (char)deoct(*++str); |
1239 | 1016 | } |
1240 | - | |
1241 | - /* Octal-mode */ | |
1242 | 1017 | else if (*str == '3') |
1243 | 1018 | { |
1244 | 1019 | *s = 64 * 3 + 8 * (char)deoct(*++str); |
1245 | 1020 | *s++ += (char)deoct(*++str); |
1246 | 1021 | } |
1022 | + } | |
1247 | 1023 | |
1248 | - /* Skip the final char */ | |
1249 | 1024 | str++; |
1250 | 1025 | } |
1251 | - | |
1252 | - /* Normal Control codes */ | |
1253 | 1026 | else if (*str == '^') |
1254 | 1027 | { |
1255 | 1028 | str++; |
1256 | 1029 | *s++ = (*str++ & 037); |
1257 | 1030 | } |
1258 | - | |
1259 | - /* Normal chars */ | |
1260 | 1031 | else |
1261 | 1032 | { |
1262 | 1033 | *s++ = *str++; |
1263 | 1034 | } |
1264 | 1035 | } |
1265 | 1036 | |
1266 | - /* Terminate */ | |
1267 | 1037 | *s = '\0'; |
1268 | 1038 | } |
1269 | 1039 |
@@ -1274,17 +1044,15 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr) | ||
1274 | 1044 | concptr str = *strptr; |
1275 | 1045 | char key_code[100]; |
1276 | 1046 | int i; |
1277 | - concptr tmp; | |
1278 | - | |
1279 | 1047 | if (macro_template == NULL) |
1280 | 1048 | return FALSE; |
1281 | 1049 | |
1282 | 1050 | *s++ = '\\'; |
1283 | 1051 | *s++ = '['; |
1284 | 1052 | |
1053 | + concptr tmp; | |
1285 | 1054 | for (i = 0; macro_template[i]; i++) |
1286 | 1055 | { |
1287 | - int j; | |
1288 | 1056 | char ch = macro_template[i]; |
1289 | 1057 | |
1290 | 1058 | switch (ch) |
@@ -1292,22 +1060,27 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr) | ||
1292 | 1060 | case '&': |
1293 | 1061 | while ((tmp = my_strchr(macro_modifier_chr, *str)) != 0) |
1294 | 1062 | { |
1295 | - j = (int)(tmp - macro_modifier_chr); | |
1063 | + int j = (int)(tmp - macro_modifier_chr); | |
1296 | 1064 | tmp = macro_modifier_name[j]; |
1297 | 1065 | while (*tmp) *s++ = *tmp++; |
1298 | 1066 | str++; |
1299 | 1067 | } |
1068 | + | |
1300 | 1069 | break; |
1301 | 1070 | case '#': |
1071 | + { | |
1072 | + int j; | |
1302 | 1073 | for (j = 0; *str && *str != '\r'; j++) |
1303 | 1074 | key_code[j] = *str++; |
1304 | 1075 | key_code[j] = '\0'; |
1305 | 1076 | break; |
1077 | + } | |
1306 | 1078 | default: |
1307 | 1079 | if (ch != *str) return FALSE; |
1308 | 1080 | str++; |
1309 | 1081 | } |
1310 | 1082 | } |
1083 | + | |
1311 | 1084 | if (*str++ != '\r') return FALSE; |
1312 | 1085 | |
1313 | 1086 | for (i = 0; i < max_macrotrigger; i++) |
@@ -1316,6 +1089,7 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr) | ||
1316 | 1089 | || !my_stricmp(key_code, macro_trigger_keycode[1][i])) |
1317 | 1090 | break; |
1318 | 1091 | } |
1092 | + | |
1319 | 1093 | if (i == max_macrotrigger) |
1320 | 1094 | return FALSE; |
1321 | 1095 |
@@ -1336,13 +1110,9 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr) | ||
1336 | 1110 | void ascii_to_text(char *buf, concptr str) |
1337 | 1111 | { |
1338 | 1112 | char *s = buf; |
1339 | - | |
1340 | - /* Analyze the "ascii" string */ | |
1341 | 1113 | while (*str) |
1342 | 1114 | { |
1343 | 1115 | byte i = (byte)(*str++); |
1344 | - | |
1345 | - /* Macro Trigger */ | |
1346 | 1116 | if (i == 31) |
1347 | 1117 | { |
1348 | 1118 | if (!trigger_ascii_to_text(&s, &str)) |
@@ -1352,7 +1122,7 @@ void ascii_to_text(char *buf, concptr str) | ||
1352 | 1122 | } |
1353 | 1123 | } |
1354 | 1124 | else |
1355 | - | |
1125 | + { | |
1356 | 1126 | if (i == ESCAPE) |
1357 | 1127 | { |
1358 | 1128 | *s++ = '\\'; |
@@ -1416,24 +1186,13 @@ void ascii_to_text(char *buf, concptr str) | ||
1416 | 1186 | *s++ = hexify(i / 16); |
1417 | 1187 | *s++ = hexify(i % 16); |
1418 | 1188 | } |
1189 | + } | |
1419 | 1190 | } |
1420 | 1191 | |
1421 | - /* Terminate */ | |
1422 | 1192 | *s = '\0'; |
1423 | 1193 | } |
1424 | 1194 | |
1425 | 1195 | |
1426 | - | |
1427 | -/* | |
1428 | - * The "macro" package | |
1429 | - * | |
1430 | - * Functions are provided to manipulate a collection of macros, each | |
1431 | - * of which has a trigger pattern string and a resulting action string | |
1432 | - * and a small set of flags. | |
1433 | - */ | |
1434 | - | |
1435 | - | |
1436 | - | |
1437 | 1196 | /* |
1438 | 1197 | * Determine if any macros have ever started with a given character. |
1439 | 1198 | */ |
@@ -1445,25 +1204,18 @@ static bool macro__use[256]; | ||
1445 | 1204 | */ |
1446 | 1205 | sint macro_find_exact(concptr pat) |
1447 | 1206 | { |
1448 | - int i; | |
1449 | - | |
1450 | - /* Nothing possible */ | |
1451 | 1207 | if (!macro__use[(byte)(pat[0])]) |
1452 | 1208 | { |
1453 | 1209 | return -1; |
1454 | 1210 | } |
1455 | 1211 | |
1456 | - /* Scan the macros */ | |
1457 | - for (i = 0; i < macro__num; ++i) | |
1212 | + for (int i = 0; i < macro__num; ++i) | |
1458 | 1213 | { |
1459 | - /* Skip macros which do not match the pattern */ | |
1460 | 1214 | if (!streq(macro__pat[i], pat)) continue; |
1461 | 1215 | |
1462 | - /* Found one */ | |
1463 | 1216 | return (i); |
1464 | 1217 | } |
1465 | 1218 | |
1466 | - /* No matches */ | |
1467 | 1219 | return -1; |
1468 | 1220 | } |
1469 | 1221 |
@@ -1473,25 +1225,18 @@ sint macro_find_exact(concptr pat) | ||
1473 | 1225 | */ |
1474 | 1226 | static sint macro_find_check(concptr pat) |
1475 | 1227 | { |
1476 | - int i; | |
1477 | - | |
1478 | - /* Nothing possible */ | |
1479 | 1228 | if (!macro__use[(byte)(pat[0])]) |
1480 | 1229 | { |
1481 | 1230 | return -1; |
1482 | 1231 | } |
1483 | 1232 | |
1484 | - /* Scan the macros */ | |
1485 | - for (i = 0; i < macro__num; ++i) | |
1233 | + for (int i = 0; i < macro__num; ++i) | |
1486 | 1234 | { |
1487 | - /* Skip macros which do not contain the pattern */ | |
1488 | 1235 | if (!prefix(macro__pat[i], pat)) continue; |
1489 | 1236 | |
1490 | - /* Found one */ | |
1491 | 1237 | return (i); |
1492 | 1238 | } |
1493 | 1239 | |
1494 | - /* Nothing */ | |
1495 | 1240 | return -1; |
1496 | 1241 | } |
1497 | 1242 |
@@ -1501,28 +1246,19 @@ static sint macro_find_check(concptr pat) | ||
1501 | 1246 | */ |
1502 | 1247 | static sint macro_find_maybe(concptr pat) |
1503 | 1248 | { |
1504 | - int i; | |
1505 | - | |
1506 | - /* Nothing possible */ | |
1507 | 1249 | if (!macro__use[(byte)(pat[0])]) |
1508 | 1250 | { |
1509 | 1251 | return -1; |
1510 | 1252 | } |
1511 | 1253 | |
1512 | - /* Scan the macros */ | |
1513 | - for (i = 0; i < macro__num; ++i) | |
1254 | + for (int i = 0; i < macro__num; ++i) | |
1514 | 1255 | { |
1515 | - /* Skip macros which do not contain the pattern */ | |
1516 | 1256 | if (!prefix(macro__pat[i], pat)) continue; |
1517 | - | |
1518 | - /* Skip macros which exactly match the pattern XXX XXX */ | |
1519 | 1257 | if (streq(macro__pat[i], pat)) continue; |
1520 | 1258 | |
1521 | - /* Found one */ | |
1522 | 1259 | return (i); |
1523 | 1260 | } |
1524 | 1261 | |
1525 | - /* Nothing */ | |
1526 | 1262 | return -1; |
1527 | 1263 | } |
1528 | 1264 |
@@ -1532,30 +1268,24 @@ static sint macro_find_maybe(concptr pat) | ||
1532 | 1268 | */ |
1533 | 1269 | static sint macro_find_ready(concptr pat) |
1534 | 1270 | { |
1535 | - int i, t, n = -1, s = -1; | |
1271 | + int t, n = -1, s = -1; | |
1536 | 1272 | |
1537 | - /* Nothing possible */ | |
1538 | 1273 | if (!macro__use[(byte)(pat[0])]) |
1539 | 1274 | { |
1540 | 1275 | return -1; |
1541 | 1276 | } |
1542 | 1277 | |
1543 | - /* Scan the macros */ | |
1544 | - for (i = 0; i < macro__num; ++i) | |
1278 | + for (int i = 0; i < macro__num; ++i) | |
1545 | 1279 | { |
1546 | - /* Skip macros which are not contained by the pattern */ | |
1547 | 1280 | if (!prefix(pat, macro__pat[i])) continue; |
1548 | 1281 | |
1549 | - /* Obtain the length of this macro */ | |
1550 | 1282 | t = strlen(macro__pat[i]); |
1551 | - | |
1552 | - /* Only track the "longest" pattern */ | |
1553 | 1283 | if ((n >= 0) && (s > t)) continue; |
1554 | 1284 | |
1555 | - /* Track the entry */ | |
1556 | 1285 | n = i; |
1557 | 1286 | s = t; |
1558 | 1287 | } |
1288 | + | |
1559 | 1289 | return (n); |
1560 | 1290 | } |
1561 | 1291 |
@@ -1576,45 +1306,25 @@ static sint macro_find_ready(concptr pat) | ||
1576 | 1306 | */ |
1577 | 1307 | errr macro_add(concptr pat, concptr act) |
1578 | 1308 | { |
1579 | - int n; | |
1580 | - | |
1581 | - | |
1582 | - /* Paranoia -- require data */ | |
1583 | 1309 | if (!pat || !act) return -1; |
1584 | 1310 | |
1585 | - | |
1586 | - /* Look for any existing macro */ | |
1587 | - n = macro_find_exact(pat); | |
1588 | - | |
1589 | - /* Replace existing macro */ | |
1311 | + int n = macro_find_exact(pat); | |
1590 | 1312 | if (n >= 0) |
1591 | 1313 | { |
1592 | - /* Free the old macro action */ | |
1593 | 1314 | string_free(macro__act[n]); |
1594 | 1315 | } |
1595 | - | |
1596 | - /* Create a new macro */ | |
1597 | 1316 | else |
1598 | 1317 | { |
1599 | - /* Acquire a new index */ | |
1600 | 1318 | n = macro__num++; |
1601 | - | |
1602 | - /* Save the pattern */ | |
1603 | 1319 | macro__pat[n] = string_make(pat); |
1604 | 1320 | } |
1605 | 1321 | |
1606 | - /* Save the action */ | |
1607 | 1322 | macro__act[n] = string_make(act); |
1608 | - | |
1609 | - /* Efficiency */ | |
1610 | 1323 | macro__use[(byte)(pat[0])] = TRUE; |
1611 | - | |
1612 | - /* Success */ | |
1613 | 1324 | return 0; |
1614 | 1325 | } |
1615 | 1326 | |
1616 | 1327 | |
1617 | - | |
1618 | 1328 | /* |
1619 | 1329 | * Local variable -- we are inside a "macro action" |
1620 | 1330 | * |
@@ -1629,7 +1339,6 @@ static bool parse_macro = FALSE; | ||
1629 | 1339 | */ |
1630 | 1340 | static bool parse_under = FALSE; |
1631 | 1341 | |
1632 | - | |
1633 | 1342 | /* |
1634 | 1343 | * Flush all input chars. Actually, remember the flush, |
1635 | 1344 | * and do a "special flush" before the next "inkey()". |
@@ -1639,7 +1348,6 @@ static bool parse_under = FALSE; | ||
1639 | 1348 | */ |
1640 | 1349 | void flush(void) |
1641 | 1350 | { |
1642 | - /* Do it later */ | |
1643 | 1351 | inkey_xtra = TRUE; |
1644 | 1352 | } |
1645 | 1353 |
@@ -1649,13 +1357,9 @@ void flush(void) | ||
1649 | 1357 | */ |
1650 | 1358 | void bell(void) |
1651 | 1359 | { |
1652 | - /* Mega-Hack -- Flush the output */ | |
1653 | 1360 | Term_fresh(); |
1654 | - | |
1655 | - /* Make a bell noise (if allowed) */ | |
1656 | 1361 | if (ring_bell) Term_xtra(TERM_XTRA_NOISE, 0); |
1657 | 1362 | |
1658 | - /* Flush the input (later!) */ | |
1659 | 1363 | flush(); |
1660 | 1364 | } |
1661 | 1365 |
@@ -1665,25 +1369,23 @@ void bell(void) | ||
1665 | 1369 | */ |
1666 | 1370 | void sound(int val) |
1667 | 1371 | { |
1668 | - /* No sound */ | |
1669 | 1372 | if (!use_sound) return; |
1670 | 1373 | |
1671 | - /* Make a sound (if allowed) */ | |
1672 | 1374 | Term_xtra(TERM_XTRA_SOUND, val); |
1673 | 1375 | } |
1674 | 1376 | |
1377 | + | |
1675 | 1378 | /* |
1676 | 1379 | * Hack -- Play a music |
1677 | 1380 | */ |
1678 | 1381 | errr play_music(int type, int val) |
1679 | 1382 | { |
1680 | - /* No sound */ | |
1681 | 1383 | if (!use_music) return 1; |
1682 | 1384 | |
1683 | - /* Make a sound (if allowed) */ | |
1684 | 1385 | return Term_xtra(type, val); |
1685 | 1386 | } |
1686 | 1387 | |
1388 | + | |
1687 | 1389 | /* |
1688 | 1390 | * Hack -- Select floor music. |
1689 | 1391 | */ |
@@ -1794,147 +1496,85 @@ void select_floor_music(player_type *player_ptr) | ||
1794 | 1496 | static char inkey_aux(void) |
1795 | 1497 | { |
1796 | 1498 | int k = 0, n, p = 0, w = 0; |
1797 | - | |
1798 | 1499 | char ch; |
1799 | - | |
1800 | - concptr pat, act; | |
1801 | - | |
1802 | 1500 | char *buf = inkey_macro_trigger_string; |
1803 | 1501 | |
1804 | - /* Hack : キー入力待ちで止まっているので、流れた行の記憶は不要。 */ | |
1805 | 1502 | num_more = 0; |
1806 | 1503 | |
1807 | 1504 | if (parse_macro) |
1808 | 1505 | { |
1809 | - /* Scan next keypress from macro action */ | |
1810 | 1506 | if (Term_inkey(&ch, FALSE, TRUE)) |
1811 | 1507 | { |
1812 | - /* Over-flowed? Cancel macro action */ | |
1813 | 1508 | parse_macro = FALSE; |
1814 | 1509 | } |
1815 | 1510 | } |
1816 | 1511 | else |
1817 | 1512 | { |
1818 | - /* Wait for a keypress */ | |
1819 | 1513 | (void)(Term_inkey(&ch, TRUE, TRUE)); |
1820 | 1514 | } |
1821 | 1515 | |
1822 | - | |
1823 | - /* End "macro action" */ | |
1824 | 1516 | if (ch == 30) parse_macro = FALSE; |
1825 | 1517 | |
1826 | - /* Inside "macro action" */ | |
1827 | 1518 | if (ch == 30) return (ch); |
1828 | - | |
1829 | - /* Inside "macro action" */ | |
1830 | 1519 | if (parse_macro) return (ch); |
1831 | - | |
1832 | - /* Inside "macro trigger" */ | |
1833 | 1520 | if (parse_under) return (ch); |
1834 | 1521 | |
1835 | - /* Save the first key, advance */ | |
1836 | 1522 | buf[p++] = ch; |
1837 | 1523 | buf[p] = '\0'; |
1838 | - | |
1839 | - | |
1840 | - /* Check for possible macro */ | |
1841 | 1524 | k = macro_find_check(buf); |
1842 | - | |
1843 | - /* No macro pending */ | |
1844 | 1525 | if (k < 0) return (ch); |
1845 | 1526 | |
1846 | - | |
1847 | - /* Wait for a macro, or a timeout */ | |
1848 | 1527 | while (TRUE) |
1849 | 1528 | { |
1850 | - /* Check for pending macro */ | |
1851 | 1529 | k = macro_find_maybe(buf); |
1852 | 1530 | |
1853 | - /* No macro pending */ | |
1854 | 1531 | if (k < 0) break; |
1855 | 1532 | |
1856 | - /* Check for (and remove) a pending key */ | |
1857 | 1533 | if (0 == Term_inkey(&ch, FALSE, TRUE)) |
1858 | 1534 | { |
1859 | - /* Append the key */ | |
1860 | 1535 | buf[p++] = ch; |
1861 | 1536 | buf[p] = '\0'; |
1862 | - | |
1863 | - /* Restart wait */ | |
1864 | 1537 | w = 0; |
1865 | 1538 | } |
1866 | - | |
1867 | - /* No key ready */ | |
1868 | 1539 | else |
1869 | 1540 | { |
1870 | - /* Increase "wait" */ | |
1871 | 1541 | w += 1; |
1872 | - | |
1873 | - /* Excessive delay */ | |
1874 | 1542 | if (w >= 10) break; |
1875 | 1543 | |
1876 | 1544 | Term_xtra(TERM_XTRA_DELAY, w); |
1877 | 1545 | } |
1878 | 1546 | } |
1879 | 1547 | |
1880 | - | |
1881 | - /* Check for available macro */ | |
1882 | 1548 | k = macro_find_ready(buf); |
1883 | - | |
1884 | - /* No macro available */ | |
1885 | 1549 | if (k < 0) |
1886 | 1550 | { |
1887 | - /* Push all the keys back on the queue */ | |
1888 | 1551 | while (p > 0) |
1889 | 1552 | { |
1890 | - /* Push the key, notice over-flow */ | |
1891 | 1553 | if (Term_key_push(buf[--p])) return 0; |
1892 | 1554 | } |
1893 | 1555 | |
1894 | - /* Wait for (and remove) a pending key */ | |
1895 | 1556 | (void)Term_inkey(&ch, TRUE, TRUE); |
1896 | - | |
1897 | - /* Return the key */ | |
1898 | 1557 | return (ch); |
1899 | 1558 | } |
1900 | 1559 | |
1901 | - | |
1902 | - /* Get the pattern */ | |
1903 | - pat = macro__pat[k]; | |
1904 | - | |
1905 | - /* Get the length of the pattern */ | |
1560 | + concptr pat = macro__pat[k]; | |
1906 | 1561 | n = strlen(pat); |
1907 | - | |
1908 | - /* Push the "extra" keys back on the queue */ | |
1909 | 1562 | while (p > n) |
1910 | 1563 | { |
1911 | - /* Push the key, notice over-flow */ | |
1912 | 1564 | if (Term_key_push(buf[--p])) return 0; |
1913 | 1565 | } |
1914 | 1566 | |
1915 | - | |
1916 | - /* Begin "macro action" */ | |
1917 | 1567 | parse_macro = TRUE; |
1918 | - | |
1919 | - /* Push the "end of macro action" key */ | |
1920 | 1568 | if (Term_key_push(30)) return 0; |
1921 | 1569 | |
1570 | + concptr act = macro__act[k]; | |
1922 | 1571 | |
1923 | - /* Access the macro action */ | |
1924 | - act = macro__act[k]; | |
1925 | - | |
1926 | - /* Get the length of the action */ | |
1927 | 1572 | n = strlen(act); |
1928 | - | |
1929 | - /* Push the macro "action" onto the key queue */ | |
1930 | 1573 | while (n > 0) |
1931 | 1574 | { |
1932 | - /* Push the key, notice over-flow */ | |
1933 | 1575 | if (Term_key_push(act[--n])) return 0; |
1934 | 1576 | } |
1935 | 1577 | |
1936 | - | |
1937 | - /* Hack -- Force "inkey()" to call us again */ | |
1938 | 1578 | return 0; |
1939 | 1579 | } |
1940 | 1580 |
@@ -1946,22 +1586,14 @@ static void forget_macro_action(void) | ||
1946 | 1586 | { |
1947 | 1587 | if (!parse_macro) return; |
1948 | 1588 | |
1949 | - /* Drop following macro action string */ | |
1950 | 1589 | while (TRUE) |
1951 | 1590 | { |
1952 | 1591 | char ch; |
1953 | - | |
1954 | - /* End loop if no key ready */ | |
1955 | 1592 | if (Term_inkey(&ch, FALSE, TRUE)) break; |
1956 | - | |
1957 | - /* End loop if no key ready */ | |
1958 | 1593 | if (ch == 0) break; |
1959 | - | |
1960 | - /* End of "macro action" */ | |
1961 | 1594 | if (ch == 30) break; |
1962 | 1595 | } |
1963 | 1596 | |
1964 | - /* No longer inside "macro action" */ | |
1965 | 1597 | parse_macro = FALSE; |
1966 | 1598 | } |
1967 | 1599 |
@@ -2039,100 +1671,60 @@ static concptr inkey_next = NULL; | ||
2039 | 1671 | */ |
2040 | 1672 | char inkey(void) |
2041 | 1673 | { |
2042 | - int v; | |
2043 | - char kk; | |
2044 | 1674 | char ch = 0; |
2045 | 1675 | bool done = FALSE; |
2046 | 1676 | term *old = Term; |
2047 | 1677 | |
2048 | - /* Hack -- Use the "inkey_next" pointer */ | |
2049 | 1678 | if (inkey_next && *inkey_next && !inkey_xtra) |
2050 | 1679 | { |
2051 | - /* Get next character, and advance */ | |
2052 | 1680 | ch = *inkey_next++; |
2053 | - | |
2054 | - /* Cancel the various "global parameters" */ | |
2055 | 1681 | inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE; |
2056 | - | |
2057 | - /* Accept result */ | |
2058 | 1682 | return (ch); |
2059 | 1683 | } |
2060 | 1684 | |
2061 | - /* Forget pointer */ | |
2062 | 1685 | inkey_next = NULL; |
2063 | - | |
2064 | - /* Hack -- handle delayed "flush()" */ | |
2065 | 1686 | if (inkey_xtra) |
2066 | 1687 | { |
2067 | - /* End "macro action" */ | |
2068 | 1688 | parse_macro = FALSE; |
2069 | - | |
2070 | - /* End "macro trigger" */ | |
2071 | 1689 | parse_under = FALSE; |
2072 | - | |
2073 | - /* Forget old keypresses */ | |
2074 | 1690 | Term_flush(); |
2075 | 1691 | } |
2076 | 1692 | |
2077 | - | |
2078 | - /* Access cursor state */ | |
1693 | + int v; | |
2079 | 1694 | (void)Term_get_cursor(&v); |
2080 | 1695 | |
2081 | 1696 | /* Show the cursor if waiting, except sometimes in "command" mode */ |
2082 | 1697 | if (!inkey_scan && (!inkey_flag || hilite_player || current_world_ptr->character_icky)) |
2083 | 1698 | { |
2084 | - /* Show the cursor */ | |
2085 | 1699 | (void)Term_set_cursor(1); |
2086 | 1700 | } |
2087 | 1701 | |
2088 | - | |
2089 | - /* Hack -- Activate main screen */ | |
2090 | 1702 | Term_activate(angband_term[0]); |
2091 | - | |
2092 | - | |
2093 | - /* Get a key */ | |
1703 | + char kk; | |
2094 | 1704 | while (!ch) |
2095 | 1705 | { |
2096 | - /* Hack -- Handle "inkey_scan" */ | |
2097 | 1706 | if (!inkey_base && inkey_scan && |
2098 | 1707 | (0 != Term_inkey(&kk, FALSE, FALSE))) |
2099 | 1708 | { |
2100 | 1709 | break; |
2101 | 1710 | } |
2102 | 1711 | |
2103 | - | |
2104 | - /* Hack -- Flush output once when no key ready */ | |
2105 | 1712 | if (!done && (0 != Term_inkey(&kk, FALSE, FALSE))) |
2106 | 1713 | { |
2107 | - /* Hack -- activate proper term */ | |
2108 | 1714 | Term_activate(old); |
2109 | - | |
2110 | - /* Flush output */ | |
2111 | 1715 | Term_fresh(); |
2112 | - | |
2113 | - /* Hack -- activate main screen */ | |
2114 | 1716 | Term_activate(angband_term[0]); |
2115 | - | |
2116 | - /* Mega-Hack -- reset saved flag */ | |
2117 | 1717 | current_world_ptr->character_saved = FALSE; |
2118 | 1718 | |
2119 | - /* Mega-Hack -- reset signal counter */ | |
2120 | 1719 | signal_count = 0; |
2121 | - | |
2122 | - /* Only once */ | |
2123 | 1720 | done = TRUE; |
2124 | 1721 | } |
2125 | 1722 | |
2126 | - | |
2127 | - /* Hack -- Handle "inkey_base" */ | |
2128 | 1723 | if (inkey_base) |
2129 | 1724 | { |
2130 | 1725 | int w = 0; |
2131 | - | |
2132 | - /* Wait forever */ | |
2133 | 1726 | if (!inkey_scan) |
2134 | 1727 | { |
2135 | - /* Wait for (and remove) a pending key */ | |
2136 | 1728 | if (0 == Term_inkey(&ch, TRUE, TRUE)) |
2137 | 1729 | { |
2138 | 1730 | break; |
@@ -2141,22 +1733,15 @@ char inkey(void) | ||
2141 | 1733 | break; |
2142 | 1734 | } |
2143 | 1735 | |
2144 | - /* Wait */ | |
2145 | 1736 | while (TRUE) |
2146 | 1737 | { |
2147 | - /* Check for (and remove) a pending key */ | |
2148 | 1738 | if (0 == Term_inkey(&ch, FALSE, TRUE)) |
2149 | 1739 | { |
2150 | 1740 | break; |
2151 | 1741 | } |
2152 | - | |
2153 | - /* No key ready */ | |
2154 | 1742 | else |
2155 | 1743 | { |
2156 | - /* Increase "wait" */ | |
2157 | 1744 | w += 10; |
2158 | - | |
2159 | - /* Excessive delay */ | |
2160 | 1745 | if (w >= 100) break; |
2161 | 1746 | |
2162 | 1747 | Term_xtra(TERM_XTRA_DELAY, w); |
@@ -2166,107 +1751,48 @@ char inkey(void) | ||
2166 | 1751 | break; |
2167 | 1752 | } |
2168 | 1753 | |
2169 | - | |
2170 | - /* Get a key (see above) */ | |
2171 | 1754 | ch = inkey_aux(); |
2172 | - | |
2173 | - | |
2174 | - /* Handle "control-right-bracket" */ | |
2175 | 1755 | if (ch == 29) |
2176 | 1756 | { |
2177 | - /* Strip this key */ | |
2178 | 1757 | ch = 0; |
2179 | 1758 | continue; |
2180 | 1759 | } |
2181 | 1760 | |
2182 | - | |
2183 | - /* Treat back-quote as escape */ | |
2184 | -/* if (ch == '`') ch = ESCAPE; */ | |
2185 | - | |
2186 | - | |
2187 | - /* End "macro trigger" */ | |
2188 | 1761 | if (parse_under && (ch <= 32)) |
2189 | 1762 | { |
2190 | - /* Strip this key */ | |
2191 | 1763 | ch = 0; |
2192 | - | |
2193 | - /* End "macro trigger" */ | |
2194 | 1764 | parse_under = FALSE; |
2195 | 1765 | } |
2196 | 1766 | |
2197 | - | |
2198 | - /* Handle "control-caret" */ | |
2199 | 1767 | if (ch == 30) |
2200 | 1768 | { |
2201 | - /* Strip this key */ | |
2202 | 1769 | ch = 0; |
2203 | 1770 | } |
2204 | - | |
2205 | - /* Handle "control-underscore" */ | |
2206 | 1771 | else if (ch == 31) |
2207 | 1772 | { |
2208 | - /* Strip this key */ | |
2209 | 1773 | ch = 0; |
2210 | - | |
2211 | - /* Begin "macro trigger" */ | |
2212 | 1774 | parse_under = TRUE; |
2213 | 1775 | } |
2214 | - | |
2215 | - /* Inside "macro trigger" */ | |
2216 | 1776 | else if (parse_under) |
2217 | 1777 | { |
2218 | - /* Strip this key */ | |
2219 | 1778 | ch = 0; |
2220 | 1779 | } |
2221 | 1780 | } |
2222 | 1781 | |
2223 | - | |
2224 | - /* Hack -- restore the term */ | |
2225 | 1782 | Term_activate(old); |
2226 | - | |
2227 | - | |
2228 | - /* Restore the cursor */ | |
2229 | 1783 | Term_set_cursor(v); |
2230 | - | |
2231 | - | |
2232 | - /* Cancel the various "global parameters" */ | |
2233 | 1784 | inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE; |
2234 | - | |
2235 | - /* Return the keypress */ | |
2236 | 1785 | return (ch); |
2237 | 1786 | } |
2238 | 1787 | |
2239 | 1788 | |
2240 | - | |
2241 | - | |
2242 | -/* | |
2243 | - * We use a global array for all inscriptions to reduce the memory | |
2244 | - * spent maintaining inscriptions. Of course, it is still possible | |
2245 | - * to run out of inscription memory, especially if too many different | |
2246 | - * inscriptions are used, but hopefully this will be rare. | |
2247 | - * | |
2248 | - * We use dynamic string allocation because otherwise it is necessary | |
2249 | - * to pre-guess the amount of quark activity. We limit the total | |
2250 | - * number of quarks, but this is much easier to "expand" as needed. | |
2251 | - * | |
2252 | - * Any two items with the same inscription will have the same "quark" | |
2253 | - * index, which should greatly reduce the need for inscription space. | |
2254 | - * | |
2255 | - * Note that "quark zero" is NULL and should not be "dereferenced". | |
2256 | - */ | |
2257 | - | |
2258 | 1789 | /* |
2259 | 1790 | * Initialize the quark array |
2260 | 1791 | */ |
2261 | 1792 | void quark_init(void) |
2262 | 1793 | { |
2263 | - /* Quark variables */ | |
2264 | 1794 | C_MAKE(quark__str, QUARK_MAX, concptr); |
2265 | - | |
2266 | - /* Prepare first quark, which is used when quark_add() is failed */ | |
2267 | 1795 | quark__str[1] = string_make(""); |
2268 | - | |
2269 | - /* There is one quark (+ NULL) */ | |
2270 | 1796 | quark__num = 2; |
2271 | 1797 | } |
2272 | 1798 |
@@ -2277,24 +1803,15 @@ void quark_init(void) | ||
2277 | 1803 | u16b quark_add(concptr str) |
2278 | 1804 | { |
2279 | 1805 | u16b i; |
2280 | - | |
2281 | - /* Look for an existing quark */ | |
2282 | 1806 | for (i = 1; i < quark__num; i++) |
2283 | 1807 | { |
2284 | - /* Check for equality */ | |
2285 | 1808 | if (streq(quark__str[i], str)) return (i); |
2286 | 1809 | } |
2287 | 1810 | |
2288 | - /* Return "" when no room is available */ | |
2289 | 1811 | if (quark__num == QUARK_MAX) return 1; |
2290 | 1812 | |
2291 | - /* New maximal quark */ | |
2292 | 1813 | quark__num = i + 1; |
2293 | - | |
2294 | - /* Add a new quark */ | |
2295 | 1814 | quark__str[i] = string_make(str); |
2296 | - | |
2297 | - /* Return the index */ | |
2298 | 1815 | return (i); |
2299 | 1816 | } |
2300 | 1817 |
@@ -2317,50 +1834,19 @@ concptr quark_str(STR_OFFSET i) | ||
2317 | 1834 | } |
2318 | 1835 | |
2319 | 1836 | |
2320 | - | |
2321 | - | |
2322 | -/* | |
2323 | - * Second try for the "message" handling routines. | |
2324 | - * | |
2325 | - * Each call to "message_add(s)" will add a new "most recent" message | |
2326 | - * to the "message recall list", using the contents of the string "s". | |
2327 | - * | |
2328 | - * The messages will be stored in such a way as to maximize "efficiency", | |
2329 | - * that is, we attempt to maximize the number of sequential messages that | |
2330 | - * can be retrieved, given a limited amount of storage space. | |
2331 | - * | |
2332 | - * We keep a buffer of chars to hold the "text" of the messages, not | |
2333 | - * necessarily in "order", and an array of offsets into that buffer, | |
2334 | - * representing the actual messages. This is made more complicated | |
2335 | - * by the fact that both the array of indexes, and the buffer itself, | |
2336 | - * are both treated as "circular arrays" for efficiency purposes, but | |
2337 | - * the strings may not be "broken" across the ends of the array. | |
2338 | - * | |
2339 | - * The "message_add()" function is rather "complex", because it must be | |
2340 | - * extremely efficient, both in space and time, for use with the Borg. | |
2341 | - */ | |
2342 | - | |
2343 | - | |
2344 | - | |
2345 | 1837 | /*! |
2346 | 1838 | * @brief 保存中の過去ゲームメッセージの数を返す。 / How many messages are "available"? |
2347 | 1839 | * @return 残っているメッセージの数 |
2348 | 1840 | */ |
2349 | 1841 | s32b message_num(void) |
2350 | 1842 | { |
2351 | - int last, next, n; | |
2352 | - | |
2353 | - /* Extract the indexes */ | |
2354 | - last = message__last; | |
2355 | - next = message__next; | |
1843 | + int n; | |
1844 | + int last = message__last; | |
1845 | + int next = message__next; | |
2356 | 1846 | |
2357 | - /* Handle "wrap" */ | |
2358 | 1847 | if (next < last) next += MESSAGE_MAX; |
2359 | 1848 | |
2360 | - /* Extract the space */ | |
2361 | 1849 | n = (next - last); |
2362 | - | |
2363 | - /* Return the result */ | |
2364 | 1850 | return (n); |
2365 | 1851 | } |
2366 | 1852 |
@@ -2372,23 +1858,11 @@ s32b message_num(void) | ||
2372 | 1858 | */ |
2373 | 1859 | concptr message_str(int age) |
2374 | 1860 | { |
2375 | - s32b x; | |
2376 | - s32b o; | |
2377 | - concptr s; | |
2378 | - | |
2379 | - /* Forgotten messages have no text */ | |
2380 | 1861 | if ((age < 0) || (age >= message_num())) return (""); |
2381 | 1862 | |
2382 | - /* Acquire the "logical" index */ | |
2383 | - x = (message__next + MESSAGE_MAX - (age + 1)) % MESSAGE_MAX; | |
2384 | - | |
2385 | - /* Get the "offset" for the message */ | |
2386 | - o = message__ptr[x]; | |
2387 | - | |
2388 | - /* Access the message text */ | |
2389 | - s = &message__buf[o]; | |
2390 | - | |
2391 | - /* Return the message text */ | |
1863 | + s32b x = (message__next + MESSAGE_MAX - (age + 1)) % MESSAGE_MAX; | |
1864 | + s32b o = message__ptr[x]; | |
1865 | + concptr s = &message__buf[o]; | |
2392 | 1866 | return (s); |
2393 | 1867 | } |
2394 | 1868 |
@@ -2400,29 +1874,21 @@ concptr message_str(int age) | ||
2400 | 1874 | */ |
2401 | 1875 | void message_add(concptr str) |
2402 | 1876 | { |
2403 | - u32b i, n; | |
2404 | - int k, x, m; | |
2405 | - | |
1877 | + u32b i; | |
1878 | + int x, m; | |
2406 | 1879 | char u[4096]; |
2407 | 1880 | char splitted1[81]; |
2408 | 1881 | concptr splitted2; |
2409 | 1882 | |
2410 | - /*** Step 1 -- Analyze the message ***/ | |
2411 | - | |
2412 | - /* Hack -- Ignore "non-messages" */ | |
2413 | 1883 | if (!str) return; |
2414 | 1884 | |
2415 | - /* Message length */ | |
2416 | - n = strlen(str); | |
2417 | - | |
2418 | - /* Important Hack -- Ignore "long" messages */ | |
1885 | + int n = strlen(str); | |
2419 | 1886 | if (n >= MESSAGE_BUF / 4) return; |
2420 | 1887 | |
2421 | - /* extra step -- split the message if n>80.(added by Mogami) */ | |
2422 | - if (n > 80) { | |
1888 | + if (n > 80) | |
1889 | + { | |
2423 | 1890 | #ifdef JP |
2424 | 1891 | concptr t = str; |
2425 | - | |
2426 | 1892 | for (n = 0; n < 80; n++, t++) |
2427 | 1893 | { |
2428 | 1894 | if (iskanji(*t)) { |
@@ -2430,7 +1896,9 @@ void message_add(concptr str) | ||
2430 | 1896 | n++; |
2431 | 1897 | } |
2432 | 1898 | } |
2433 | - if (n == 81) n = 79; /* 最後の文字が漢字半分 */ | |
1899 | + | |
1900 | + /* 最後の文字が漢字半分 */ | |
1901 | + if (n == 81) n = 79; | |
2434 | 1902 | #else |
2435 | 1903 | for (n = 80; n > 60; n--) |
2436 | 1904 | if (str[n] == ' ') break; |
@@ -2441,234 +1909,140 @@ void message_add(concptr str) | ||
2441 | 1909 | splitted1[n] = '\0'; |
2442 | 1910 | str = splitted1; |
2443 | 1911 | } |
2444 | - else { | |
1912 | + else | |
1913 | + { | |
2445 | 1914 | splitted2 = NULL; |
2446 | 1915 | } |
2447 | 1916 | |
2448 | - /*** Step 2 -- 最適化の試行 / Attempt to optimize ***/ | |
2449 | - | |
2450 | - /* Limit number of messages to check */ | |
2451 | 1917 | m = message_num(); |
2452 | - k = m / 4; | |
1918 | + int k = m / 4; | |
2453 | 1919 | if (k > MESSAGE_MAX / 32) k = MESSAGE_MAX / 32; |
2454 | - | |
2455 | - /* Check previous message */ | |
2456 | 1920 | for (i = message__next; m; m--) |
2457 | 1921 | { |
2458 | 1922 | int j = 1; |
2459 | - | |
2460 | 1923 | char buf[1024]; |
2461 | 1924 | char *t; |
2462 | - | |
2463 | 1925 | concptr old; |
2464 | - | |
2465 | - /* Back up and wrap if needed */ | |
2466 | 1926 | if (i-- == 0) i = MESSAGE_MAX - 1; |
2467 | 1927 | |
2468 | - /* Access the old string */ | |
2469 | 1928 | old = &message__buf[message__ptr[i]]; |
2470 | - | |
2471 | - /* Skip small messages */ | |
2472 | 1929 | if (!old) continue; |
2473 | 1930 | |
2474 | 1931 | strcpy(buf, old); |
2475 | - | |
2476 | - /* Find multiple */ | |
2477 | 1932 | #ifdef JP |
2478 | 1933 | for (t = buf; *t && (*t != '<' || (*(t + 1) != 'x')); t++) |
2479 | 1934 | if (iskanji(*t))t++; |
2480 | 1935 | #else |
2481 | 1936 | for (t = buf; *t && (*t != '<'); t++); |
2482 | 1937 | #endif |
2483 | - | |
2484 | 1938 | if (*t) |
2485 | 1939 | { |
2486 | - /* Message is too small */ | |
2487 | 1940 | if (strlen(buf) < A_MAX) break; |
2488 | 1941 | |
2489 | - /* Drop the space */ | |
2490 | 1942 | *(t - 1) = '\0'; |
2491 | - | |
2492 | - /* Get multiplier */ | |
2493 | 1943 | j = atoi(t + 2); |
2494 | 1944 | } |
2495 | 1945 | |
2496 | - /* Limit the multiplier to 1000 */ | |
2497 | 1946 | if (streq(buf, str) && (j < 1000)) |
2498 | 1947 | { |
2499 | 1948 | j++; |
2500 | - | |
2501 | - /* Overwrite */ | |
2502 | 1949 | message__next = i; |
2503 | - | |
2504 | 1950 | str = u; |
2505 | - | |
2506 | - /* Write it out */ | |
2507 | 1951 | sprintf(u, "%s <x%d>", buf, j); |
2508 | - | |
2509 | - /* Message length */ | |
2510 | 1952 | n = strlen(str); |
2511 | - | |
2512 | 1953 | if (!now_message) now_message++; |
2513 | 1954 | } |
2514 | 1955 | else |
2515 | 1956 | { |
2516 | - num_more++;/*流れた行の数を数えておく */ | |
1957 | + /*流れた行の数を数えておく */ | |
1958 | + num_more++; | |
2517 | 1959 | now_message++; |
2518 | 1960 | } |
2519 | 1961 | |
2520 | 1962 | break; |
2521 | 1963 | } |
2522 | 1964 | |
2523 | - /* Check the last few messages (if any to count) */ | |
2524 | 1965 | for (i = message__next; k; k--) |
2525 | 1966 | { |
2526 | 1967 | int q; |
2527 | 1968 | concptr old; |
2528 | 1969 | |
2529 | - /* Back up and wrap if needed */ | |
2530 | 1970 | if (i-- == 0) i = MESSAGE_MAX - 1; |
2531 | 1971 | |
2532 | - /* Stop before oldest message */ | |
2533 | 1972 | if (i == message__last) break; |
2534 | 1973 | |
2535 | - /* Extract "distance" from "head" */ | |
2536 | 1974 | q = (message__head + MESSAGE_BUF - message__ptr[i]) % MESSAGE_BUF; |
2537 | 1975 | |
2538 | - /* Do not optimize over large distance */ | |
2539 | 1976 | if (q > MESSAGE_BUF / 2) continue; |
2540 | 1977 | |
2541 | - /* Access the old string */ | |
2542 | 1978 | old = &message__buf[message__ptr[i]]; |
2543 | - | |
2544 | - /* Compare */ | |
2545 | 1979 | if (!streq(old, str)) continue; |
2546 | 1980 | |
2547 | - /* Get the next message index, advance */ | |
2548 | 1981 | x = message__next++; |
2549 | - | |
2550 | - /* Handle wrap */ | |
2551 | 1982 | if (message__next == MESSAGE_MAX) message__next = 0; |
2552 | - | |
2553 | - /* Kill last message if needed */ | |
2554 | 1983 | if (message__next == message__last) message__last++; |
2555 | - | |
2556 | - /* Handle wrap */ | |
2557 | 1984 | if (message__last == MESSAGE_MAX) message__last = 0; |
2558 | 1985 | |
2559 | - /* Assign the starting address */ | |
2560 | 1986 | message__ptr[x] = message__ptr[i]; |
2561 | 1987 | |
2562 | - /* Success */ | |
2563 | - /* return; */ | |
2564 | 1988 | goto end_of_message_add; |
2565 | - | |
2566 | 1989 | } |
2567 | 1990 | |
2568 | - | |
2569 | - /*** Step 3 -- Ensure space before end of buffer ***/ | |
2570 | - | |
2571 | - /* Kill messages and Wrap if needed */ | |
2572 | 1991 | if (message__head + n + 1 >= MESSAGE_BUF) |
2573 | 1992 | { |
2574 | - /* Kill all "dead" messages */ | |
2575 | 1993 | for (i = message__last; TRUE; i++) |
2576 | 1994 | { |
2577 | - /* Wrap if needed */ | |
2578 | 1995 | if (i == MESSAGE_MAX) i = 0; |
2579 | - | |
2580 | - /* Stop before the new message */ | |
2581 | 1996 | if (i == message__next) break; |
2582 | - | |
2583 | - /* Kill "dead" messages */ | |
2584 | 1997 | if (message__ptr[i] >= message__head) |
2585 | 1998 | { |
2586 | - /* Track oldest message */ | |
2587 | 1999 | message__last = i + 1; |
2588 | 2000 | } |
2589 | 2001 | } |
2590 | 2002 | |
2591 | - /* Wrap "tail" if needed */ | |
2592 | 2003 | if (message__tail >= message__head) message__tail = 0; |
2593 | 2004 | |
2594 | - /* Start over */ | |
2595 | 2005 | message__head = 0; |
2596 | 2006 | } |
2597 | 2007 | |
2598 | - | |
2599 | - /*** Step 4 -- Ensure space before next message ***/ | |
2600 | - | |
2601 | - /* Kill messages if needed */ | |
2602 | 2008 | if (message__head + n + 1 > message__tail) |
2603 | 2009 | { |
2604 | - /* Grab new "tail" */ | |
2605 | 2010 | message__tail = message__head + n + 1; |
2606 | - | |
2607 | - /* Advance tail while possible past first "nul" */ | |
2608 | 2011 | while (message__buf[message__tail - 1]) message__tail++; |
2609 | 2012 | |
2610 | - /* Kill all "dead" messages */ | |
2611 | 2013 | for (i = message__last; TRUE; i++) |
2612 | 2014 | { |
2613 | - /* Wrap if needed */ | |
2614 | 2015 | if (i == MESSAGE_MAX) i = 0; |
2615 | - | |
2616 | - /* Stop before the new message */ | |
2617 | 2016 | if (i == message__next) break; |
2618 | - | |
2619 | - /* Kill "dead" messages */ | |
2620 | 2017 | if ((message__ptr[i] >= message__head) && |
2621 | 2018 | (message__ptr[i] < message__tail)) |
2622 | 2019 | { |
2623 | - /* Track oldest message */ | |
2624 | 2020 | message__last = i + 1; |
2625 | 2021 | } |
2626 | 2022 | } |
2627 | 2023 | } |
2628 | 2024 | |
2629 | 2025 | |
2630 | - /*** Step 5 -- Grab a new message index ***/ | |
2631 | - | |
2632 | - /* Get the next message index, advance */ | |
2633 | 2026 | x = message__next++; |
2634 | - | |
2635 | - /* Handle wrap */ | |
2636 | 2027 | if (message__next == MESSAGE_MAX) message__next = 0; |
2637 | - | |
2638 | - /* Kill last message if needed */ | |
2639 | 2028 | if (message__next == message__last) message__last++; |
2029 | + if (message__last == MESSAGE_MAX) message__last = 0; | |
2640 | 2030 | |
2641 | - /* Handle wrap */ | |
2642 | - if (message__last == MESSAGE_MAX) message__last = 0; | |
2643 | - | |
2644 | - | |
2645 | - | |
2646 | - /*** Step 6 -- Insert the message text ***/ | |
2647 | - | |
2648 | - /* Assign the starting address */ | |
2649 | 2031 | message__ptr[x] = message__head; |
2650 | - | |
2651 | - /* Append the new part of the message */ | |
2652 | 2032 | for (i = 0; i < n; i++) |
2653 | 2033 | { |
2654 | - /* Copy the message */ | |
2655 | 2034 | message__buf[message__head + i] = str[i]; |
2656 | 2035 | } |
2657 | 2036 | |
2658 | - /* Terminate */ | |
2659 | 2037 | message__buf[message__head + i] = '\0'; |
2660 | - | |
2661 | - /* Advance the "head" pointer */ | |
2662 | 2038 | message__head += n + 1; |
2663 | 2039 | |
2664 | - /* recursively add splitted message (added by Mogami) */ | |
2665 | 2040 | end_of_message_add: |
2666 | 2041 | if (splitted2 != NULL) |
2667 | 2042 | message_add(splitted2); |
2668 | 2043 | } |
2669 | 2044 | |
2670 | 2045 | |
2671 | - | |
2672 | 2046 | /* |
2673 | 2047 | * Hack -- flush |
2674 | 2048 | */ |
@@ -2676,7 +2050,6 @@ static void msg_flush(player_type *player_ptr, int x) | ||
2676 | 2050 | { |
2677 | 2051 | byte a = TERM_L_BLUE; |
2678 | 2052 | bool nagasu = FALSE; |
2679 | - | |
2680 | 2053 | if ((auto_more && !player_ptr->now_damaged) || num_more < 0) { |
2681 | 2054 | int i; |
2682 | 2055 | for (i = 0; i < 8; i++) |
@@ -2694,34 +2067,36 @@ static void msg_flush(player_type *player_ptr, int x) | ||
2694 | 2067 | } |
2695 | 2068 | |
2696 | 2069 | player_ptr->now_damaged = FALSE; |
2697 | - | |
2698 | 2070 | if (!player_ptr->playing || !nagasu) |
2699 | 2071 | { |
2700 | - /* Pause for response */ | |
2701 | 2072 | Term_putstr(x, 0, -1, a, _("-続く-", "-more-")); |
2702 | - | |
2703 | - /* Get an acceptable keypress */ | |
2704 | 2073 | while (TRUE) |
2705 | 2074 | { |
2706 | 2075 | int cmd = inkey(); |
2707 | - if (cmd == ESCAPE) { | |
2708 | - num_more = -9999; /*auto_moreのとき、全て流す。 */ | |
2076 | + if (cmd == ESCAPE) | |
2077 | + { | |
2078 | + /* auto_moreのとき、全て流す */ | |
2079 | + num_more = -9999; | |
2709 | 2080 | break; |
2710 | 2081 | } |
2711 | - else if (cmd == ' ') { | |
2712 | - num_more = 0; /*1画面だけ流す。 */ | |
2082 | + else if (cmd == ' ') | |
2083 | + { | |
2084 | + /* 1画面だけ流す */ | |
2085 | + num_more = 0; | |
2713 | 2086 | break; |
2714 | 2087 | } |
2715 | - else if ((cmd == '\n') || (cmd == '\r')) { | |
2716 | - num_more--; /*1行だけ流す。 */ | |
2088 | + else if ((cmd == '\n') || (cmd == '\r')) | |
2089 | + { | |
2090 | + /* 1行だけ流す */ | |
2091 | + num_more--; | |
2717 | 2092 | break; |
2718 | 2093 | } |
2094 | + | |
2719 | 2095 | if (quick_messages) break; |
2720 | 2096 | bell(); |
2721 | 2097 | } |
2722 | 2098 | } |
2723 | 2099 | |
2724 | - /* Clear the line */ | |
2725 | 2100 | Term_erase(0, 0, 255); |
2726 | 2101 | } |
2727 | 2102 |
@@ -2733,6 +2108,7 @@ void msg_erase(void) | ||
2733 | 2108 | |
2734 | 2109 | |
2735 | 2110 | /* |
2111 | + * todo ここのp_ptrを削除するのは破滅的に作業が増えるので保留 | |
2736 | 2112 | * Output a message to the top line of the screen. |
2737 | 2113 | * |
2738 | 2114 | * Break long messages into multiple pieces (40-72 chars). |
@@ -2760,39 +2136,28 @@ void msg_erase(void) | ||
2760 | 2136 | void msg_print(concptr msg) |
2761 | 2137 | { |
2762 | 2138 | static int p = 0; |
2763 | - int n; | |
2764 | 2139 | char *t; |
2765 | 2140 | char buf[1024]; |
2766 | 2141 | |
2767 | 2142 | if (current_world_ptr->timewalk_m_idx) return; |
2768 | 2143 | |
2769 | - /* Hack -- Reset */ | |
2770 | - if (!msg_flag) { | |
2771 | - /* Clear the line */ | |
2144 | + if (!msg_flag) | |
2145 | + { | |
2772 | 2146 | Term_erase(0, 0, 255); |
2773 | 2147 | p = 0; |
2774 | 2148 | } |
2775 | 2149 | |
2776 | - /* Original Message Length */ | |
2777 | - n = (msg ? strlen(msg) : 0); | |
2778 | - | |
2779 | - /* Hack -- flush when requested or needed */ | |
2150 | + int n = (msg ? strlen(msg) : 0); | |
2780 | 2151 | if (p && (!msg || ((p + n) > 72))) |
2781 | 2152 | { |
2782 | 2153 | msg_flush(p_ptr, p); |
2783 | - | |
2784 | - /* Forget it */ | |
2785 | 2154 | msg_flag = FALSE; |
2786 | - | |
2787 | - /* Reset */ | |
2788 | 2155 | p = 0; |
2789 | 2156 | } |
2790 | 2157 | |
2791 | - /* No message */ | |
2792 | 2158 | if (!msg) return; |
2793 | 2159 | if (n > 1000) return; |
2794 | 2160 | |
2795 | - /* Copy it */ | |
2796 | 2161 | if (!cheat_turn) |
2797 | 2162 | { |
2798 | 2163 | strcpy(buf, msg); |
@@ -2802,26 +2167,16 @@ void msg_print(concptr msg) | ||
2802 | 2167 | sprintf(buf, ("T:%d - %s"), (int)current_world_ptr->game_turn, msg); |
2803 | 2168 | } |
2804 | 2169 | |
2805 | - /* New Message Length */ | |
2806 | 2170 | n = strlen(buf); |
2807 | - | |
2808 | - /* Memorize the message */ | |
2809 | 2171 | if (current_world_ptr->character_generated) message_add(buf); |
2810 | 2172 | |
2811 | - /* Analyze the buffer */ | |
2812 | 2173 | t = buf; |
2813 | - | |
2814 | - /* Split message */ | |
2815 | 2174 | while (n > 72) |
2816 | 2175 | { |
2817 | - char oops; | |
2818 | 2176 | int check, split = 72; |
2819 | - | |
2820 | 2177 | #ifdef JP |
2821 | 2178 | bool k_flag = FALSE; |
2822 | 2179 | int wordlen = 0; |
2823 | - | |
2824 | - /* Find the "best" split point */ | |
2825 | 2180 | for (check = 0; check < 72; check++) |
2826 | 2181 | { |
2827 | 2182 | if (k_flag) |
@@ -2830,7 +2185,6 @@ void msg_print(concptr msg) | ||
2830 | 2185 | continue; |
2831 | 2186 | } |
2832 | 2187 | |
2833 | - /* Found a valid split point */ | |
2834 | 2188 | if (iskanji(t[check])) |
2835 | 2189 | { |
2836 | 2190 | k_flag = TRUE; |
@@ -2848,60 +2202,34 @@ void msg_print(concptr msg) | ||
2848 | 2202 | split = check; |
2849 | 2203 | } |
2850 | 2204 | } |
2205 | + | |
2851 | 2206 | #else |
2852 | - /* Find the "best" split point */ | |
2853 | 2207 | for (check = 40; check < 72; check++) |
2854 | 2208 | { |
2855 | - /* Found a valid split point */ | |
2856 | 2209 | if (t[check] == ' ') split = check; |
2857 | 2210 | } |
2858 | 2211 | #endif |
2859 | 2212 | |
2860 | - /* Save the split character */ | |
2861 | - oops = t[split]; | |
2862 | - | |
2863 | - /* Split the message */ | |
2213 | + char oops = t[split]; | |
2864 | 2214 | t[split] = '\0'; |
2865 | - | |
2866 | - /* Display part of the message */ | |
2867 | 2215 | Term_putstr(0, 0, split, TERM_WHITE, t); |
2868 | - | |
2869 | - /* Flush it */ | |
2870 | 2216 | msg_flush(p_ptr, split + 1); |
2871 | - | |
2872 | - /* Memorize the piece */ | |
2873 | - /* if (current_world_ptr->character_generated) message_add(t); */ | |
2874 | - | |
2875 | - /* Restore the split character */ | |
2876 | 2217 | t[split] = oops; |
2877 | - | |
2878 | - /* Insert a space */ | |
2879 | 2218 | t[--split] = ' '; |
2880 | - | |
2881 | - /* Prepare to recurse on the rest of "buf" */ | |
2882 | 2219 | t += split; n -= split; |
2883 | 2220 | } |
2884 | 2221 | |
2885 | - /* Display the tail of the message */ | |
2886 | 2222 | Term_putstr(p, 0, n, TERM_WHITE, t); |
2887 | - | |
2888 | - /* Memorize the tail */ | |
2889 | - /* if (current_world_ptr->character_generated) message_add(t); */ | |
2890 | - | |
2891 | 2223 | p_ptr->window |= (PW_MESSAGE); |
2892 | 2224 | update_output(p_ptr); |
2893 | 2225 | |
2894 | - /* Remember the message */ | |
2895 | 2226 | msg_flag = TRUE; |
2896 | - | |
2897 | - /* Remember the position */ | |
2898 | 2227 | #ifdef JP |
2899 | 2228 | p += n; |
2900 | 2229 | #else |
2901 | 2230 | p += n + 1; |
2902 | 2231 | #endif |
2903 | 2232 | |
2904 | - /* Optional refresh */ | |
2905 | 2233 | if (fresh_message) Term_fresh(); |
2906 | 2234 | } |
2907 | 2235 |
@@ -2939,13 +2267,9 @@ static int screen_depth = 0; | ||
2939 | 2267 | */ |
2940 | 2268 | void screen_save() |
2941 | 2269 | { |
2942 | - /* Hack -- Flush messages */ | |
2943 | 2270 | msg_print(NULL); |
2944 | - | |
2945 | - /* Save the screen (if legal) */ | |
2946 | 2271 | if (screen_depth++ == 0) Term_save(); |
2947 | 2272 | |
2948 | - /* Increase "icky" depth */ | |
2949 | 2273 | current_world_ptr->character_icky++; |
2950 | 2274 | } |
2951 | 2275 |
@@ -2957,13 +2281,9 @@ void screen_save() | ||
2957 | 2281 | */ |
2958 | 2282 | void screen_load() |
2959 | 2283 | { |
2960 | - /* Hack -- Flush messages */ | |
2961 | 2284 | msg_print(NULL); |
2962 | - | |
2963 | - /* Load the screen (if legal) */ | |
2964 | 2285 | if (--screen_depth == 0) Term_load(); |
2965 | 2286 | |
2966 | - /* Decrease "icky" depth */ | |
2967 | 2287 | current_world_ptr->character_icky--; |
2968 | 2288 | } |
2969 | 2289 |
@@ -2974,22 +2294,14 @@ void screen_load() | ||
2974 | 2294 | void msg_format(concptr fmt, ...) |
2975 | 2295 | { |
2976 | 2296 | va_list vp; |
2977 | - | |
2978 | 2297 | char buf[1024]; |
2979 | - | |
2980 | - /* Begin the Varargs Stuff */ | |
2981 | 2298 | va_start(vp, fmt); |
2982 | - | |
2983 | - /* Format the args, save the length */ | |
2984 | 2299 | (void)vstrnfmt(buf, 1024, fmt, vp); |
2985 | - | |
2986 | - /* End the Varargs Stuff */ | |
2987 | 2300 | va_end(vp); |
2988 | - | |
2989 | - /* Display */ | |
2990 | 2301 | msg_print(buf); |
2991 | 2302 | } |
2992 | 2303 | |
2304 | + | |
2993 | 2305 | /* |
2994 | 2306 | * Display a formatted message, using "vstrnfmt()" and "msg_print()". |
2995 | 2307 | */ |
@@ -3002,17 +2314,9 @@ void msg_format_wizard(int cheat_type, concptr fmt, ...) | ||
3002 | 2314 | |
3003 | 2315 | va_list vp; |
3004 | 2316 | char buf[1024]; |
3005 | - | |
3006 | - /* Begin the Varargs Stuff */ | |
3007 | 2317 | va_start(vp, fmt); |
3008 | - | |
3009 | - /* Format the args, save the length */ | |
3010 | 2318 | (void)vstrnfmt(buf, 1024, fmt, vp); |
3011 | - | |
3012 | - /* End the Varargs Stuff */ | |
3013 | 2319 | va_end(vp); |
3014 | - | |
3015 | - /* Display */ | |
3016 | 2320 | msg_print_wizard(cheat_type, buf); |
3017 | 2321 | } |
3018 | 2322 |
@@ -3025,34 +2329,30 @@ void msg_format_wizard(int cheat_type, concptr fmt, ...) | ||
3025 | 2329 | */ |
3026 | 2330 | void c_put_str(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col) |
3027 | 2331 | { |
3028 | - /* Position cursor, Dump the attr/text */ | |
3029 | 2332 | Term_putstr(col, row, -1, attr, str); |
3030 | 2333 | } |
3031 | 2334 | |
2335 | + | |
3032 | 2336 | /* |
3033 | 2337 | * As above, but in "white" |
3034 | 2338 | */ |
3035 | 2339 | void put_str(concptr str, TERM_LEN row, TERM_LEN col) |
3036 | 2340 | { |
3037 | - /* Spawn */ | |
3038 | 2341 | Term_putstr(col, row, -1, TERM_WHITE, str); |
3039 | 2342 | } |
3040 | 2343 | |
3041 | 2344 | |
3042 | - | |
3043 | 2345 | /* |
3044 | 2346 | * Display a string on the screen using an attribute, and clear |
3045 | 2347 | * to the end of the line. |
3046 | 2348 | */ |
3047 | 2349 | void c_prt(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col) |
3048 | 2350 | { |
3049 | - /* Clear line, position cursor */ | |
3050 | 2351 | Term_erase(col, row, 255); |
3051 | - | |
3052 | - /* Dump the attr/text */ | |
3053 | 2352 | Term_addstr(-1, attr, str); |
3054 | 2353 | } |
3055 | 2354 | |
2355 | + | |
3056 | 2356 | /* |
3057 | 2357 | * As above, but in "white" |
3058 | 2358 | */ |
@@ -3063,8 +2363,6 @@ void prt(concptr str, TERM_LEN row, TERM_LEN col) | ||
3063 | 2363 | } |
3064 | 2364 | |
3065 | 2365 | |
3066 | - | |
3067 | - | |
3068 | 2366 | /* |
3069 | 2367 | * Print some (colored) text to the screen at the current cursor position, |
3070 | 2368 | * automatically "wrapping" existing text (at spaces) when necessary to |
@@ -3081,67 +2379,46 @@ void prt(concptr str, TERM_LEN row, TERM_LEN col) | ||
3081 | 2379 | */ |
3082 | 2380 | void c_roff(TERM_COLOR a, concptr str) |
3083 | 2381 | { |
3084 | - int x, y; | |
3085 | - | |
3086 | 2382 | int w, h; |
3087 | - | |
3088 | - concptr s; | |
3089 | - | |
3090 | - /* Obtain the size */ | |
3091 | 2383 | (void)Term_get_size(&w, &h); |
3092 | 2384 | |
3093 | - /* Obtain the cursor */ | |
2385 | + int x, y; | |
3094 | 2386 | (void)Term_locate(&x, &y); |
3095 | 2387 | |
3096 | - /* Hack -- No more space */ | |
3097 | 2388 | if (y == h - 1 && x > w - 3) return; |
3098 | 2389 | |
3099 | - /* Process the string */ | |
3100 | - for (s = str; *s; s++) | |
2390 | + for (concptr s = str; *s; s++) | |
3101 | 2391 | { |
3102 | 2392 | char ch; |
3103 | - | |
3104 | 2393 | #ifdef JP |
3105 | 2394 | int k_flag = iskanji(*s); |
3106 | 2395 | #endif |
3107 | - /* Force wrap */ | |
3108 | 2396 | if (*s == '\n') |
3109 | 2397 | { |
3110 | - /* Wrap */ | |
3111 | 2398 | x = 0; |
3112 | 2399 | y++; |
3113 | - | |
3114 | - /* No more space */ | |
3115 | 2400 | if (y == h) break; |
3116 | 2401 | |
3117 | - /* Clear line, move cursor */ | |
3118 | 2402 | Term_erase(x, y, 255); |
3119 | - | |
3120 | 2403 | break; |
3121 | 2404 | } |
3122 | 2405 | |
3123 | - /* Clean up the char */ | |
3124 | 2406 | #ifdef JP |
3125 | 2407 | ch = ((k_flag || isprint(*s)) ? *s : ' '); |
3126 | 2408 | #else |
3127 | 2409 | ch = (isprint(*s) ? *s : ' '); |
3128 | 2410 | #endif |
3129 | 2411 | |
3130 | - | |
3131 | - /* Wrap words as needed */ | |
3132 | 2412 | #ifdef JP |
3133 | 2413 | if ((x >= ((k_flag) ? w - 2 : w - 1)) && (ch != ' ')) |
3134 | 2414 | #else |
3135 | 2415 | if ((x >= w - 1) && (ch != ' ')) |
3136 | 2416 | #endif |
3137 | - | |
3138 | 2417 | { |
3139 | 2418 | int i, n = 0; |
3140 | 2419 | |
3141 | 2420 | TERM_COLOR av[256]; |
3142 | 2421 | char cv[256]; |
3143 | - | |
3144 | - /* Wrap word */ | |
3145 | 2422 | if (x < w) |
3146 | 2423 | #ifdef JP |
3147 | 2424 | { |
@@ -3149,23 +2426,17 @@ void c_roff(TERM_COLOR a, concptr str) | ||
3149 | 2426 | if (!k_flag) |
3150 | 2427 | #endif |
3151 | 2428 | { |
3152 | - /* Scan existing text */ | |
3153 | 2429 | for (i = w - 2; i >= 0; i--) |
3154 | 2430 | { |
3155 | - /* Grab existing attr/char */ | |
3156 | 2431 | Term_what(i, y, &av[i], &cv[i]); |
3157 | - | |
3158 | - /* Break on space */ | |
3159 | 2432 | if (cv[i] == ' ') break; |
3160 | 2433 | |
3161 | - /* Track current word */ | |
3162 | 2434 | n = i; |
3163 | 2435 | #ifdef JP |
3164 | 2436 | if (cv[i] == '(') break; |
3165 | 2437 | #endif |
3166 | 2438 | } |
3167 | 2439 | } |
3168 | - | |
3169 | 2440 | #ifdef JP |
3170 | 2441 | else |
3171 | 2442 | { |
@@ -3182,44 +2453,30 @@ void c_roff(TERM_COLOR a, concptr str) | ||
3182 | 2453 | } |
3183 | 2454 | } |
3184 | 2455 | #endif |
3185 | - /* Special case */ | |
3186 | 2456 | if (n == 0) n = w; |
3187 | 2457 | |
3188 | - /* Clear line */ | |
3189 | 2458 | Term_erase(n, y, 255); |
3190 | - | |
3191 | - /* Wrap */ | |
3192 | 2459 | x = 0; |
3193 | 2460 | y++; |
3194 | - | |
3195 | - /* No more space */ | |
3196 | 2461 | if (y == h) break; |
3197 | 2462 | |
3198 | - /* Clear line, move cursor */ | |
3199 | 2463 | Term_erase(x, y, 255); |
3200 | - | |
3201 | - /* Wrap the word (if any) */ | |
3202 | 2464 | for (i = n; i < w - 1; i++) |
3203 | 2465 | { |
3204 | 2466 | #ifdef JP |
3205 | 2467 | if (cv[i] == '\0') break; |
3206 | 2468 | #endif |
3207 | - /* Dump */ | |
3208 | 2469 | Term_addch(av[i], cv[i]); |
3209 | - | |
3210 | - /* Advance (no wrap) */ | |
3211 | 2470 | if (++x > w) x = w; |
3212 | 2471 | } |
3213 | 2472 | } |
3214 | 2473 | |
3215 | - /* Dump */ | |
3216 | 2474 | #ifdef JP |
3217 | 2475 | Term_addch((byte)(a | 0x10), ch); |
3218 | 2476 | #else |
3219 | 2477 | Term_addch(a, ch); |
3220 | 2478 | #endif |
3221 | 2479 | |
3222 | - | |
3223 | 2480 | #ifdef JP |
3224 | 2481 | if (k_flag) |
3225 | 2482 | { |
@@ -3229,11 +2486,12 @@ void c_roff(TERM_COLOR a, concptr str) | ||
3229 | 2486 | Term_addch((byte)(a | 0x20), ch); |
3230 | 2487 | } |
3231 | 2488 | #endif |
3232 | - /* Advance */ | |
2489 | + | |
3233 | 2490 | if (++x > w) x = w; |
3234 | 2491 | } |
3235 | 2492 | } |
3236 | 2493 | |
2494 | + | |
3237 | 2495 | /* |
3238 | 2496 | * As above, but in "white" |
3239 | 2497 | */ |
@@ -3244,26 +2502,18 @@ void roff(concptr str) | ||
3244 | 2502 | } |
3245 | 2503 | |
3246 | 2504 | |
3247 | - | |
3248 | - | |
3249 | 2505 | /* |
3250 | 2506 | * Clear part of the screen |
3251 | 2507 | */ |
3252 | 2508 | void clear_from(int row) |
3253 | 2509 | { |
3254 | - int y; | |
3255 | - | |
3256 | - /* Erase requested rows */ | |
3257 | - for (y = row; y < Term->hgt; y++) | |
2510 | + for (int y = row; y < Term->hgt; y++) | |
3258 | 2511 | { |
3259 | - /* Erase part of the screen */ | |
3260 | 2512 | Term_erase(0, y, 255); |
3261 | 2513 | } |
3262 | 2514 | } |
3263 | 2515 | |
3264 | 2516 | |
3265 | - | |
3266 | - | |
3267 | 2517 | /* |
3268 | 2518 | * Get some string input at the cursor location. |
3269 | 2519 | * Assume the buffer is initialized to a default string. |
@@ -3283,9 +2533,6 @@ void clear_from(int row) | ||
3283 | 2533 | */ |
3284 | 2534 | bool askfor_aux(char *buf, int len, bool numpad_cursor) |
3285 | 2535 | { |
3286 | - int y, x; | |
3287 | - int pos = 0; | |
3288 | - | |
3289 | 2536 | /* |
3290 | 2537 | * Text color |
3291 | 2538 | * TERM_YELLOW : Overwrite mode |
@@ -3293,194 +2540,120 @@ bool askfor_aux(char *buf, int len, bool numpad_cursor) | ||
3293 | 2540 | */ |
3294 | 2541 | byte color = TERM_YELLOW; |
3295 | 2542 | |
3296 | - /* Locate the cursor position */ | |
2543 | + int y, x; | |
3297 | 2544 | Term_locate(&x, &y); |
3298 | - | |
3299 | - /* Paranoia -- check len */ | |
3300 | 2545 | if (len < 1) len = 1; |
3301 | - | |
3302 | - /* Paranoia -- check column */ | |
3303 | 2546 | if ((x < 0) || (x >= 80)) x = 0; |
3304 | - | |
3305 | - /* Restrict the length */ | |
3306 | 2547 | if (x + len > 80) len = 80 - x; |
3307 | 2548 | |
3308 | - /* Paranoia -- Clip the default entry */ | |
3309 | 2549 | buf[len] = '\0'; |
3310 | 2550 | |
3311 | - | |
3312 | - /* Process input */ | |
2551 | + int pos = 0; | |
3313 | 2552 | while (TRUE) |
3314 | 2553 | { |
3315 | - int skey; | |
3316 | - | |
3317 | - /* Display the string */ | |
3318 | 2554 | Term_erase(x, y, len); |
3319 | 2555 | Term_putstr(x, y, -1, color, buf); |
3320 | 2556 | |
3321 | - /* Place cursor */ | |
3322 | 2557 | Term_gotoxy(x + pos, y); |
2558 | + int skey = inkey_special(numpad_cursor); | |
3323 | 2559 | |
3324 | - /* Get a special key code */ | |
3325 | - skey = inkey_special(numpad_cursor); | |
3326 | - | |
3327 | - /* Analyze the key */ | |
3328 | 2560 | switch (skey) |
3329 | 2561 | { |
3330 | 2562 | case SKEY_LEFT: |
3331 | 2563 | case KTRL('b'): |
3332 | 2564 | { |
3333 | 2565 | int i = 0; |
3334 | - | |
3335 | - /* Now on insert mode */ | |
3336 | 2566 | color = TERM_WHITE; |
3337 | 2567 | |
3338 | - /* No move at beginning of line */ | |
3339 | 2568 | if (0 == pos) break; |
3340 | - | |
3341 | 2569 | while (TRUE) |
3342 | 2570 | { |
3343 | 2571 | int next_pos = i + 1; |
3344 | - | |
3345 | 2572 | #ifdef JP |
3346 | 2573 | if (iskanji(buf[i])) next_pos++; |
3347 | 2574 | #endif |
3348 | - | |
3349 | - /* Is there the cursor at next position? */ | |
3350 | 2575 | if (next_pos >= pos) break; |
3351 | 2576 | |
3352 | - /* Move to next */ | |
3353 | 2577 | i = next_pos; |
3354 | 2578 | } |
3355 | 2579 | |
3356 | - /* Get previous position */ | |
3357 | 2580 | pos = i; |
3358 | - | |
3359 | 2581 | break; |
3360 | 2582 | } |
3361 | 2583 | |
3362 | 2584 | case SKEY_RIGHT: |
3363 | 2585 | case KTRL('f'): |
3364 | - /* Now on insert mode */ | |
3365 | 2586 | color = TERM_WHITE; |
3366 | - | |
3367 | - /* No move at end of line */ | |
3368 | 2587 | if ('\0' == buf[pos]) break; |
3369 | 2588 | |
3370 | 2589 | #ifdef JP |
3371 | - /* Move right */ | |
3372 | 2590 | if (iskanji(buf[pos])) pos += 2; |
3373 | 2591 | else pos++; |
3374 | 2592 | #else |
3375 | 2593 | pos++; |
3376 | 2594 | #endif |
3377 | - | |
3378 | 2595 | break; |
3379 | 2596 | |
3380 | 2597 | case ESCAPE: |
3381 | - /* Cancel input */ | |
3382 | 2598 | buf[0] = '\0'; |
3383 | 2599 | return FALSE; |
3384 | 2600 | |
3385 | 2601 | case '\n': |
3386 | 2602 | case '\r': |
3387 | - /* Success */ | |
3388 | 2603 | return TRUE; |
3389 | 2604 | |
3390 | 2605 | case '\010': |
3391 | - /* Backspace */ | |
3392 | 2606 | { |
3393 | 2607 | int i = 0; |
3394 | - | |
3395 | - /* Now on insert mode */ | |
3396 | 2608 | color = TERM_WHITE; |
3397 | - | |
3398 | - /* No move at beginning of line */ | |
3399 | 2609 | if (0 == pos) break; |
3400 | - | |
3401 | 2610 | while (TRUE) |
3402 | 2611 | { |
3403 | 2612 | int next_pos = i + 1; |
3404 | - | |
3405 | 2613 | #ifdef JP |
3406 | 2614 | if (iskanji(buf[i])) next_pos++; |
3407 | 2615 | #endif |
3408 | - | |
3409 | - /* Is there the cursor at next position? */ | |
3410 | 2616 | if (next_pos >= pos) break; |
3411 | 2617 | |
3412 | - /* Move to next */ | |
3413 | 2618 | i = next_pos; |
3414 | 2619 | } |
3415 | 2620 | |
3416 | - /* Get previous position */ | |
3417 | 2621 | pos = i; |
3418 | - | |
3419 | - /* Fall through to 'Delete key' */ | |
3420 | 2622 | } |
3421 | 2623 | |
3422 | 2624 | case 0x7F: |
3423 | 2625 | case KTRL('d'): |
3424 | - /* Delete key */ | |
3425 | 2626 | { |
3426 | - int dst, src; | |
3427 | - | |
3428 | - /* Now on insert mode */ | |
3429 | 2627 | color = TERM_WHITE; |
3430 | - | |
3431 | - /* No move at end of line */ | |
3432 | 2628 | if ('\0' == buf[pos]) break; |
3433 | - | |
3434 | - /* Position of next character */ | |
3435 | - src = pos + 1; | |
3436 | - | |
2629 | + int src = pos + 1; | |
3437 | 2630 | #ifdef JP |
3438 | - /* Next character is one more byte away */ | |
3439 | 2631 | if (iskanji(buf[pos])) src++; |
3440 | 2632 | #endif |
3441 | 2633 | |
3442 | - dst = pos; | |
3443 | - | |
3444 | - /* Move characters at src to dst */ | |
3445 | - while ('\0' != (buf[dst++] = buf[src++])) | |
3446 | - /* loop */; | |
3447 | - | |
2634 | + int dst = pos; | |
2635 | + while ('\0' != (buf[dst++] = buf[src++])); | |
3448 | 2636 | break; |
3449 | 2637 | } |
3450 | 2638 | |
3451 | 2639 | default: |
3452 | 2640 | { |
3453 | - /* Insert a character */ | |
3454 | - | |
3455 | 2641 | char tmp[100]; |
3456 | - char c; | |
3457 | - | |
3458 | - /* Ignore special keys */ | |
3459 | 2642 | if (skey & SKEY_MASK) break; |
3460 | - | |
3461 | - /* Get a character code */ | |
3462 | - c = (char)skey; | |
2643 | + char c = (char)skey; | |
3463 | 2644 | |
3464 | 2645 | if (color == TERM_YELLOW) |
3465 | 2646 | { |
3466 | - /* Overwrite default string */ | |
3467 | 2647 | buf[0] = '\0'; |
3468 | - | |
3469 | - /* Go to insert mode */ | |
3470 | 2648 | color = TERM_WHITE; |
3471 | 2649 | } |
3472 | 2650 | |
3473 | - /* Save right part of string */ | |
3474 | 2651 | strcpy(tmp, buf + pos); |
3475 | 2652 | #ifdef JP |
3476 | 2653 | if (iskanji(c)) |
3477 | 2654 | { |
3478 | - char next; | |
3479 | - | |
3480 | - /* Bypass macro processing */ | |
3481 | 2655 | inkey_base = TRUE; |
3482 | - next = inkey(); | |
3483 | - | |
2656 | + char next = inkey(); | |
3484 | 2657 | if (pos + 1 < len) |
3485 | 2658 | { |
3486 | 2659 | buf[pos++] = c; |
@@ -3508,18 +2681,14 @@ bool askfor_aux(char *buf, int len, bool numpad_cursor) | ||
3508 | 2681 | } |
3509 | 2682 | } |
3510 | 2683 | |
3511 | - /* Terminate */ | |
3512 | 2684 | buf[pos] = '\0'; |
3513 | - | |
3514 | - /* Write back the left part of string */ | |
3515 | 2685 | my_strcat(buf, tmp, len + 1); |
3516 | 2686 | |
3517 | 2687 | break; |
3518 | - } /* default: */ | |
3519 | - | |
2688 | + } | |
3520 | 2689 | } |
3521 | 2690 | |
3522 | - } /* while (TRUE) */ | |
2691 | + } | |
3523 | 2692 | } |
3524 | 2693 | |
3525 | 2694 |
@@ -3548,14 +2717,8 @@ bool get_string(concptr prompt, char *buf, int len) | ||
3548 | 2717 | { |
3549 | 2718 | bool res; |
3550 | 2719 | msg_print(NULL); |
3551 | - | |
3552 | - /* Display prompt */ | |
3553 | 2720 | prt(prompt, 0, 0); |
3554 | - | |
3555 | - /* Ask the user for a string */ | |
3556 | 2721 | res = askfor(buf, len); |
3557 | - | |
3558 | - /* Clear prompt */ | |
3559 | 2722 | prt("", 0, 0); |
3560 | 2723 | return (res); |
3561 | 2724 | } |
@@ -3573,6 +2736,7 @@ bool get_check(concptr prompt) | ||
3573 | 2736 | return get_check_strict(prompt, 0); |
3574 | 2737 | } |
3575 | 2738 | |
2739 | + | |
3576 | 2740 | /* |
3577 | 2741 | * Verify something with the user strictly |
3578 | 2742 | * |
@@ -3583,10 +2747,7 @@ bool get_check(concptr prompt) | ||
3583 | 2747 | */ |
3584 | 2748 | bool get_check_strict(concptr prompt, BIT_FLAGS mode) |
3585 | 2749 | { |
3586 | - int i; | |
3587 | 2750 | char buf[80]; |
3588 | - bool flag = FALSE; | |
3589 | - | |
3590 | 2751 | if (auto_more) |
3591 | 2752 | { |
3592 | 2753 | p_ptr->window |= PW_MESSAGE; |
@@ -3595,11 +2756,9 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode) | ||
3595 | 2756 | } |
3596 | 2757 | |
3597 | 2758 | msg_print(NULL); |
3598 | - | |
3599 | 2759 | if (!rogue_like_commands) |
3600 | 2760 | mode &= ~CHECK_OKAY_CANCEL; |
3601 | 2761 | |
3602 | - /* Hack -- Build a "useful" prompt */ | |
3603 | 2762 | if (mode & CHECK_OKAY_CANCEL) |
3604 | 2763 | { |
3605 | 2764 | my_strcpy(buf, prompt, sizeof(buf) - 15); |
@@ -3616,21 +2775,18 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode) | ||
3616 | 2775 | strcat(buf, "[y/n]"); |
3617 | 2776 | } |
3618 | 2777 | |
3619 | - /* Prompt for it */ | |
3620 | 2778 | prt(buf, 0, 0); |
3621 | - | |
3622 | 2779 | if (!(mode & CHECK_NO_HISTORY) && p_ptr->playing) |
3623 | 2780 | { |
3624 | - /* HACK : Add the line to message buffer */ | |
3625 | 2781 | message_add(buf); |
3626 | 2782 | p_ptr->window |= (PW_MESSAGE); |
3627 | 2783 | handle_stuff(p_ptr); |
3628 | 2784 | } |
3629 | 2785 | |
3630 | - /* Get an acceptable answer */ | |
2786 | + bool flag = FALSE; | |
3631 | 2787 | while (TRUE) |
3632 | 2788 | { |
3633 | - i = inkey(); | |
2789 | + int i = inkey(); | |
3634 | 2790 | |
3635 | 2791 | if (!(mode & CHECK_NO_ESCAPE)) |
3636 | 2792 | { |
@@ -3677,10 +2833,7 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode) | ||
3677 | 2833 | bell(); |
3678 | 2834 | } |
3679 | 2835 | |
3680 | - /* Erase the prompt */ | |
3681 | 2836 | prt("", 0, 0); |
3682 | - | |
3683 | - /* Return the flag */ | |
3684 | 2837 | return flag; |
3685 | 2838 | } |
3686 | 2839 |
@@ -3695,24 +2848,16 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode) | ||
3695 | 2848 | bool get_com(concptr prompt, char *command, bool z_escape) |
3696 | 2849 | { |
3697 | 2850 | msg_print(NULL); |
3698 | - | |
3699 | - /* Display a prompt */ | |
3700 | 2851 | prt(prompt, 0, 0); |
3701 | - | |
3702 | - /* Get a key */ | |
3703 | 2852 | if (get_com_no_macros) |
3704 | 2853 | *command = (char)inkey_special(FALSE); |
3705 | 2854 | else |
3706 | 2855 | *command = inkey(); |
3707 | 2856 | |
3708 | - /* Clear the prompt */ | |
3709 | 2857 | prt("", 0, 0); |
3710 | - | |
3711 | - /* Handle "cancel" */ | |
3712 | 2858 | if (*command == ESCAPE) return FALSE; |
3713 | 2859 | if (z_escape && ((*command == 'z') || (*command == 'Z'))) return FALSE; |
3714 | 2860 | |
3715 | - /* Success */ | |
3716 | 2861 | return TRUE; |
3717 | 2862 | } |
3718 | 2863 |
@@ -3724,61 +2869,40 @@ bool get_com(concptr prompt, char *command, bool z_escape) | ||
3724 | 2869 | */ |
3725 | 2870 | QUANTITY get_quantity(concptr prompt, QUANTITY max) |
3726 | 2871 | { |
3727 | - bool res, result; | |
3728 | - QUANTITY amt; | |
2872 | + bool res; | |
3729 | 2873 | char tmp[80]; |
3730 | 2874 | char buf[80]; |
3731 | - COMMAND_CODE code; | |
3732 | 2875 | |
3733 | - | |
3734 | - /* Use "command_arg" */ | |
2876 | + QUANTITY amt; | |
3735 | 2877 | if (command_arg) |
3736 | 2878 | { |
3737 | - /* Extract a number */ | |
3738 | 2879 | amt = command_arg; |
3739 | - | |
3740 | - /* Clear "command_arg" */ | |
3741 | 2880 | command_arg = 0; |
3742 | - | |
3743 | - /* Enforce the maximum */ | |
3744 | 2881 | if (amt > max) amt = max; |
3745 | 2882 | |
3746 | - /* Use it */ | |
3747 | 2883 | return (amt); |
3748 | 2884 | } |
3749 | 2885 | |
3750 | - /* Get the item index */ | |
3751 | - result = repeat_pull(&code); | |
2886 | + COMMAND_CODE code; | |
2887 | + bool result = repeat_pull(&code); | |
3752 | 2888 | amt = (QUANTITY)code; |
3753 | 2889 | if ((max != 1) && result) |
3754 | 2890 | { |
3755 | - /* Enforce the maximum */ | |
3756 | 2891 | if (amt > max) amt = max; |
3757 | - | |
3758 | - /* Enforce the minimum */ | |
3759 | 2892 | if (amt < 0) amt = 0; |
3760 | 2893 | |
3761 | - /* Use it */ | |
3762 | 2894 | return (amt); |
3763 | 2895 | } |
3764 | 2896 | |
3765 | - /* Build a prompt if needed */ | |
3766 | 2897 | if (!prompt) |
3767 | 2898 | { |
3768 | 2899 | sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max); |
3769 | - | |
3770 | - /* Use that prompt */ | |
3771 | 2900 | prompt = tmp; |
3772 | 2901 | } |
3773 | - msg_print(NULL); | |
3774 | 2902 | |
3775 | - /* Display prompt */ | |
2903 | + msg_print(NULL); | |
3776 | 2904 | prt(prompt, 0, 0); |
3777 | - | |
3778 | - /* Default to one */ | |
3779 | 2905 | amt = 1; |
3780 | - | |
3781 | - /* Build the default */ | |
3782 | 2906 | sprintf(buf, "%d", amt); |
3783 | 2907 | |
3784 | 2908 | /* |
@@ -3787,27 +2911,15 @@ QUANTITY get_quantity(concptr prompt, QUANTITY max) | ||
3787 | 2911 | */ |
3788 | 2912 | res = askfor_aux(buf, 6, FALSE); |
3789 | 2913 | |
3790 | - /* Clear prompt */ | |
3791 | 2914 | prt("", 0, 0); |
3792 | - | |
3793 | - /* Cancelled */ | |
3794 | 2915 | if (!res) return 0; |
3795 | 2916 | |
3796 | - /* Extract a number */ | |
3797 | 2917 | amt = (COMMAND_CODE)atoi(buf); |
3798 | - | |
3799 | - /* A letter means "all" */ | |
3800 | 2918 | if (isalpha(buf[0])) amt = max; |
3801 | - | |
3802 | - /* Enforce the maximum */ | |
3803 | 2919 | if (amt > max) amt = max; |
3804 | - | |
3805 | - /* Enforce the minimum */ | |
3806 | 2920 | if (amt < 0) amt = 0; |
3807 | - | |
3808 | 2921 | if (amt) repeat_push((COMMAND_CODE)amt); |
3809 | 2922 | |
3810 | - /* Return the result */ | |
3811 | 2923 | return (amt); |
3812 | 2924 | } |
3813 | 2925 |
@@ -3824,14 +2936,11 @@ void pause_line(int row) | ||
3824 | 2936 | prt("", row, 0); |
3825 | 2937 | } |
3826 | 2938 | |
3827 | - | |
3828 | 2939 | /* |
3829 | 2940 | * Hack -- special buffer to hold the action of the current keymap |
3830 | 2941 | */ |
3831 | 2942 | static char request_command_buffer[256]; |
3832 | 2943 | |
3833 | - | |
3834 | - | |
3835 | 2944 | typedef struct |
3836 | 2945 | { |
3837 | 2946 | concptr name; |
@@ -4165,9 +3274,7 @@ static char inkey_from_menu(player_type *player_ptr) | ||
4165 | 3274 | else basey = 13; |
4166 | 3275 | basex = 15; |
4167 | 3276 | |
4168 | - /* Clear top line */ | |
4169 | 3277 | prt("", 0, 0); |
4170 | - | |
4171 | 3278 | screen_save(); |
4172 | 3279 | |
4173 | 3280 | floor_type* floor_ptr = player_ptr->current_floor_ptr; |
@@ -4209,15 +3316,15 @@ static char inkey_from_menu(player_type *player_ptr) | ||
4209 | 3316 | break; |
4210 | 3317 | } |
4211 | 3318 | } |
3319 | + | |
4212 | 3320 | put_str(menu_name, basey + 1 + i / 2, basex + 4 + (i % 2) * 24); |
4213 | 3321 | } |
3322 | + | |
4214 | 3323 | max_num = i; |
4215 | 3324 | kisuu = max_num % 2; |
4216 | 3325 | put_str(_("》", "> "), basey + 1 + num / 2, basex + 2 + (num % 2) * 24); |
4217 | 3326 | |
4218 | - /* Place the cursor on the player */ | |
4219 | 3327 | move_cursor_relative(player_ptr->y, player_ptr->x); |
4220 | - | |
4221 | 3328 | sub_cmd = inkey(); |
4222 | 3329 | if ((sub_cmd == ' ') || (sub_cmd == 'x') || (sub_cmd == 'X') || (sub_cmd == '\r') || (sub_cmd == '\n')) |
4223 | 3330 | { |
@@ -4293,6 +3400,7 @@ static char inkey_from_menu(player_type *player_ptr) | ||
4293 | 3400 | return (cmd); |
4294 | 3401 | } |
4295 | 3402 | |
3403 | + | |
4296 | 3404 | /* |
4297 | 3405 | * Request a command from the user. |
4298 | 3406 | * |
@@ -4314,8 +3422,6 @@ static char inkey_from_menu(player_type *player_ptr) | ||
4314 | 3422 | */ |
4315 | 3423 | void request_command(player_type *player_ptr, int shopping) |
4316 | 3424 | { |
4317 | - int i; | |
4318 | - | |
4319 | 3425 | s16b cmd; |
4320 | 3426 | int mode; |
4321 | 3427 |
@@ -4324,231 +3430,142 @@ void request_command(player_type *player_ptr, int shopping) | ||
4324 | 3430 | #ifdef JP |
4325 | 3431 | int caretcmd = 0; |
4326 | 3432 | #endif |
4327 | - /* Roguelike */ | |
4328 | 3433 | if (rogue_like_commands) |
4329 | 3434 | { |
4330 | 3435 | mode = KEYMAP_MODE_ROGUE; |
4331 | 3436 | } |
4332 | - | |
4333 | - /* Original */ | |
4334 | 3437 | else |
4335 | 3438 | { |
4336 | 3439 | mode = KEYMAP_MODE_ORIG; |
4337 | 3440 | } |
4338 | 3441 | |
4339 | - | |
4340 | - /* No command yet */ | |
4341 | 3442 | command_cmd = 0; |
4342 | - | |
4343 | - /* No "argument" yet */ | |
4344 | 3443 | command_arg = 0; |
4345 | - | |
4346 | - /* No "direction" yet */ | |
4347 | 3444 | command_dir = 0; |
4348 | - | |
4349 | 3445 | use_menu = FALSE; |
4350 | 3446 | |
4351 | - | |
4352 | - /* Get command */ | |
4353 | 3447 | while (TRUE) |
4354 | 3448 | { |
4355 | - /* Hack -- auto-commands */ | |
4356 | 3449 | if (command_new) |
4357 | 3450 | { |
4358 | 3451 | msg_erase(); |
4359 | - | |
4360 | - /* Use auto-command */ | |
4361 | 3452 | cmd = command_new; |
4362 | - | |
4363 | - /* Forget it */ | |
4364 | 3453 | command_new = 0; |
4365 | 3454 | } |
4366 | - | |
4367 | - /* Get a keypress in "command" mode */ | |
4368 | 3455 | else |
4369 | 3456 | { |
4370 | - /* Hack -- no flush needed */ | |
4371 | 3457 | msg_flag = FALSE; |
4372 | 3458 | num_more = 0; |
4373 | - | |
4374 | - /* Activate "command mode" */ | |
4375 | 3459 | inkey_flag = TRUE; |
4376 | - | |
4377 | 3460 | cmd = inkey(); |
4378 | - | |
4379 | 3461 | if (!shopping && command_menu && ((cmd == '\r') || (cmd == '\n') || (cmd == 'x') || (cmd == 'X')) |
4380 | 3462 | && !keymap_act[mode][(byte)(cmd)]) |
4381 | 3463 | cmd = inkey_from_menu(player_ptr); |
4382 | 3464 | } |
4383 | 3465 | |
4384 | - /* Clear top line */ | |
4385 | 3466 | prt("", 0, 0); |
4386 | - | |
4387 | - | |
4388 | - /* Command Count */ | |
4389 | 3467 | if (cmd == '0') |
4390 | 3468 | { |
4391 | 3469 | COMMAND_ARG old_arg = command_arg; |
4392 | - | |
4393 | - /* Reset */ | |
4394 | 3470 | command_arg = 0; |
4395 | - | |
4396 | - /* Begin the input */ | |
4397 | 3471 | prt(_("回数: ", "Count: "), 0, 0); |
4398 | - | |
4399 | - /* Get a command count */ | |
4400 | 3472 | while (TRUE) |
4401 | 3473 | { |
4402 | - /* Get a new keypress */ | |
4403 | 3474 | cmd = inkey(); |
4404 | - | |
4405 | - /* Simple editing (delete or backspace) */ | |
4406 | 3475 | if ((cmd == 0x7F) || (cmd == KTRL('H'))) |
4407 | 3476 | { |
4408 | - /* Delete a digit */ | |
4409 | 3477 | command_arg = command_arg / 10; |
4410 | - | |
4411 | - /* Show current count */ | |
4412 | 3478 | prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0); |
4413 | 3479 | } |
4414 | - | |
4415 | - /* Actual numeric data */ | |
4416 | 3480 | else if (cmd >= '0' && cmd <= '9') |
4417 | 3481 | { |
4418 | - /* Stop count at 9999 */ | |
4419 | 3482 | if (command_arg >= 1000) |
4420 | 3483 | { |
4421 | - /* Warn */ | |
4422 | 3484 | bell(); |
4423 | - | |
4424 | - /* Limit */ | |
4425 | 3485 | command_arg = 9999; |
4426 | 3486 | } |
4427 | - | |
4428 | - /* Increase count */ | |
4429 | 3487 | else |
4430 | 3488 | { |
4431 | - /* Incorporate that digit */ | |
4432 | 3489 | command_arg = command_arg * 10 + D2I(cmd); |
4433 | 3490 | } |
4434 | 3491 | |
4435 | - /* Show current count */ | |
4436 | 3492 | prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0); |
4437 | 3493 | } |
4438 | - | |
4439 | - /* Exit on "unusable" input */ | |
4440 | 3494 | else |
4441 | 3495 | { |
4442 | 3496 | break; |
4443 | 3497 | } |
4444 | 3498 | } |
4445 | 3499 | |
4446 | - /* Hack -- Handle "zero" */ | |
4447 | 3500 | if (command_arg == 0) |
4448 | 3501 | { |
4449 | - /* Default to 99 */ | |
4450 | 3502 | command_arg = 99; |
4451 | - | |
4452 | - /* Show current count */ | |
4453 | 3503 | prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0); |
4454 | 3504 | } |
4455 | 3505 | |
4456 | - /* Hack -- Handle "old_arg" */ | |
4457 | 3506 | if (old_arg != 0) |
4458 | 3507 | { |
4459 | - /* Restore old_arg */ | |
4460 | 3508 | command_arg = old_arg; |
4461 | - | |
4462 | - /* Show current count */ | |
4463 | 3509 | prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0); |
4464 | 3510 | } |
4465 | 3511 | |
4466 | - /* Hack -- white-space means "enter command now" */ | |
4467 | 3512 | if ((cmd == ' ') || (cmd == '\n') || (cmd == '\r')) |
4468 | 3513 | { |
4469 | - /* Get a real command */ | |
4470 | 3514 | if (!get_com(_("コマンド: ", "Command: "), (char *)&cmd, FALSE)) |
4471 | 3515 | { |
4472 | - /* Clear count */ | |
4473 | 3516 | command_arg = 0; |
4474 | 3517 | continue; |
4475 | 3518 | } |
4476 | 3519 | } |
4477 | 3520 | } |
4478 | 3521 | |
4479 | - | |
4480 | - /* Allow "keymaps" to be bypassed */ | |
4481 | 3522 | if (cmd == '\\') |
4482 | 3523 | { |
4483 | - /* Get a real command */ | |
4484 | 3524 | (void)get_com(_("コマンド: ", "Command: "), (char *)&cmd, FALSE); |
4485 | - | |
4486 | - /* Hack -- bypass keymaps */ | |
4487 | 3525 | if (!inkey_next) inkey_next = ""; |
4488 | 3526 | } |
4489 | 3527 | |
4490 | - | |
4491 | - /* Allow "control chars" to be entered */ | |
4492 | 3528 | if (cmd == '^') |
4493 | 3529 | { |
4494 | - /* Get a new command and controlify it */ | |
4495 | 3530 | if (get_com(_("CTRL: ", "Control: "), (char *)&cmd, FALSE)) cmd = KTRL(cmd); |
4496 | 3531 | } |
4497 | 3532 | |
4498 | - | |
4499 | - /* Look up applicable keymap */ | |
4500 | 3533 | act = keymap_act[mode][(byte)(cmd)]; |
4501 | - | |
4502 | - /* Apply keymap if not inside a keymap already */ | |
4503 | 3534 | if (act && !inkey_next) |
4504 | 3535 | { |
4505 | - /* Install the keymap (limited buffer size) */ | |
4506 | 3536 | (void)strnfmt(request_command_buffer, 256, "%s", act); |
4507 | - | |
4508 | - /* Start using the buffer */ | |
4509 | 3537 | inkey_next = request_command_buffer; |
4510 | 3538 | continue; |
4511 | 3539 | } |
4512 | 3540 | |
4513 | 3541 | if (!cmd) continue; |
4514 | 3542 | |
4515 | - | |
4516 | - /* Use command */ | |
4517 | 3543 | command_cmd = (byte)cmd; |
4518 | - | |
4519 | 3544 | break; |
4520 | 3545 | } |
4521 | 3546 | |
4522 | - /* Hack -- Auto-repeat certain commands */ | |
4523 | 3547 | if (always_repeat && (command_arg <= 0)) |
4524 | 3548 | { |
4525 | - /* Hack -- auto repeat certain commands */ | |
4526 | 3549 | if (my_strchr("TBDoc+", (char)command_cmd)) |
4527 | 3550 | { |
4528 | - /* Repeat 99 times */ | |
4529 | 3551 | command_arg = 99; |
4530 | 3552 | } |
4531 | 3553 | } |
4532 | 3554 | |
4533 | - /* Shopping */ | |
4534 | 3555 | if (shopping == 1) |
4535 | 3556 | { |
4536 | - /* Convert */ | |
4537 | 3557 | switch (command_cmd) |
4538 | 3558 | { |
4539 | - /* Command "p" -> "purchase" (get) */ | |
4540 | 3559 | case 'p': command_cmd = 'g'; break; |
4541 | 3560 | |
4542 | - /* Command "m" -> "purchase" (get) */ | |
4543 | 3561 | case 'm': command_cmd = 'g'; break; |
4544 | 3562 | |
4545 | - /* Command "s" -> "sell" (drop) */ | |
4546 | 3563 | case 's': command_cmd = 'd'; break; |
4547 | 3564 | } |
4548 | 3565 | } |
4549 | 3566 | |
4550 | 3567 | #ifdef JP |
4551 | - for (i = 0; i < 256; i++) | |
3568 | + for (int i = 0; i < 256; i++) | |
4552 | 3569 | { |
4553 | 3570 | concptr s; |
4554 | 3571 | if ((s = keymap_act[mode][i]) != NULL) |
@@ -4560,58 +3577,42 @@ void request_command(player_type *player_ptr, int shopping) | ||
4560 | 3577 | } |
4561 | 3578 | } |
4562 | 3579 | } |
3580 | + | |
4563 | 3581 | if (!caretcmd) |
4564 | 3582 | caretcmd = command_cmd; |
4565 | 3583 | #endif |
4566 | 3584 | |
4567 | - /* Hack -- Scan equipment */ | |
4568 | - for (i = INVEN_RARM; i < INVEN_TOTAL; i++) | |
3585 | + for (int i = INVEN_RARM; i < INVEN_TOTAL; i++) | |
4569 | 3586 | { |
4570 | - concptr s; | |
4571 | - | |
4572 | 3587 | object_type *o_ptr = &player_ptr->inventory_list[i]; |
4573 | 3588 | if (!o_ptr->k_idx) continue; |
4574 | 3589 | |
4575 | - /* No inscription */ | |
4576 | 3590 | if (!o_ptr->inscription) continue; |
4577 | 3591 | |
4578 | - /* Obtain the inscription */ | |
4579 | - s = quark_str(o_ptr->inscription); | |
4580 | - | |
4581 | - /* Find a '^' */ | |
3592 | + concptr s = quark_str(o_ptr->inscription); | |
4582 | 3593 | s = my_strchr(s, '^'); |
4583 | - | |
4584 | - /* Process preventions */ | |
4585 | 3594 | while (s) |
4586 | 3595 | { |
4587 | - /* Check the "restriction" character */ | |
4588 | 3596 | #ifdef JP |
4589 | 3597 | if ((s[1] == caretcmd) || (s[1] == '*')) |
4590 | 3598 | #else |
4591 | 3599 | if ((s[1] == command_cmd) || (s[1] == '*')) |
4592 | 3600 | #endif |
4593 | - | |
4594 | 3601 | { |
4595 | - /* Hack -- Verify command */ | |
4596 | 3602 | if (!get_check(_("本当ですか? ", "Are you sure? "))) |
4597 | 3603 | { |
4598 | - /* Hack -- Use space */ | |
4599 | 3604 | command_cmd = ' '; |
4600 | 3605 | } |
4601 | 3606 | } |
4602 | 3607 | |
4603 | - /* Find another '^' */ | |
4604 | 3608 | s = my_strchr(s + 1, '^'); |
4605 | 3609 | } |
4606 | 3610 | } |
4607 | 3611 | |
4608 | - | |
4609 | - /* Hack -- erase the message line. */ | |
4610 | 3612 | prt("", 0, 0); |
4611 | 3613 | } |
4612 | 3614 | |
4613 | 3615 | |
4614 | - | |
4615 | 3616 | /* |
4616 | 3617 | * Check a char for "vowel-hood" |
4617 | 3618 | */ |
@@ -4648,7 +3649,6 @@ int get_keymap_dir(char ch) | ||
4648 | 3649 | { |
4649 | 3650 | int d = 0; |
4650 | 3651 | |
4651 | - /* Already a direction? */ | |
4652 | 3652 | if (isdigit(ch)) |
4653 | 3653 | { |
4654 | 3654 | d = D2I(ch); |
@@ -4656,37 +3656,27 @@ int get_keymap_dir(char ch) | ||
4656 | 3656 | else |
4657 | 3657 | { |
4658 | 3658 | BIT_FLAGS mode; |
4659 | - concptr act, s; | |
4660 | - | |
4661 | - /* Roguelike */ | |
4662 | 3659 | if (rogue_like_commands) |
4663 | 3660 | { |
4664 | 3661 | mode = KEYMAP_MODE_ROGUE; |
4665 | 3662 | } |
4666 | - | |
4667 | - /* Original */ | |
4668 | 3663 | else |
4669 | 3664 | { |
4670 | 3665 | mode = KEYMAP_MODE_ORIG; |
4671 | 3666 | } |
4672 | 3667 | |
4673 | - /* Extract the action (if any) */ | |
4674 | - act = keymap_act[mode][(byte)(ch)]; | |
4675 | - | |
4676 | - /* Analyze */ | |
3668 | + concptr act = keymap_act[mode][(byte)(ch)]; | |
4677 | 3669 | if (act) |
4678 | 3670 | { |
4679 | - /* Convert to a direction */ | |
4680 | - for (s = act; *s; ++s) | |
3671 | + for (concptr s = act; *s; ++s) | |
4681 | 3672 | { |
4682 | - /* Use any digits in keymap */ | |
4683 | 3673 | if (isdigit(*s)) d = D2I(*s); |
4684 | 3674 | } |
4685 | 3675 | } |
4686 | 3676 | } |
3677 | + | |
4687 | 3678 | if (d == 5) d = 0; |
4688 | 3679 | |
4689 | - /* Return direction */ | |
4690 | 3680 | return (d); |
4691 | 3681 | } |
4692 | 3682 |
@@ -4702,66 +3692,44 @@ static int repeat__idx = 0; | ||
4702 | 3692 | /* Saved "stuff" */ |
4703 | 3693 | static COMMAND_CODE repeat__key[REPEAT_MAX]; |
4704 | 3694 | |
4705 | - | |
4706 | 3695 | void repeat_push(COMMAND_CODE what) |
4707 | 3696 | { |
4708 | - /* Too many keys */ | |
4709 | 3697 | if (repeat__cnt == REPEAT_MAX) return; |
4710 | 3698 | |
4711 | - /* Push the "stuff" */ | |
4712 | 3699 | repeat__key[repeat__cnt++] = what; |
4713 | - | |
4714 | - /* Prevents us from pulling keys */ | |
4715 | 3700 | ++repeat__idx; |
4716 | 3701 | } |
4717 | 3702 | |
4718 | 3703 | |
4719 | 3704 | bool repeat_pull(COMMAND_CODE *what) |
4720 | 3705 | { |
4721 | - /* All out of keys */ | |
4722 | 3706 | if (repeat__idx == repeat__cnt) return FALSE; |
4723 | 3707 | |
4724 | - /* Grab the next key, advance */ | |
4725 | 3708 | *what = repeat__key[repeat__idx++]; |
4726 | - | |
4727 | - /* Success */ | |
4728 | 3709 | return TRUE; |
4729 | 3710 | } |
4730 | 3711 | |
4731 | 3712 | void repeat_check(void) |
4732 | 3713 | { |
4733 | - COMMAND_CODE what; | |
4734 | - | |
4735 | - /* Ignore some commands */ | |
4736 | 3714 | if (command_cmd == ESCAPE) return; |
4737 | 3715 | if (command_cmd == ' ') return; |
4738 | 3716 | if (command_cmd == '\r') return; |
4739 | 3717 | if (command_cmd == '\n') return; |
4740 | 3718 | |
4741 | - /* Repeat Last Command */ | |
3719 | + COMMAND_CODE what; | |
4742 | 3720 | if (command_cmd == 'n') |
4743 | 3721 | { |
4744 | - /* Reset */ | |
4745 | 3722 | repeat__idx = 0; |
4746 | - | |
4747 | - /* Get the command */ | |
4748 | 3723 | if (repeat_pull(&what)) |
4749 | 3724 | { |
4750 | - /* Save the command */ | |
4751 | 3725 | command_cmd = what; |
4752 | 3726 | } |
4753 | 3727 | } |
4754 | - | |
4755 | - /* Start saving new command */ | |
4756 | 3728 | else |
4757 | 3729 | { |
4758 | - /* Reset */ | |
4759 | 3730 | repeat__cnt = 0; |
4760 | 3731 | repeat__idx = 0; |
4761 | - | |
4762 | 3732 | what = command_cmd; |
4763 | - | |
4764 | - /* Save this command */ | |
4765 | 3733 | repeat_push(what); |
4766 | 3734 | } |
4767 | 3735 | } |
@@ -4795,14 +3763,12 @@ static void swap(tag_type *a, tag_type *b) | ||
4795 | 3763 | */ |
4796 | 3764 | static void InsertionSort(tag_type elements[], int number) |
4797 | 3765 | { |
4798 | - int j, P; | |
4799 | - | |
4800 | 3766 | tag_type tmp; |
4801 | - | |
4802 | - for (P = 1; P < number; P++) | |
3767 | + for (int i = 1; i < number; i++) | |
4803 | 3768 | { |
4804 | - tmp = elements[P]; | |
4805 | - for (j = P; (j > 0) && (elements[j - 1].tag > tmp.tag); j--) | |
3769 | + tmp = elements[i]; | |
3770 | + int j; | |
3771 | + for (j = i; (j > 0) && (elements[j - 1].tag > tmp.tag); j--) | |
4806 | 3772 | elements[j] = elements[j - 1]; |
4807 | 3773 | elements[j] = tmp; |
4808 | 3774 | } |
@@ -4842,14 +3808,13 @@ static tag_type median3(tag_type elements[], int left, int right) | ||
4842 | 3808 | */ |
4843 | 3809 | static void quicksort(tag_type elements[], int left, int right) |
4844 | 3810 | { |
4845 | - int i, j; | |
4846 | 3811 | tag_type pivot; |
4847 | - | |
4848 | 3812 | if (left + CUTOFF <= right) |
4849 | 3813 | { |
4850 | 3814 | pivot = median3(elements, left, right); |
4851 | 3815 | |
4852 | - i = left; j = right - 1; | |
3816 | + int i = left; | |
3817 | + int j = right - 1; | |
4853 | 3818 | |
4854 | 3819 | while (TRUE) |
4855 | 3820 | { |
@@ -4862,7 +3827,6 @@ static void quicksort(tag_type elements[], int left, int right) | ||
4862 | 3827 | break; |
4863 | 3828 | } |
4864 | 3829 | |
4865 | - /* Restore pivot */ | |
4866 | 3830 | swap(&elements[i], &elements[right - 1]); |
4867 | 3831 | |
4868 | 3832 | quicksort(elements, left, i - 1); |
@@ -4870,7 +3834,6 @@ static void quicksort(tag_type elements[], int left, int right) | ||
4870 | 3834 | } |
4871 | 3835 | else |
4872 | 3836 | { |
4873 | - /* Use InsertionSort on small arrays */ | |
4874 | 3837 | InsertionSort(elements + left, right - left + 1); |
4875 | 3838 | } |
4876 | 3839 | } |
@@ -4919,29 +3882,18 @@ static s16b gamma_helper[256] = | ||
4919 | 3882 | */ |
4920 | 3883 | void build_gamma_table(int gamma) |
4921 | 3884 | { |
4922 | - int i, n; | |
4923 | - | |
4924 | - /* | |
4925 | - * value is the current sum. | |
4926 | - * diff is the new term to add to the series. | |
4927 | - */ | |
4928 | - long value, diff; | |
4929 | - | |
4930 | - /* Hack - convergence is bad in these cases. */ | |
4931 | 3885 | gamma_table[0] = 0; |
4932 | 3886 | gamma_table[255] = 255; |
4933 | - | |
4934 | - for (i = 1; i < 255; i++) | |
3887 | + for (int i = 1; i < 255; i++) | |
4935 | 3888 | { |
4936 | 3889 | /* |
4937 | 3890 | * Initialise the Taylor series |
4938 | 3891 | * |
4939 | 3892 | * value and diff have been scaled by 256 |
4940 | 3893 | */ |
4941 | - | |
4942 | - n = 1; | |
4943 | - value = 256 * 256; | |
4944 | - diff = ((long)gamma_helper[i]) * (gamma - 256); | |
3894 | + int n = 1; | |
3895 | + long value = 256 * 256; | |
3896 | + long diff = ((long)gamma_helper[i]) * (gamma - 256); | |
4945 | 3897 | |
4946 | 3898 | while (diff) |
4947 | 3899 | { |
@@ -4994,38 +3946,24 @@ void build_gamma_table(int gamma) | ||
4994 | 3946 | errr type_string(concptr str, uint len) |
4995 | 3947 | { |
4996 | 3948 | errr err = 0; |
4997 | - concptr s; | |
4998 | - | |
4999 | 3949 | term *old = Term; |
5000 | - | |
5001 | - /* Paranoia - no string. */ | |
5002 | 3950 | if (!str) return -1; |
5003 | - | |
5004 | - /* Hack - calculate the string length here if none given. */ | |
5005 | 3951 | if (!len) len = strlen(str); |
5006 | 3952 | |
5007 | - /* Activate the main window, as all pastes go there. */ | |
5008 | 3953 | Term_activate(term_screen); |
5009 | - | |
5010 | - for (s = str; s < str + len; s++) | |
3954 | + for (concptr s = str; s < str + len; s++) | |
5011 | 3955 | { |
5012 | - /* Catch end of string */ | |
5013 | 3956 | if (*s == '\0') break; |
5014 | 3957 | |
5015 | 3958 | err = Term_keypress(*s); |
5016 | - | |
5017 | - /* Catch errors */ | |
5018 | 3959 | if (err) break; |
5019 | 3960 | } |
5020 | 3961 | |
5021 | - /* Activate the original window. */ | |
5022 | 3962 | Term_activate(old); |
5023 | - | |
5024 | 3963 | return err; |
5025 | 3964 | } |
5026 | 3965 | |
5027 | 3966 | |
5028 | - | |
5029 | 3967 | void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize) |
5030 | 3968 | { |
5031 | 3969 | int read_pt = 0; |
@@ -5042,8 +3980,6 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize) | ||
5042 | 3980 | bool kanji; |
5043 | 3981 | #endif |
5044 | 3982 | int ch_len = 1; |
5045 | - | |
5046 | - /* Prepare one character */ | |
5047 | 3983 | ch[0] = str[read_pt]; |
5048 | 3984 | ch[1] = '\0'; |
5049 | 3985 | #ifdef JP |
@@ -5069,11 +4005,7 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize) | ||
5069 | 4005 | |
5070 | 4006 | if (line_len + ch_len > maxlen - 1 || str[read_pt] == '\n') |
5071 | 4007 | { |
5072 | - int word_len; | |
5073 | - | |
5074 | - /* return to better wrapping point. */ | |
5075 | - /* Space character at the end of the line need not to be printed. */ | |
5076 | - word_len = read_pt - word_punct; | |
4008 | + int word_len = read_pt - word_punct; | |
5077 | 4009 | #ifdef JP |
5078 | 4010 | if (kanji && !kinsoku) |
5079 | 4011 | /* nothing */; |
@@ -5094,13 +4026,14 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize) | ||
5094 | 4026 | word_punct = read_pt; |
5095 | 4027 | continue; |
5096 | 4028 | } |
4029 | + | |
5097 | 4030 | if (ch[0] == ' ') |
5098 | 4031 | word_punct = read_pt; |
4032 | + | |
5099 | 4033 | #ifdef JP |
5100 | 4034 | if (!kinsoku) word_punct = read_pt; |
5101 | 4035 | #endif |
5102 | 4036 | |
5103 | - /* Not enough buffer size */ | |
5104 | 4037 | if ((size_t)(write_pt + 3) >= bufsize) break; |
5105 | 4038 | |
5106 | 4039 | tbuf[write_pt++] = ch[0]; |
@@ -5115,9 +4048,9 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize) | ||
5115 | 4048 | } |
5116 | 4049 | #endif |
5117 | 4050 | } |
4051 | + | |
5118 | 4052 | tbuf[write_pt] = '\0'; |
5119 | 4053 | tbuf[write_pt + 1] = '\0'; |
5120 | - | |
5121 | 4054 | return; |
5122 | 4055 | } |
5123 | 4056 |
@@ -5135,7 +4068,6 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize) | ||
5135 | 4068 | size_t my_strcpy(char *buf, concptr src, size_t bufsize) |
5136 | 4069 | { |
5137 | 4070 | #ifdef JP |
5138 | - | |
5139 | 4071 | char *d = buf; |
5140 | 4072 | concptr s = src; |
5141 | 4073 | size_t len = 0; |
@@ -5164,25 +4096,18 @@ size_t my_strcpy(char *buf, concptr src, size_t bufsize) | ||
5164 | 4096 | } |
5165 | 4097 | |
5166 | 4098 | while (*s++) len++; |
5167 | - | |
5168 | 4099 | return len; |
5169 | 4100 | |
5170 | 4101 | #else |
5171 | - | |
5172 | 4102 | size_t len = strlen(src); |
5173 | 4103 | size_t ret = len; |
5174 | 4104 | if (bufsize == 0) return ret; |
5175 | 4105 | |
5176 | - /* Truncate */ | |
5177 | 4106 | if (len >= bufsize) len = bufsize - 1; |
5178 | 4107 | |
5179 | - /* Copy the string and terminate it */ | |
5180 | 4108 | (void)memcpy(buf, src, len); |
5181 | 4109 | buf[len] = '\0'; |
5182 | - | |
5183 | - /* Return strlen(src) */ | |
5184 | 4110 | return ret; |
5185 | - | |
5186 | 4111 | #endif |
5187 | 4112 | } |
5188 | 4113 |
@@ -5201,16 +4126,12 @@ size_t my_strcpy(char *buf, concptr src, size_t bufsize) | ||
5201 | 4126 | size_t my_strcat(char *buf, concptr src, size_t bufsize) |
5202 | 4127 | { |
5203 | 4128 | size_t dlen = strlen(buf); |
5204 | - | |
5205 | - /* Is there room left in the buffer? */ | |
5206 | 4129 | if (dlen < bufsize - 1) |
5207 | 4130 | { |
5208 | - /* Append as much as possible */ | |
5209 | 4131 | return (dlen + my_strcpy(buf + dlen, src, bufsize - dlen)); |
5210 | 4132 | } |
5211 | 4133 | else |
5212 | 4134 | { |
5213 | - /* Return without appending */ | |
5214 | 4135 | return (dlen + strlen(src)); |
5215 | 4136 | } |
5216 | 4137 | } |
@@ -5223,13 +4144,12 @@ size_t my_strcat(char *buf, concptr src, size_t bufsize) | ||
5223 | 4144 | */ |
5224 | 4145 | char *my_strstr(concptr haystack, concptr needle) |
5225 | 4146 | { |
5226 | - int i; | |
5227 | 4147 | int l1 = strlen(haystack); |
5228 | 4148 | int l2 = strlen(needle); |
5229 | 4149 | |
5230 | 4150 | if (l1 >= l2) |
5231 | 4151 | { |
5232 | - for (i = 0; i <= l1 - l2; i++) | |
4152 | + for (int i = 0; i <= l1 - l2; i++) | |
5233 | 4153 | { |
5234 | 4154 | if (!strncmp(haystack + i, needle, l2)) |
5235 | 4155 | return (char *)haystack + i; |
@@ -5269,7 +4189,6 @@ char *my_strchr(concptr ptr, char ch) | ||
5269 | 4189 | */ |
5270 | 4190 | void str_tolower(char *str) |
5271 | 4191 | { |
5272 | - /* Force to be lower case string */ | |
5273 | 4192 | for (; *str; str++) |
5274 | 4193 | { |
5275 | 4194 | #ifdef JP |
@@ -5363,59 +4282,36 @@ int inkey_special(bool numpad_cursor) | ||
5363 | 4282 | */ |
5364 | 4283 | inkey_macro_trigger_string[0] = '\0'; |
5365 | 4284 | |
5366 | - /* Get a keypress */ | |
5367 | 4285 | key = inkey(); |
5368 | - | |
5369 | - /* Examine trigger string */ | |
5370 | 4286 | trig_len = strlen(inkey_macro_trigger_string); |
5371 | - | |
5372 | - /* Already known that no special key */ | |
5373 | 4287 | if (!trig_len) return (int)((unsigned char)key); |
5374 | - | |
5375 | - /* | |
5376 | - * Hack -- Ignore macro defined on ASCII characters. | |
5377 | - */ | |
5378 | 4288 | if (trig_len == 1 && parse_macro) |
5379 | 4289 | { |
5380 | 4290 | char c = inkey_macro_trigger_string[0]; |
5381 | - | |
5382 | - /* Cancel macro action on the queue */ | |
5383 | 4291 | forget_macro_action(); |
5384 | - | |
5385 | - /* Return the originaly pressed key */ | |
5386 | 4292 | return (int)((unsigned char)c); |
5387 | 4293 | } |
5388 | 4294 | |
5389 | - /* Convert the trigger */ | |
5390 | 4295 | ascii_to_text(buf, inkey_macro_trigger_string); |
5391 | - | |
5392 | - /* Check the prefix "\[" */ | |
5393 | 4296 | if (prefix(str, "\\[")) |
5394 | 4297 | { |
5395 | - /* Skip "\[" */ | |
5396 | 4298 | str += 2; |
5397 | - | |
5398 | - /* Examine modifier keys */ | |
5399 | 4299 | while (TRUE) |
5400 | 4300 | { |
5401 | 4301 | for (i = 0; modifier_key_list[i].keyname; i++) |
5402 | 4302 | { |
5403 | 4303 | if (prefix(str, modifier_key_list[i].keyname)) |
5404 | 4304 | { |
5405 | - /* Get modifier key flag */ | |
5406 | 4305 | str += strlen(modifier_key_list[i].keyname); |
5407 | 4306 | modifier |= modifier_key_list[i].keyflag; |
5408 | 4307 | } |
5409 | 4308 | } |
5410 | 4309 | |
5411 | - /* No more modifier key found */ | |
5412 | 4310 | if (!modifier_key_list[i].keyname) break; |
5413 | 4311 | } |
5414 | 4312 | |
5415 | - /* numpad_as_cursorkey option force numpad keys to input numbers */ | |
5416 | 4313 | if (!numpad_as_cursorkey) numpad_cursor = FALSE; |
5417 | 4314 | |
5418 | - /* Get a special key code */ | |
5419 | 4315 | for (i = 0; special_key_list[i].keyname; i++) |
5420 | 4316 | { |
5421 | 4317 | if ((!special_key_list[i].numpad || numpad_cursor) && |
@@ -5426,13 +4322,9 @@ int inkey_special(bool numpad_cursor) | ||
5426 | 4322 | } |
5427 | 4323 | } |
5428 | 4324 | |
5429 | - /* A special key found */ | |
5430 | 4325 | if (skey) |
5431 | 4326 | { |
5432 | - /* Cancel macro action on the queue */ | |
5433 | 4327 | forget_macro_action(); |
5434 | - | |
5435 | - /* Return special key code and modifier flags */ | |
5436 | 4328 | return (skey | modifier); |
5437 | 4329 | } |
5438 | 4330 | } |
@@ -5450,12 +4342,6 @@ int inkey_special(bool numpad_cursor) | ||
5450 | 4342 | } |
5451 | 4343 | } |
5452 | 4344 | |
5453 | - /* No special key found? */ | |
5454 | - | |
5455 | - /* Don't bother with this trigger no more */ | |
5456 | 4345 | inkey_macro_trigger_string[0] = '\0'; |
5457 | - | |
5458 | - /* Return normal keycode */ | |
5459 | 4346 | return (int)((unsigned char)key); |
5460 | 4347 | } |
5461 | - |