• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

変愚蛮怒のメインリポジトリです


Commit MetaInfo

修订版7643737c7ad6cadd9195dcc986b4600ea387b5af (tree)
时间2020-02-01 10:37:17
作者Hourier <hourier@user...>
CommiterHourier

Log Message

[Refactor] #37353 util.c において、1行ごとに挟まれていたコメントを削除 / Removed many comments per 1 line in util.c

更改概述

差异

--- a/src/util.c
+++ b/src/util.c
@@ -139,8 +139,6 @@ s16b command_wrk; /* See "object1.c" */
139139 TERM_LEN command_gap = 999; /* See "object1.c" */
140140 s16b command_new; /* Command chaining from inven/equip view */
141141
142-
143-
144142 #ifdef SET_UID
145143
146144 # ifndef HAVE_USLEEP
@@ -152,42 +150,28 @@ s16b command_new; /* Command chaining from inven/equip view */
152150 */
153151 int usleep(huge usecs)
154152 {
155- struct timeval Timer;
153+ struct timeval timer;
156154
157- int nfds = 0;
155+ int nfds = 0;
158156
159157 #ifdef FD_SET
160158 fd_set *no_fds = NULL;
161159 #else
162160 int *no_fds = NULL;
163161 #endif
164-
165-
166- /* Was: int readfds, writefds, exceptfds; */
167- /* Was: readfds = writefds = exceptfds = 0; */
168-
169-
170- /* Paranoia -- No excessive sleeping */
171162 if (usecs > 4000000L) core(_("不当な usleep() 呼び出し", "Illegal usleep() call"));
172163
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)
179167 {
180- /* Hack -- ignore interrupts */
181168 if (errno != EINTR) return -1;
182169 }
183170
184- /* Success */
185171 return 0;
186172 }
187-
188173 # endif
189174
190-
191175 /*
192176 * Hack -- External functions
193177 */
@@ -196,21 +180,17 @@ extern struct passwd *getpwuid(uid_t uid);
196180 extern struct passwd *getpwnam(concptr name);
197181 #endif
198182
199-
200183 /*
201184 * Find a default user name from the system.
202185 */
203186 void user_name(char *buf, int id)
204187 {
205188 struct passwd *pw;
206-
207- /* Look up the user name */
208189 if ((pw = getpwuid(id)))
209190 {
210191 (void)strcpy(buf, pw->pw_name);
211192 buf[16] = '\0';
212193
213- /* Hack -- capitalize the user name */
214194 #ifdef JP
215195 if (!iskanji(buf[0]))
216196 #endif
@@ -220,15 +200,12 @@ void user_name(char *buf, int id)
220200 return;
221201 }
222202
223- /* Oops. Hack -- default to "PLAYER" */
224203 strcpy(buf, "PLAYER");
225204 }
226205
227206 #endif /* SET_UID */
228207
229208
230-
231-
232209 /*
233210 * The concept of the "file" routines below (and elsewhere) is that all
234211 * file handling should be done using as few routines as possible, since
@@ -257,9 +234,7 @@ void user_name(char *buf, int id)
257234 * We should probably parse a leading "~~/" as referring to "ANGBAND_DIR". (?)
258235 */
259236
260-
261237 #ifdef SET_UID
262-
263238 /*
264239 * Extract a "parsed" path from an initial filename
265240 * Normally, we simply copy the filename into the buffer
@@ -269,34 +244,20 @@ void user_name(char *buf, int id)
269244 */
270245 errr path_parse(char *buf, int max, concptr file)
271246 {
272- concptr u, s;
273- struct passwd *pw;
274- char user[128];
275-
276-
277- /* Assume no result */
278247 buf[0] = '\0';
279-
280- /* No file? */
281248 if (!file) return -1;
282249
283- /* File needs no parsing */
284250 if (file[0] != '~')
285251 {
286252 (void)strnfmt(buf, max, "%s", file);
287253 return 0;
288254 }
289255
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];
297259 if (s && (s >= u + sizeof(user))) return 1;
298260
299- /* Extract a user name */
300261 if (s)
301262 {
302263 int i;
@@ -305,28 +266,20 @@ errr path_parse(char *buf, int max, concptr file)
305266 u = user;
306267 }
307268
308- /* Look up the "current" user */
309269 if (u[0] == '\0') u = getlogin();
310270
311- /* Look up a user (or "current" user) */
271+ struct passwd *pw;
312272 if (u) pw = getpwnam(u);
313273 else pw = getpwuid(getuid());
314274
315- /* Nothing found? */
316275 if (!pw) return 1;
317276
318- /* Make use of the info */
319277 if (s) strnfmt(buf, max, "%s%s", pw->pw_dir, s);
320278 else strnfmt(buf, max, "%s", pw->pw_dir);
321279
322- /* Success */
323280 return 0;
324281 }
325-
326-
327282 #else /* SET_UID */
328-
329-
330283 /*
331284 * Extract a "parsed" path from an initial filename
332285 *
@@ -335,12 +288,9 @@ errr path_parse(char *buf, int max, concptr file)
335288 */
336289 errr path_parse(char *buf, int max, concptr file)
337290 {
338- /* Accept the filename */
339291 (void)strnfmt(buf, max, "%s", file);
340292 return 0;
341293 }
342-
343-
344294 #endif /* SET_UID */
345295
346296
@@ -353,26 +303,20 @@ errr path_parse(char *buf, int max, concptr file)
353303 */
354304 static errr path_temp(char *buf, int max)
355305 {
356- concptr s;
357-
358- /* Temp file */
359- s = tmpnam(NULL);
360-
306+ concptr s = tmpnam(NULL);
361307 if (!s) return -1;
362308
363- /* Format to length */
364309 #if !defined(WIN32) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
365310 (void)strnfmt(buf, max, "%s", s);
366311 #else
367312 (void)strnfmt(buf, max, ".%s", s);
368313 #endif
369314
370- /* Success */
371315 return 0;
372316 }
373-
374317 #endif
375318
319+
376320 /*!
377321 * @brief ファイル入出力のためのパス生成する。/ Create a new path by appending a file (or directory) to a path.
378322 * @param buf ファイルのフルを返すバッファ
@@ -393,35 +337,23 @@ static errr path_temp(char *buf, int max)
393337 */
394338 errr path_build(char *buf, int max, concptr path, concptr file)
395339 {
396- /* Special file */
397340 if (file[0] == '~')
398341 {
399- /* Use the file itself */
400342 (void)strnfmt(buf, max, "%s", file);
401343 }
402-
403- /* Absolute file, on "normal" systems */
404344 else if (prefix(file, PATH_SEP) && !streq(PATH_SEP, ""))
405345 {
406- /* Use the file itself */
407346 (void)strnfmt(buf, max, "%s", file);
408347 }
409-
410- /* No path given */
411348 else if (!path[0])
412349 {
413- /* Use the file itself */
414350 (void)strnfmt(buf, max, "%s", file);
415351 }
416-
417- /* Path and File */
418352 else
419353 {
420- /* Build the new path */
421354 (void)strnfmt(buf, max, "%s%s%s", path, PATH_SEP, file);
422355 }
423356
424- /* Success */
425357 return 0;
426358 }
427359
@@ -431,26 +363,20 @@ errr path_build(char *buf, int max, concptr path, concptr file)
431363 */
432364 FILE *my_fopen(concptr file, concptr mode)
433365 {
434- char buf[1024];
435-
436366 #if defined(MACH_O_CARBON)
437367 FILE *tempfff;
438368 #endif
439-
440- /* Hack -- Try to parse the path */
369+ char buf[1024];
441370 if (path_parse(buf, 1024, file)) return (NULL);
442-
443371 #if defined(MACH_O_CARBON)
444372 if (my_strchr(mode, 'w'))
445373 {
446- /* setting file type/creator */
447374 tempfff = fopen(buf, mode);
448375 fsetfileinfo(buf, _fcreator, _ftype);
449376 fclose(tempfff);
450377 }
451378 #endif
452379
453- /* Attempt to fopen the file anyway */
454380 return (fopen(buf, mode));
455381 }
456382
@@ -460,45 +386,27 @@ FILE *my_fopen(concptr file, concptr mode)
460386 */
461387 errr my_fclose(FILE *fff)
462388 {
463- /* Require a file */
464389 if (!fff) return -1;
465-
466- /* Close, check for error */
467390 if (fclose(fff) == EOF) return 1;
468-
469- /* Success */
470391 return 0;
471392 }
472393
473394
474395 #ifdef HAVE_MKSTEMP
475-
476396 FILE *my_fopen_temp(char *buf, int max)
477397 {
478- int fd;
479-
480- /* Prepare the buffer for mkstemp */
481398 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);
487400 if (fd < 0) return (NULL);
488401
489- /* Return a file stream */
490402 return (fdopen(fd, "w"));
491403 }
492-
493404 #else /* HAVE_MKSTEMP */
494-
495405 FILE *my_fopen_temp(char *buf, int max)
496406 {
497- /* Generate a temporary filename */
498407 if (path_temp(buf, max)) return (NULL);
499408 return (my_fopen(buf, "w"));
500409 }
501-
502410 #endif /* HAVE_MKSTEMP */
503411
504412
@@ -515,14 +423,11 @@ errr my_fgets(FILE *fff, char *buf, huge n)
515423 char *s;
516424 char tmp[1024];
517425
518- /* Read a line */
519426 if (fgets(tmp, 1024, fff))
520427 {
521428 #ifdef JP
522429 guess_convert_to_system_encoding(tmp, sizeof(tmp));
523430 #endif
524-
525- /* Convert weirdness */
526431 for (s = tmp; *s; s++)
527432 {
528433 #if defined(MACH_O_CARBON)
@@ -535,30 +440,19 @@ errr my_fgets(FILE *fff, char *buf, huge n)
535440 if (*s == '\r') *s = '\n';
536441
537442 #endif /* MACH_O_CARBON */
538-
539- /* Handle newline */
540443 if (*s == '\n')
541444 {
542- /* Terminate */
543445 buf[i] = '\0';
544-
545- /* Success */
546446 return 0;
547447 }
548-
549- /* Handle tabs */
550448 else if (*s == '\t')
551449 {
552- /* Hack -- require room */
553450 if (i + 8 >= n) break;
554451
555- /* Append a space */
556452 buf[i++] = ' ';
557-
558- /* Append some more spaces */
559- while (0 != (i % 8)) buf[i++] = ' ';
453+ while (0 != (i % 8))
454+ buf[i++] = ' ';
560455 }
561-
562456 #ifdef JP
563457 else if (iskanji(*s))
564458 {
@@ -566,35 +460,25 @@ errr my_fgets(FILE *fff, char *buf, huge n)
566460 buf[i++] = *s++;
567461 buf[i++] = *s;
568462 }
569-
570- /* 半角かなに対応 */
571463 else if (iskana(*s))
572464 {
465+ /* 半角かなに対応 */
573466 buf[i++] = *s;
574467 if (i >= n) break;
575468 }
576469 #endif
577- /* Handle printables */
578470 else if (isprint((unsigned char)*s))
579471 {
580- /* Copy */
581472 buf[i++] = *s;
582-
583- /* Check length */
584473 if (i >= n) break;
585474 }
586475 }
587- /* No newline character, but terminate */
588- buf[i] = '\0';
589476
590- /* Success */
477+ buf[i] = '\0';
591478 return 0;
592479 }
593480
594- /* Nothing */
595481 buf[0] = '\0';
596-
597- /* Failure */
598482 return 1;
599483 }
600484
@@ -606,13 +490,8 @@ errr my_fgets(FILE *fff, char *buf, huge n)
606490 */
607491 errr my_fputs(FILE *fff, concptr buf, huge n)
608492 {
609- /* XXX XXX */
610493 n = n ? n : 0;
611-
612- /* Dump, ignore errors */
613494 (void)fprintf(fff, "%s\n", buf);
614-
615- /* Success */
616495 return 0;
617496 }
618497
@@ -625,19 +504,15 @@ errr my_fputs(FILE *fff, concptr buf, huge n)
625504 #endif /* O_BINARY */
626505
627506
628- /*
629- * Hack -- attempt to delete a file
630- */
507+/*
508+ * Hack -- attempt to delete a file
509+ */
631510 errr fd_kill(concptr file)
632511 {
633512 char buf[1024];
634-
635- /* Hack -- Try to parse the path */
636513 if (path_parse(buf, 1024, file)) return -1;
637514
638- /* Remove */
639515 (void)remove(buf);
640-
641516 return 0;
642517 }
643518
@@ -649,16 +524,10 @@ errr fd_move(concptr file, concptr what)
649524 {
650525 char buf[1024];
651526 char aux[1024];
652-
653- /* Hack -- Try to parse the path */
654527 if (path_parse(buf, 1024, file)) return -1;
655-
656- /* Hack -- Try to parse the path */
657528 if (path_parse(aux, 1024, what)) return -1;
658529
659- /* Rename */
660530 (void)rename(buf, aux);
661-
662531 return 0;
663532 }
664533
@@ -673,45 +542,39 @@ errr fd_copy(concptr file, concptr what)
673542 int read_num;
674543 int src_fd, dst_fd;
675544
676- /* Hack -- Try to parse the path */
677545 if (path_parse(buf, 1024, file)) return -1;
678-
679- /* Hack -- Try to parse the path */
680546 if (path_parse(aux, 1024, what)) return -1;
681547
682- /* Open source file */
683548 src_fd = fd_open(buf, O_RDONLY);
684549 if (src_fd < 0) return -1;
685550
686- /* Open destination file */
687551 dst_fd = fd_open(aux, O_WRONLY | O_TRUNC | O_CREAT);
688552 if (dst_fd < 0) return -1;
689553
690- /* Copy */
691554 while ((read_num = read(src_fd, buf, 1024)) > 0)
692555 {
693556 int write_num = 0;
694557 while (write_num < read_num)
695558 {
696559 int ret = write(dst_fd, buf + write_num, read_num - write_num);
697- if (ret < 0) {
698- /* Close files */
560+ if (ret < 0)
561+ {
699562 fd_close(src_fd);
700563 fd_close(dst_fd);
701564
702565 return ret;
703566 }
567+
704568 write_num += ret;
705569 }
706570 }
707571
708- /* Close files */
709572 fd_close(src_fd);
710573 fd_close(dst_fd);
711-
712574 return 0;
713575 }
714576
577+
715578 /*
716579 * Hack -- attempt to open a file descriptor (create file)
717580 * This function should fail if the file already exists
@@ -720,25 +583,19 @@ errr fd_copy(concptr file, concptr what)
720583 int fd_make(concptr file, BIT_FLAGS mode)
721584 {
722585 char buf[1024];
723-
724- /* Hack -- Try to parse the path */
725586 if (path_parse(buf, 1024, file)) return -1;
726587
727588 #if defined(MACH_O_CARBON)
728589 {
729590 int fdes;
730- /* Create the file, fail if exists, write-only, binary */
731591 fdes = open(buf, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, mode);
732- /* Set creator and type if the file is successfully opened */
733592 if (fdes >= 0) fsetfileinfo(buf, _fcreator, _ftype);
734- /* Return the descriptor */
735593 return (fdes);
736594 }
595+
737596 #else
738- /* Create the file, fail if exists, write-only, binary */
739597 return (open(buf, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, mode));
740598 #endif
741-
742599 }
743600
744601
@@ -750,11 +607,8 @@ int fd_make(concptr file, BIT_FLAGS mode)
750607 int fd_open(concptr file, int flags)
751608 {
752609 char buf[1024];
753-
754- /* Hack -- Try to parse the path */
755610 if (path_parse(buf, 1024, file)) return -1;
756611
757- /* Attempt to open the file */
758612 return (open(buf, flags | O_BINARY, 0));
759613 }
760614
@@ -766,29 +620,20 @@ int fd_open(concptr file, int flags)
766620 */
767621 errr fd_lock(int fd, int what)
768622 {
769- /* XXX XXX */
770623 what = what ? what : 0;
771-
772- /* Verify the fd */
773624 if (fd < 0) return -1;
774625
775626 #if defined(SET_UID) && defined(LOCK_UN) && defined(LOCK_EX)
776- /* Un-Lock */
777627 if (what == F_UNLCK)
778628 {
779- /* Unlock it, Ignore errors */
780629 (void)flock(fd, LOCK_UN);
781630 }
782-
783- /* Lock */
784631 else
785632 {
786- /* Lock the score file */
787633 if (flock(fd, LOCK_EX) != 0) return 1;
788634 }
789635 #endif
790636
791- /* Success */
792637 return 0;
793638 }
794639
@@ -798,18 +643,11 @@ errr fd_lock(int fd, int what)
798643 */
799644 errr fd_seek(int fd, huge n)
800645 {
801- huge p;
802-
803- /* Verify fd */
804646 if (fd < 0) return -1;
805647
806- /* Seek to the given position */
807- p = lseek(fd, n, SEEK_SET);
808-
809- /* Failure */
648+ huge p = lseek(fd, n, SEEK_SET);
810649 if (p != n) return 1;
811650
812- /* Success */
813651 return 0;
814652 }
815653
@@ -819,18 +657,12 @@ errr fd_seek(int fd, huge n)
819657 */
820658 errr fd_chop(int fd, huge n)
821659 {
822- /* XXX XXX */
823660 n = n ? n : 0;
824-
825- /* Verify the fd */
826661 if (fd < 0) return -1;
827662
828663 #if defined(NeXT)
829- /* Truncate */
830664 ftruncate(fd, n);
831665 #endif
832-
833- /* Success */
834666 return 0;
835667 }
836668
@@ -840,30 +672,19 @@ errr fd_chop(int fd, huge n)
840672 */
841673 errr fd_read(int fd, char *buf, huge n)
842674 {
843- /* Verify the fd */
844675 if (fd < 0) return -1;
845-
846676 #ifndef SET_UID
847-
848- /* Read pieces */
849677 while (n >= 16384)
850678 {
851- /* Read a piece */
852679 if (read(fd, buf, 16384) != 16384) return 1;
853680
854- /* Shorten the task */
855681 buf += 16384;
856-
857- /* Shorten the task */
858682 n -= 16384;
859683 }
860-
861684 #endif
862685
863- /* Read the final piece */
864686 if (read(fd, buf, n) != (int)n) return 1;
865687
866- /* Success */
867688 return 0;
868689 }
869690
@@ -873,30 +694,20 @@ errr fd_read(int fd, char *buf, huge n)
873694 */
874695 errr fd_write(int fd, concptr buf, huge n)
875696 {
876- /* Verify the fd */
877697 if (fd < 0) return -1;
878698
879699 #ifndef SET_UID
880-
881- /* Write pieces */
882700 while (n >= 16384)
883701 {
884- /* Write a piece */
885702 if (write(fd, buf, 16384) != 16384) return 1;
886703
887- /* Shorten the task */
888704 buf += 16384;
889-
890- /* Shorten the task */
891705 n -= 16384;
892706 }
893-
894707 #endif
895708
896- /* Write the final piece */
897709 if (write(fd, buf, n) != (int)n) return 1;
898710
899- /* Success */
900711 return 0;
901712 }
902713
@@ -906,12 +717,9 @@ errr fd_write(int fd, concptr buf, huge n)
906717 */
907718 errr fd_close(int fd)
908719 {
909- /* Verify the fd */
910720 if (fd < 0) return -1;
911721
912- /* Close */
913722 (void)close(fd);
914-
915723 return 0;
916724 }
917725
@@ -971,7 +779,6 @@ void move_cursor(int row, int col)
971779 }
972780
973781
974-
975782 /*
976783 * Convert a decimal to a single digit octal number
977784 */
@@ -980,6 +787,7 @@ static char octify(uint i)
980787 return (hexsym[i % 8]);
981788 }
982789
790+
983791 /*
984792 * Convert a decimal to a single digit hex number
985793 */
@@ -998,6 +806,7 @@ static int deoct(char c)
998806 return 0;
999807 }
1000808
809+
1001810 /*
1002811 * Convert a hexidecimal-digit into a decimal
1003812 */
@@ -1012,14 +821,10 @@ static int dehex(char c)
1012821
1013822 static int my_stricmp(concptr a, concptr b)
1014823 {
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++)
1020825 {
1021- z1 = FORCEUPPER(*s1);
1022- z2 = FORCEUPPER(*s2);
826+ char z1 = FORCEUPPER(*s1);
827+ char z2 = FORCEUPPER(*s2);
1023828 if (z1 < z2) return -1;
1024829 if (z1 > z2) return 1;
1025830 if (!z1) return 0;
@@ -1028,18 +833,15 @@ static int my_stricmp(concptr a, concptr b)
1028833
1029834 static int my_strnicmp(concptr a, concptr b, int n)
1030835 {
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--)
1036837 {
1037- z1 = FORCEUPPER(*s1);
1038- z2 = FORCEUPPER(*s2);
838+ char z1 = FORCEUPPER(*s1);
839+ char z2 = FORCEUPPER(*s2);
1039840 if (z1 < z2) return -1;
1040841 if (z1 > z2) return 1;
1041842 if (!z1) return 0;
1042843 }
844+
1043845 return 0;
1044846 }
1045847
@@ -1071,23 +873,23 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr)
1071873 if (!my_strnicmp(str, macro_modifier_name[i], len))
1072874 break;
1073875 }
876+
1074877 if (!macro_modifier_chr[i]) break;
1075878 str += len;
1076879 mod_status[i] = TRUE;
1077880 if ('S' == macro_modifier_chr[i])
1078881 shiftstatus = 1;
1079882 }
883+
1080884 for (i = 0; i < max_macrotrigger; i++)
1081885 {
1082886 len = strlen(macro_trigger_name[i]);
1083887 if (!my_strnicmp(str, macro_trigger_name[i], len) && ']' == str[len])
1084888 {
1085- /* a trigger name found */
1086889 break;
1087890 }
1088891 }
1089892
1090- /* Invalid trigger name? */
1091893 if (i == max_macrotrigger)
1092894 {
1093895 str = my_strchr(str, ']');
@@ -1098,8 +900,10 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr)
1098900 *bufptr = s;
1099901 *strptr = str; /* where **strptr == ']' */
1100902 }
903+
1101904 return;
1102905 }
906+
1103907 key_code = macro_trigger_keycode[shiftstatus][i];
1104908 str += len;
1105909
@@ -1107,15 +911,15 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr)
1107911 for (i = 0; macro_template[i]; i++)
1108912 {
1109913 char ch = macro_template[i];
1110- int j;
1111-
1112914 switch (ch)
1113915 {
1114916 case '&':
1115- for (j = 0; macro_modifier_chr[j]; j++) {
917+ for (int j = 0; macro_modifier_chr[j]; j++)
918+ {
1116919 if (mod_status[j])
1117920 *s++ = macro_modifier_chr[j];
1118921 }
922+
1119923 break;
1120924 case '#':
1121925 strcpy(s, key_code);
@@ -1126,6 +930,7 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr)
1126930 break;
1127931 }
1128932 }
933+
1129934 *s++ = '\r';
1130935
1131936 *bufptr = s;
@@ -1144,126 +949,91 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr)
1144949 void text_to_ascii(char *buf, concptr str)
1145950 {
1146951 char *s = buf;
1147-
1148- /* Analyze the "ascii" string */
1149952 while (*str)
1150953 {
1151- /* Backslash codes */
1152954 if (*str == '\\')
1153955 {
1154- /* Skip the backslash */
1155956 str++;
1156957 if (!(*str)) break;
1157958
1158- /* Macro Trigger */
1159959 if (*str == '[')
1160960 {
1161961 trigger_text_to_ascii(&s, &str);
1162962 }
1163963 else
1164-
1165- /* Hex-mode XXX */
964+ {
1166965 if (*str == 'x')
1167966 {
1168967 *s = 16 * (char)dehex(*++str);
1169968 *s++ += (char)dehex(*++str);
1170969 }
1171-
1172- /* Hack -- simple way to specify "backslash" */
1173970 else if (*str == '\\')
1174971 {
1175972 *s++ = '\\';
1176973 }
1177-
1178- /* Hack -- simple way to specify "caret" */
1179974 else if (*str == '^')
1180975 {
1181976 *s++ = '^';
1182977 }
1183-
1184- /* Hack -- simple way to specify "space" */
1185978 else if (*str == 's')
1186979 {
1187980 *s++ = ' ';
1188981 }
1189-
1190- /* Hack -- simple way to specify Escape */
1191982 else if (*str == 'e')
1192983 {
1193984 *s++ = ESCAPE;
1194985 }
1195-
1196- /* Backspace */
1197986 else if (*str == 'b')
1198987 {
1199988 *s++ = '\b';
1200989 }
1201-
1202- /* Newline */
1203990 else if (*str == 'n')
1204991 {
1205992 *s++ = '\n';
1206993 }
1207-
1208- /* Return */
1209994 else if (*str == 'r')
1210995 {
1211996 *s++ = '\r';
1212997 }
1213-
1214- /* Tab */
1215998 else if (*str == 't')
1216999 {
12171000 *s++ = '\t';
12181001 }
1219-
1220- /* Octal-mode */
12211002 else if (*str == '0')
12221003 {
12231004 *s = 8 * (char)deoct(*++str);
12241005 *s++ += (char)deoct(*++str);
12251006 }
1226-
1227- /* Octal-mode */
12281007 else if (*str == '1')
12291008 {
12301009 *s = 64 + 8 * (char)deoct(*++str);
12311010 *s++ += (char)deoct(*++str);
12321011 }
1233-
1234- /* Octal-mode */
12351012 else if (*str == '2')
12361013 {
12371014 *s = 64 * 2 + 8 * (char)deoct(*++str);
12381015 *s++ += (char)deoct(*++str);
12391016 }
1240-
1241- /* Octal-mode */
12421017 else if (*str == '3')
12431018 {
12441019 *s = 64 * 3 + 8 * (char)deoct(*++str);
12451020 *s++ += (char)deoct(*++str);
12461021 }
1022+ }
12471023
1248- /* Skip the final char */
12491024 str++;
12501025 }
1251-
1252- /* Normal Control codes */
12531026 else if (*str == '^')
12541027 {
12551028 str++;
12561029 *s++ = (*str++ & 037);
12571030 }
1258-
1259- /* Normal chars */
12601031 else
12611032 {
12621033 *s++ = *str++;
12631034 }
12641035 }
12651036
1266- /* Terminate */
12671037 *s = '\0';
12681038 }
12691039
@@ -1274,17 +1044,15 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr)
12741044 concptr str = *strptr;
12751045 char key_code[100];
12761046 int i;
1277- concptr tmp;
1278-
12791047 if (macro_template == NULL)
12801048 return FALSE;
12811049
12821050 *s++ = '\\';
12831051 *s++ = '[';
12841052
1053+ concptr tmp;
12851054 for (i = 0; macro_template[i]; i++)
12861055 {
1287- int j;
12881056 char ch = macro_template[i];
12891057
12901058 switch (ch)
@@ -1292,22 +1060,27 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr)
12921060 case '&':
12931061 while ((tmp = my_strchr(macro_modifier_chr, *str)) != 0)
12941062 {
1295- j = (int)(tmp - macro_modifier_chr);
1063+ int j = (int)(tmp - macro_modifier_chr);
12961064 tmp = macro_modifier_name[j];
12971065 while (*tmp) *s++ = *tmp++;
12981066 str++;
12991067 }
1068+
13001069 break;
13011070 case '#':
1071+ {
1072+ int j;
13021073 for (j = 0; *str && *str != '\r'; j++)
13031074 key_code[j] = *str++;
13041075 key_code[j] = '\0';
13051076 break;
1077+ }
13061078 default:
13071079 if (ch != *str) return FALSE;
13081080 str++;
13091081 }
13101082 }
1083+
13111084 if (*str++ != '\r') return FALSE;
13121085
13131086 for (i = 0; i < max_macrotrigger; i++)
@@ -1316,6 +1089,7 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr)
13161089 || !my_stricmp(key_code, macro_trigger_keycode[1][i]))
13171090 break;
13181091 }
1092+
13191093 if (i == max_macrotrigger)
13201094 return FALSE;
13211095
@@ -1336,13 +1110,9 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr)
13361110 void ascii_to_text(char *buf, concptr str)
13371111 {
13381112 char *s = buf;
1339-
1340- /* Analyze the "ascii" string */
13411113 while (*str)
13421114 {
13431115 byte i = (byte)(*str++);
1344-
1345- /* Macro Trigger */
13461116 if (i == 31)
13471117 {
13481118 if (!trigger_ascii_to_text(&s, &str))
@@ -1352,7 +1122,7 @@ void ascii_to_text(char *buf, concptr str)
13521122 }
13531123 }
13541124 else
1355-
1125+ {
13561126 if (i == ESCAPE)
13571127 {
13581128 *s++ = '\\';
@@ -1416,24 +1186,13 @@ void ascii_to_text(char *buf, concptr str)
14161186 *s++ = hexify(i / 16);
14171187 *s++ = hexify(i % 16);
14181188 }
1189+ }
14191190 }
14201191
1421- /* Terminate */
14221192 *s = '\0';
14231193 }
14241194
14251195
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-
14371196 /*
14381197 * Determine if any macros have ever started with a given character.
14391198 */
@@ -1445,25 +1204,18 @@ static bool macro__use[256];
14451204 */
14461205 sint macro_find_exact(concptr pat)
14471206 {
1448- int i;
1449-
1450- /* Nothing possible */
14511207 if (!macro__use[(byte)(pat[0])])
14521208 {
14531209 return -1;
14541210 }
14551211
1456- /* Scan the macros */
1457- for (i = 0; i < macro__num; ++i)
1212+ for (int i = 0; i < macro__num; ++i)
14581213 {
1459- /* Skip macros which do not match the pattern */
14601214 if (!streq(macro__pat[i], pat)) continue;
14611215
1462- /* Found one */
14631216 return (i);
14641217 }
14651218
1466- /* No matches */
14671219 return -1;
14681220 }
14691221
@@ -1473,25 +1225,18 @@ sint macro_find_exact(concptr pat)
14731225 */
14741226 static sint macro_find_check(concptr pat)
14751227 {
1476- int i;
1477-
1478- /* Nothing possible */
14791228 if (!macro__use[(byte)(pat[0])])
14801229 {
14811230 return -1;
14821231 }
14831232
1484- /* Scan the macros */
1485- for (i = 0; i < macro__num; ++i)
1233+ for (int i = 0; i < macro__num; ++i)
14861234 {
1487- /* Skip macros which do not contain the pattern */
14881235 if (!prefix(macro__pat[i], pat)) continue;
14891236
1490- /* Found one */
14911237 return (i);
14921238 }
14931239
1494- /* Nothing */
14951240 return -1;
14961241 }
14971242
@@ -1501,28 +1246,19 @@ static sint macro_find_check(concptr pat)
15011246 */
15021247 static sint macro_find_maybe(concptr pat)
15031248 {
1504- int i;
1505-
1506- /* Nothing possible */
15071249 if (!macro__use[(byte)(pat[0])])
15081250 {
15091251 return -1;
15101252 }
15111253
1512- /* Scan the macros */
1513- for (i = 0; i < macro__num; ++i)
1254+ for (int i = 0; i < macro__num; ++i)
15141255 {
1515- /* Skip macros which do not contain the pattern */
15161256 if (!prefix(macro__pat[i], pat)) continue;
1517-
1518- /* Skip macros which exactly match the pattern XXX XXX */
15191257 if (streq(macro__pat[i], pat)) continue;
15201258
1521- /* Found one */
15221259 return (i);
15231260 }
15241261
1525- /* Nothing */
15261262 return -1;
15271263 }
15281264
@@ -1532,30 +1268,24 @@ static sint macro_find_maybe(concptr pat)
15321268 */
15331269 static sint macro_find_ready(concptr pat)
15341270 {
1535- int i, t, n = -1, s = -1;
1271+ int t, n = -1, s = -1;
15361272
1537- /* Nothing possible */
15381273 if (!macro__use[(byte)(pat[0])])
15391274 {
15401275 return -1;
15411276 }
15421277
1543- /* Scan the macros */
1544- for (i = 0; i < macro__num; ++i)
1278+ for (int i = 0; i < macro__num; ++i)
15451279 {
1546- /* Skip macros which are not contained by the pattern */
15471280 if (!prefix(pat, macro__pat[i])) continue;
15481281
1549- /* Obtain the length of this macro */
15501282 t = strlen(macro__pat[i]);
1551-
1552- /* Only track the "longest" pattern */
15531283 if ((n >= 0) && (s > t)) continue;
15541284
1555- /* Track the entry */
15561285 n = i;
15571286 s = t;
15581287 }
1288+
15591289 return (n);
15601290 }
15611291
@@ -1576,45 +1306,25 @@ static sint macro_find_ready(concptr pat)
15761306 */
15771307 errr macro_add(concptr pat, concptr act)
15781308 {
1579- int n;
1580-
1581-
1582- /* Paranoia -- require data */
15831309 if (!pat || !act) return -1;
15841310
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);
15901312 if (n >= 0)
15911313 {
1592- /* Free the old macro action */
15931314 string_free(macro__act[n]);
15941315 }
1595-
1596- /* Create a new macro */
15971316 else
15981317 {
1599- /* Acquire a new index */
16001318 n = macro__num++;
1601-
1602- /* Save the pattern */
16031319 macro__pat[n] = string_make(pat);
16041320 }
16051321
1606- /* Save the action */
16071322 macro__act[n] = string_make(act);
1608-
1609- /* Efficiency */
16101323 macro__use[(byte)(pat[0])] = TRUE;
1611-
1612- /* Success */
16131324 return 0;
16141325 }
16151326
16161327
1617-
16181328 /*
16191329 * Local variable -- we are inside a "macro action"
16201330 *
@@ -1629,7 +1339,6 @@ static bool parse_macro = FALSE;
16291339 */
16301340 static bool parse_under = FALSE;
16311341
1632-
16331342 /*
16341343 * Flush all input chars. Actually, remember the flush,
16351344 * and do a "special flush" before the next "inkey()".
@@ -1639,7 +1348,6 @@ static bool parse_under = FALSE;
16391348 */
16401349 void flush(void)
16411350 {
1642- /* Do it later */
16431351 inkey_xtra = TRUE;
16441352 }
16451353
@@ -1649,13 +1357,9 @@ void flush(void)
16491357 */
16501358 void bell(void)
16511359 {
1652- /* Mega-Hack -- Flush the output */
16531360 Term_fresh();
1654-
1655- /* Make a bell noise (if allowed) */
16561361 if (ring_bell) Term_xtra(TERM_XTRA_NOISE, 0);
16571362
1658- /* Flush the input (later!) */
16591363 flush();
16601364 }
16611365
@@ -1665,25 +1369,23 @@ void bell(void)
16651369 */
16661370 void sound(int val)
16671371 {
1668- /* No sound */
16691372 if (!use_sound) return;
16701373
1671- /* Make a sound (if allowed) */
16721374 Term_xtra(TERM_XTRA_SOUND, val);
16731375 }
16741376
1377+
16751378 /*
16761379 * Hack -- Play a music
16771380 */
16781381 errr play_music(int type, int val)
16791382 {
1680- /* No sound */
16811383 if (!use_music) return 1;
16821384
1683- /* Make a sound (if allowed) */
16841385 return Term_xtra(type, val);
16851386 }
16861387
1388+
16871389 /*
16881390 * Hack -- Select floor music.
16891391 */
@@ -1794,147 +1496,85 @@ void select_floor_music(player_type *player_ptr)
17941496 static char inkey_aux(void)
17951497 {
17961498 int k = 0, n, p = 0, w = 0;
1797-
17981499 char ch;
1799-
1800- concptr pat, act;
1801-
18021500 char *buf = inkey_macro_trigger_string;
18031501
1804- /* Hack : キー入力待ちで止まっているので、流れた行の記憶は不要。 */
18051502 num_more = 0;
18061503
18071504 if (parse_macro)
18081505 {
1809- /* Scan next keypress from macro action */
18101506 if (Term_inkey(&ch, FALSE, TRUE))
18111507 {
1812- /* Over-flowed? Cancel macro action */
18131508 parse_macro = FALSE;
18141509 }
18151510 }
18161511 else
18171512 {
1818- /* Wait for a keypress */
18191513 (void)(Term_inkey(&ch, TRUE, TRUE));
18201514 }
18211515
1822-
1823- /* End "macro action" */
18241516 if (ch == 30) parse_macro = FALSE;
18251517
1826- /* Inside "macro action" */
18271518 if (ch == 30) return (ch);
1828-
1829- /* Inside "macro action" */
18301519 if (parse_macro) return (ch);
1831-
1832- /* Inside "macro trigger" */
18331520 if (parse_under) return (ch);
18341521
1835- /* Save the first key, advance */
18361522 buf[p++] = ch;
18371523 buf[p] = '\0';
1838-
1839-
1840- /* Check for possible macro */
18411524 k = macro_find_check(buf);
1842-
1843- /* No macro pending */
18441525 if (k < 0) return (ch);
18451526
1846-
1847- /* Wait for a macro, or a timeout */
18481527 while (TRUE)
18491528 {
1850- /* Check for pending macro */
18511529 k = macro_find_maybe(buf);
18521530
1853- /* No macro pending */
18541531 if (k < 0) break;
18551532
1856- /* Check for (and remove) a pending key */
18571533 if (0 == Term_inkey(&ch, FALSE, TRUE))
18581534 {
1859- /* Append the key */
18601535 buf[p++] = ch;
18611536 buf[p] = '\0';
1862-
1863- /* Restart wait */
18641537 w = 0;
18651538 }
1866-
1867- /* No key ready */
18681539 else
18691540 {
1870- /* Increase "wait" */
18711541 w += 1;
1872-
1873- /* Excessive delay */
18741542 if (w >= 10) break;
18751543
18761544 Term_xtra(TERM_XTRA_DELAY, w);
18771545 }
18781546 }
18791547
1880-
1881- /* Check for available macro */
18821548 k = macro_find_ready(buf);
1883-
1884- /* No macro available */
18851549 if (k < 0)
18861550 {
1887- /* Push all the keys back on the queue */
18881551 while (p > 0)
18891552 {
1890- /* Push the key, notice over-flow */
18911553 if (Term_key_push(buf[--p])) return 0;
18921554 }
18931555
1894- /* Wait for (and remove) a pending key */
18951556 (void)Term_inkey(&ch, TRUE, TRUE);
1896-
1897- /* Return the key */
18981557 return (ch);
18991558 }
19001559
1901-
1902- /* Get the pattern */
1903- pat = macro__pat[k];
1904-
1905- /* Get the length of the pattern */
1560+ concptr pat = macro__pat[k];
19061561 n = strlen(pat);
1907-
1908- /* Push the "extra" keys back on the queue */
19091562 while (p > n)
19101563 {
1911- /* Push the key, notice over-flow */
19121564 if (Term_key_push(buf[--p])) return 0;
19131565 }
19141566
1915-
1916- /* Begin "macro action" */
19171567 parse_macro = TRUE;
1918-
1919- /* Push the "end of macro action" key */
19201568 if (Term_key_push(30)) return 0;
19211569
1570+ concptr act = macro__act[k];
19221571
1923- /* Access the macro action */
1924- act = macro__act[k];
1925-
1926- /* Get the length of the action */
19271572 n = strlen(act);
1928-
1929- /* Push the macro "action" onto the key queue */
19301573 while (n > 0)
19311574 {
1932- /* Push the key, notice over-flow */
19331575 if (Term_key_push(act[--n])) return 0;
19341576 }
19351577
1936-
1937- /* Hack -- Force "inkey()" to call us again */
19381578 return 0;
19391579 }
19401580
@@ -1946,22 +1586,14 @@ static void forget_macro_action(void)
19461586 {
19471587 if (!parse_macro) return;
19481588
1949- /* Drop following macro action string */
19501589 while (TRUE)
19511590 {
19521591 char ch;
1953-
1954- /* End loop if no key ready */
19551592 if (Term_inkey(&ch, FALSE, TRUE)) break;
1956-
1957- /* End loop if no key ready */
19581593 if (ch == 0) break;
1959-
1960- /* End of "macro action" */
19611594 if (ch == 30) break;
19621595 }
19631596
1964- /* No longer inside "macro action" */
19651597 parse_macro = FALSE;
19661598 }
19671599
@@ -2039,100 +1671,60 @@ static concptr inkey_next = NULL;
20391671 */
20401672 char inkey(void)
20411673 {
2042- int v;
2043- char kk;
20441674 char ch = 0;
20451675 bool done = FALSE;
20461676 term *old = Term;
20471677
2048- /* Hack -- Use the "inkey_next" pointer */
20491678 if (inkey_next && *inkey_next && !inkey_xtra)
20501679 {
2051- /* Get next character, and advance */
20521680 ch = *inkey_next++;
2053-
2054- /* Cancel the various "global parameters" */
20551681 inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
2056-
2057- /* Accept result */
20581682 return (ch);
20591683 }
20601684
2061- /* Forget pointer */
20621685 inkey_next = NULL;
2063-
2064- /* Hack -- handle delayed "flush()" */
20651686 if (inkey_xtra)
20661687 {
2067- /* End "macro action" */
20681688 parse_macro = FALSE;
2069-
2070- /* End "macro trigger" */
20711689 parse_under = FALSE;
2072-
2073- /* Forget old keypresses */
20741690 Term_flush();
20751691 }
20761692
2077-
2078- /* Access cursor state */
1693+ int v;
20791694 (void)Term_get_cursor(&v);
20801695
20811696 /* Show the cursor if waiting, except sometimes in "command" mode */
20821697 if (!inkey_scan && (!inkey_flag || hilite_player || current_world_ptr->character_icky))
20831698 {
2084- /* Show the cursor */
20851699 (void)Term_set_cursor(1);
20861700 }
20871701
2088-
2089- /* Hack -- Activate main screen */
20901702 Term_activate(angband_term[0]);
2091-
2092-
2093- /* Get a key */
1703+ char kk;
20941704 while (!ch)
20951705 {
2096- /* Hack -- Handle "inkey_scan" */
20971706 if (!inkey_base && inkey_scan &&
20981707 (0 != Term_inkey(&kk, FALSE, FALSE)))
20991708 {
21001709 break;
21011710 }
21021711
2103-
2104- /* Hack -- Flush output once when no key ready */
21051712 if (!done && (0 != Term_inkey(&kk, FALSE, FALSE)))
21061713 {
2107- /* Hack -- activate proper term */
21081714 Term_activate(old);
2109-
2110- /* Flush output */
21111715 Term_fresh();
2112-
2113- /* Hack -- activate main screen */
21141716 Term_activate(angband_term[0]);
2115-
2116- /* Mega-Hack -- reset saved flag */
21171717 current_world_ptr->character_saved = FALSE;
21181718
2119- /* Mega-Hack -- reset signal counter */
21201719 signal_count = 0;
2121-
2122- /* Only once */
21231720 done = TRUE;
21241721 }
21251722
2126-
2127- /* Hack -- Handle "inkey_base" */
21281723 if (inkey_base)
21291724 {
21301725 int w = 0;
2131-
2132- /* Wait forever */
21331726 if (!inkey_scan)
21341727 {
2135- /* Wait for (and remove) a pending key */
21361728 if (0 == Term_inkey(&ch, TRUE, TRUE))
21371729 {
21381730 break;
@@ -2141,22 +1733,15 @@ char inkey(void)
21411733 break;
21421734 }
21431735
2144- /* Wait */
21451736 while (TRUE)
21461737 {
2147- /* Check for (and remove) a pending key */
21481738 if (0 == Term_inkey(&ch, FALSE, TRUE))
21491739 {
21501740 break;
21511741 }
2152-
2153- /* No key ready */
21541742 else
21551743 {
2156- /* Increase "wait" */
21571744 w += 10;
2158-
2159- /* Excessive delay */
21601745 if (w >= 100) break;
21611746
21621747 Term_xtra(TERM_XTRA_DELAY, w);
@@ -2166,107 +1751,48 @@ char inkey(void)
21661751 break;
21671752 }
21681753
2169-
2170- /* Get a key (see above) */
21711754 ch = inkey_aux();
2172-
2173-
2174- /* Handle "control-right-bracket" */
21751755 if (ch == 29)
21761756 {
2177- /* Strip this key */
21781757 ch = 0;
21791758 continue;
21801759 }
21811760
2182-
2183- /* Treat back-quote as escape */
2184-/* if (ch == '`') ch = ESCAPE; */
2185-
2186-
2187- /* End "macro trigger" */
21881761 if (parse_under && (ch <= 32))
21891762 {
2190- /* Strip this key */
21911763 ch = 0;
2192-
2193- /* End "macro trigger" */
21941764 parse_under = FALSE;
21951765 }
21961766
2197-
2198- /* Handle "control-caret" */
21991767 if (ch == 30)
22001768 {
2201- /* Strip this key */
22021769 ch = 0;
22031770 }
2204-
2205- /* Handle "control-underscore" */
22061771 else if (ch == 31)
22071772 {
2208- /* Strip this key */
22091773 ch = 0;
2210-
2211- /* Begin "macro trigger" */
22121774 parse_under = TRUE;
22131775 }
2214-
2215- /* Inside "macro trigger" */
22161776 else if (parse_under)
22171777 {
2218- /* Strip this key */
22191778 ch = 0;
22201779 }
22211780 }
22221781
2223-
2224- /* Hack -- restore the term */
22251782 Term_activate(old);
2226-
2227-
2228- /* Restore the cursor */
22291783 Term_set_cursor(v);
2230-
2231-
2232- /* Cancel the various "global parameters" */
22331784 inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
2234-
2235- /* Return the keypress */
22361785 return (ch);
22371786 }
22381787
22391788
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-
22581789 /*
22591790 * Initialize the quark array
22601791 */
22611792 void quark_init(void)
22621793 {
2263- /* Quark variables */
22641794 C_MAKE(quark__str, QUARK_MAX, concptr);
2265-
2266- /* Prepare first quark, which is used when quark_add() is failed */
22671795 quark__str[1] = string_make("");
2268-
2269- /* There is one quark (+ NULL) */
22701796 quark__num = 2;
22711797 }
22721798
@@ -2277,24 +1803,15 @@ void quark_init(void)
22771803 u16b quark_add(concptr str)
22781804 {
22791805 u16b i;
2280-
2281- /* Look for an existing quark */
22821806 for (i = 1; i < quark__num; i++)
22831807 {
2284- /* Check for equality */
22851808 if (streq(quark__str[i], str)) return (i);
22861809 }
22871810
2288- /* Return "" when no room is available */
22891811 if (quark__num == QUARK_MAX) return 1;
22901812
2291- /* New maximal quark */
22921813 quark__num = i + 1;
2293-
2294- /* Add a new quark */
22951814 quark__str[i] = string_make(str);
2296-
2297- /* Return the index */
22981815 return (i);
22991816 }
23001817
@@ -2317,50 +1834,19 @@ concptr quark_str(STR_OFFSET i)
23171834 }
23181835
23191836
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-
23451837 /*!
23461838 * @brief 保存中の過去ゲームメッセージの数を返す。 / How many messages are "available"?
23471839 * @return 残っているメッセージの数
23481840 */
23491841 s32b message_num(void)
23501842 {
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;
23561846
2357- /* Handle "wrap" */
23581847 if (next < last) next += MESSAGE_MAX;
23591848
2360- /* Extract the space */
23611849 n = (next - last);
2362-
2363- /* Return the result */
23641850 return (n);
23651851 }
23661852
@@ -2372,23 +1858,11 @@ s32b message_num(void)
23721858 */
23731859 concptr message_str(int age)
23741860 {
2375- s32b x;
2376- s32b o;
2377- concptr s;
2378-
2379- /* Forgotten messages have no text */
23801861 if ((age < 0) || (age >= message_num())) return ("");
23811862
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];
23921866 return (s);
23931867 }
23941868
@@ -2400,29 +1874,21 @@ concptr message_str(int age)
24001874 */
24011875 void message_add(concptr str)
24021876 {
2403- u32b i, n;
2404- int k, x, m;
2405-
1877+ u32b i;
1878+ int x, m;
24061879 char u[4096];
24071880 char splitted1[81];
24081881 concptr splitted2;
24091882
2410- /*** Step 1 -- Analyze the message ***/
2411-
2412- /* Hack -- Ignore "non-messages" */
24131883 if (!str) return;
24141884
2415- /* Message length */
2416- n = strlen(str);
2417-
2418- /* Important Hack -- Ignore "long" messages */
1885+ int n = strlen(str);
24191886 if (n >= MESSAGE_BUF / 4) return;
24201887
2421- /* extra step -- split the message if n>80.(added by Mogami) */
2422- if (n > 80) {
1888+ if (n > 80)
1889+ {
24231890 #ifdef JP
24241891 concptr t = str;
2425-
24261892 for (n = 0; n < 80; n++, t++)
24271893 {
24281894 if (iskanji(*t)) {
@@ -2430,7 +1896,9 @@ void message_add(concptr str)
24301896 n++;
24311897 }
24321898 }
2433- if (n == 81) n = 79; /* 最後の文字が漢字半分 */
1899+
1900+ /* 最後の文字が漢字半分 */
1901+ if (n == 81) n = 79;
24341902 #else
24351903 for (n = 80; n > 60; n--)
24361904 if (str[n] == ' ') break;
@@ -2441,234 +1909,140 @@ void message_add(concptr str)
24411909 splitted1[n] = '\0';
24421910 str = splitted1;
24431911 }
2444- else {
1912+ else
1913+ {
24451914 splitted2 = NULL;
24461915 }
24471916
2448- /*** Step 2 -- 最適化の試行 / Attempt to optimize ***/
2449-
2450- /* Limit number of messages to check */
24511917 m = message_num();
2452- k = m / 4;
1918+ int k = m / 4;
24531919 if (k > MESSAGE_MAX / 32) k = MESSAGE_MAX / 32;
2454-
2455- /* Check previous message */
24561920 for (i = message__next; m; m--)
24571921 {
24581922 int j = 1;
2459-
24601923 char buf[1024];
24611924 char *t;
2462-
24631925 concptr old;
2464-
2465- /* Back up and wrap if needed */
24661926 if (i-- == 0) i = MESSAGE_MAX - 1;
24671927
2468- /* Access the old string */
24691928 old = &message__buf[message__ptr[i]];
2470-
2471- /* Skip small messages */
24721929 if (!old) continue;
24731930
24741931 strcpy(buf, old);
2475-
2476- /* Find multiple */
24771932 #ifdef JP
24781933 for (t = buf; *t && (*t != '<' || (*(t + 1) != 'x')); t++)
24791934 if (iskanji(*t))t++;
24801935 #else
24811936 for (t = buf; *t && (*t != '<'); t++);
24821937 #endif
2483-
24841938 if (*t)
24851939 {
2486- /* Message is too small */
24871940 if (strlen(buf) < A_MAX) break;
24881941
2489- /* Drop the space */
24901942 *(t - 1) = '\0';
2491-
2492- /* Get multiplier */
24931943 j = atoi(t + 2);
24941944 }
24951945
2496- /* Limit the multiplier to 1000 */
24971946 if (streq(buf, str) && (j < 1000))
24981947 {
24991948 j++;
2500-
2501- /* Overwrite */
25021949 message__next = i;
2503-
25041950 str = u;
2505-
2506- /* Write it out */
25071951 sprintf(u, "%s <x%d>", buf, j);
2508-
2509- /* Message length */
25101952 n = strlen(str);
2511-
25121953 if (!now_message) now_message++;
25131954 }
25141955 else
25151956 {
2516- num_more++;/*流れた行の数を数えておく */
1957+ /*流れた行の数を数えておく */
1958+ num_more++;
25171959 now_message++;
25181960 }
25191961
25201962 break;
25211963 }
25221964
2523- /* Check the last few messages (if any to count) */
25241965 for (i = message__next; k; k--)
25251966 {
25261967 int q;
25271968 concptr old;
25281969
2529- /* Back up and wrap if needed */
25301970 if (i-- == 0) i = MESSAGE_MAX - 1;
25311971
2532- /* Stop before oldest message */
25331972 if (i == message__last) break;
25341973
2535- /* Extract "distance" from "head" */
25361974 q = (message__head + MESSAGE_BUF - message__ptr[i]) % MESSAGE_BUF;
25371975
2538- /* Do not optimize over large distance */
25391976 if (q > MESSAGE_BUF / 2) continue;
25401977
2541- /* Access the old string */
25421978 old = &message__buf[message__ptr[i]];
2543-
2544- /* Compare */
25451979 if (!streq(old, str)) continue;
25461980
2547- /* Get the next message index, advance */
25481981 x = message__next++;
2549-
2550- /* Handle wrap */
25511982 if (message__next == MESSAGE_MAX) message__next = 0;
2552-
2553- /* Kill last message if needed */
25541983 if (message__next == message__last) message__last++;
2555-
2556- /* Handle wrap */
25571984 if (message__last == MESSAGE_MAX) message__last = 0;
25581985
2559- /* Assign the starting address */
25601986 message__ptr[x] = message__ptr[i];
25611987
2562- /* Success */
2563- /* return; */
25641988 goto end_of_message_add;
2565-
25661989 }
25671990
2568-
2569- /*** Step 3 -- Ensure space before end of buffer ***/
2570-
2571- /* Kill messages and Wrap if needed */
25721991 if (message__head + n + 1 >= MESSAGE_BUF)
25731992 {
2574- /* Kill all "dead" messages */
25751993 for (i = message__last; TRUE; i++)
25761994 {
2577- /* Wrap if needed */
25781995 if (i == MESSAGE_MAX) i = 0;
2579-
2580- /* Stop before the new message */
25811996 if (i == message__next) break;
2582-
2583- /* Kill "dead" messages */
25841997 if (message__ptr[i] >= message__head)
25851998 {
2586- /* Track oldest message */
25871999 message__last = i + 1;
25882000 }
25892001 }
25902002
2591- /* Wrap "tail" if needed */
25922003 if (message__tail >= message__head) message__tail = 0;
25932004
2594- /* Start over */
25952005 message__head = 0;
25962006 }
25972007
2598-
2599- /*** Step 4 -- Ensure space before next message ***/
2600-
2601- /* Kill messages if needed */
26022008 if (message__head + n + 1 > message__tail)
26032009 {
2604- /* Grab new "tail" */
26052010 message__tail = message__head + n + 1;
2606-
2607- /* Advance tail while possible past first "nul" */
26082011 while (message__buf[message__tail - 1]) message__tail++;
26092012
2610- /* Kill all "dead" messages */
26112013 for (i = message__last; TRUE; i++)
26122014 {
2613- /* Wrap if needed */
26142015 if (i == MESSAGE_MAX) i = 0;
2615-
2616- /* Stop before the new message */
26172016 if (i == message__next) break;
2618-
2619- /* Kill "dead" messages */
26202017 if ((message__ptr[i] >= message__head) &&
26212018 (message__ptr[i] < message__tail))
26222019 {
2623- /* Track oldest message */
26242020 message__last = i + 1;
26252021 }
26262022 }
26272023 }
26282024
26292025
2630- /*** Step 5 -- Grab a new message index ***/
2631-
2632- /* Get the next message index, advance */
26332026 x = message__next++;
2634-
2635- /* Handle wrap */
26362027 if (message__next == MESSAGE_MAX) message__next = 0;
2637-
2638- /* Kill last message if needed */
26392028 if (message__next == message__last) message__last++;
2029+ if (message__last == MESSAGE_MAX) message__last = 0;
26402030
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 */
26492031 message__ptr[x] = message__head;
2650-
2651- /* Append the new part of the message */
26522032 for (i = 0; i < n; i++)
26532033 {
2654- /* Copy the message */
26552034 message__buf[message__head + i] = str[i];
26562035 }
26572036
2658- /* Terminate */
26592037 message__buf[message__head + i] = '\0';
2660-
2661- /* Advance the "head" pointer */
26622038 message__head += n + 1;
26632039
2664- /* recursively add splitted message (added by Mogami) */
26652040 end_of_message_add:
26662041 if (splitted2 != NULL)
26672042 message_add(splitted2);
26682043 }
26692044
26702045
2671-
26722046 /*
26732047 * Hack -- flush
26742048 */
@@ -2676,7 +2050,6 @@ static void msg_flush(player_type *player_ptr, int x)
26762050 {
26772051 byte a = TERM_L_BLUE;
26782052 bool nagasu = FALSE;
2679-
26802053 if ((auto_more && !player_ptr->now_damaged) || num_more < 0) {
26812054 int i;
26822055 for (i = 0; i < 8; i++)
@@ -2694,34 +2067,36 @@ static void msg_flush(player_type *player_ptr, int x)
26942067 }
26952068
26962069 player_ptr->now_damaged = FALSE;
2697-
26982070 if (!player_ptr->playing || !nagasu)
26992071 {
2700- /* Pause for response */
27012072 Term_putstr(x, 0, -1, a, _("-続く-", "-more-"));
2702-
2703- /* Get an acceptable keypress */
27042073 while (TRUE)
27052074 {
27062075 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;
27092080 break;
27102081 }
2711- else if (cmd == ' ') {
2712- num_more = 0; /*1画面だけ流す。 */
2082+ else if (cmd == ' ')
2083+ {
2084+ /* 1画面だけ流す */
2085+ num_more = 0;
27132086 break;
27142087 }
2715- else if ((cmd == '\n') || (cmd == '\r')) {
2716- num_more--; /*1行だけ流す。 */
2088+ else if ((cmd == '\n') || (cmd == '\r'))
2089+ {
2090+ /* 1行だけ流す */
2091+ num_more--;
27172092 break;
27182093 }
2094+
27192095 if (quick_messages) break;
27202096 bell();
27212097 }
27222098 }
27232099
2724- /* Clear the line */
27252100 Term_erase(0, 0, 255);
27262101 }
27272102
@@ -2733,6 +2108,7 @@ void msg_erase(void)
27332108
27342109
27352110 /*
2111+ * todo ここのp_ptrを削除するのは破滅的に作業が増えるので保留
27362112 * Output a message to the top line of the screen.
27372113 *
27382114 * Break long messages into multiple pieces (40-72 chars).
@@ -2760,39 +2136,28 @@ void msg_erase(void)
27602136 void msg_print(concptr msg)
27612137 {
27622138 static int p = 0;
2763- int n;
27642139 char *t;
27652140 char buf[1024];
27662141
27672142 if (current_world_ptr->timewalk_m_idx) return;
27682143
2769- /* Hack -- Reset */
2770- if (!msg_flag) {
2771- /* Clear the line */
2144+ if (!msg_flag)
2145+ {
27722146 Term_erase(0, 0, 255);
27732147 p = 0;
27742148 }
27752149
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);
27802151 if (p && (!msg || ((p + n) > 72)))
27812152 {
27822153 msg_flush(p_ptr, p);
2783-
2784- /* Forget it */
27852154 msg_flag = FALSE;
2786-
2787- /* Reset */
27882155 p = 0;
27892156 }
27902157
2791- /* No message */
27922158 if (!msg) return;
27932159 if (n > 1000) return;
27942160
2795- /* Copy it */
27962161 if (!cheat_turn)
27972162 {
27982163 strcpy(buf, msg);
@@ -2802,26 +2167,16 @@ void msg_print(concptr msg)
28022167 sprintf(buf, ("T:%d - %s"), (int)current_world_ptr->game_turn, msg);
28032168 }
28042169
2805- /* New Message Length */
28062170 n = strlen(buf);
2807-
2808- /* Memorize the message */
28092171 if (current_world_ptr->character_generated) message_add(buf);
28102172
2811- /* Analyze the buffer */
28122173 t = buf;
2813-
2814- /* Split message */
28152174 while (n > 72)
28162175 {
2817- char oops;
28182176 int check, split = 72;
2819-
28202177 #ifdef JP
28212178 bool k_flag = FALSE;
28222179 int wordlen = 0;
2823-
2824- /* Find the "best" split point */
28252180 for (check = 0; check < 72; check++)
28262181 {
28272182 if (k_flag)
@@ -2830,7 +2185,6 @@ void msg_print(concptr msg)
28302185 continue;
28312186 }
28322187
2833- /* Found a valid split point */
28342188 if (iskanji(t[check]))
28352189 {
28362190 k_flag = TRUE;
@@ -2848,60 +2202,34 @@ void msg_print(concptr msg)
28482202 split = check;
28492203 }
28502204 }
2205+
28512206 #else
2852- /* Find the "best" split point */
28532207 for (check = 40; check < 72; check++)
28542208 {
2855- /* Found a valid split point */
28562209 if (t[check] == ' ') split = check;
28572210 }
28582211 #endif
28592212
2860- /* Save the split character */
2861- oops = t[split];
2862-
2863- /* Split the message */
2213+ char oops = t[split];
28642214 t[split] = '\0';
2865-
2866- /* Display part of the message */
28672215 Term_putstr(0, 0, split, TERM_WHITE, t);
2868-
2869- /* Flush it */
28702216 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 */
28762217 t[split] = oops;
2877-
2878- /* Insert a space */
28792218 t[--split] = ' ';
2880-
2881- /* Prepare to recurse on the rest of "buf" */
28822219 t += split; n -= split;
28832220 }
28842221
2885- /* Display the tail of the message */
28862222 Term_putstr(p, 0, n, TERM_WHITE, t);
2887-
2888- /* Memorize the tail */
2889- /* if (current_world_ptr->character_generated) message_add(t); */
2890-
28912223 p_ptr->window |= (PW_MESSAGE);
28922224 update_output(p_ptr);
28932225
2894- /* Remember the message */
28952226 msg_flag = TRUE;
2896-
2897- /* Remember the position */
28982227 #ifdef JP
28992228 p += n;
29002229 #else
29012230 p += n + 1;
29022231 #endif
29032232
2904- /* Optional refresh */
29052233 if (fresh_message) Term_fresh();
29062234 }
29072235
@@ -2939,13 +2267,9 @@ static int screen_depth = 0;
29392267 */
29402268 void screen_save()
29412269 {
2942- /* Hack -- Flush messages */
29432270 msg_print(NULL);
2944-
2945- /* Save the screen (if legal) */
29462271 if (screen_depth++ == 0) Term_save();
29472272
2948- /* Increase "icky" depth */
29492273 current_world_ptr->character_icky++;
29502274 }
29512275
@@ -2957,13 +2281,9 @@ void screen_save()
29572281 */
29582282 void screen_load()
29592283 {
2960- /* Hack -- Flush messages */
29612284 msg_print(NULL);
2962-
2963- /* Load the screen (if legal) */
29642285 if (--screen_depth == 0) Term_load();
29652286
2966- /* Decrease "icky" depth */
29672287 current_world_ptr->character_icky--;
29682288 }
29692289
@@ -2974,22 +2294,14 @@ void screen_load()
29742294 void msg_format(concptr fmt, ...)
29752295 {
29762296 va_list vp;
2977-
29782297 char buf[1024];
2979-
2980- /* Begin the Varargs Stuff */
29812298 va_start(vp, fmt);
2982-
2983- /* Format the args, save the length */
29842299 (void)vstrnfmt(buf, 1024, fmt, vp);
2985-
2986- /* End the Varargs Stuff */
29872300 va_end(vp);
2988-
2989- /* Display */
29902301 msg_print(buf);
29912302 }
29922303
2304+
29932305 /*
29942306 * Display a formatted message, using "vstrnfmt()" and "msg_print()".
29952307 */
@@ -3002,17 +2314,9 @@ void msg_format_wizard(int cheat_type, concptr fmt, ...)
30022314
30032315 va_list vp;
30042316 char buf[1024];
3005-
3006- /* Begin the Varargs Stuff */
30072317 va_start(vp, fmt);
3008-
3009- /* Format the args, save the length */
30102318 (void)vstrnfmt(buf, 1024, fmt, vp);
3011-
3012- /* End the Varargs Stuff */
30132319 va_end(vp);
3014-
3015- /* Display */
30162320 msg_print_wizard(cheat_type, buf);
30172321 }
30182322
@@ -3025,34 +2329,30 @@ void msg_format_wizard(int cheat_type, concptr fmt, ...)
30252329 */
30262330 void c_put_str(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col)
30272331 {
3028- /* Position cursor, Dump the attr/text */
30292332 Term_putstr(col, row, -1, attr, str);
30302333 }
30312334
2335+
30322336 /*
30332337 * As above, but in "white"
30342338 */
30352339 void put_str(concptr str, TERM_LEN row, TERM_LEN col)
30362340 {
3037- /* Spawn */
30382341 Term_putstr(col, row, -1, TERM_WHITE, str);
30392342 }
30402343
30412344
3042-
30432345 /*
30442346 * Display a string on the screen using an attribute, and clear
30452347 * to the end of the line.
30462348 */
30472349 void c_prt(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col)
30482350 {
3049- /* Clear line, position cursor */
30502351 Term_erase(col, row, 255);
3051-
3052- /* Dump the attr/text */
30532352 Term_addstr(-1, attr, str);
30542353 }
30552354
2355+
30562356 /*
30572357 * As above, but in "white"
30582358 */
@@ -3063,8 +2363,6 @@ void prt(concptr str, TERM_LEN row, TERM_LEN col)
30632363 }
30642364
30652365
3066-
3067-
30682366 /*
30692367 * Print some (colored) text to the screen at the current cursor position,
30702368 * automatically "wrapping" existing text (at spaces) when necessary to
@@ -3081,67 +2379,46 @@ void prt(concptr str, TERM_LEN row, TERM_LEN col)
30812379 */
30822380 void c_roff(TERM_COLOR a, concptr str)
30832381 {
3084- int x, y;
3085-
30862382 int w, h;
3087-
3088- concptr s;
3089-
3090- /* Obtain the size */
30912383 (void)Term_get_size(&w, &h);
30922384
3093- /* Obtain the cursor */
2385+ int x, y;
30942386 (void)Term_locate(&x, &y);
30952387
3096- /* Hack -- No more space */
30972388 if (y == h - 1 && x > w - 3) return;
30982389
3099- /* Process the string */
3100- for (s = str; *s; s++)
2390+ for (concptr s = str; *s; s++)
31012391 {
31022392 char ch;
3103-
31042393 #ifdef JP
31052394 int k_flag = iskanji(*s);
31062395 #endif
3107- /* Force wrap */
31082396 if (*s == '\n')
31092397 {
3110- /* Wrap */
31112398 x = 0;
31122399 y++;
3113-
3114- /* No more space */
31152400 if (y == h) break;
31162401
3117- /* Clear line, move cursor */
31182402 Term_erase(x, y, 255);
3119-
31202403 break;
31212404 }
31222405
3123- /* Clean up the char */
31242406 #ifdef JP
31252407 ch = ((k_flag || isprint(*s)) ? *s : ' ');
31262408 #else
31272409 ch = (isprint(*s) ? *s : ' ');
31282410 #endif
31292411
3130-
3131- /* Wrap words as needed */
31322412 #ifdef JP
31332413 if ((x >= ((k_flag) ? w - 2 : w - 1)) && (ch != ' '))
31342414 #else
31352415 if ((x >= w - 1) && (ch != ' '))
31362416 #endif
3137-
31382417 {
31392418 int i, n = 0;
31402419
31412420 TERM_COLOR av[256];
31422421 char cv[256];
3143-
3144- /* Wrap word */
31452422 if (x < w)
31462423 #ifdef JP
31472424 {
@@ -3149,23 +2426,17 @@ void c_roff(TERM_COLOR a, concptr str)
31492426 if (!k_flag)
31502427 #endif
31512428 {
3152- /* Scan existing text */
31532429 for (i = w - 2; i >= 0; i--)
31542430 {
3155- /* Grab existing attr/char */
31562431 Term_what(i, y, &av[i], &cv[i]);
3157-
3158- /* Break on space */
31592432 if (cv[i] == ' ') break;
31602433
3161- /* Track current word */
31622434 n = i;
31632435 #ifdef JP
31642436 if (cv[i] == '(') break;
31652437 #endif
31662438 }
31672439 }
3168-
31692440 #ifdef JP
31702441 else
31712442 {
@@ -3182,44 +2453,30 @@ void c_roff(TERM_COLOR a, concptr str)
31822453 }
31832454 }
31842455 #endif
3185- /* Special case */
31862456 if (n == 0) n = w;
31872457
3188- /* Clear line */
31892458 Term_erase(n, y, 255);
3190-
3191- /* Wrap */
31922459 x = 0;
31932460 y++;
3194-
3195- /* No more space */
31962461 if (y == h) break;
31972462
3198- /* Clear line, move cursor */
31992463 Term_erase(x, y, 255);
3200-
3201- /* Wrap the word (if any) */
32022464 for (i = n; i < w - 1; i++)
32032465 {
32042466 #ifdef JP
32052467 if (cv[i] == '\0') break;
32062468 #endif
3207- /* Dump */
32082469 Term_addch(av[i], cv[i]);
3209-
3210- /* Advance (no wrap) */
32112470 if (++x > w) x = w;
32122471 }
32132472 }
32142473
3215- /* Dump */
32162474 #ifdef JP
32172475 Term_addch((byte)(a | 0x10), ch);
32182476 #else
32192477 Term_addch(a, ch);
32202478 #endif
32212479
3222-
32232480 #ifdef JP
32242481 if (k_flag)
32252482 {
@@ -3229,11 +2486,12 @@ void c_roff(TERM_COLOR a, concptr str)
32292486 Term_addch((byte)(a | 0x20), ch);
32302487 }
32312488 #endif
3232- /* Advance */
2489+
32332490 if (++x > w) x = w;
32342491 }
32352492 }
32362493
2494+
32372495 /*
32382496 * As above, but in "white"
32392497 */
@@ -3244,26 +2502,18 @@ void roff(concptr str)
32442502 }
32452503
32462504
3247-
3248-
32492505 /*
32502506 * Clear part of the screen
32512507 */
32522508 void clear_from(int row)
32532509 {
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++)
32582511 {
3259- /* Erase part of the screen */
32602512 Term_erase(0, y, 255);
32612513 }
32622514 }
32632515
32642516
3265-
3266-
32672517 /*
32682518 * Get some string input at the cursor location.
32692519 * Assume the buffer is initialized to a default string.
@@ -3283,9 +2533,6 @@ void clear_from(int row)
32832533 */
32842534 bool askfor_aux(char *buf, int len, bool numpad_cursor)
32852535 {
3286- int y, x;
3287- int pos = 0;
3288-
32892536 /*
32902537 * Text color
32912538 * TERM_YELLOW : Overwrite mode
@@ -3293,194 +2540,120 @@ bool askfor_aux(char *buf, int len, bool numpad_cursor)
32932540 */
32942541 byte color = TERM_YELLOW;
32952542
3296- /* Locate the cursor position */
2543+ int y, x;
32972544 Term_locate(&x, &y);
3298-
3299- /* Paranoia -- check len */
33002545 if (len < 1) len = 1;
3301-
3302- /* Paranoia -- check column */
33032546 if ((x < 0) || (x >= 80)) x = 0;
3304-
3305- /* Restrict the length */
33062547 if (x + len > 80) len = 80 - x;
33072548
3308- /* Paranoia -- Clip the default entry */
33092549 buf[len] = '\0';
33102550
3311-
3312- /* Process input */
2551+ int pos = 0;
33132552 while (TRUE)
33142553 {
3315- int skey;
3316-
3317- /* Display the string */
33182554 Term_erase(x, y, len);
33192555 Term_putstr(x, y, -1, color, buf);
33202556
3321- /* Place cursor */
33222557 Term_gotoxy(x + pos, y);
2558+ int skey = inkey_special(numpad_cursor);
33232559
3324- /* Get a special key code */
3325- skey = inkey_special(numpad_cursor);
3326-
3327- /* Analyze the key */
33282560 switch (skey)
33292561 {
33302562 case SKEY_LEFT:
33312563 case KTRL('b'):
33322564 {
33332565 int i = 0;
3334-
3335- /* Now on insert mode */
33362566 color = TERM_WHITE;
33372567
3338- /* No move at beginning of line */
33392568 if (0 == pos) break;
3340-
33412569 while (TRUE)
33422570 {
33432571 int next_pos = i + 1;
3344-
33452572 #ifdef JP
33462573 if (iskanji(buf[i])) next_pos++;
33472574 #endif
3348-
3349- /* Is there the cursor at next position? */
33502575 if (next_pos >= pos) break;
33512576
3352- /* Move to next */
33532577 i = next_pos;
33542578 }
33552579
3356- /* Get previous position */
33572580 pos = i;
3358-
33592581 break;
33602582 }
33612583
33622584 case SKEY_RIGHT:
33632585 case KTRL('f'):
3364- /* Now on insert mode */
33652586 color = TERM_WHITE;
3366-
3367- /* No move at end of line */
33682587 if ('\0' == buf[pos]) break;
33692588
33702589 #ifdef JP
3371- /* Move right */
33722590 if (iskanji(buf[pos])) pos += 2;
33732591 else pos++;
33742592 #else
33752593 pos++;
33762594 #endif
3377-
33782595 break;
33792596
33802597 case ESCAPE:
3381- /* Cancel input */
33822598 buf[0] = '\0';
33832599 return FALSE;
33842600
33852601 case '\n':
33862602 case '\r':
3387- /* Success */
33882603 return TRUE;
33892604
33902605 case '\010':
3391- /* Backspace */
33922606 {
33932607 int i = 0;
3394-
3395- /* Now on insert mode */
33962608 color = TERM_WHITE;
3397-
3398- /* No move at beginning of line */
33992609 if (0 == pos) break;
3400-
34012610 while (TRUE)
34022611 {
34032612 int next_pos = i + 1;
3404-
34052613 #ifdef JP
34062614 if (iskanji(buf[i])) next_pos++;
34072615 #endif
3408-
3409- /* Is there the cursor at next position? */
34102616 if (next_pos >= pos) break;
34112617
3412- /* Move to next */
34132618 i = next_pos;
34142619 }
34152620
3416- /* Get previous position */
34172621 pos = i;
3418-
3419- /* Fall through to 'Delete key' */
34202622 }
34212623
34222624 case 0x7F:
34232625 case KTRL('d'):
3424- /* Delete key */
34252626 {
3426- int dst, src;
3427-
3428- /* Now on insert mode */
34292627 color = TERM_WHITE;
3430-
3431- /* No move at end of line */
34322628 if ('\0' == buf[pos]) break;
3433-
3434- /* Position of next character */
3435- src = pos + 1;
3436-
2629+ int src = pos + 1;
34372630 #ifdef JP
3438- /* Next character is one more byte away */
34392631 if (iskanji(buf[pos])) src++;
34402632 #endif
34412633
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++]));
34482636 break;
34492637 }
34502638
34512639 default:
34522640 {
3453- /* Insert a character */
3454-
34552641 char tmp[100];
3456- char c;
3457-
3458- /* Ignore special keys */
34592642 if (skey & SKEY_MASK) break;
3460-
3461- /* Get a character code */
3462- c = (char)skey;
2643+ char c = (char)skey;
34632644
34642645 if (color == TERM_YELLOW)
34652646 {
3466- /* Overwrite default string */
34672647 buf[0] = '\0';
3468-
3469- /* Go to insert mode */
34702648 color = TERM_WHITE;
34712649 }
34722650
3473- /* Save right part of string */
34742651 strcpy(tmp, buf + pos);
34752652 #ifdef JP
34762653 if (iskanji(c))
34772654 {
3478- char next;
3479-
3480- /* Bypass macro processing */
34812655 inkey_base = TRUE;
3482- next = inkey();
3483-
2656+ char next = inkey();
34842657 if (pos + 1 < len)
34852658 {
34862659 buf[pos++] = c;
@@ -3508,18 +2681,14 @@ bool askfor_aux(char *buf, int len, bool numpad_cursor)
35082681 }
35092682 }
35102683
3511- /* Terminate */
35122684 buf[pos] = '\0';
3513-
3514- /* Write back the left part of string */
35152685 my_strcat(buf, tmp, len + 1);
35162686
35172687 break;
3518- } /* default: */
3519-
2688+ }
35202689 }
35212690
3522- } /* while (TRUE) */
2691+ }
35232692 }
35242693
35252694
@@ -3548,14 +2717,8 @@ bool get_string(concptr prompt, char *buf, int len)
35482717 {
35492718 bool res;
35502719 msg_print(NULL);
3551-
3552- /* Display prompt */
35532720 prt(prompt, 0, 0);
3554-
3555- /* Ask the user for a string */
35562721 res = askfor(buf, len);
3557-
3558- /* Clear prompt */
35592722 prt("", 0, 0);
35602723 return (res);
35612724 }
@@ -3573,6 +2736,7 @@ bool get_check(concptr prompt)
35732736 return get_check_strict(prompt, 0);
35742737 }
35752738
2739+
35762740 /*
35772741 * Verify something with the user strictly
35782742 *
@@ -3583,10 +2747,7 @@ bool get_check(concptr prompt)
35832747 */
35842748 bool get_check_strict(concptr prompt, BIT_FLAGS mode)
35852749 {
3586- int i;
35872750 char buf[80];
3588- bool flag = FALSE;
3589-
35902751 if (auto_more)
35912752 {
35922753 p_ptr->window |= PW_MESSAGE;
@@ -3595,11 +2756,9 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
35952756 }
35962757
35972758 msg_print(NULL);
3598-
35992759 if (!rogue_like_commands)
36002760 mode &= ~CHECK_OKAY_CANCEL;
36012761
3602- /* Hack -- Build a "useful" prompt */
36032762 if (mode & CHECK_OKAY_CANCEL)
36042763 {
36052764 my_strcpy(buf, prompt, sizeof(buf) - 15);
@@ -3616,21 +2775,18 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
36162775 strcat(buf, "[y/n]");
36172776 }
36182777
3619- /* Prompt for it */
36202778 prt(buf, 0, 0);
3621-
36222779 if (!(mode & CHECK_NO_HISTORY) && p_ptr->playing)
36232780 {
3624- /* HACK : Add the line to message buffer */
36252781 message_add(buf);
36262782 p_ptr->window |= (PW_MESSAGE);
36272783 handle_stuff(p_ptr);
36282784 }
36292785
3630- /* Get an acceptable answer */
2786+ bool flag = FALSE;
36312787 while (TRUE)
36322788 {
3633- i = inkey();
2789+ int i = inkey();
36342790
36352791 if (!(mode & CHECK_NO_ESCAPE))
36362792 {
@@ -3677,10 +2833,7 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
36772833 bell();
36782834 }
36792835
3680- /* Erase the prompt */
36812836 prt("", 0, 0);
3682-
3683- /* Return the flag */
36842837 return flag;
36852838 }
36862839
@@ -3695,24 +2848,16 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
36952848 bool get_com(concptr prompt, char *command, bool z_escape)
36962849 {
36972850 msg_print(NULL);
3698-
3699- /* Display a prompt */
37002851 prt(prompt, 0, 0);
3701-
3702- /* Get a key */
37032852 if (get_com_no_macros)
37042853 *command = (char)inkey_special(FALSE);
37052854 else
37062855 *command = inkey();
37072856
3708- /* Clear the prompt */
37092857 prt("", 0, 0);
3710-
3711- /* Handle "cancel" */
37122858 if (*command == ESCAPE) return FALSE;
37132859 if (z_escape && ((*command == 'z') || (*command == 'Z'))) return FALSE;
37142860
3715- /* Success */
37162861 return TRUE;
37172862 }
37182863
@@ -3724,61 +2869,40 @@ bool get_com(concptr prompt, char *command, bool z_escape)
37242869 */
37252870 QUANTITY get_quantity(concptr prompt, QUANTITY max)
37262871 {
3727- bool res, result;
3728- QUANTITY amt;
2872+ bool res;
37292873 char tmp[80];
37302874 char buf[80];
3731- COMMAND_CODE code;
37322875
3733-
3734- /* Use "command_arg" */
2876+ QUANTITY amt;
37352877 if (command_arg)
37362878 {
3737- /* Extract a number */
37382879 amt = command_arg;
3739-
3740- /* Clear "command_arg" */
37412880 command_arg = 0;
3742-
3743- /* Enforce the maximum */
37442881 if (amt > max) amt = max;
37452882
3746- /* Use it */
37472883 return (amt);
37482884 }
37492885
3750- /* Get the item index */
3751- result = repeat_pull(&code);
2886+ COMMAND_CODE code;
2887+ bool result = repeat_pull(&code);
37522888 amt = (QUANTITY)code;
37532889 if ((max != 1) && result)
37542890 {
3755- /* Enforce the maximum */
37562891 if (amt > max) amt = max;
3757-
3758- /* Enforce the minimum */
37592892 if (amt < 0) amt = 0;
37602893
3761- /* Use it */
37622894 return (amt);
37632895 }
37642896
3765- /* Build a prompt if needed */
37662897 if (!prompt)
37672898 {
37682899 sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max);
3769-
3770- /* Use that prompt */
37712900 prompt = tmp;
37722901 }
3773- msg_print(NULL);
37742902
3775- /* Display prompt */
2903+ msg_print(NULL);
37762904 prt(prompt, 0, 0);
3777-
3778- /* Default to one */
37792905 amt = 1;
3780-
3781- /* Build the default */
37822906 sprintf(buf, "%d", amt);
37832907
37842908 /*
@@ -3787,27 +2911,15 @@ QUANTITY get_quantity(concptr prompt, QUANTITY max)
37872911 */
37882912 res = askfor_aux(buf, 6, FALSE);
37892913
3790- /* Clear prompt */
37912914 prt("", 0, 0);
3792-
3793- /* Cancelled */
37942915 if (!res) return 0;
37952916
3796- /* Extract a number */
37972917 amt = (COMMAND_CODE)atoi(buf);
3798-
3799- /* A letter means "all" */
38002918 if (isalpha(buf[0])) amt = max;
3801-
3802- /* Enforce the maximum */
38032919 if (amt > max) amt = max;
3804-
3805- /* Enforce the minimum */
38062920 if (amt < 0) amt = 0;
3807-
38082921 if (amt) repeat_push((COMMAND_CODE)amt);
38092922
3810- /* Return the result */
38112923 return (amt);
38122924 }
38132925
@@ -3824,14 +2936,11 @@ void pause_line(int row)
38242936 prt("", row, 0);
38252937 }
38262938
3827-
38282939 /*
38292940 * Hack -- special buffer to hold the action of the current keymap
38302941 */
38312942 static char request_command_buffer[256];
38322943
3833-
3834-
38352944 typedef struct
38362945 {
38372946 concptr name;
@@ -4165,9 +3274,7 @@ static char inkey_from_menu(player_type *player_ptr)
41653274 else basey = 13;
41663275 basex = 15;
41673276
4168- /* Clear top line */
41693277 prt("", 0, 0);
4170-
41713278 screen_save();
41723279
41733280 floor_type* floor_ptr = player_ptr->current_floor_ptr;
@@ -4209,15 +3316,15 @@ static char inkey_from_menu(player_type *player_ptr)
42093316 break;
42103317 }
42113318 }
3319+
42123320 put_str(menu_name, basey + 1 + i / 2, basex + 4 + (i % 2) * 24);
42133321 }
3322+
42143323 max_num = i;
42153324 kisuu = max_num % 2;
42163325 put_str(_("》", "> "), basey + 1 + num / 2, basex + 2 + (num % 2) * 24);
42173326
4218- /* Place the cursor on the player */
42193327 move_cursor_relative(player_ptr->y, player_ptr->x);
4220-
42213328 sub_cmd = inkey();
42223329 if ((sub_cmd == ' ') || (sub_cmd == 'x') || (sub_cmd == 'X') || (sub_cmd == '\r') || (sub_cmd == '\n'))
42233330 {
@@ -4293,6 +3400,7 @@ static char inkey_from_menu(player_type *player_ptr)
42933400 return (cmd);
42943401 }
42953402
3403+
42963404 /*
42973405 * Request a command from the user.
42983406 *
@@ -4314,8 +3422,6 @@ static char inkey_from_menu(player_type *player_ptr)
43143422 */
43153423 void request_command(player_type *player_ptr, int shopping)
43163424 {
4317- int i;
4318-
43193425 s16b cmd;
43203426 int mode;
43213427
@@ -4324,231 +3430,142 @@ void request_command(player_type *player_ptr, int shopping)
43243430 #ifdef JP
43253431 int caretcmd = 0;
43263432 #endif
4327- /* Roguelike */
43283433 if (rogue_like_commands)
43293434 {
43303435 mode = KEYMAP_MODE_ROGUE;
43313436 }
4332-
4333- /* Original */
43343437 else
43353438 {
43363439 mode = KEYMAP_MODE_ORIG;
43373440 }
43383441
4339-
4340- /* No command yet */
43413442 command_cmd = 0;
4342-
4343- /* No "argument" yet */
43443443 command_arg = 0;
4345-
4346- /* No "direction" yet */
43473444 command_dir = 0;
4348-
43493445 use_menu = FALSE;
43503446
4351-
4352- /* Get command */
43533447 while (TRUE)
43543448 {
4355- /* Hack -- auto-commands */
43563449 if (command_new)
43573450 {
43583451 msg_erase();
4359-
4360- /* Use auto-command */
43613452 cmd = command_new;
4362-
4363- /* Forget it */
43643453 command_new = 0;
43653454 }
4366-
4367- /* Get a keypress in "command" mode */
43683455 else
43693456 {
4370- /* Hack -- no flush needed */
43713457 msg_flag = FALSE;
43723458 num_more = 0;
4373-
4374- /* Activate "command mode" */
43753459 inkey_flag = TRUE;
4376-
43773460 cmd = inkey();
4378-
43793461 if (!shopping && command_menu && ((cmd == '\r') || (cmd == '\n') || (cmd == 'x') || (cmd == 'X'))
43803462 && !keymap_act[mode][(byte)(cmd)])
43813463 cmd = inkey_from_menu(player_ptr);
43823464 }
43833465
4384- /* Clear top line */
43853466 prt("", 0, 0);
4386-
4387-
4388- /* Command Count */
43893467 if (cmd == '0')
43903468 {
43913469 COMMAND_ARG old_arg = command_arg;
4392-
4393- /* Reset */
43943470 command_arg = 0;
4395-
4396- /* Begin the input */
43973471 prt(_("回数: ", "Count: "), 0, 0);
4398-
4399- /* Get a command count */
44003472 while (TRUE)
44013473 {
4402- /* Get a new keypress */
44033474 cmd = inkey();
4404-
4405- /* Simple editing (delete or backspace) */
44063475 if ((cmd == 0x7F) || (cmd == KTRL('H')))
44073476 {
4408- /* Delete a digit */
44093477 command_arg = command_arg / 10;
4410-
4411- /* Show current count */
44123478 prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
44133479 }
4414-
4415- /* Actual numeric data */
44163480 else if (cmd >= '0' && cmd <= '9')
44173481 {
4418- /* Stop count at 9999 */
44193482 if (command_arg >= 1000)
44203483 {
4421- /* Warn */
44223484 bell();
4423-
4424- /* Limit */
44253485 command_arg = 9999;
44263486 }
4427-
4428- /* Increase count */
44293487 else
44303488 {
4431- /* Incorporate that digit */
44323489 command_arg = command_arg * 10 + D2I(cmd);
44333490 }
44343491
4435- /* Show current count */
44363492 prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
44373493 }
4438-
4439- /* Exit on "unusable" input */
44403494 else
44413495 {
44423496 break;
44433497 }
44443498 }
44453499
4446- /* Hack -- Handle "zero" */
44473500 if (command_arg == 0)
44483501 {
4449- /* Default to 99 */
44503502 command_arg = 99;
4451-
4452- /* Show current count */
44533503 prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
44543504 }
44553505
4456- /* Hack -- Handle "old_arg" */
44573506 if (old_arg != 0)
44583507 {
4459- /* Restore old_arg */
44603508 command_arg = old_arg;
4461-
4462- /* Show current count */
44633509 prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
44643510 }
44653511
4466- /* Hack -- white-space means "enter command now" */
44673512 if ((cmd == ' ') || (cmd == '\n') || (cmd == '\r'))
44683513 {
4469- /* Get a real command */
44703514 if (!get_com(_("コマンド: ", "Command: "), (char *)&cmd, FALSE))
44713515 {
4472- /* Clear count */
44733516 command_arg = 0;
44743517 continue;
44753518 }
44763519 }
44773520 }
44783521
4479-
4480- /* Allow "keymaps" to be bypassed */
44813522 if (cmd == '\\')
44823523 {
4483- /* Get a real command */
44843524 (void)get_com(_("コマンド: ", "Command: "), (char *)&cmd, FALSE);
4485-
4486- /* Hack -- bypass keymaps */
44873525 if (!inkey_next) inkey_next = "";
44883526 }
44893527
4490-
4491- /* Allow "control chars" to be entered */
44923528 if (cmd == '^')
44933529 {
4494- /* Get a new command and controlify it */
44953530 if (get_com(_("CTRL: ", "Control: "), (char *)&cmd, FALSE)) cmd = KTRL(cmd);
44963531 }
44973532
4498-
4499- /* Look up applicable keymap */
45003533 act = keymap_act[mode][(byte)(cmd)];
4501-
4502- /* Apply keymap if not inside a keymap already */
45033534 if (act && !inkey_next)
45043535 {
4505- /* Install the keymap (limited buffer size) */
45063536 (void)strnfmt(request_command_buffer, 256, "%s", act);
4507-
4508- /* Start using the buffer */
45093537 inkey_next = request_command_buffer;
45103538 continue;
45113539 }
45123540
45133541 if (!cmd) continue;
45143542
4515-
4516- /* Use command */
45173543 command_cmd = (byte)cmd;
4518-
45193544 break;
45203545 }
45213546
4522- /* Hack -- Auto-repeat certain commands */
45233547 if (always_repeat && (command_arg <= 0))
45243548 {
4525- /* Hack -- auto repeat certain commands */
45263549 if (my_strchr("TBDoc+", (char)command_cmd))
45273550 {
4528- /* Repeat 99 times */
45293551 command_arg = 99;
45303552 }
45313553 }
45323554
4533- /* Shopping */
45343555 if (shopping == 1)
45353556 {
4536- /* Convert */
45373557 switch (command_cmd)
45383558 {
4539- /* Command "p" -> "purchase" (get) */
45403559 case 'p': command_cmd = 'g'; break;
45413560
4542- /* Command "m" -> "purchase" (get) */
45433561 case 'm': command_cmd = 'g'; break;
45443562
4545- /* Command "s" -> "sell" (drop) */
45463563 case 's': command_cmd = 'd'; break;
45473564 }
45483565 }
45493566
45503567 #ifdef JP
4551- for (i = 0; i < 256; i++)
3568+ for (int i = 0; i < 256; i++)
45523569 {
45533570 concptr s;
45543571 if ((s = keymap_act[mode][i]) != NULL)
@@ -4560,58 +3577,42 @@ void request_command(player_type *player_ptr, int shopping)
45603577 }
45613578 }
45623579 }
3580+
45633581 if (!caretcmd)
45643582 caretcmd = command_cmd;
45653583 #endif
45663584
4567- /* Hack -- Scan equipment */
4568- for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3585+ for (int i = INVEN_RARM; i < INVEN_TOTAL; i++)
45693586 {
4570- concptr s;
4571-
45723587 object_type *o_ptr = &player_ptr->inventory_list[i];
45733588 if (!o_ptr->k_idx) continue;
45743589
4575- /* No inscription */
45763590 if (!o_ptr->inscription) continue;
45773591
4578- /* Obtain the inscription */
4579- s = quark_str(o_ptr->inscription);
4580-
4581- /* Find a '^' */
3592+ concptr s = quark_str(o_ptr->inscription);
45823593 s = my_strchr(s, '^');
4583-
4584- /* Process preventions */
45853594 while (s)
45863595 {
4587- /* Check the "restriction" character */
45883596 #ifdef JP
45893597 if ((s[1] == caretcmd) || (s[1] == '*'))
45903598 #else
45913599 if ((s[1] == command_cmd) || (s[1] == '*'))
45923600 #endif
4593-
45943601 {
4595- /* Hack -- Verify command */
45963602 if (!get_check(_("本当ですか? ", "Are you sure? ")))
45973603 {
4598- /* Hack -- Use space */
45993604 command_cmd = ' ';
46003605 }
46013606 }
46023607
4603- /* Find another '^' */
46043608 s = my_strchr(s + 1, '^');
46053609 }
46063610 }
46073611
4608-
4609- /* Hack -- erase the message line. */
46103612 prt("", 0, 0);
46113613 }
46123614
46133615
4614-
46153616 /*
46163617 * Check a char for "vowel-hood"
46173618 */
@@ -4648,7 +3649,6 @@ int get_keymap_dir(char ch)
46483649 {
46493650 int d = 0;
46503651
4651- /* Already a direction? */
46523652 if (isdigit(ch))
46533653 {
46543654 d = D2I(ch);
@@ -4656,37 +3656,27 @@ int get_keymap_dir(char ch)
46563656 else
46573657 {
46583658 BIT_FLAGS mode;
4659- concptr act, s;
4660-
4661- /* Roguelike */
46623659 if (rogue_like_commands)
46633660 {
46643661 mode = KEYMAP_MODE_ROGUE;
46653662 }
4666-
4667- /* Original */
46683663 else
46693664 {
46703665 mode = KEYMAP_MODE_ORIG;
46713666 }
46723667
4673- /* Extract the action (if any) */
4674- act = keymap_act[mode][(byte)(ch)];
4675-
4676- /* Analyze */
3668+ concptr act = keymap_act[mode][(byte)(ch)];
46773669 if (act)
46783670 {
4679- /* Convert to a direction */
4680- for (s = act; *s; ++s)
3671+ for (concptr s = act; *s; ++s)
46813672 {
4682- /* Use any digits in keymap */
46833673 if (isdigit(*s)) d = D2I(*s);
46843674 }
46853675 }
46863676 }
3677+
46873678 if (d == 5) d = 0;
46883679
4689- /* Return direction */
46903680 return (d);
46913681 }
46923682
@@ -4702,66 +3692,44 @@ static int repeat__idx = 0;
47023692 /* Saved "stuff" */
47033693 static COMMAND_CODE repeat__key[REPEAT_MAX];
47043694
4705-
47063695 void repeat_push(COMMAND_CODE what)
47073696 {
4708- /* Too many keys */
47093697 if (repeat__cnt == REPEAT_MAX) return;
47103698
4711- /* Push the "stuff" */
47123699 repeat__key[repeat__cnt++] = what;
4713-
4714- /* Prevents us from pulling keys */
47153700 ++repeat__idx;
47163701 }
47173702
47183703
47193704 bool repeat_pull(COMMAND_CODE *what)
47203705 {
4721- /* All out of keys */
47223706 if (repeat__idx == repeat__cnt) return FALSE;
47233707
4724- /* Grab the next key, advance */
47253708 *what = repeat__key[repeat__idx++];
4726-
4727- /* Success */
47283709 return TRUE;
47293710 }
47303711
47313712 void repeat_check(void)
47323713 {
4733- COMMAND_CODE what;
4734-
4735- /* Ignore some commands */
47363714 if (command_cmd == ESCAPE) return;
47373715 if (command_cmd == ' ') return;
47383716 if (command_cmd == '\r') return;
47393717 if (command_cmd == '\n') return;
47403718
4741- /* Repeat Last Command */
3719+ COMMAND_CODE what;
47423720 if (command_cmd == 'n')
47433721 {
4744- /* Reset */
47453722 repeat__idx = 0;
4746-
4747- /* Get the command */
47483723 if (repeat_pull(&what))
47493724 {
4750- /* Save the command */
47513725 command_cmd = what;
47523726 }
47533727 }
4754-
4755- /* Start saving new command */
47563728 else
47573729 {
4758- /* Reset */
47593730 repeat__cnt = 0;
47603731 repeat__idx = 0;
4761-
47623732 what = command_cmd;
4763-
4764- /* Save this command */
47653733 repeat_push(what);
47663734 }
47673735 }
@@ -4795,14 +3763,12 @@ static void swap(tag_type *a, tag_type *b)
47953763 */
47963764 static void InsertionSort(tag_type elements[], int number)
47973765 {
4798- int j, P;
4799-
48003766 tag_type tmp;
4801-
4802- for (P = 1; P < number; P++)
3767+ for (int i = 1; i < number; i++)
48033768 {
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--)
48063772 elements[j] = elements[j - 1];
48073773 elements[j] = tmp;
48083774 }
@@ -4842,14 +3808,13 @@ static tag_type median3(tag_type elements[], int left, int right)
48423808 */
48433809 static void quicksort(tag_type elements[], int left, int right)
48443810 {
4845- int i, j;
48463811 tag_type pivot;
4847-
48483812 if (left + CUTOFF <= right)
48493813 {
48503814 pivot = median3(elements, left, right);
48513815
4852- i = left; j = right - 1;
3816+ int i = left;
3817+ int j = right - 1;
48533818
48543819 while (TRUE)
48553820 {
@@ -4862,7 +3827,6 @@ static void quicksort(tag_type elements[], int left, int right)
48623827 break;
48633828 }
48643829
4865- /* Restore pivot */
48663830 swap(&elements[i], &elements[right - 1]);
48673831
48683832 quicksort(elements, left, i - 1);
@@ -4870,7 +3834,6 @@ static void quicksort(tag_type elements[], int left, int right)
48703834 }
48713835 else
48723836 {
4873- /* Use InsertionSort on small arrays */
48743837 InsertionSort(elements + left, right - left + 1);
48753838 }
48763839 }
@@ -4919,29 +3882,18 @@ static s16b gamma_helper[256] =
49193882 */
49203883 void build_gamma_table(int gamma)
49213884 {
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. */
49313885 gamma_table[0] = 0;
49323886 gamma_table[255] = 255;
4933-
4934- for (i = 1; i < 255; i++)
3887+ for (int i = 1; i < 255; i++)
49353888 {
49363889 /*
49373890 * Initialise the Taylor series
49383891 *
49393892 * value and diff have been scaled by 256
49403893 */
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);
49453897
49463898 while (diff)
49473899 {
@@ -4994,38 +3946,24 @@ void build_gamma_table(int gamma)
49943946 errr type_string(concptr str, uint len)
49953947 {
49963948 errr err = 0;
4997- concptr s;
4998-
49993949 term *old = Term;
5000-
5001- /* Paranoia - no string. */
50023950 if (!str) return -1;
5003-
5004- /* Hack - calculate the string length here if none given. */
50053951 if (!len) len = strlen(str);
50063952
5007- /* Activate the main window, as all pastes go there. */
50083953 Term_activate(term_screen);
5009-
5010- for (s = str; s < str + len; s++)
3954+ for (concptr s = str; s < str + len; s++)
50113955 {
5012- /* Catch end of string */
50133956 if (*s == '\0') break;
50143957
50153958 err = Term_keypress(*s);
5016-
5017- /* Catch errors */
50183959 if (err) break;
50193960 }
50203961
5021- /* Activate the original window. */
50223962 Term_activate(old);
5023-
50243963 return err;
50253964 }
50263965
50273966
5028-
50293967 void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
50303968 {
50313969 int read_pt = 0;
@@ -5042,8 +3980,6 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
50423980 bool kanji;
50433981 #endif
50443982 int ch_len = 1;
5045-
5046- /* Prepare one character */
50473983 ch[0] = str[read_pt];
50483984 ch[1] = '\0';
50493985 #ifdef JP
@@ -5069,11 +4005,7 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
50694005
50704006 if (line_len + ch_len > maxlen - 1 || str[read_pt] == '\n')
50714007 {
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;
50774009 #ifdef JP
50784010 if (kanji && !kinsoku)
50794011 /* nothing */;
@@ -5094,13 +4026,14 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
50944026 word_punct = read_pt;
50954027 continue;
50964028 }
4029+
50974030 if (ch[0] == ' ')
50984031 word_punct = read_pt;
4032+
50994033 #ifdef JP
51004034 if (!kinsoku) word_punct = read_pt;
51014035 #endif
51024036
5103- /* Not enough buffer size */
51044037 if ((size_t)(write_pt + 3) >= bufsize) break;
51054038
51064039 tbuf[write_pt++] = ch[0];
@@ -5115,9 +4048,9 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
51154048 }
51164049 #endif
51174050 }
4051+
51184052 tbuf[write_pt] = '\0';
51194053 tbuf[write_pt + 1] = '\0';
5120-
51214054 return;
51224055 }
51234056
@@ -5135,7 +4068,6 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
51354068 size_t my_strcpy(char *buf, concptr src, size_t bufsize)
51364069 {
51374070 #ifdef JP
5138-
51394071 char *d = buf;
51404072 concptr s = src;
51414073 size_t len = 0;
@@ -5164,25 +4096,18 @@ size_t my_strcpy(char *buf, concptr src, size_t bufsize)
51644096 }
51654097
51664098 while (*s++) len++;
5167-
51684099 return len;
51694100
51704101 #else
5171-
51724102 size_t len = strlen(src);
51734103 size_t ret = len;
51744104 if (bufsize == 0) return ret;
51754105
5176- /* Truncate */
51774106 if (len >= bufsize) len = bufsize - 1;
51784107
5179- /* Copy the string and terminate it */
51804108 (void)memcpy(buf, src, len);
51814109 buf[len] = '\0';
5182-
5183- /* Return strlen(src) */
51844110 return ret;
5185-
51864111 #endif
51874112 }
51884113
@@ -5201,16 +4126,12 @@ size_t my_strcpy(char *buf, concptr src, size_t bufsize)
52014126 size_t my_strcat(char *buf, concptr src, size_t bufsize)
52024127 {
52034128 size_t dlen = strlen(buf);
5204-
5205- /* Is there room left in the buffer? */
52064129 if (dlen < bufsize - 1)
52074130 {
5208- /* Append as much as possible */
52094131 return (dlen + my_strcpy(buf + dlen, src, bufsize - dlen));
52104132 }
52114133 else
52124134 {
5213- /* Return without appending */
52144135 return (dlen + strlen(src));
52154136 }
52164137 }
@@ -5223,13 +4144,12 @@ size_t my_strcat(char *buf, concptr src, size_t bufsize)
52234144 */
52244145 char *my_strstr(concptr haystack, concptr needle)
52254146 {
5226- int i;
52274147 int l1 = strlen(haystack);
52284148 int l2 = strlen(needle);
52294149
52304150 if (l1 >= l2)
52314151 {
5232- for (i = 0; i <= l1 - l2; i++)
4152+ for (int i = 0; i <= l1 - l2; i++)
52334153 {
52344154 if (!strncmp(haystack + i, needle, l2))
52354155 return (char *)haystack + i;
@@ -5269,7 +4189,6 @@ char *my_strchr(concptr ptr, char ch)
52694189 */
52704190 void str_tolower(char *str)
52714191 {
5272- /* Force to be lower case string */
52734192 for (; *str; str++)
52744193 {
52754194 #ifdef JP
@@ -5363,59 +4282,36 @@ int inkey_special(bool numpad_cursor)
53634282 */
53644283 inkey_macro_trigger_string[0] = '\0';
53654284
5366- /* Get a keypress */
53674285 key = inkey();
5368-
5369- /* Examine trigger string */
53704286 trig_len = strlen(inkey_macro_trigger_string);
5371-
5372- /* Already known that no special key */
53734287 if (!trig_len) return (int)((unsigned char)key);
5374-
5375- /*
5376- * Hack -- Ignore macro defined on ASCII characters.
5377- */
53784288 if (trig_len == 1 && parse_macro)
53794289 {
53804290 char c = inkey_macro_trigger_string[0];
5381-
5382- /* Cancel macro action on the queue */
53834291 forget_macro_action();
5384-
5385- /* Return the originaly pressed key */
53864292 return (int)((unsigned char)c);
53874293 }
53884294
5389- /* Convert the trigger */
53904295 ascii_to_text(buf, inkey_macro_trigger_string);
5391-
5392- /* Check the prefix "\[" */
53934296 if (prefix(str, "\\["))
53944297 {
5395- /* Skip "\[" */
53964298 str += 2;
5397-
5398- /* Examine modifier keys */
53994299 while (TRUE)
54004300 {
54014301 for (i = 0; modifier_key_list[i].keyname; i++)
54024302 {
54034303 if (prefix(str, modifier_key_list[i].keyname))
54044304 {
5405- /* Get modifier key flag */
54064305 str += strlen(modifier_key_list[i].keyname);
54074306 modifier |= modifier_key_list[i].keyflag;
54084307 }
54094308 }
54104309
5411- /* No more modifier key found */
54124310 if (!modifier_key_list[i].keyname) break;
54134311 }
54144312
5415- /* numpad_as_cursorkey option force numpad keys to input numbers */
54164313 if (!numpad_as_cursorkey) numpad_cursor = FALSE;
54174314
5418- /* Get a special key code */
54194315 for (i = 0; special_key_list[i].keyname; i++)
54204316 {
54214317 if ((!special_key_list[i].numpad || numpad_cursor) &&
@@ -5426,13 +4322,9 @@ int inkey_special(bool numpad_cursor)
54264322 }
54274323 }
54284324
5429- /* A special key found */
54304325 if (skey)
54314326 {
5432- /* Cancel macro action on the queue */
54334327 forget_macro_action();
5434-
5435- /* Return special key code and modifier flags */
54364328 return (skey | modifier);
54374329 }
54384330 }
@@ -5450,12 +4342,6 @@ int inkey_special(bool numpad_cursor)
54504342 }
54514343 }
54524344
5453- /* No special key found? */
5454-
5455- /* Don't bother with this trigger no more */
54564345 inkey_macro_trigger_string[0] = '\0';
5457-
5458- /* Return normal keycode */
54594346 return (int)((unsigned char)key);
54604347 }
5461-