Author: cazfi
Date: Mon Apr 11 22:28:07 2016
New Revision: 32367

URL: http://svn.gna.org/viewcvs/freeciv?rev=32367&view=rev
Log:
Use "\" as directory separator on Windows builds

See patch #7026

Modified:
    trunk/client/options.c
    trunk/configure.ac
    trunk/server/gamehand.c
    trunk/utility/shared.c

Modified: trunk/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.c?rev=32367&r1=32366&r2=32367&view=diff
==============================================================================
--- trunk/client/options.c      (original)
+++ trunk/client/options.c      Mon Apr 11 22:28:07 2016
@@ -5056,6 +5056,17 @@
   }
 }
 
+#ifndef DIR_SEPARATOR
+#if defined(WIN32_NATIVE) || defined(_WIN32) || defined(__WIN32__) || 
defined(__EMX__) || defined(__DJGPP__)
+  /* Win32, OS/2, DOS */
+# define DIR_SEPARATOR "\\"
+# define DIR_SEPARATOR_CHAR '\\'
+#else
+  /* Unix */
+# define DIR_SEPARATOR "/"
+# define DIR_SEPARATOR_CHAR '/'
+#endif
+#endif
 
 /* Old rc file name. */
 #define OLD_OPTION_FILE_NAME ".civclientrc"
@@ -5108,7 +5119,7 @@
       return NULL;
     }
     fc_snprintf(name_buffer, sizeof(name_buffer),
-                "%s/" NEW_OPTION_FILE_NAME, name,
+                "%s" DIR_SEPARATOR NEW_OPTION_FILE_NAME, name,
                 MAJOR_NEW_OPTION_FILE_NAME, MINOR_NEW_OPTION_FILE_NAME);
 #endif /* OPTION_FILE_NAME */
   }
@@ -5165,7 +5176,7 @@
               ? minor >= FIRST_MINOR_NEW_OPTION_FILE_NAME 
               : minor >= 0); minor--) {
         fc_snprintf(name_buffer, sizeof(name_buffer),
-                    "%s/" NEW_OPTION_FILE_NAME, name, major, minor);
+                    "%s" DIR_SEPARATOR NEW_OPTION_FILE_NAME, name, major, 
minor);
         if (0 == fc_stat(name_buffer, &buf)) {
           if (MAJOR_NEW_OPTION_FILE_NAME != major
               || MINOR_NEW_OPTION_FILE_NAME != minor) {
@@ -5197,7 +5208,7 @@
          minor >= FIRST_MINOR_MID_OPTION_FILE_NAME ;
          minor--) {
       fc_snprintf(name_buffer, sizeof(name_buffer),
-                  "%s/" MID_OPTION_FILE_NAME, name, major, minor);
+                  "%s" DIR_SEPARATOR MID_OPTION_FILE_NAME, name, major, minor);
       if (0 == fc_stat(name_buffer, &buf)) {
         log_normal(_("Didn't find '%s' option file, "
                      "loading from '%s' instead."),
@@ -5213,7 +5224,7 @@
 
     /* Try with the old one. */
     fc_snprintf(name_buffer, sizeof(name_buffer),
-                "%s/" OLD_OPTION_FILE_NAME, name);
+                "%s" DIR_SEPARATOR OLD_OPTION_FILE_NAME, name);
     if (0 == fc_stat(name_buffer, &buf)) {
       log_normal(_("Didn't find '%s' option file, "
                    "loading from '%s' instead."),

Modified: trunk/configure.ac
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/configure.ac?rev=32367&r1=32366&r2=32367&view=diff
==============================================================================
--- trunk/configure.ac  (original)
+++ trunk/configure.ac  Mon Apr 11 22:28:07 2016
@@ -289,8 +289,6 @@
   AC_DEFINE_UNQUOTED([MODPACK_LIST_URL], ["${MODPACK_LIST_URL}"], [Default 
modpack list URL])
 fi
 
-AC_DEFINE_UNQUOTED([FREECIV_STORAGE_DIR], ["$FREECIV_STORAGE_DIR"], [Location 
for freeciv to store its information])
-
 AC_ARG_WITH([readline],
   AS_HELP_STRING([--with-readline], [support fancy command line editing]),
 WITH_READLINE=$withval,        dnl yes/no - required to use / never use
@@ -715,6 +713,7 @@
 
 dnl Defaults to override with host specific values
 HOST_PATH_SEPARATOR=":"
+HOST_DIR_SEPARATOR="/"
 
 dnl Settings specific to host OS
 case "$host_os" in
@@ -727,6 +726,9 @@
     fi
 
     HOST_PATH_SEPARATOR=";"
+    HOST_DIR_SEPARATOR="\\"
+
+    FREECIV_STORAGE_DIR=$(echo $FREECIV_STORAGE_DIR | $SED 's,/,\\\\\\\\,g')
 
     AC_DEFINE([FREECIV_SOCKET_ZERO_NOT_STDIN], [1], [Mingw-specific setting - 
stdin])
     AC_DEFINE([ALWAYS_ROOT], [1], [Can execute program as root - Mingw])
@@ -763,11 +765,13 @@
 dnl   HOST_PATH_SEPARATOR=$PATH_SEPARATOR
 dnl fi
 
+AC_DEFINE_UNQUOTED([FREECIV_STORAGE_DIR], ["$FREECIV_STORAGE_DIR"], [Location 
for freeciv to store its information])
+
 dnl note this has to match the path installed by translations/*/Makefile
 if test x"$MINGW" != "xyes"; then
   CPPFLAGS="$CPPFLAGS -DLOCALEDIR=\"\\\"$localedir\\\"\""
 else
-  AC_DEFINE_UNQUOTED([LOCALEDIR], ["./share/locale"], [Locale directory 
(windows)])
+  AC_DEFINE_UNQUOTED([LOCALEDIR], [".\\\\share\\\\locale"], [Locale directory 
(windows)])
 fi
 
 CPPFLAGS="$CPPFLAGS -DBINDIR=\"\\\"$bindir\\\"\""
@@ -1206,6 +1210,7 @@
 AC_SUBST([VERSION_WITHOUT_LABEL])
 AC_SUBST([VERSION_LABEL])
 AC_SUBST([HOST_PATH_SEPARATOR])
+AC_SUBST([HOST_DIR_SEPARATOR])
 AC_SUBST([FREECIV_STORAGE_DIR])
 AM_CONDITIONAL(AUDIO_SDL, test "x$SDL_mixer" != "xno")
 AM_CONDITIONAL(CLIENT_GUI_SDL2, test "x$gui_sdl2" = "xyes")
@@ -1356,15 +1361,15 @@
 FC_EXPAND_DIR(FREECIV_DATADIR, "$datadir/freeciv")
 
 if test x"$MINGW" = xyes; then
-  DEFAULT_SAVE_PATH=".;$FREECIV_STORAGE_DIR/saves"
+  DEFAULT_SAVE_PATH=".;$FREECIV_STORAGE_DIR\\\\\\\\saves"
   if test x$crosser = xyes ; then
     FC_CONF_PATH="../etc/freeciv"
     
DEFAULT_DATA_PATH=".;data;$FREECIV_STORAGE_DIR/$DATASUBDIR;$datadir/freeciv;../share/freeciv"
     
DEFAULT_SCENARIO_PATH=".;data/scenarios;$FREECIV_STORAGE_DIR/$DATASUBDIR/scenarios;$FREECIV_STORAGE_DIR/scenarios;$datadir/freeciv/scenarios;../share/freeciv/scenarios"
   else
-    FC_CONF_PATH="etc/freeciv"
-    
DEFAULT_DATA_PATH=".;data;$FREECIV_STORAGE_DIR/$DATASUBDIR;$datadir/freeciv"
-    
DEFAULT_SCENARIO_PATH=".;data/scenarios;$FREECIV_STORAGE_DIR/$DATASUBDIR/scenarios;$FREECIV_STORAGE_DIR/scenarios;$datadir/freeciv/scenarios"
+    FC_CONF_PATH="etc\\\\\\\\freeciv"
+    
DEFAULT_DATA_PATH=".;data;$FREECIV_STORAGE_DIR\\\\\\\\$DATASUBDIR;$datadir\\\\\\\\freeciv"
+    
DEFAULT_SCENARIO_PATH=".;data\\\\\\\\scenarios;$FREECIV_STORAGE_DIR\\\\\\\\$DATASUBDIR\\\\\\\\scenarios;$FREECIV_STORAGE_DIR\\\\\\\\scenarios;$datadir\\\\\\\\freeciv\\\\\\\\scenarios"
   fi
 else
   FC_CONF_PATH="$sysconfdir/freeciv"

Modified: trunk/server/gamehand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/gamehand.c?rev=32367&r1=32366&r2=32367&view=diff
==============================================================================
--- trunk/server/gamehand.c     (original)
+++ trunk/server/gamehand.c     Mon Apr 11 22:28:07 2016
@@ -53,6 +53,17 @@
 
 #define CHALLENGE_ROOT "challenge"
 
+#ifndef DIR_SEPARATOR
+#if defined(WIN32_NATIVE) || defined(_WIN32) || defined(__WIN32__) || 
defined(__EMX__) || defined(__DJGPP__)
+  /* Win32, OS/2, DOS */
+# define DIR_SEPARATOR "\\"
+# define DIR_SEPARATOR_CHAR '\\'
+#else
+  /* Unix */
+# define DIR_SEPARATOR "/"
+# define DIR_SEPARATOR_CHAR '/'
+#endif
+#endif
 
 #define SPECLIST_TAG startpos
 #define SPECLIST_TYPE struct startpos
@@ -1041,7 +1052,7 @@
     return NULL;
   }
 
-  fc_snprintf(fullname, sizeof(fullname), "%s/%s", sdir, cname);
+  fc_snprintf(fullname, sizeof(fullname), "%s" DIR_SEPARATOR "%s", sdir, 
cname);
 
   return fullname;
 }

Modified: trunk/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/shared.c?rev=32367&r1=32366&r2=32367&view=diff
==============================================================================
--- trunk/utility/shared.c      (original)
+++ trunk/utility/shared.c      Mon Apr 11 22:28:07 2016
@@ -79,24 +79,36 @@
 #endif
 #endif
 
+#ifndef DIR_SEPARATOR
+#if defined(WIN32_NATIVE) || defined(_WIN32) || defined(__WIN32__) || 
defined(__EMX__) || defined(__DJGPP__)
+  /* Win32, OS/2, DOS */
+# define DIR_SEPARATOR "\\"
+# define DIR_SEPARATOR_CHAR '\\'
+#else
+  /* Unix */
+# define DIR_SEPARATOR "/"
+# define DIR_SEPARATOR_CHAR '/'
+#endif
+#endif
+
 #define PARENT_DIR_OPERATOR ".."
 
 /* If no default data path is defined use the default default one */
 #ifndef DEFAULT_DATA_PATH
 #define DEFAULT_DATA_PATH "." PATH_SEPARATOR \
                           "data" PATH_SEPARATOR \
-                          FREECIV_STORAGE_DIR DATASUBDIR
+                          FREECIV_STORAGE_DIR DIR_SEPARATOR DATASUBDIR
 #endif
 #ifndef DEFAULT_SAVE_PATH
 #define DEFAULT_SAVE_PATH "." PATH_SEPARATOR \
-                          FREECIV_STORAGE_DIR "/saves"
+                          FREECIV_STORAGE_DIR DIR_SEPARATOR "saves"
 #endif
 #ifndef DEFAULT_SCENARIO_PATH
 #define DEFAULT_SCENARIO_PATH                          \
   "." PATH_SEPARATOR                                   \
-  "data/scenarios" PATH_SEPARATOR                      \
-  FREECIV_STORAGE_DIR DATASUBDIR "/scenarios" PATH_SEPARATOR \
-  FREECIV_STORAGE_DIR "/scenarios"
+  "data" DIR_SEPARATOR "scenarios" PATH_SEPARATOR                      \
+  FREECIV_STORAGE_DIR DATASUBDIR DIR_SEPARATOR "scenarios" PATH_SEPARATOR \
+  FREECIV_STORAGE_DIR DIR_SEPARATOR "scenarios"
 #endif /* DEFAULT_SCENARIO_PATH */
 
 /* environment */
@@ -984,15 +996,15 @@
 
   tok = skip_leading_spaces(tok_in);
   remove_trailing_spaces(tok);
-  if (strcmp(tok, "/") != 0) {
-    remove_trailing_char(tok, '/');
+  if (strcmp(tok, DIR_SEPARATOR) != 0) {
+    remove_trailing_char(tok, DIR_SEPARATOR_CHAR);
   }
 
   i = strlen(tok);
   if (tok[0] == '~') {
-    if (i > 1 && tok[1] != '/') {
+    if (i > 1 && tok[1] != DIR_SEPARATOR_CHAR) {
       log_error("For \"%s\" in path cannot expand '~'"
-                " except as '~/'; ignoring", tok);
+                " except as '~" DIR_SEPARATOR "'; ignoring", tok);
       i = 0;  /* skip this one */
     } else {
       char *home = user_home_dir();
@@ -1196,7 +1208,7 @@
   struct strvec *files = strvec_new();
   size_t suffix_len = strlen(suffix);
 
-  fc_assert_ret_val(!strchr(suffix, '/'), NULL);
+  fc_assert_ret_val(!strchr(suffix, DIR_SEPARATOR_CHAR), NULL);
 
   if (NULL == dirs) {
     return files;
@@ -1267,6 +1279,13 @@
 ***************************************************************************/
 const char *fileinfoname(const struct strvec *dirs, const char *filename)
 {
+#ifdef WIN32_NATIVE
+  char fnbuf[strlen(filename) + 1];
+  int i;
+#else  /* WIN32_NATIVE */
+  const char *fnbuf = filename;
+#endif /* WIN32_NATIVE */
+
   if (NULL == dirs) {
     return NULL;
   }
@@ -1287,10 +1306,21 @@
     return astr_str(&realfile);
   }
 
+#ifdef WIN32_NATIVE
+  for (i = 0; filename[i] != '\0'; i++) {
+    if (filename[i] == '/') {
+      fnbuf[i] = DIR_SEPARATOR_CHAR;
+    } else {
+      fnbuf[i] = filename[i];
+    }
+  }
+  fnbuf[i] = '\0';
+#endif /* WIN32_NATIVE */
+
   strvec_iterate(dirs, dirname) {
     struct stat buf;    /* see if we can open the file or directory */
 
-    astr_set(&realfile, "%s/%s", dirname, filename);
+    astr_set(&realfile, "%s" DIR_SEPARATOR "%s", dirname, fnbuf);
     if (fc_stat(astr_str(&realfile), &buf) == 0) {
       return astr_str(&realfile);
     }
@@ -1824,8 +1854,8 @@
 ***************************************************************************/
 void interpret_tilde(char* buf, size_t buf_size, const char* filename)
 {
-  if (filename[0] == '~' && filename[1] == '/') {
-    fc_snprintf(buf, buf_size, "%s/%s", user_home_dir(), filename + 2);
+  if (filename[0] == '~' && filename[1] == DIR_SEPARATOR_CHAR) {
+    fc_snprintf(buf, buf_size, "%s" DIR_SEPARATOR "%s", user_home_dir(), 
filename + 2);
   } else if (filename[0] == '~' && filename[1] == '\0') {
     strncpy(buf, user_home_dir(), buf_size);
   } else  {
@@ -1841,7 +1871,7 @@
 ***************************************************************************/
 char *interpret_tilde_alloc(const char* filename)
 {
-  if (filename[0] == '~' && filename[1] == '/') {
+  if (filename[0] == '~' && filename[1] == DIR_SEPARATOR_CHAR) {
     const char *home = user_home_dir();
     size_t sz;
     char *buf;
@@ -1868,7 +1898,7 @@
   fc_assert_ret_val(NULL != filepath, NULL);
 
   for (j = strlen(filepath); j >= 0; j--) {
-    if (filepath[j] == '/') {
+    if (filepath[j] == DIR_SEPARATOR_CHAR) {
       return &filepath[j+1];
     }
   }
@@ -1887,7 +1917,7 @@
   path = interpret_tilde_alloc(pathname);
   dir = path;
   do {
-    dir = strchr(dir, '/');
+    dir = strchr(dir, DIR_SEPARATOR_CHAR);
     /* We set the current / with 0, and restore it afterwards */
     if (dir) {
       *dir = 0;
@@ -1902,7 +1932,7 @@
 #endif
 
     if (dir) {
-      *dir = '/';
+      *dir = DIR_SEPARATOR_CHAR;
       dir++;
     }
   } while (dir);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to