OSDN Git Service

Merge branch 'For2.2.2-Refactoring' into For2.2.2-Refactoring-Cocoa2
authorEric Branlund <ebranlund@fastmail.com>
Mon, 15 Jun 2020 01:01:06 +0000 (18:01 -0700)
committerEric Branlund <ebranlund@fastmail.com>
Mon, 15 Jun 2020 01:01:06 +0000 (18:01 -0700)
1  2 
src/Makefile.am
src/main-win.c
src/main.c
src/main/init.c
src/main/init.h
src/system/h-config.h
src/util/angband-files.c

diff --cc src/Makefile.am
@@@ -430,128 -596,22 +596,140 @@@ hengband_SOURCES = 
  
  EXTRA_hengband_SOURCES = \
        angband.ico angband.rc ang_eng.rc maid-x11.c main-win.c \
 -      makefile.bcc makefile.std term/readdib.c term/readdib.h wall.bmp
 +      main-cap.c main-xaw.c \
 +      makefile.bcc makefile.std term/readdib.c term/readdib.h wall.bmp 
 +
 +cocoa_xcode_files = \
 +      cocoa/AppDelegate.m \
 +      cocoa/Base.lproj/MainMenu.xib
 +cocoa_icon_files = \
 +      cocoa/hengband_Icons.icns \
 +      cocoa/Save.icns \
 +      cocoa/Edit.icns \
 +      cocoa/Data.icns
 +cocoa_plist_template = cocoa/Angband-Cocoa.xml
 +cocoa_plist_strings_template = cocoa/Angband-Cocoa.strings
 +cocoa_plist_files = \
 +      cocoa/CommandMenu.plist
 +cocoa_en_nib_files = \
 +      cocoa/Base.lproj/MainMenu.nib
 +cocoa_en_strings_files = \
 +      cocoa/en.lproj/Localizable.strings \
 +      cocoa/en.lproj/CommandMenu.strings \
 +      cocoa/en.lproj/GraphicsMenu.strings
 +cocoa_ja_strings_files = \
 +      cocoa/ja.lproj/MainMenu.strings \
 +      cocoa/ja.lproj/Localizable.strings \
 +      cocoa/ja.lproj/CommandMenu.strings \
 +      cocoa/ja.lproj/GraphicsMenu.strings
  
  EXTRA_DIST = \
 -      gcc-wrap
 +      gcc-wrap \
 +      $(cocoa_xcode_files) \
 +      $(cocoa_icon_files) \
 +      $(cocoa_plist_template) \
 +      $(cocoa_plist_strings_template) \
 +      $(cocoa_plist_files) \
 +      $(cocoa_en_nib_files) \
 +      $(cocoa_en_strings_files) \
 +      $(cocoa_ja_strings_files)
 +
 +if COCOA
 +hengband_SOURCES += main-cocoa.m grafmode.h grafmode.c cocoa/AppDelegate.h
 +AM_CFLAGS = -mmacosx-version-min=10.8 -Wunguarded-availability
 +AM_OBJCFLAGS = -fobjc-arc -mmacosx-version-min=10.8 -Wunguarded-availability
 +hengband_LDFLAGS = -framework cocoa $(AM_LDFLAGS)
 +hengband_LINK = MACOSX_DEPLOYMENT_TARGET=10.8 $(OBJCLINK) $(hengband_LDFLAGS) $(LDFLAGS) -o $@
 +APPNAME = $(PACKAGE_NAME)
 +APPEXE = hengband
 +APPDIR = $(APPNAME).app
 +BUNDLE_IDENTIFIER = jp.osdn.hengband
 +BUNDLE_VERSION = $(PACKAGE_VERSION)
 +BUNDLE_DISPLAY_NAME = $(APPNAME)
 +BUNDLE_NAME = $(BUNDLE_DISPLAY_NAME)
 +BUNDLE_DISPLAY_NAME_JA = 変愚蛮怒
 +BUNDLE_NAME_JA = $(BUNDLE_DISPLAY_NAME_JA)
 +# Be careful with characters (like '&') in the copyright that have special
 +# meanings to sed.
 +COPYRIGHT = Copyright © Mr. Hoge and many others
 +# For now, using the line that appears in news_j.txt.  Is that appropriate?
 +# The ampersand is a kanji so it doesn't seem to be treated as a special
 +# character by sed.
 +COPYRIGHT_JA = Mr.hoge (echizen@users.sourceforge.jp) & 多くの方々
 +APPBNDL = $(bindir)/$(APPDIR)
 +APPCONT = $(APPBNDL)/Contents
 +APPBIN = $(APPCONT)/MacOS
 +APPRES = $(APPCONT)/Resources
 +appbin_PROGRAMS = $(APPEXE)
 +appbindir = $(APPBIN)
 +dist_appicon_DATA = $(cocoa_icon_files)
 +appicondir = $(APPRES)
 +appplist_DATA = $(cocoa_plist_files)
 +appplistdir = $(APPRES)
 +appennib_DATA = $(cocoa_en_nib_files)
 +appennibdir = $(APPRES)/Base.lproj
 +appen_DATA = $(cocoa_en_strings_files)
 +appendir = $(APPRES)/en.lproj
 +appja_DATA = $(cocoa_ja_strings_files)
 +appjadir = $(APPRES)/ja.lproj
 +else
 +EXTRA_hengband_SOURCES += main-cocoa.m grafmode.h grafmode.c \
 +      cocoa/AppDelegate.h
 +hengband_LINK = $(LINK)
 +endif
  
 +DEFAULT_INCLUDES = -I$(srcdir) \
 +      -I$(srcdir)/autopick \
 +      -I$(srcdir)/birth \
 +      -I$(srcdir)/cmd \
 +      -I$(srcdir)/cmd-io \
 +      -I$(srcdir)/cmd-item \
 +      -I$(srcdir)/combat \
 +      -I$(srcdir)/core \
 +      -I$(srcdir)/dungeon \
 +      -I$(srcdir)/effect \
 +      -I$(srcdir)/floor \
++      -I$(srcdir)/game-option \
 +      -I$(srcdir)/grid \
++      -I$(srcdir)/info-reader \
 +      -I$(srcdir)/inventory \
 +      -I$(srcdir)/io \
 +      -I$(srcdir)/io-dump \
 +      -I$(srcdir)/knowledge \
++      -I$(srcdir)/lore \
 +      -I$(srcdir)/market \
 +      -I$(srcdir)/mind \
 +      -I$(srcdir)/monster \
++      -I$(srcdir)/monster-attack \
++      -I$(srcdir)/monster-floor \
++      -I$(srcdir)/monster-race \
 +      -I$(srcdir)/mspell \
 +      -I$(srcdir)/mutation \
 +      -I$(srcdir)/object \
++      -I$(srcdir)/object-enchant \
 +      -I$(srcdir)/pet \
 +      -I$(srcdir)/player \
++      -I$(srcdir)/player-attack \
 +      -I$(srcdir)/realm \
 +      -I$(srcdir)/room \
++      -I$(srcdir)/specific-object \
 +      -I$(srcdir)/spell \
++      -I$(srcdir)/spell-kind \
++      -I$(srcdir)/spell-realm \
++      -I$(srcdir)/sv-definition \
 +      -I$(srcdir)/system \
 +      -I$(srcdir)/term \
 +      -I$(srcdir)/util \
 +      -I$(srcdir)/view \
 +      -I$(srcdir)/wizard \
 +      -I$(srcdir)/world \
 +      -I$(top_builddir)/src
  CFLAGS += $(XFT_CFLAGS)
  LIBS += $(XFT_LIBS)
 -COMPILE = $(srcdir)/gcc-wrap $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
 -      $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) \
 -      -Iart-definition -Iautopick -Ibirth -Icmd -Icmd-io -Icmd-item -Icombat \
 -      -Icore -Idungeon -Ieffect -Ifloor -Igame-option -Igrid -Iinfo-reader \
 -      -Iinventory -Iio -Iio-dump -Iknowledge -Imarket -Imelee -Imind -Imonster \
 -      -Imonster-attack -Imonster-floor -Imonster-race -Ilore -Imspell -Imutation \
 -      -Iobject -Iobject-enchant -Ipet -Iplayer -Iplayer-attack -Irealm -Iroom \
 -      -Ispecific-object -Ispell -Ispell-kind -Ispell-realm -Isv-definition \
 -      -Isystem -Iterm -Iutil -Iview -Iwizard -Iworld
 +COMPILE = $(srcdir)/gcc-wrap $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 +      $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 +OBJCCOMPILE = $(srcdir)/gcc-wrap $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) \
 +      $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)
  
  install-exec-hook:
  if SET_GID
diff --cc src/main-win.c
Simple merge
diff --cc src/main.c
Simple merge
diff --cc src/main/init.c
Simple merge
diff --cc src/main/init.h
  
  #endif /* INCLUDED_INIT_H */
  
- extern s16b f_tag_to_index(concptr str);
- extern s16b f_tag_to_index_in_init(concptr str);
- extern void init_angband(player_type *player_ptr, void(*process_autopick_file_command)(char*));
- extern concptr get_check_sum(void);
- extern void init_file_paths(concptr libpath, concptr varpath);
- extern void create_needed_dirs(void);
+ void init_angband(player_type *player_ptr, void(*process_autopick_file_command)(char*));
+ concptr get_check_sum(void);
 -void init_file_paths(char *path);
++void init_file_paths(concptr libpath, concptr varpath);
++void create_needed_dirs(void);
+ errr init_v_info(void);
+ errr init_buildings(void);
  #define DEFAULT_X11_FONT_7            "5x8"
  #endif
  
-  * behavior (PRIVATE_USER_PATH, SAVEFILE_USE_UID) for both the historical
-  * Mac OS X interface (MACH_O_CARBON) and the modern one (MACH_O_COCOA).
 +/*
 + * Hack -- Mach-O (native binary format of OS X) is basically a Un*x
 + * but has Mac OS/Windows-like user interface.  Disabling the Un*x-like
++ * behavior (PRIVATE_USER_PATH, SAVEFILE_USE_UID) for the modern Mac OS X
++ * interface (MACH_O_COCOA).
 + */
 +#if defined(MACH_O_CARBON) || defined(MACH_O_COCOA)
 +# ifdef PRIVATE_USER_PATH
 +#  undef PRIVATE_USER_PATH
 +# endif
 +# ifdef SAVEFILE_USE_UID
 +#  undef SAVEFILE_USE_UID
 +# endif
 +#endif
 +
  #ifndef HAVE_CONFIG_H
  #define WORLD_SCORE
  #endif /* HAVE_CONFIG_H */
index 0000000,6ba5440..bd3dc3e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,515 +1,523 @@@
+ #include "util/angband-files.h"
+ #include "locale/japanese.h"
+ #ifdef SET_UID
+ #ifndef HAVE_USLEEP
+ /*
+  * For those systems that don't have "usleep()" but need it.
+  *
+  * Fake "usleep()" function grabbed from the inl netrek server -cba
+  */
+ int usleep(huge usecs)
+ {
+     struct timeval timer;
+     int nfds = 0;
+ #ifdef FD_SET
+     fd_set *no_fds = NULL;
+ #else
+     int *no_fds = NULL;
+ #endif
+     if (usecs > 4000000L)
+         core(_("不当な usleep() 呼び出し", "Illegal usleep() call"));
+     timer.tv_sec = (usecs / 1000000L);
+     timer.tv_usec = (usecs % 1000000L);
+     if (select(nfds, no_fds, no_fds, no_fds, &timer) < 0) {
+         if (errno != EINTR)
+             return -1;
+     }
+     return 0;
+ }
+ #endif
+ /*
+  * Hack -- External functions
+  */
+ #ifdef SET_UID
+ extern struct passwd *getpwuid(uid_t uid);
+ extern struct passwd *getpwnam(concptr name);
+ #endif
+ /*
+  * Find a default user name from the system.
+  */
+ void user_name(char *buf, int id)
+ {
+     struct passwd *pw;
+     if ((pw = getpwuid(id))) {
+         (void)strcpy(buf, pw->pw_name);
+         buf[16] = '\0';
+ #ifdef JP
+         if (!iskanji(buf[0]))
+ #endif
+             if (islower(buf[0]))
+                 buf[0] = toupper(buf[0]);
+         return;
+     }
+     strcpy(buf, "PLAYER");
+ }
+ #endif /* SET_UID */
+ #ifdef SET_UID
+ /*
+  * Extract a "parsed" path from an initial filename
+  * Normally, we simply copy the filename into the buffer
+  * But leading tilde symbols must be handled in a special way
+  * Replace "~user/" by the home directory of the user named "user"
+  * Replace "~/" by the home directory of the current user
+  */
+ errr path_parse(char *buf, int max, concptr file)
+ {
+     buf[0] = '\0';
+     if (!file)
+         return -1;
+     if (file[0] != '~') {
+         (void)strnfmt(buf, max, "%s", file);
+         return 0;
+     }
+     concptr u = file + 1;
+     concptr s = angband_strstr(u, PATH_SEP);
+     char user[128];
+     if (s && (s >= u + sizeof(user)))
+         return 1;
+     if (s) {
+         int i;
+         for (i = 0; u < s; ++i)
+             user[i] = *u++;
+         user[i] = '\0';
+         u = user;
+     }
+     if (u[0] == '\0')
+         u = getlogin();
+     struct passwd *pw;
+     if (u)
+         pw = getpwnam(u);
+     else
+         pw = getpwuid(getuid());
+     if (!pw)
+         return 1;
+     if (s)
+         strnfmt(buf, max, "%s%s", pw->pw_dir, s);
+     else
+         strnfmt(buf, max, "%s", pw->pw_dir);
+     return 0;
+ }
+ #else /* SET_UID */
+ /*
+  * Extract a "parsed" path from an initial filename
+  *
+  * This requires no special processing on simple machines,
+  * except for verifying the size of the filename.
+  */
+ errr path_parse(char *buf, int max, concptr file)
+ {
+     (void)strnfmt(buf, max, "%s", file);
+     return 0;
+ }
+ #endif /* SET_UID */
+ #ifndef HAVE_MKSTEMP
+ /*
+  * Hack -- acquire a "temporary" file name if possible
+  *
+  * This filename is always in "system-specific" form.
+  */
+ static errr path_temp(char *buf, int max)
+ {
+     concptr s = tmpnam(NULL);
+     if (!s)
+         return -1;
+ #if !defined(WIN32) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
+     (void)strnfmt(buf, max, "%s", s);
+ #else
+     (void)strnfmt(buf, max, ".%s", s);
+ #endif
+     return 0;
+ }
+ #endif
+ /*!
+  * @brief ファイル入出力のためのパス生成する。/ Create a new path by appending a file (or directory) to a path.
+  * @param buf ファイルのフルを返すバッファ
+  * @param max bufのサイズ
+  * @param path ファイルパス
+  * @param file ファイル名
+  * @return エラーコード(ただし常に0を返す)
+  *
+  * This requires no special processing on simple machines, except
+  * for verifying the size of the filename, but note the ability to
+  * bypass the given "path" with certain special file-names.
+  *
+  * Note that the "file" may actually be a "sub-path", including
+  * a path and a file.
+  *
+  * Note that this function yields a path which must be "parsed"
+  * using the "parse" function above.
+  */
+ errr path_build(char *buf, int max, concptr path, concptr file)
+ {
+     if (file[0] == '~') {
+         (void)strnfmt(buf, max, "%s", file);
+     } else if (prefix(file, PATH_SEP) && !streq(PATH_SEP, "")) {
+         (void)strnfmt(buf, max, "%s", file);
+     } else if (!path[0]) {
+         (void)strnfmt(buf, max, "%s", file);
+     } else {
+         (void)strnfmt(buf, max, "%s%s%s", path, PATH_SEP, file);
+     }
+     return 0;
+ }
+ /*
+  * Hack -- replacement for "fopen()"
+  */
+ FILE *angband_fopen(concptr file, concptr mode)
+ {
+     char buf[1024];
+     if (path_parse(buf, 1024, file))
+         return (NULL);
+     return (fopen(buf, mode));
+ }
+ /*
+  * Hack -- replacement for "fclose()"
+  */
+ errr angband_fclose(FILE *fff)
+ {
+     if (!fff)
+         return -1;
+     if (fclose(fff) == EOF)
+         return 1;
+     return 0;
+ }
+ #ifdef HAVE_MKSTEMP
+ FILE *angband_fopen_temp(char *buf, int max)
+ {
+     strncpy(buf, "/tmp/anXXXXXX", max);
+     int fd = mkstemp(buf);
+     if (fd < 0)
+         return (NULL);
+     return (fdopen(fd, "w"));
+ }
+ #else /* HAVE_MKSTEMP */
+ FILE *angband_fopen_temp(char *buf, int max)
+ {
+     if (path_temp(buf, max))
+         return (NULL);
+     return (angband_fopen(buf, "w"));
+ }
+ #endif /* HAVE_MKSTEMP */
+ /*
+  * Hack -- replacement for "fgets()"
+  *
+  * Read a string, without a newline, to a file
+  *
+  * Process tabs, strip internal non-printables
+  */
+ errr angband_fgets(FILE *fff, char *buf, huge n)
+ {
+     huge i = 0;
+     char *s;
+     char tmp[1024];
+     if (fgets(tmp, 1024, fff)) {
+ #ifdef JP
+         guess_convert_to_system_encoding(tmp, sizeof(tmp));
+ #endif
+         for (s = tmp; *s; s++) {
++#ifdef MACH_O_COCOA
++            /*
++             * Be nice to the Macintosh, where a file can have Mac or Unix
++             * end of line, especially since the introduction of OS X.
++             * MPW tools were also very tolerant to the Unix EOL.
++             */
++            if (*s == '\r') *s = '\n';
++#endif /* MACH_O_COCOA */
+             if (*s == '\n') {
+                 buf[i] = '\0';
+                 return 0;
+             } else if (*s == '\t') {
+                 if (i + 8 >= n)
+                     break;
+                 buf[i++] = ' ';
+                 while (0 != (i % 8))
+                     buf[i++] = ' ';
+             }
+ #ifdef JP
+             else if (iskanji(*s)) {
+                 if (!s[1])
+                     break;
+                 buf[i++] = *s++;
+                 buf[i++] = *s;
+             } else if (iskana(*s)) {
+                 /* 半角かなに対応 */
+                 buf[i++] = *s;
+                 if (i >= n)
+                     break;
+             }
+ #endif
+             else if (isprint((unsigned char)*s)) {
+                 buf[i++] = *s;
+                 if (i >= n)
+                     break;
+             }
+         }
+         buf[i] = '\0';
+         return 0;
+     }
+     buf[0] = '\0';
+     return 1;
+ }
+ /*
+  * Hack -- replacement for "fputs()"
+  * Dump a string, plus a newline, to a file
+  * Process internal weirdness?
+  */
+ errr angband_fputs(FILE *fff, concptr buf, huge n)
+ {
+     n = n ? n : 0;
+     (void)fprintf(fff, "%s\n", buf);
+     return 0;
+ }
+ /*
+  * Several systems have no "O_BINARY" flag
+  */
+ #ifndef O_BINARY
+ #define O_BINARY 0
+ #endif /* O_BINARY */
+ /*
+  * Hack -- attempt to delete a file
+  */
+ errr fd_kill(concptr file)
+ {
+     char buf[1024];
+     if (path_parse(buf, 1024, file))
+         return -1;
+     (void)remove(buf);
+     return 0;
+ }
+ /*
+  * Hack -- attempt to move a file
+  */
+ errr fd_move(concptr file, concptr what)
+ {
+     char buf[1024];
+     char aux[1024];
+     if (path_parse(buf, 1024, file))
+         return -1;
+     if (path_parse(aux, 1024, what))
+         return -1;
+     (void)rename(buf, aux);
+     return 0;
+ }
+ /*
+  * Hack -- attempt to copy a file
+  */
+ errr fd_copy(concptr file, concptr what)
+ {
+     char buf[1024];
+     char aux[1024];
+     int read_num;
+     int src_fd, dst_fd;
+     if (path_parse(buf, 1024, file))
+         return -1;
+     if (path_parse(aux, 1024, what))
+         return -1;
+     src_fd = fd_open(buf, O_RDONLY);
+     if (src_fd < 0)
+         return -1;
+     dst_fd = fd_open(aux, O_WRONLY | O_TRUNC | O_CREAT);
+     if (dst_fd < 0)
+         return -1;
+     while ((read_num = read(src_fd, buf, 1024)) > 0) {
+         int write_num = 0;
+         while (write_num < read_num) {
+             int ret = write(dst_fd, buf + write_num, read_num - write_num);
+             if (ret < 0) {
+                 fd_close(src_fd);
+                 fd_close(dst_fd);
+                 return ret;
+             }
+             write_num += ret;
+         }
+     }
+     fd_close(src_fd);
+     fd_close(dst_fd);
+     return 0;
+ }
+ /*
+  * Hack -- attempt to open a file descriptor (create file)
+  * This function should fail if the file already exists
+  * Note that we assume that the file should be "binary"
+  */
+ int fd_make(concptr file, BIT_FLAGS mode)
+ {
+     char buf[1024];
+     if (path_parse(buf, 1024, file))
+         return -1;
+     return (open(buf, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, mode));
+ }
+ /*
+  * Hack -- attempt to open a file descriptor (existing file)
+  *
+  * Note that we assume that the file should be "binary"
+  */
+ int fd_open(concptr file, int flags)
+ {
+     char buf[1024];
+     if (path_parse(buf, 1024, file))
+         return -1;
+     return (open(buf, flags | O_BINARY, 0));
+ }
+ /*
+  * Hack -- attempt to lock a file descriptor
+  *
+  * Legal lock types -- F_UNLCK, F_RDLCK, F_WRLCK
+  */
+ errr fd_lock(int fd, int what)
+ {
+     what = what ? what : 0;
+     if (fd < 0)
+         return -1;
+ #if defined(SET_UID) && defined(LOCK_UN) && defined(LOCK_EX)
+     if (what == F_UNLCK) {
+         (void)flock(fd, LOCK_UN);
+     } else {
+         if (flock(fd, LOCK_EX) != 0)
+             return 1;
+     }
+ #endif
+     return 0;
+ }
+ /*
+  * Hack -- attempt to seek on a file descriptor
+  */
+ errr fd_seek(int fd, huge n)
+ {
+     if (fd < 0)
+         return -1;
+     huge p = lseek(fd, n, SEEK_SET);
+     if (p != n)
+         return 1;
+     return 0;
+ }
+ /*
+  * Hack -- attempt to truncate a file descriptor
+  */
+ errr fd_chop(int fd, huge n)
+ {
+     n = n ? n : 0;
+     return fd >= 0 ? 0 : -1;
+ }
+ /*
+  * Hack -- attempt to read data from a file descriptor
+  */
+ errr fd_read(int fd, char *buf, huge n)
+ {
+     if (fd < 0)
+         return -1;
+ #ifndef SET_UID
+     while (n >= 16384) {
+         if (read(fd, buf, 16384) != 16384)
+             return 1;
+         buf += 16384;
+         n -= 16384;
+     }
+ #endif
+     if (read(fd, buf, n) != (int)n)
+         return 1;
+     return 0;
+ }
+ /*
+  * Hack -- Attempt to write data to a file descriptor
+  */
+ errr fd_write(int fd, concptr buf, huge n)
+ {
+     if (fd < 0)
+         return -1;
+ #ifndef SET_UID
+     while (n >= 16384) {
+         if (write(fd, buf, 16384) != 16384)
+             return 1;
+         buf += 16384;
+         n -= 16384;
+     }
+ #endif
+     if (write(fd, buf, n) != (int)n)
+         return 1;
+     return 0;
+ }
+ /*
+  * Hack -- attempt to close a file descriptor
+  */
+ errr fd_close(int fd)
+ {
+     if (fd < 0)
+         return -1;
+     (void)close(fd);
+     return 0;
+ }