# HG changeset patch # User Matti Hamalainen # Date 1428237355 -10800 # Node ID cb23b23a2d8b1ffc61c9c6cc12f0e4f8ee1cdcb4 # Parent f650ae251d8c50a20cd60ace74b00086b2e412f5 Improve commandline parsing, fix some potential bug situations. diff -r f650ae251d8c -r cb23b23a2d8b faptool.php --- a/faptool.php Sun Mar 29 15:55:54 2015 +0300 +++ b/faptool.php Sun Apr 05 15:35:55 2015 +0300 @@ -729,7 +729,7 @@ // Act according to specified command -switch (substr(stCArgLC(1), 0, 3)) +switch (stCArgLC(1, 3)) { case "-?": case "--h": wtShowHelp(); @@ -810,12 +810,12 @@ // // Entry files handling // - $mode = substr(stCArgLC(2), 0, 3); + $mode = stCArgLC(2, 3); switch ($mode) { case "sta": case "lis": - $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; + $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) { @@ -830,7 +830,7 @@ break; case "unp": - if (($setPrefix = stCArg(3)) == "") + if (($setPrefix = stCArg(3)) === FALSE) die("Unpack needs a destination path.\n"); foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) @@ -842,7 +842,7 @@ break; case "rel": - if (($setPrefix = stCArg(3)) == "") + if (($setPrefix = stCArg(3)) === FALSE) die("Releases needs a destination path.\n"); if (!file_exists($setPrefix) || is_dir($setPrefix)) @@ -899,14 +899,14 @@ // // Preview files handling // - $mode = substr(stCArgLC(2), 0, 3); + $mode = stCArgLC(2, 3); switch ($mode) { case "gen": case "upd": case "sta": case "lis": - $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; + $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) { diff -r f650ae251d8c -r cb23b23a2d8b msitegen.inc.php --- a/msitegen.inc.php Sun Mar 29 15:55:54 2015 +0300 +++ b/msitegen.inc.php Sun Apr 05 15:35:55 2015 +0300 @@ -955,21 +955,27 @@ } -function stCArg($index) +function stCArg($index, $clip = FALSE) { global $argc, $argv; if ($index < $argc) - return $argv[$index]; + { + $str = $argv[$index]; + return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; + } else return FALSE; } -function stCArgLC($index) +function stCArgLC($index, $clip = FALSE) { global $argc, $argv; if ($index < $argc) - return strtolower($argv[$index]); + { + $str = strtolower($argv[$index]); + return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; + } else return FALSE; }