Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ds = array(
- 0 => array("pipe", "r"),
- 1 => array("pipe", "w"),
- 2 => array("pipe", "w")
- );
- $proc = array();
- $pipe_fd = array();
- define('STDIN_FILENO', 0);
- define('STDOUT_FILENO', 1);
- define('STDERR_FILENO', 2);
- if (!is_resource($proc[0] = proc_open("dot", $ds, $pipe_fd[0]))) {
- die("Error creating proc[0]");
- return;
- }
- $scriptname = tempnam("/tmp", "diff");
- $script = <<<SCRIPT
- N[$.nlp!=""] {
- double x, y, lx, ly;
- sscanf($.pos,"%f,%f",&x,&y);
- sscanf($.nlp,"%f,%f",&lx,&ly);
- $.xlp = sprintf("%.03f,%.03f",x+lx,y+ly);
- }
- SCRIPT;
- $script_fd = fopen($scriptname, "w");
- fwrite($script_fd, $script);
- fclose($script_fd);
- if (!is_resource($proc[1] = proc_open("gvpr -c -f $scriptname", $ds, $pipe_fd[1]))) {
- die("Error creating proc[1]");
- proc_close($proc[0]);
- return;
- }
- if (!is_resource($proc[2] = proc_open("neato -Tsvg -n2", $ds, $pipe_fd[2]))) {
- die("Error creating proc[2]");
- proc_close($proc[0]);
- proc_close($proc[1]);
- return;
- }
- echo "Send dot file\n";
- // Send dot file
- fwrite($pipe_fd[0][STDIN_FILENO], $dot);
- fclose($pipe_fd[0][STDIN_FILENO]);
- // Read from proc[0]
- $sc = stream_get_contents($pipe_fd[0][STDOUT_FILENO]);
- fclose($pipe_fd[0][STDOUT_FILENO]);
- fclose($pipe_fd[0][STDERR_FILENO]);
- // Write to proc[1]
- fwrite($pipe_fd[1][STDIN_FILENO], $sc);
- fclose($pipe_fd[1][STDIN_FILENO]);
- // Read from proc[1]
- $sc = stream_get_contents($pipe_fd[1][STDOUT_FILENO]);
- fclose($pipe_fd[1][STDOUT_FILENO]);
- fclose($pipe_fd[1][STDERR_FILENO]);
- // Write to proc[2]
- fwrite($pipe_fd[2][STDIN_FILENO], $sc);
- fclose($pipe_fd[2][STDIN_FILENO]);
- // Read from proc[2]
- $svg = stream_get_contents($pipe_fd[2][STDOUT_FILENO]);
- fclose($pipe_fd[2][STDOUT_FILENO]);
- fclose($pipe_fd[2][STDERR_FILENO]);
- proc_close($proc[0]);
- proc_close($proc[1]);
- proc_close($proc[2]);
- unlink($scriptname);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement