MCPcopy Create free account
hub / github.com/gwsw/less / pipe_data

Function pipe_data

lsystem.c:286–370  ·  view source on GitHub ↗

* Create a pipe to the given shell command. * Feed it the file contents between the positions spos and epos. */

(cmd, spos, epos)

Source from the content-addressed store, hash-verified

284 * Feed it the file contents between the positions spos and epos.
285 */
286 public int
287pipe_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 */

Callers 1

pipe_markFunction · 0.85

Calls 14

ch_seekFunction · 0.85
clear_botFunction · 0.85
putstrFunction · 0.85
deinitFunction · 0.85
flushFunction · 0.85
init_signalsFunction · 0.85
close_getchrFunction · 0.85
ch_forw_getFunction · 0.85
pcloseFunction · 0.85
open_getchrFunction · 0.85
initFunction · 0.85
winchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…