* Create a pipe to the given shell command. * Feed it the file contents between the positions spos and epos. */
(cmd, spos, epos)
| 284 | * Feed it the file contents between the positions spos and epos. |
| 285 | */ |
| 286 | public int |
| 287 | pipe_data(cmd, spos, epos) |
| 288 | char *cmd; |
| 289 | POSITION spos; |
| 290 | POSITION epos; |
| 291 | { |
| 292 | FILE *f; |
| 293 | int c; |
| 294 | |
| 295 | /* |
| 296 | * This is structured much like lsystem(). |
| 297 | * Since we're running a shell program, we must be careful |
| 298 | * to perform the necessary deinitialization before running |
| 299 | * the command, and reinitialization after it. |
| 300 | */ |
| 301 | if (ch_seek(spos) != 0) |
| 302 | { |
| 303 | error("Cannot seek to start position", NULL_PARG); |
| 304 | return (-1); |
| 305 | } |
| 306 | |
| 307 | if ((f = popen(cmd, "w")) == NULL) |
| 308 | { |
| 309 | error("Cannot create pipe", NULL_PARG); |
| 310 | return (-1); |
| 311 | } |
| 312 | clear_bot(); |
| 313 | putstr("!"); |
| 314 | putstr(cmd); |
| 315 | putstr("\n"); |
| 316 | |
| 317 | deinit(); |
| 318 | flush(); |
| 319 | raw_mode(0); |
| 320 | init_signals(0); |
| 321 | #if MSDOS_COMPILER==WIN32C |
| 322 | close_getchr(); |
| 323 | #endif |
| 324 | #ifdef SIGPIPE |
| 325 | LSIGNAL(SIGPIPE, SIG_IGN); |
| 326 | #endif |
| 327 | |
| 328 | c = EOI; |
| 329 | while (epos == NULL_POSITION || spos++ <= epos) |
| 330 | { |
| 331 | /* |
| 332 | * Read a character from the file and give it to the pipe. |
| 333 | */ |
| 334 | c = ch_forw_get(); |
| 335 | if (c == EOI) |
| 336 | break; |
| 337 | if (putc(c, f) == EOF) |
| 338 | break; |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | * Finish up the last line. |
| 343 | */ |
no test coverage detected
searching dependent graphs…