changeset 242:72aea6651857 gmap2

Improve configuration.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 17 Mar 2014 02:45:29 +0200
parents f0a36bb9a334
children 08b2cc0350d0
files tools/makegmaps.php
diffstat 1 files changed, 40 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/tools/makegmaps.php	Mon Mar 17 02:11:08 2014 +0200
+++ b/tools/makegmaps.php	Mon Mar 17 02:45:29 2014 +0200
@@ -6,14 +6,18 @@
 
 // Paths and files
 $cfgDefaults = array(
-  "binConvert" => array(1, "convert", ""),
-  "binMercurial" => array(1, "hg", ""),
-  "binMake" => array(1, "make", ""),
+  "binConvert" => array(1, "convert", "Path of 'convert' binary from ImageMagick or GraphicsMagick."),
+  "binMercurial" => array(1, "hg", "Path of 'hg' binary of Mercurial DVCS."),
+  "binMake" => array(1, "make", "Path of 'make', preferably GNU make."),
 
-$cfg["pathMapUtils"] = "maputils/";
-$pathImageCache = "cache/";
-$pathMarkerData = "../";
-$pathTileData = "../tiles/";
+  "pathMapUtils" => array(2, "maputils/", "Path for maputils directory tree."),
+  "pathImageCache" => array(2, "cache/", "Image cache directory."),
+  "pathMarkerData" => array(2, "../", "Path to marker data files."),
+  "pathTileData" => array(2, "../tiles/", "Path to map tiles directory structure."),
+
+  "pathRawMaps" => array(3, FALSE, "Path to the raw ASCII maps."),
+  "pathLocFiles" => array(3, FALSE, "Path to the location data LOC files."),
+  "worldConfig" => array(3, FALSE, "Path of the world configuration file 'world.inc.php' from MapUtils."),
 );
 
 
@@ -149,7 +153,7 @@
   $valid = FALSE;
   while (!$valid)
   {
-    echo $msg;
+    echo $msg."\n".($default !== FALSE ? "[".$default."]" : "")."> ";
     $sprompt = strtolower(trim(fgets(STDIN)));
 
     if ($sprompt == "")
@@ -161,6 +165,18 @@
 }
 
 
+function stValidateNotEmpty($val)
+{
+  if ($val == "")
+  {
+    echo "The value can't be empty.\n";
+    return FALSE;
+  }
+  else
+    return TRUE;
+}
+
+
 function stValidateURLPrefix($sprefix)
 {
   if (substr($sprefix, 0, 7) != "http://" &&
@@ -200,11 +216,14 @@
 
 function stQueryConfigItems($level)
 {
-  global $cfgDefaults;
+  global $cfgDefaults, $cfg;
   foreach ($cfgDefaults as $citem => $cdata)
   {
     if ($cdata[0] == $level)
-      $cfg[$citem] = stInputPrompt($cdata[2], $cdata[1], "stValidateNotEmpty");
+    {
+      $def = ($cdata[1] !== FALSE) ? $cdata[1] : $cfg[$citem];
+      $cfg[$citem] = stInputPrompt($cdata[2], $def, "stValidateNotEmpty");
+    }
   }
 }
 
@@ -230,12 +249,21 @@
     "You will be asked some information this time, which will be\n".
     "and saved for later use in file '".$gmapsConfig."'\n";
 
+  stQueryConfigItems(1);
+  stQueryConfigItems(2);
+
+  $cfg["pathRawMaps"] = $cfg["pathMapUtils"]."maps/";
+  $cfg["pathLocFiles"] = $cfg["pathMapUtils"]."maps/";
+  $cfg["worldConfig"] = $cfg["pathMapUtils"]."www/world.inc.php";
+
+  stQueryConfigItems(3);
+
   $sdone = FALSE;
   while (!$sdone)
   {
     $cfg["urlTilePrefix"] = stInputPrompt("Enter URL prefix for tiles:\n", FALSE, "stValidateURLPrefix");
     $sdone = stYesNoPrompt("The URL prefix to be used is \"".$cfg["urlTilePrefix"]."\", e.g.\n".
-      "htaccess to be created would be: \"".$cfg["urlTilePrefix"].$spath."sea.png\"\n".
+      "htaccess to be created would be: \"".$cfg["urlTilePrefix"]."sea.png\"\n".
       "Is this correct?");
     echo "\n";
   }
@@ -370,7 +398,7 @@
 // Export tradelane waypoint data
 //
 if (!isset($tradelanePoints))
-  die("PHP array \$tradelanePoints not set, '$cfg["worldConfig"]' is old or incompatible.\n");
+  die("PHP array \$tradelanePoints not set, '".$cfg["worldConfig"]."' is old or incompatible.\n");
 
 echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n";