[poppler] 3 commits - utils/pdfseparate.cc utils/pdftoppm.cc utils/pdfunite.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Feb 13 10:50:18 UTC 2021


 utils/pdfseparate.cc |   31 ++++++++++++-------------------
 utils/pdftoppm.cc    |   28 +++++++++++++++-------------
 utils/pdfunite.cc    |   14 ++++++--------
 3 files changed, 33 insertions(+), 40 deletions(-)

New commits:
commit 5528ab8a5c274fb8da938bff9ed51e492a39a12b
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Feb 12 14:30:25 2021 +0100

    pdfseparate: Remove exitCode variable

diff --git a/utils/pdfseparate.cc b/utils/pdfseparate.cc
index 7fc5d029..afe29cef 100644
--- a/utils/pdfseparate.cc
+++ b/utils/pdfseparate.cc
@@ -5,7 +5,7 @@
 // This file is licensed under the GPLv2 or later
 //
 // Copyright (C) 2011, 2012, 2015 Thomas Freitag <Thomas.Freitag at alfa.de>
-// Copyright (C) 2012-2014, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2012-2014, 2017, 2018, 2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2013, 2016 Pino Toscano <pino at kde.org>
 // Copyright (C) 2013 Daniel Kahn Gillmor <dkg at fifthhorseman.net>
 // Copyright (C) 2013 Suzuki Toshiya <mpsuzuki at hiroshima-u.ac.jp>
@@ -134,34 +134,27 @@ static bool extractPages(const char *srcFileName, const char *destFileName)
     return true;
 }
 
+static constexpr int kOtherError = 99;
+
 int main(int argc, char *argv[])
 {
-    bool ok;
-    int exitCode;
-
-    exitCode = 99;
-
     // parse args
     Win32Console win32console(&argc, &argv);
-    ok = parseArgs(argDesc, &argc, argv);
-    if (!ok || argc != 3 || printVersion || printHelp) {
+    const bool parseOK = parseArgs(argDesc, &argc, argv);
+    if (!parseOK || argc != 3 || printVersion || printHelp) {
         fprintf(stderr, "pdfseparate version %s\n", PACKAGE_VERSION);
         fprintf(stderr, "%s\n", popplerCopyright);
         fprintf(stderr, "%s\n", xpdfCopyright);
         if (!printVersion) {
             printUsage("pdfseparate", "<PDF-sourcefile> <PDF-pattern-destfile>", argDesc);
         }
-        if (printVersion || printHelp)
-            exitCode = 0;
-        goto err0;
+        if (printVersion || printHelp) {
+            return 0;
+        } else {
+            return kOtherError;
+        }
     }
     globalParams = std::make_unique<GlobalParams>();
-    ok = extractPages(argv[1], argv[2]);
-    if (ok) {
-        exitCode = 0;
-    }
-
-err0:
-
-    return exitCode;
+    const bool extractOK = extractPages(argv[1], argv[2]);
+    return extractOK ? 0 : kOtherError;
 }
commit 2cc34b8e14649381fc1d8b90c0a861f7fe2c08e3
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Feb 12 14:27:24 2021 +0100

    pdftoppm: Remove exitcode variable

diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 74c3d3c0..1789aadf 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -18,7 +18,7 @@
 // Copyright (C) 2009 Michael K. Johnson <a1237 at danlj.org>
 // Copyright (C) 2009 Shen Liang <shenzhuxi at gmail.com>
 // Copyright (C) 2009 Stefan Thomas <thomas at eload24.com>
-// Copyright (C) 2009-2011, 2015, 2018-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2009-2011, 2015, 2018-2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2010, 2012, 2017 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2010 Jonathan Liu <net147 at gmail.com>
@@ -209,6 +209,8 @@ static const ArgDesc argDesc[] = { { "-f", argInt, &firstPage, 0, "first page to
                                    { "-?", argFlag, &printHelp, 0, "print usage information" },
                                    {} };
 
+static constexpr int kOtherError = 99;
+
 static bool needToRotate(int angle)
 {
     return (angle == 90) || (angle == 270);
@@ -399,7 +401,6 @@ int main(int argc, char *argv[])
     pthread_t *jobs;
 #endif // UTILS_USE_PTHREADS
     bool ok;
-    int exitCode;
     int pg, pg_num_len;
     double pg_w, pg_h;
 #ifdef USE_CMS
@@ -407,7 +408,6 @@ int main(int argc, char *argv[])
 #endif
 
     Win32Console win32Console(&argc, &argv);
-    exitCode = 99;
 
     // parse args
     ok = parseArgs(argDesc, &argc, argv);
@@ -425,9 +425,11 @@ int main(int argc, char *argv[])
         if (!printVersion) {
             printUsage("pdftoppm", "[PDF-file [PPM-file-prefix]]", argDesc);
         }
-        if (printVersion || printHelp)
-            exitCode = 0;
-        return exitCode;
+        if (printVersion || printHelp) {
+            return 0;
+        } else {
+            return kOtherError;
+        }
     }
     if (argc > 1)
         fileName = new GooString(argv[1]);
@@ -512,7 +514,7 @@ int main(int argc, char *argv[])
         lastPage = doc->getNumPages();
     if (lastPage < firstPage) {
         fprintf(stderr, "Wrong page range given: the first page (%d) can not be after the last page (%d).\n", firstPage, lastPage);
-        return exitCode;
+        return kOtherError;
     }
 
     // If our page range selection and document size indicate we're only
@@ -520,7 +522,7 @@ int main(int argc, char *argv[])
     // filter out that single page.
     if (firstPage == lastPage && ((printOnlyEven && firstPage % 2 == 1) || (printOnlyOdd && firstPage % 2 == 0))) {
         fprintf(stderr, "Invalid even/odd page selection, no pages match criteria.\n");
-        return exitCode;
+        return kOtherError;
     }
 
     if (singleFile && firstPage < lastPage) {
@@ -545,12 +547,12 @@ int main(int argc, char *argv[])
         displayprofile = make_GfxLCMSProfilePtr(cmsOpenProfileFromFile(displayprofilename.c_str(), "r"));
         if (!displayprofile) {
             fprintf(stderr, "Could not open the ICC profile \"%s\".\n", displayprofilename.c_str());
-            return exitCode;
+            return kOtherError;
         }
         if (!cmsIsIntentSupported(displayprofile.get(), INTENT_RELATIVE_COLORIMETRIC, LCMS_USED_AS_OUTPUT) && !cmsIsIntentSupported(displayprofile.get(), INTENT_ABSOLUTE_COLORIMETRIC, LCMS_USED_AS_OUTPUT)
             && !cmsIsIntentSupported(displayprofile.get(), INTENT_SATURATION, LCMS_USED_AS_OUTPUT) && !cmsIsIntentSupported(displayprofile.get(), INTENT_PERCEPTUAL, LCMS_USED_AS_OUTPUT)) {
             fprintf(stderr, "ICC profile \"%s\" is not an output profile.\n", displayprofilename.c_str());
-            return exitCode;
+            return kOtherError;
         }
         profilecolorspace = cmsGetColorSpace(displayprofile.get());
         // Note: In contrast to pdftops we do not fail if a non-matching ICC profile is supplied.
@@ -573,19 +575,19 @@ int main(int argc, char *argv[])
     if (!defaultgrayprofilename.toStr().empty()) {
         defaultgrayprofile = make_GfxLCMSProfilePtr(cmsOpenProfileFromFile(defaultgrayprofilename.c_str(), "r"));
         if (!checkICCProfile(defaultgrayprofile, defaultgrayprofilename.c_str(), LCMS_USED_AS_INPUT, cmsSigGrayData)) {
-            return exitCode;
+            return kOtherError;
         }
     }
     if (!defaultrgbprofilename.toStr().empty()) {
         defaultrgbprofile = make_GfxLCMSProfilePtr(cmsOpenProfileFromFile(defaultrgbprofilename.c_str(), "r"));
         if (!checkICCProfile(defaultrgbprofile, defaultrgbprofilename.c_str(), LCMS_USED_AS_INPUT, cmsSigRgbData)) {
-            return exitCode;
+            return kOtherError;
         }
     }
     if (!defaultcmykprofilename.toStr().empty()) {
         defaultcmykprofile = make_GfxLCMSProfilePtr(cmsOpenProfileFromFile(defaultcmykprofilename.c_str(), "r"));
         if (!checkICCProfile(defaultcmykprofile, defaultcmykprofilename.c_str(), LCMS_USED_AS_INPUT, cmsSigCmykData)) {
-            return exitCode;
+            return kOtherError;
         }
     }
 #endif
commit f51a042ace89c6fa69948356da6f7422a1e9a88b
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Feb 12 14:23:53 2021 +0100

    pdfunite: remove exitCode variable

diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc
index 1ea1a346..1203de0e 100644
--- a/utils/pdfunite.cc
+++ b/utils/pdfunite.cc
@@ -7,7 +7,7 @@
 // Copyright (C) 2011-2015, 2017 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2012 Arseny Solokha <asolokha at gmx.com>
 // Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
-// Copyright (C) 2012, 2014, 2017-2019 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2012, 2014, 2017-2019, 2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2013 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2015 Arthur Stavisky <vovodroid at gmail.com>
@@ -137,9 +137,7 @@ int main(int argc, char *argv[])
     int majorVersion = 0;
     int minorVersion = 0;
     char *fileName = argv[argc - 1];
-    int exitCode;
 
-    exitCode = 99;
     const bool ok = parseArgs(argDesc, &argc, argv);
     if (!ok || argc < 3 || printVersion || printHelp) {
         fprintf(stderr, "pdfunite version %s\n", PACKAGE_VERSION);
@@ -148,11 +146,11 @@ int main(int argc, char *argv[])
         if (!printVersion) {
             printUsage("pdfunite", "<PDF-sourcefile-1>..<PDF-sourcefile-n> <PDF-destfile>", argDesc);
         }
-        if (printVersion || printHelp)
-            exitCode = 0;
-        return exitCode;
+        if (printVersion || printHelp) {
+            return 0;
+        }
+        return 99;
     }
-    exitCode = 0;
     globalParams = std::make_unique<GlobalParams>();
 
     for (i = 1; i < argc - 1; i++) {
@@ -394,5 +392,5 @@ int main(int argc, char *argv[])
     delete countRef;
     for (i = 0; i < (int)docs.size(); i++)
         delete docs[i];
-    return exitCode;
+    return 0;
 }


More information about the poppler mailing list