summaryrefslogtreecommitdiff
path: root/foomaticrip.c
diff options
context:
space:
mode:
authorDidier Raboud <didier@raboud.com>2010-07-19 15:56:58 +0200
committerDidier Raboud <didier@raboud.com>2010-07-19 15:56:58 +0200
commit1a03de334fd4e6aafb91b806ea35092a7774a8d7 (patch)
tree122dc48818d103149727c7212f3d551e63aa2039 /foomaticrip.c
parent7b7bb0240eda341c29d786e97f6ad7c52d10cac7 (diff)
Imported Upstream version 4.0.4upstream/4.0.4
Diffstat (limited to 'foomaticrip.c')
-rw-r--r--foomaticrip.c83
1 files changed, 66 insertions, 17 deletions
diff --git a/foomaticrip.c b/foomaticrip.c
index 8c5b352..b548b1e 100644
--- a/foomaticrip.c
+++ b/foomaticrip.c
@@ -1,3 +1,25 @@
+/* foomaticrip.c
+ *
+ * Copyright (C) 2008 Till Kamppeter <till.kamppeter@gmail.com>
+ * Copyright (C) 2008 Lars Uebernickel <larsuebernickel@gmx.de>
+ *
+ * This file is part of foomatic-rip.
+ *
+ * Foomatic-rip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Foomatic-rip is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
#include "foomaticrip.h"
#include "util.h"
@@ -965,10 +987,13 @@ int print_file(const char *filename, int convert)
n = fread(buf, 1, sizeof(buf) - 1, file);
buf[n] = '\0';
type = guess_file_type(buf, n, &startpos);
- if (startpos > 0) {
+ /* We do not use any JCL preceeded to the inputr data, as it is simply
+ the PJL commands from the PPD file, and these commands we can also
+ generate, end we even merge them with PJl from the driver */
+ /*if (startpos > 0) {
jobhasjcl = 1;
write_output(buf, startpos);
- }
+ }*/
if (file != stdin)
rewind(file);
@@ -983,26 +1008,48 @@ int print_file(const char *filename, int convert)
char pdf2ps_cmd[PATH_MAX];
FILE *out, *in;
int renderer_pid;
+ char tmpfilename[PATH_MAX] = "";
_log("Driver does not understand PDF input, "
"converting to PostScript\n");
pdfconvertedtops = 1;
+
+ /* If reading from stdin, write everything into a temporary file */
+ if (file == stdin)
+ {
+ int fd;
+ FILE *tmpfile;
+
+ snprintf(tmpfilename, PATH_MAX, "%s/foomatic-XXXXXX", temp_dir());
+ fd = mkstemp(tmpfilename);
+ if (fd < 0) {
+ _log("Could not create temporary file: %s\n", strerror(errno));
+ return EXIT_PRNERR_NORETRY_BAD_SETTINGS;
+ }
+ tmpfile = fdopen(fd, "r+");
+ copy_file(tmpfile, stdin, buf, n);
+ fclose(tmpfile);
+
+ filename = tmpfilename;
+ }
+
+ /* If the spooler is CUPS we remove the /usr/lib/cups/filter
+ (CUPS filter directory, can be different, but ends with
+ "/cups/filter") which CUPS adds to the beginning of $PATH,
+ so that Poppler's/XPDF's pdftops filter is called and not
+ the one of CUPS, as the one of CUPS has a different command
+ line and does undesired page management operations */
snprintf(pdf2ps_cmd, PATH_MAX,
- "gs -q -sstdout=%%stderr -sDEVICE=pswrite -sOutputFile=- "
- "-dBATCH -dNOPAUSE -dPARANOIDSAFER %s",
- file == stdin ? "-" : filename);
+ "%spdftops -level2 -origpagesizes %s - 2>/dev/null || "
+ "gs -q -sstdout=%%stderr -sDEVICE=pswrite -sOutputFile=- "
+ "-dBATCH -dNOPAUSE -dPARANOIDSAFER %s 2>/dev/null",
+ (spooler == SPOOLER_CUPS ?
+ "PATH=${PATH#*/cups/filter:} " : ""),
+ filename, filename);
renderer_pid = start_system_process("pdf-to-ps", pdf2ps_cmd, &in, &out);
- if (file == stdin)
- {
- fwrite(buf, 1, n, in);
- while ((n = fread(buf, 1, sizeof(buf), file)))
- fwrite(buf, 1, n, in);
- fclose(in);
- }
-
if (dup2(fileno(out), fileno(stdin)) < 0)
rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS,
"Couldn't dup stdout of pdf-to-ps\n");
@@ -1192,12 +1239,13 @@ int main(int argc, char** argv)
spooler = SPOOLER_LPRNG;
if ((str = strstr(getenv("PRINTCAP_ENTRY"), "ppd=")))
str += 4;
- else if ((str = strstr(getenv("PRINTCAP_ENTRY"), "ppdfile=")));
- str += 8;
+ else if ((str = strstr(getenv("PRINTCAP_ENTRY"), "ppdfile=")))
+ str += 8;
if (str) {
while (isspace(*str)) str++;
p = job->ppdfile;
- while (*str != '\0' && !isspace(*str) && *str != '\n') {
+ while (*str != '\0' && !isspace(*str) && *str != '\n' &&
+ *str != ':') {
if (isprint(*str) && strchr(shellescapes, *str) == NULL)
*p++ = *str;
str++;
@@ -1306,8 +1354,9 @@ int main(int argc, char** argv)
init_cups(arglist, filelist, job);
break;
- case SPOOLER_LPD:
case SPOOLER_LPRNG:
+ if (job->ppdfile[0] != '\0') break;
+ case SPOOLER_LPD:
case SPOOLER_GNULPR:
/* Get PPD file name as the last command line argument */
if (arglist->last)