--- drupal.sh.txt	2006-09-12 06:31:07.329829500 +0200
+++ drupal.sh_.txt	2007-02-22 17:52:14.472578500 +0100
@@ -68,7 +68,9 @@ while ($param = array_shift($_SERVER['ar
       $path = array_shift($_SERVER['argv']);
       if (is_dir($path)) {
         chdir($path);
-        echo "cwd changed to: {$path}\n";
+        if ($_verbose_mode) {
+          echo "cwd changed to: {$path}\n";
+        }
       }
       else {
         echo "\nERROR: {$path} not found.\n\n";
@@ -81,48 +83,36 @@ while ($param = array_shift($_SERVER['ar
       }
       else {
         // parse the URI
-        // disregarding 'http://', it's only for usability
-        preg_match('@^(?:http://)?([^/]+)(.+)@i', $param, $matches);
+        $path = parse_url($param);
         
         // site name
-        $_SERVER['HTTP_HOST'] = $matches[1];
-        if ($_verbose_mode) {
-          echo "Site set to: {$_SERVER['HTTP_HOST']}\n";
-        }
+        if (isset($path['host'])) {
+          $_SERVER['HTTP_HOST'] = $path['host'];
         
-        // custom script or file invocation
-        if (preg_match('@^/[^\?]+@', $matches[2], $file)) {
-          // alter invocation if URI contains a custom file
-          // remove first slash, since we're already in cwd
-          $cmd = $_SERVER['PHP_SELF'] = substr( $file[0], 1);
           if ($_verbose_mode) {
-            echo "Script name set to: {$cmd}\n";
+            echo "Site set to: {$_SERVER['HTTP_HOST']}\n";
+          }
+        }
+        
+        if (isset($path['query'])) {
+          parse_str($path['query'], $_GET);
+          $_REQUEST = $_GET;
+          if ($_verbose_mode && isset($_GET['q'])) {
+            echo "Path set to: {$_GET['q']}\n";
           }
-        } else if (file_exists( substr($matches[2], 1) )) {
-          // test to invoke a real file
-          // remove first slash, since we're already in cwd
-          $cmd = $_SERVER['PHP_SELF'] = substr($matches[2], 1);
+        }
+        if (isset($path['path']) && file_exists(substr($path['path'], 1))) {
+          $cmd = substr($_SERVER['PHP_SELF'] = $path['path'], 1);
           if ($_verbose_mode) {
             echo "Script name set to: {$cmd}\n";
           }
         }
-        
-        // path (clean urls)
-        // parse only if it is not passed through GET
-        if (!isset($_GET['q'])) {
-          if (strpos( $matches[2], 'q=' )) {
-            // try to match a path in a custom script
-            preg_match('@q=([^\&]+)@', $matches[2], $path);
-            if (substr( $path[1], 0 != '/')) {
-              $path[1] = '/'. $path[1];
+        elseif (isset($path['path'])) {
+          if (!isset($_GET['q'])) {
+            $_REQUEST['q'] = $_GET['q'] = $path['path'];
+            if ($_verbose_mode) {
+              echo "Path set to: {$_GET['q']}\n";
             }
-            $_REQUEST['q'] = $_GET['q'] = $path[1];
-          } else {
-            // assume clean url path
-            $_REQUEST['q'] = $_GET['q'] = $matches[2];
-          }
-          if ($_verbose_mode) {
-            echo "Path set to: {$_GET['q']}\n";
           }
         }
       }
