]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/pdftops.cc
Imported Xpdf 2.03 and fixed build.
[evince.git] / pdf / xpdf / pdftops.cc
index 7f60be024f9063f20ffd1a3b50b8eb8be227c2c8..247e45506c08b13bd612e8b2c27f15777849a758 100644 (file)
@@ -2,7 +2,7 @@
 //
 // pdftops.cc
 //
-// Copyright 1996-2002 Glyph & Cog, LLC
+// Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
@@ -48,8 +48,8 @@ static char paperSize[15] = "";
 static int paperWidth = 0;
 static int paperHeight = 0;
 static GBool duplex = gFalse;
-static char ownerPassword[33] = "";
-static char userPassword[33] = "";
+static char ownerPassword[33] = "\001";
+static char userPassword[33] = "\001";
 static GBool quiet = gFalse;
 static char cfgFileName[256] = "";
 static GBool printVersion = gFalse;
@@ -89,7 +89,7 @@ static ArgDesc argDesc[] = {
   {"-noembcidtt", argFlag, &noEmbedCIDTTFonts, 0,
    "don't embed CID TrueType fonts"},
   {"-paper",  argString,   paperSize,       sizeof(paperSize),
-   "paper size (letter, legal, A4, A3)"},
+   "paper size (letter, legal, A4, A3, match)"},
   {"-paperw", argInt,      &paperWidth,     0,
    "paper width, in points"},
   {"-paperh", argInt,      &paperHeight,    0,
@@ -127,6 +127,9 @@ int main(int argc, char *argv[]) {
   PSOutputDev *psOut;
   GBool ok;
   char *p;
+  int exitCode;
+
+  exitCode = 99;
 
   // parse args
   ok = parseArgs(argDesc, &argc, argv);
@@ -178,7 +181,8 @@ int main(int argc, char *argv[]) {
   if (paperSize[0]) {
     if (!globalParams->setPSPaperSize(paperSize)) {
       fprintf(stderr, "Invalid paper size\n");
-      exit(1);
+      delete fileName;
+      goto err0;
     }
   } else {
     if (paperWidth) {
@@ -216,12 +220,12 @@ int main(int argc, char *argv[]) {
   }
 
   // open PDF file
-  if (ownerPassword[0]) {
+  if (ownerPassword[0] != '\001') {
     ownerPW = new GString(ownerPassword);
   } else {
     ownerPW = NULL;
   }
-  if (userPassword[0]) {
+  if (userPassword[0] != '\001') {
     userPW = new GString(userPassword);
   } else {
     userPW = NULL;
@@ -234,12 +238,14 @@ int main(int argc, char *argv[]) {
     delete ownerPW;
   }
   if (!doc->isOk()) {
+    exitCode = 1;
     goto err1;
   }
 
   // check for print permission
   if (!doc->okToPrint()) {
     error(-1, "Printing this document is not allowed.");
+    exitCode = 3;
     goto err1;
   }
 
@@ -275,20 +281,27 @@ int main(int argc, char *argv[]) {
   psOut = new PSOutputDev(psFileName->getCString(), doc->getXRef(),
                          doc->getCatalog(), firstPage, lastPage, mode);
   if (psOut->isOk()) {
-    doc->displayPages(psOut, firstPage, lastPage, 72, 0, gFalse);
+    doc->displayPages(psOut, firstPage, lastPage, 72, 72, 0, gFalse);
+  } else {
+    delete psOut;
+    exitCode = 2;
+    goto err2;
   }
   delete psOut;
 
+  exitCode = 0;
+
   // clean up
  err2:
   delete psFileName;
  err1:
   delete doc;
+ err0:
   delete globalParams;
 
   // check for memory leaks
   Object::memCheck(stderr);
   gMemReport(stderr);
 
-  return 0;
+  return exitCode;
 }