]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/pdftotext.cc
Reused eog HIG dialog in GPdf.
[evince.git] / pdf / xpdf / pdftotext.cc
index f4b39ce9452ffc2e150bdd5b283cccf66b4a6650..a67f92439990d1249b35d0dff79a5cde54709bdd 100644 (file)
@@ -2,7 +2,7 @@
 //
 // pdftotext.cc
 //
-// Copyright 1997-2002 Glyph & Cog, LLC
+// Copyright 1997-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
@@ -35,6 +35,7 @@ static void printInfoDate(FILE *f, Dict *infoDict, char *key, char *fmt);
 
 static int firstPage = 1;
 static int lastPage = 0;
+static GBool physLayout = gFalse;
 static GBool rawOrder = gFalse;
 static GBool htmlMeta = gFalse;
 static char textEncName[128] = "";
@@ -51,6 +52,8 @@ static ArgDesc argDesc[] = {
    "first page to convert"},
   {"-l",      argInt,      &lastPage,      0,
    "last page to convert"},
+  {"-layout", argFlag,     &physLayout,    0,
+   "maintain original physical layout"},
   {"-raw",    argFlag,     &rawOrder,      0,
    "keep strings in content stream order"},
   {"-htmlmeta", argFlag,   &htmlMeta,      0,
@@ -91,6 +94,9 @@ int main(int argc, char *argv[]) {
   Object info;
   GBool ok;
   char *p;
+  int exitCode;
+
+  exitCode = 99;
 
   // parse args
   ok = parseArgs(argDesc, &argc, argv);
@@ -100,7 +106,7 @@ int main(int argc, char *argv[]) {
     if (!printVersion) {
       printUsage("pdftotext", "<PDF-file> [<text-file>]", argDesc);
     }
-    exit(1);
+    goto err0;
   }
   fileName = new GString(argv[1]);
 
@@ -144,12 +150,14 @@ int main(int argc, char *argv[]) {
     delete ownerPW;
   }
   if (!doc->isOk()) {
+    exitCode = 1;
     goto err2;
   }
 
   // check for copy permission
   if (!doc->okToCopy()) {
     error(-1, "Copying of text from this document is not allowed.");
+    exitCode = 3;
     goto err2;
   }
 
@@ -182,6 +190,7 @@ int main(int argc, char *argv[]) {
     } else {
       if (!(f = fopen(textFileName->getCString(), "wb"))) {
        error(-1, "Couldn't open text file '%s'", textFileName->getCString());
+       exitCode = 2;
        goto err3;
       }
     }
@@ -216,9 +225,14 @@ int main(int argc, char *argv[]) {
   }
 
   // write text file
-  textOut = new TextOutputDev(textFileName->getCString(), rawOrder, htmlMeta);
+  textOut = new TextOutputDev(textFileName->getCString(),
+                             physLayout, rawOrder, htmlMeta);
   if (textOut->isOk()) {
     doc->displayPages(textOut, firstPage, lastPage, 72, 0, gFalse);
+  } else {
+    delete textOut;
+    exitCode = 2;
+    goto err3;
   }
   delete textOut;
 
@@ -229,6 +243,7 @@ int main(int argc, char *argv[]) {
     } else {
       if (!(f = fopen(textFileName->getCString(), "ab"))) {
        error(-1, "Couldn't open text file '%s'", textFileName->getCString());
+       exitCode = 2;
        goto err3;
       }
     }
@@ -240,6 +255,8 @@ int main(int argc, char *argv[]) {
     }
   }
 
+  exitCode = 0;
+
   // clean up
  err3:
   delete textFileName;
@@ -248,12 +265,13 @@ int main(int argc, char *argv[]) {
   uMap->decRefCnt();
  err1:
   delete globalParams;
+ err0:
 
   // check for memory leaks
   Object::memCheck(stderr);
   gMemReport(stderr);
 
-  return 0;
+  return exitCode;
 }
 
 static void printInfoString(FILE *f, Dict *infoDict, char *key,