430{
  431  int pid;
  432  int in_fd[2];
  433  int out_fd[2];
  434  fd_set fdset;
  435  fd_set readset;
  436  struct timeval tv;
  437  int sel, 
index, state;
 
  438  char buffer[256];
  439  char c;
  440 
  441  if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
  442  {
  443    perror ("could open pipe");
  445  }
  446 
  447  pid = fork ();
  448  if (pid == 0)
  449  {
  450    si_close (0); si_dup2 (in_fd[0],0);   
  451    si_close (1); si_dup2 (out_fd[1],1);  
  452    si_close (2); si_dup2 (out_fd[1],2);  
  453 
  454    execvp (args[0], args);      
  455    perror ("exec failed");
  457  }
  458  else if (pid == -1)
  459  {
  460    perror ("could not fork");
  462  }
  463 
  464  FD_ZERO (&fdset);
  465  FD_SET (out_fd[0], &fdset);
  466 
  467  si_write (in_fd[1], "backtrace\n", 10);
  468  si_write (in_fd[1], "p si_stop_stack_trace_x = 0\n", 28);
  469  si_write (in_fd[1], "quit\n", 5);
  470 
  472  state = 0;
  473 
  475  {
  476    readset = fdset;
  477    tv.tv_sec = 1;
  478    tv.tv_usec = 0;
  479 
  480    sel = si_select (FD_SETSIZE, &readset, 
NULL, 
NULL, &tv);
 
  481    if (sel == -1)
  482      break;
  483 
  484    if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
  485    {
  486      if (si_read (out_fd[0], &c, 1))
  487      {
  488        switch (state)
  489        {
  490          case 0:
  491            if (c == '#')
  492            {
  493              state = 1;
  496            }
  497            break;
  498          case 1:
  500            if ((c == '\n') || (c == '\r'))
  501            {
  503              fputs (buffer,stderr);
  504              state = 0;
  506            }
  507            break;
  508          default:
  509            break;
  510        }
  511      }
  512    }
  514      break;
  515  }
  516 
  517  si_close (in_fd[0]);
  518  si_close (in_fd[1]);
  519  si_close (out_fd[0]);
  520  si_close (out_fd[1]);
  522}
static int index(p_Length length, p_Ord ord)