Advertisement
bueddl

Untitled

Apr 17th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1.  
  2.     $ds = array(
  3.         0 => array("pipe", "r"),
  4.         1 => array("pipe", "w"),
  5.         2 => array("pipe", "w")
  6.     );
  7.     $proc = array();
  8.     $pipe_fd = array();
  9.    
  10.     define('STDIN_FILENO', 0);
  11.     define('STDOUT_FILENO', 1);
  12.     define('STDERR_FILENO', 2);
  13.  
  14.     if (!is_resource($proc[0] = proc_open("dot", $ds, $pipe_fd[0]))) {
  15.         die("Error creating proc[0]");
  16.         return;
  17.     }
  18.    
  19.     $scriptname = tempnam("/tmp", "diff");
  20.     $script = <<<SCRIPT
  21. N[$.nlp!=""] {
  22.     double x, y, lx, ly;
  23.     sscanf($.pos,"%f,%f",&x,&y);
  24.     sscanf($.nlp,"%f,%f",&lx,&ly);
  25.     $.xlp = sprintf("%.03f,%.03f",x+lx,y+ly);
  26. }
  27. SCRIPT;
  28.     $script_fd = fopen($scriptname, "w");
  29.     fwrite($script_fd, $script);
  30.     fclose($script_fd);
  31.    
  32.     if (!is_resource($proc[1] = proc_open("gvpr -c -f $scriptname", $ds, $pipe_fd[1]))) {
  33.         die("Error creating proc[1]");
  34.         proc_close($proc[0]);
  35.         return;
  36.     }
  37.    
  38.     if (!is_resource($proc[2] = proc_open("neato -Tsvg -n2", $ds, $pipe_fd[2]))) {
  39.         die("Error creating proc[2]");
  40.         proc_close($proc[0]);
  41.         proc_close($proc[1]);
  42.         return;
  43.     }
  44.    
  45.     echo "Send dot file\n";
  46.     // Send dot file
  47.     fwrite($pipe_fd[0][STDIN_FILENO], $dot);
  48.     fclose($pipe_fd[0][STDIN_FILENO]);
  49.    
  50.     // Read from proc[0]
  51.     $sc = stream_get_contents($pipe_fd[0][STDOUT_FILENO]);
  52.     fclose($pipe_fd[0][STDOUT_FILENO]);
  53.     fclose($pipe_fd[0][STDERR_FILENO]);
  54.    
  55.     // Write to proc[1]
  56.     fwrite($pipe_fd[1][STDIN_FILENO], $sc);
  57.     fclose($pipe_fd[1][STDIN_FILENO]);
  58.    
  59.     // Read from proc[1]
  60.     $sc = stream_get_contents($pipe_fd[1][STDOUT_FILENO]);
  61.     fclose($pipe_fd[1][STDOUT_FILENO]);
  62.     fclose($pipe_fd[1][STDERR_FILENO]);
  63.    
  64.     // Write to proc[2]
  65.     fwrite($pipe_fd[2][STDIN_FILENO], $sc);
  66.     fclose($pipe_fd[2][STDIN_FILENO]);
  67.    
  68.     // Read from proc[2]
  69.     $svg = stream_get_contents($pipe_fd[2][STDOUT_FILENO]);
  70.     fclose($pipe_fd[2][STDOUT_FILENO]);
  71.     fclose($pipe_fd[2][STDERR_FILENO]);
  72.    
  73.     proc_close($proc[0]);
  74.     proc_close($proc[1]);
  75.     proc_close($proc[2]);
  76.     unlink($scriptname);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement