Author: cazfi
Date: Thu Jun 16 18:45:15 2016
New Revision: 32872

URL: http://svn.gna.org/viewcvs/freeciv?rev=32872&view=rev
Log:
Made modpack installer to respect dir separator definition.

See bug #24677

Modified:
    branches/S2_6/tools/download.c
    branches/S2_6/tools/mpcmdline.c
    branches/S2_6/utility/shared.c
    branches/S2_6/utility/shared.h

Modified: branches/S2_6/tools/download.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/download.c?rev=32872&r1=32871&r2=32872&view=diff
==============================================================================
--- branches/S2_6/tools/download.c      (original)
+++ branches/S2_6/tools/download.c      Thu Jun 16 18:45:15 2016
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -33,6 +33,7 @@
 #include "capability.h"
 #include "fcintl.h"
 #include "log.h"
+#include "mem.h"
 #include "netfile.h"
 #include "registry.h"
 
@@ -167,10 +168,10 @@
 
   if (type == MPT_SCENARIO) {
     fc_snprintf(local_dir, sizeof(local_dir),
-                "%s/scenarios", fcmp->inst_prefix);
+                "%s" DIR_SEPARATOR "scenarios", fcmp->inst_prefix);
   } else {
     fc_snprintf(local_dir, sizeof(local_dir),
-                "%s/" DATASUBDIR, fcmp->inst_prefix);
+                "%s" DIR_SEPARATOR DATASUBDIR, fcmp->inst_prefix);
   }
 
   baseURLpart = secfile_lookup_str(control, "info.baseURL");
@@ -273,6 +274,13 @@
   filenbr = 0;
   for (filenbr = 0; filenbr < total_files; filenbr++) {
     const char *dest_name;
+
+#ifndef DIR_SEPARATOR_IS_DEFAULT
+    char *dest_name_copy;
+#else  /* DIR_SEPARATOR_IS_DEFAULT */
+#define dest_name_copy dest_name
+#endif /* DIR_SEPARATOR_IS_DEFAULT */
+
     int i;
     bool illegal_filename = FALSE;
 
@@ -286,6 +294,10 @@
       /* Missing dest name is ok, we just default to src_name */
       dest_name = src_name;
     }
+
+#ifndef DIR_SEPARATOR_IS_DEFAULT
+    dest_name_copy = fc_malloc(strlen(dest_name) + 1);
+#endif /* DIR_SEPARATOR_IS_DEFAULT */
 
     for (i = 0; dest_name[i] != '\0'; i++) {
       if (dest_name[i] == '.' && dest_name[i+1] == '.') {
@@ -299,12 +311,29 @@
         partial_failure = TRUE;
         illegal_filename = TRUE;
       }
-    }
+
+#ifndef DIR_SEPARATOR_IS_DEFAULT
+      if (dest_name[i] == '/') {
+        dest_name_copy[i] = DIR_SEPARATOR_CHAR;
+      } else {
+        dest_name_copy[i] = dest_name[i];
+      }
+#endif /* DIR_SEPARATOR_IS_DEFAULT */
+    }
+
+#ifndef DIR_SEPARATOR_IS_DEFAULT
+    dest_name_copy[i] = '\0';
+#endif /* DIR_SEPARATOR_IS_DEFAULT */
 
     if (!illegal_filename) {
       fc_snprintf(local_name, sizeof(local_name),
-                  "%s/%s", local_dir, dest_name);
-      for (i = strlen(local_name) - 1 ; local_name[i] != '/' ; i--) {
+                  "%s" DIR_SEPARATOR "%s", local_dir, dest_name_copy);
+
+#ifndef DIR_SEPARATOR_IS_DEFAULT
+      free(dest_name_copy);
+#endif /* DIR_SEPARATOR_IS_DEFAULT */
+
+      for (i = strlen(local_name) - 1 ; local_name[i] != DIR_SEPARATOR_CHAR ; 
i--) {
         /* Nothing */
       }
       local_name[i] = '\0';
@@ -312,7 +341,7 @@
         secfile_destroy(control);
         return _("Cannot create required directories");
       }
-      local_name[i] = '/';
+      local_name[i] = DIR_SEPARATOR_CHAR;
 
       if (mcb != NULL) {
         char buf[2048];
@@ -333,6 +362,10 @@
         }
         partial_failure = TRUE;
       }
+    } else {
+#ifndef DIR_SEPARATOR_IS_DEFAULT
+      free(dest_name_copy);
+#endif /* DIR_SEPARATOR_IS_DEFAULT */
     }
 
     if (pbcb != NULL) {

Modified: branches/S2_6/tools/mpcmdline.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpcmdline.c?rev=32872&r1=32871&r2=32872&view=diff
==============================================================================
--- branches/S2_6/tools/mpcmdline.c     (original)
+++ branches/S2_6/tools/mpcmdline.c     Thu Jun 16 18:45:15 2016
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -131,7 +131,7 @@
     } else {
       static char pfx_buf[500];
 
-      snprintf(pfx_buf, sizeof(pfx_buf), "%s/.freeciv", home);
+      snprintf(pfx_buf, sizeof(pfx_buf), "%s" DIR_SEPARATOR ".freeciv", home);
       fcmp.inst_prefix = pfx_buf;
     }
   }

Modified: branches/S2_6/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/shared.c?rev=32872&r1=32871&r2=32872&view=diff
==============================================================================
--- branches/S2_6/utility/shared.c      (original)
+++ branches/S2_6/utility/shared.c      Thu Jun 16 18:45:15 2016
@@ -1295,7 +1295,7 @@
     return astr_str(&realfile);
   }
 
-#ifdef WIN32_NATIVE
+#ifndef DIR_SEPARATOR_IS_DEFAULT
   for (i = 0; filename[i] != '\0'; i++) {
     if (filename[i] == '/') {
       fnbuf[i] = DIR_SEPARATOR_CHAR;
@@ -1304,7 +1304,7 @@
     }
   }
   fnbuf[i] = '\0';
-#endif /* WIN32_NATIVE */
+#endif /* DIR_SEPARATOR_IS_DEFAULT */
 
   strvec_iterate(dirs, dirname) {
     struct stat buf;    /* see if we can open the file or directory */

Modified: branches/S2_6/utility/shared.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/shared.h?rev=32872&r1=32871&r2=32872&view=diff
==============================================================================
--- branches/S2_6/utility/shared.h      (original)
+++ branches/S2_6/utility/shared.h      Thu Jun 16 18:45:15 2016
@@ -125,6 +125,7 @@
 # define DIR_SEPARATOR_CHAR '\\'
 #else
   /* Unix */
+# define DIR_SEPARATOR_IS_DEFAULT
 # define DIR_SEPARATOR "/"
 # define DIR_SEPARATOR_CHAR '/'
 #endif


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

Reply via email to