# HG changeset patch # User Matti Hamalainen # Date 1395017129 -7200 # Node ID 72aea665185765ba5ad535a0d38a505dc84af71a # Parent f0a36bb9a334bbeb9f05ac60d2e76777fcefc494 Improve configuration. diff -r f0a36bb9a334 -r 72aea6651857 tools/makegmaps.php --- 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";