/*--------------------------------------*/ /* ps2pcl.c --- PostScript to HP filter */ /* Written by Tim Edwards, 7/14/94 */ /* Modified 12/6/96 with code from */ /* text2pcl.c by Philippe Pouliquen */ /*--------------------------------------*/ /* Set the following to point to the GhostScript binary */ #define GS "/usr/local/bin/gs" /* If waitpid() returns a warning on compilation, check the */ /* type cast of variable status and see if BSD needs to be defined */ #include #include #include #include main() { int ip1, ip2, pid; #ifdef BSD union wait status; #else int status; #endif static char *argv[] = {"gs", "-q", "-sDEVICE=cdj550", "-sOUTPUTFILE=-", "-dBitsPerPixel=32", "-dDepletion=2", "-", NULL}; if ((ip1 = getchar()) == '%') { if ((ip2 = getchar()) == '!') { rewind(stdin); pid = fork(); if (pid == 0) { fprintf(stderr, "Running ghostscript.\n"); execve(GS, argv, NULL); fprintf(stderr, "execve has exited with error %d\n", errno); } else { waitpid(pid, &status, 0); fprintf(stderr, "ghostscript is done\n"); exit(0); } } else ungetc(ip2, stdin); } ungetc(ip1, stdin); /* text2pcl.c inserted here */ /* setup to notify PCL-compatible printer of ASCII text dump */ putchar(27); putchar(38); putchar(108); putchar('7'); putchar(68+32); putchar('6'); putchar('6'); putchar(70); /* feed file directly to printer */ while((ip1 = getchar()) != EOF) { /* replace newline with CR+LF */ if (ip1 == '\n') { putchar(13); putchar(10); } else { putchar(ip1); } } putchar(12); }