int main(int argc, char ** argv) { struct cmdlineInfo cmdline; FILE * convFileP; const char * tempfileName; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); if (cmdline.dump) convFileP = pm_openw(cmdline.dump); else pm_make_tmpfile(&convFileP, &tempfileName); writeConvolutionImage(convFileP, cmdline.width, cmdline.height, PGM_FORMAT); pm_close(convFileP); if (cmdline.dump) { /* We're done. Convolution image is in user's file */ } else { pm_system_lp("pnmconvol", NULL, NULL, NULL, NULL, "pnmconvol", tempfileName, cmdline.inputFilespec, NULL); unlink(tempfileName); strfree(tempfileName); } return 0; }
void pm_system(void stdinFeeder(int, void *), void * const feederParm, void stdoutAccepter(int, void *), void * const accepterParm, const char * const shellCommand) { /*---------------------------------------------------------------------------- Run a shell and have it run command 'shellCommand'. Feed its Standard Input with a pipe, which is fed by the routine 'stdinFeeder' with parameter 'feederParm'. Process its Standard Output with the routine 'stdoutAccepter' with parameter 'accepterParm'. But if 'stdinFeeder' is NULL, just feed the shell our own Standard Input. And if 'stdoutFeeder' is NULL, just send its Standard Output to our own Standard Output. -----------------------------------------------------------------------------*/ pm_system_lp("/bin/sh", stdinFeeder, feederParm, stdoutAccepter, accepterParm, "sh", "-c", shellCommand, NULL); }