summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/create-test.php
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/phpdbg/create-test.php')
-rwxr-xr-xsapi/phpdbg/create-test.php136
1 files changed, 68 insertions, 68 deletions
diff --git a/sapi/phpdbg/create-test.php b/sapi/phpdbg/create-test.php
index e5f7cfe2e9..3e2c8f0437 100755
--- a/sapi/phpdbg/create-test.php
+++ b/sapi/phpdbg/create-test.php
@@ -32,37 +32,37 @@ $file = "";
$cmdargv = "";
if (isset($argc) && $argc > 1) {
- $post_ddash = false;
- for ($i = 1; $i < $argc; $i++) {
- if ($argv[$i][0] == "-" && !$post_ddash) {
- switch (substr($argv[$i], 1)) {
- case "p":
- $phpdbg = $argv[++$i];
- break;
- case "n":
- $pass_options .= " -n";
- break;
- case "d":
- $pass_options .= " -d ".escapeshellarg($argv[++$i]);
- $ini[] = $argv[$i];
- break;
- case "-":
- $post_ddash = true;
- break;
- }
- } else {
- $real_argv[] = $argv[$i];
- }
- }
- if (isset($real_argv[0])) {
- $file = realpath($real_argv[0]);
- $cmdargv = implode(" ", array_map("escapeshellarg", array_slice($real_argv, 1)));
- }
+ $post_ddash = false;
+ for ($i = 1; $i < $argc; $i++) {
+ if ($argv[$i][0] == "-" && !$post_ddash) {
+ switch (substr($argv[$i], 1)) {
+ case "p":
+ $phpdbg = $argv[++$i];
+ break;
+ case "n":
+ $pass_options .= " -n";
+ break;
+ case "d":
+ $pass_options .= " -d ".escapeshellarg($argv[++$i]);
+ $ini[] = $argv[$i];
+ break;
+ case "-":
+ $post_ddash = true;
+ break;
+ }
+ } else {
+ $real_argv[] = $argv[$i];
+ }
+ }
+ if (isset($real_argv[0])) {
+ $file = realpath($real_argv[0]);
+ $cmdargv = implode(" ", array_map("escapeshellarg", array_slice($real_argv, 1)));
+ }
}
$proc = proc_open("$phpdbg $pass_options $file -- $cmdargv", [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes);
if (!$proc) {
- die("Couldn't start phpdbg\n");
+ die("Couldn't start phpdbg\n");
}
$input = $output = "";
@@ -70,47 +70,47 @@ $input = $output = "";
stream_set_blocking(STDIN, false);
do {
- $r = [$pipes[1], STDIN];
- $w = $e = null;
- $n = @stream_select($r, $w, $e, null);
-
- if ($n > 0) {
- if ("" != $in = fread(STDIN, 1024)) {
- $input .= $in;
- fwrite($pipes[0], $in);
- continue;
- }
-
- if (feof(STDIN)) {
- die("stdin closed?!\n");
- }
-
- if (feof($pipes[1])) {
- $n = false;
- } else {
- $output .= $c = fgetc($pipes[1]);
- echo $c;
- }
- }
+ $r = [$pipes[1], STDIN];
+ $w = $e = null;
+ $n = @stream_select($r, $w, $e, null);
+
+ if ($n > 0) {
+ if ("" != $in = fread(STDIN, 1024)) {
+ $input .= $in;
+ fwrite($pipes[0], $in);
+ continue;
+ }
+
+ if (feof(STDIN)) {
+ die("stdin closed?!\n");
+ }
+
+ if (feof($pipes[1])) {
+ $n = false;
+ } else {
+ $output .= $c = fgetc($pipes[1]);
+ echo $c;
+ }
+ }
} while ($n !== false);
stream_set_blocking(STDIN, true);
print "\n";
if (!isset($name)) {
- print "Specify the test description: ";
- $desc = trim(fgets(STDIN));
+ print "Specify the test description: ";
+ $desc = trim(fgets(STDIN));
}
while (!isset($testfile)) {
- print "Specify the test file name (leave empty to write to stderr): ";
- $testfile = trim(fgets(STDIN));
- if ($testfile != "" && file_exists($testfile)) {
- print "That file already exists. Type y or yes to overwrite: ";
- $y = trim(fgets(STDIN));
- if ($y !== "y" && $y !== "yes") {
- unset($testfile);
- }
- }
+ print "Specify the test file name (leave empty to write to stderr): ";
+ $testfile = trim(fgets(STDIN));
+ if ($testfile != "" && file_exists($testfile)) {
+ print "That file already exists. Type y or yes to overwrite: ";
+ $y = trim(fgets(STDIN));
+ if ($y !== "y" && $y !== "yes") {
+ unset($testfile);
+ }
+ }
}
$output = str_replace("string(".strlen($file).") \"$file\"", 'string(%d) "%s"', $output);
@@ -127,24 +127,24 @@ $output
TEST;
if (!empty($ini)) {
- $testdata .= "\n--INI--\n".implode("\n", $ini);
+ $testdata .= "\n--INI--\n".implode("\n", $ini);
}
if ($cmdargv != "") {
- $testdata .= "\n--ARGS--\n$cmdargv";
+ $testdata .= "\n--ARGS--\n$cmdargv";
}
if ($file != "") {
- $testdata .= "\n--FILE--\n".file_get_contents($file);
+ $testdata .= "\n--FILE--\n".file_get_contents($file);
}
if ($testfile == "") {
- print "\n";
+ print "\n";
} elseif (file_put_contents($testfile, $testdata)) {
- print "Test saved to $testfile\n";
+ print "Test saved to $testfile\n";
} else {
- print "The test could not be saved to $testfile; outputting on stderr now\n";
- $testfile = "";
+ print "The test could not be saved to $testfile; outputting on stderr now\n";
+ $testfile = "";
}
if ($testfile == "") {
- fwrite(STDERR, $testdata);
+ fwrite(STDERR, $testdata);
}