translate.c 804 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "common.h"
  2. #include "send.h"
  3. /* pipe an address through a command to translate it */
  4. extern dest *
  5. translate(dest *dp)
  6. {
  7. process *pp;
  8. String *line;
  9. dest *rv;
  10. char *cp;
  11. int n;
  12. pp = proc_start(s_to_c(dp->repl1), (stream *)0, outstream(), outstream(), 1, 0);
  13. if (pp == 0) {
  14. dp->status = d_resource;
  15. return 0;
  16. }
  17. line = s_new();
  18. for(;;) {
  19. cp = Brdline(pp->std[1]->fp, '\n');
  20. if(cp == 0)
  21. break;
  22. if(strncmp(cp, "_nosummary_", 11) == 0){
  23. nosummary = 1;
  24. continue;
  25. }
  26. n = Blinelen(pp->std[1]->fp);
  27. cp[n-1] = ' ';
  28. s_nappend(line, cp, n);
  29. }
  30. rv = s_to_dest(s_restart(line), dp);
  31. s_restart(line);
  32. while(s_read_line(pp->std[2]->fp, line))
  33. ;
  34. if ((dp->pstat = proc_wait(pp)) != 0) {
  35. dp->repl2 = line;
  36. rv = 0;
  37. } else
  38. s_free(line);
  39. proc_free(pp);
  40. return rv;
  41. }