[poppler] cpp/poppler-document.cpp cpp/poppler-embedded-file.cpp cpp/poppler-embedded-file-private.h glib/poppler-document.cc poppler/Catalog.cc poppler/Catalog.h qt5/src qt6/src utils/pdfdetach.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Feb 10 10:10:18 UTC 2022
cpp/poppler-document.cpp | 6 +--
cpp/poppler-embedded-file-private.h | 16 ++++-----
cpp/poppler-embedded-file.cpp | 13 ++-----
glib/poppler-document.cc | 7 +---
poppler/Catalog.cc | 12 ++----
poppler/Catalog.h | 4 +-
qt5/src/poppler-annotation.cc | 10 ++---
qt5/src/poppler-embeddedfile-private.h | 10 +----
qt5/src/poppler-embeddedfile.cc | 10 +----
qt5/src/poppler-private.h | 7 ++--
qt6/src/poppler-annotation.cc | 10 ++---
qt6/src/poppler-embeddedfile-private.h | 10 +----
qt6/src/poppler-embeddedfile.cc | 10 +----
qt6/src/poppler-private.h | 7 ++--
utils/pdfdetach.cc | 57 +++++++++++----------------------
15 files changed, 70 insertions(+), 119 deletions(-)
New commits:
commit beb5519f723cd84d8d4afa989118df5fffbe50fb
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 9 18:56:51 2022 +0100
Make Catalog::embeddedFile return an unique_ptr
diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index d7c0acfd..c4f52277 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2009-2011, Pino Toscano <pino at kde.org>
* Copyright (C) 2016 Jakub Alba <jakubalba at gmail.com>
- * Copyright (C) 2017, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2017, 2022, Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2018, 2020, Adam Reichold <adam.reichold at t-online.de>
* Copyright (C) 2019, Masamichi Hosoda <trueroad at trueroad.jp>
* Copyright (C) 2019, 2020, Oliver Sander <oliver.sander at tu-dresden.de>
@@ -959,8 +959,8 @@ std::vector<embedded_file *> document::embedded_files() const
const int num = d->doc->getCatalog()->numEmbeddedFiles();
d->embedded_files.resize(num);
for (int i = 0; i < num; ++i) {
- FileSpec *fs = d->doc->getCatalog()->embeddedFile(i);
- d->embedded_files[i] = embedded_file_private::create(fs);
+ std::unique_ptr<FileSpec> fs = d->doc->getCatalog()->embeddedFile(i);
+ d->embedded_files[i] = embedded_file_private::create(std::move(fs));
}
}
return d->embedded_files;
diff --git a/cpp/poppler-embedded-file-private.h b/cpp/poppler-embedded-file-private.h
index 0c11145e..733ed70f 100644
--- a/cpp/poppler-embedded-file-private.h
+++ b/cpp/poppler-embedded-file-private.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009, 2011, Pino Toscano <pino at kde.org>
- * Copyright (C) 2018, 2021, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2018, 2021, 2022, Albert Astals Cid <aacid at kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,22 +20,20 @@
#ifndef POPPLER_EMBEDDED_FILE_PRIVATE_H
#define POPPLER_EMBEDDED_FILE_PRIVATE_H
-class FileSpec;
+#include <FileSpec.h>
+
+#include <memory>
namespace poppler {
class embedded_file_private
{
public:
- explicit embedded_file_private(FileSpec *fs);
- ~embedded_file_private();
-
- embedded_file_private(const embedded_file_private &) = delete;
- embedded_file_private &operator=(const embedded_file_private &) = delete;
+ explicit embedded_file_private(std::unique_ptr<FileSpec> &&fs);
- static embedded_file *create(FileSpec *fs);
+ static embedded_file *create(std::unique_ptr<FileSpec> &&fs);
- FileSpec *file_spec;
+ std::unique_ptr<FileSpec> file_spec;
};
}
diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index ab873de2..04559615 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2009-2011, Pino Toscano <pino at kde.org>
* Copyright (C) 2016 Jakub Alba <jakubalba at gmail.com>
- * Copyright (C) 2018, 2020 Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2018, 2020, 2022 Albert Astals Cid <aacid at kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,16 +34,11 @@
using namespace poppler;
-embedded_file_private::embedded_file_private(FileSpec *fs) : file_spec(fs) { }
+embedded_file_private::embedded_file_private(std::unique_ptr<FileSpec> &&fs) : file_spec(std::move(fs)) { }
-embedded_file_private::~embedded_file_private()
+embedded_file *embedded_file_private::create(std::unique_ptr<FileSpec> &&fs)
{
- delete file_spec;
-}
-
-embedded_file *embedded_file_private::create(FileSpec *fs)
-{
- return new embedded_file(*new embedded_file_private(fs));
+ return new embedded_file(*new embedded_file_private(std::move(fs)));
}
/**
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index c64eb58c..b6b455e2 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -867,16 +867,13 @@ GList *poppler_document_get_attachments(PopplerDocument *document)
n_files = catalog->numEmbeddedFiles();
for (i = 0; i < n_files; i++) {
PopplerAttachment *attachment;
- FileSpec *emb_file;
- emb_file = catalog->embeddedFile(i);
+ const std::unique_ptr<FileSpec> emb_file = catalog->embeddedFile(i);
if (!emb_file->isOk() || !emb_file->getEmbeddedFile()->isOk()) {
- delete emb_file;
continue;
}
- attachment = _poppler_attachment_new(emb_file);
- delete emb_file;
+ attachment = _poppler_attachment_new(emb_file.get());
if (attachment != nullptr)
retval = g_list_prepend(retval, attachment);
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 20cfa8d9..0d2c038e 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2005-2013, 2015, 2017-2021 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2013, 2015, 2017-2022 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2005 Jeff Muizelaar <jrmuizel at nit.ca>
// Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
// Copyright (C) 2005 Marco Pesenti Gritti <mpg at redhat.com>
@@ -432,21 +432,19 @@ std::unique_ptr<LinkDest> Catalog::getDestNameTreeDest(int i)
return createLinkDest(&obj);
}
-FileSpec *Catalog::embeddedFile(int i)
+std::unique_ptr<FileSpec> Catalog::embeddedFile(int i)
{
catalogLocker();
Object *obj = getEmbeddedFileNameTree()->getValue(i);
- FileSpec *embeddedFile = nullptr;
if (obj->isRef()) {
Object fsDict = obj->fetch(xref);
- embeddedFile = new FileSpec(&fsDict);
+ return std::make_unique<FileSpec>(&fsDict);
} else if (obj->isDict()) {
- embeddedFile = new FileSpec(obj);
+ return std::make_unique<FileSpec>(obj);
} else {
Object null;
- embeddedFile = new FileSpec(&null);
+ return std::make_unique<FileSpec>(&null);
}
- return embeddedFile;
}
bool Catalog::hasEmbeddedFile(const std::string &fileName)
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index b44afcca..ffeb481c 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2005, 2007, 2009-2011, 2013, 2017-2021 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2007, 2009-2011, 2013, 2017-2022 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
// Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
// Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
@@ -183,7 +183,7 @@ public:
int numEmbeddedFiles() { return getEmbeddedFileNameTree()->numEntries(); }
// Get the i'th file embedded (at the Document level) in the document
- FileSpec *embeddedFile(int i);
+ std::unique_ptr<FileSpec> embeddedFile(int i);
// Is there an embedded file with the given name?
bool hasEmbeddedFile(const std::string &fileName);
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index 5c35e87f..eb569c41 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -1,5 +1,5 @@
/* poppler-annotation.cc: qt interface to poppler
- * Copyright (C) 2006, 2009, 2012-2015, 2018-2021 Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2006, 2009, 2012-2015, 2018-2022 Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2006, 2008, 2010 Pino Toscano <pino at kde.org>
* Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
* Copyright (C) 2012-2014 Fabio D'Urso <fabiodurso at hotmail.it>
@@ -561,8 +561,8 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
// -> fileIcon
f->setFileIconName(QString::fromLatin1(attachann->getName()->c_str()));
// -> embeddedFile
- FileSpec *filespec = new FileSpec(attachann->getFile());
- f->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(filespec)));
+ auto filespec = std::make_unique<FileSpec>(attachann->getFile());
+ f->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(std::move(filespec))));
break;
}
case Annot::typeSound: /* TODO: Move logic to getters */
@@ -768,8 +768,8 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document
if (annotAsset->getName())
asset->setName(UnicodeParsedString(annotAsset->getName()));
- FileSpec *fileSpec = new FileSpec(annotAsset->getFileSpec());
- asset->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(fileSpec)));
+ auto fileSpec = std::make_unique<FileSpec>(annotAsset->getFileSpec());
+ asset->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(std::move(fileSpec))));
assets.append(asset);
}
diff --git a/qt5/src/poppler-embeddedfile-private.h b/qt5/src/poppler-embeddedfile-private.h
index 5eacf50d..fe53f410 100644
--- a/qt5/src/poppler-embeddedfile-private.h
+++ b/qt5/src/poppler-embeddedfile-private.h
@@ -1,5 +1,5 @@
/* poppler-embeddedfile-private.h: Qt interface to poppler
- * Copyright (C) 2005, 2008, 2009, 2012, 2018, 2021, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2005, 2008, 2009, 2012, 2018, 2021, 2022, Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2005, Brad Hards <bradh at frogmouth.net>
* Copyright (C) 2008, 2011, Pino Toscano <pino at kde.org>
*
@@ -28,15 +28,11 @@ namespace Poppler {
class EmbeddedFileData
{
public:
- explicit EmbeddedFileData(FileSpec *fs);
- ~EmbeddedFileData();
-
- EmbeddedFileData(const EmbeddedFileData &) = delete;
- EmbeddedFileData &operator=(const EmbeddedFileData &) = delete;
+ explicit EmbeddedFileData(std::unique_ptr<FileSpec> &&fs);
EmbFile *embFile() const;
- FileSpec *filespec;
+ std::unique_ptr<FileSpec> filespec;
};
}
diff --git a/qt5/src/poppler-embeddedfile.cc b/qt5/src/poppler-embeddedfile.cc
index 74ed0e9f..49226e79 100644
--- a/qt5/src/poppler-embeddedfile.cc
+++ b/qt5/src/poppler-embeddedfile.cc
@@ -1,5 +1,5 @@
/* poppler-document.cc: qt interface to poppler
- * Copyright (C) 2005, 2008, 2009, 2012, 2013, 2018, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2005, 2008, 2009, 2012, 2013, 2018, 2022, Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2005, Brad Hards <bradh at frogmouth.net>
* Copyright (C) 2008, 2011, Pino Toscano <pino at kde.org>
* Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
@@ -27,19 +27,13 @@
#include "Object.h"
#include "Stream.h"
#include "Catalog.h"
-#include "FileSpec.h"
#include "poppler-private.h"
#include "poppler-embeddedfile-private.h"
namespace Poppler {
-EmbeddedFileData::EmbeddedFileData(FileSpec *fs) : filespec(fs) { }
-
-EmbeddedFileData::~EmbeddedFileData()
-{
- delete filespec;
-}
+EmbeddedFileData::EmbeddedFileData(std::unique_ptr<FileSpec> &&fs) : filespec(std::move(fs)) { }
EmbFile *EmbeddedFileData::embFile() const
{
diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h
index 42dff4fc..19029953 100644
--- a/qt5/src/poppler-private.h
+++ b/qt5/src/poppler-private.h
@@ -1,7 +1,7 @@
/* poppler-private.h: qt interface to poppler
* Copyright (C) 2005, Net Integration Technologies, Inc.
* Copyright (C) 2005, 2008, Brad Hards <bradh at frogmouth.net>
- * Copyright (C) 2006-2009, 2011, 2012, 2017-2021 by Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2006-2009, 2011, 2012, 2017-2022 by Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2007-2009, 2011, 2014 by Pino Toscano <pino at kde.org>
* Copyright (C) 2011 Andreas Hartmetz <ahartmetz at gmail.com>
* Copyright (C) 2011 Hib Eris <hib at hiberis.nl>
@@ -53,6 +53,7 @@
#include <poppler-config.h>
#include <GfxState.h>
#include <GlobalParams.h>
+#include <FileSpec.h>
#include <Form.h>
#include <PDFDoc.h>
#include <FontInfo.h>
@@ -158,8 +159,8 @@ public:
if (!(0 == numEmb)) {
// we have some embedded documents, build the list
for (int yalv = 0; yalv < numEmb; ++yalv) {
- FileSpec *fs = doc->getCatalog()->embeddedFile(yalv);
- m_embeddedFiles.append(new EmbeddedFile(*new EmbeddedFileData(fs)));
+ std::unique_ptr<FileSpec> fs = doc->getCatalog()->embeddedFile(yalv);
+ m_embeddedFiles.append(new EmbeddedFile(*new EmbeddedFileData(std::move(fs))));
}
}
}
diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc
index 40c992ab..a77332ca 100644
--- a/qt6/src/poppler-annotation.cc
+++ b/qt6/src/poppler-annotation.cc
@@ -1,5 +1,5 @@
/* poppler-annotation.cc: qt interface to poppler
- * Copyright (C) 2006, 2009, 2012-2015, 2018-2021 Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2006, 2009, 2012-2015, 2018-2022 Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2006, 2008, 2010 Pino Toscano <pino at kde.org>
* Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
* Copyright (C) 2012-2014 Fabio D'Urso <fabiodurso at hotmail.it>
@@ -484,8 +484,8 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa
// -> fileIcon
f->setFileIconName(QString::fromLatin1(attachann->getName()->c_str()));
// -> embeddedFile
- FileSpec *filespec = new FileSpec(attachann->getFile());
- f->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(filespec)));
+ auto filespec = std::make_unique<FileSpec>(attachann->getFile());
+ f->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(std::move(filespec))));
annotation.reset(f);
break;
}
@@ -692,8 +692,8 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa
if (annotAsset->getName())
asset->setName(UnicodeParsedString(annotAsset->getName()));
- FileSpec *fileSpec = new FileSpec(annotAsset->getFileSpec());
- asset->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(fileSpec)));
+ auto fileSpec = std::make_unique<FileSpec>(annotAsset->getFileSpec());
+ asset->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(std::move(fileSpec))));
assets.append(asset);
}
diff --git a/qt6/src/poppler-embeddedfile-private.h b/qt6/src/poppler-embeddedfile-private.h
index 5eacf50d..fe53f410 100644
--- a/qt6/src/poppler-embeddedfile-private.h
+++ b/qt6/src/poppler-embeddedfile-private.h
@@ -1,5 +1,5 @@
/* poppler-embeddedfile-private.h: Qt interface to poppler
- * Copyright (C) 2005, 2008, 2009, 2012, 2018, 2021, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2005, 2008, 2009, 2012, 2018, 2021, 2022, Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2005, Brad Hards <bradh at frogmouth.net>
* Copyright (C) 2008, 2011, Pino Toscano <pino at kde.org>
*
@@ -28,15 +28,11 @@ namespace Poppler {
class EmbeddedFileData
{
public:
- explicit EmbeddedFileData(FileSpec *fs);
- ~EmbeddedFileData();
-
- EmbeddedFileData(const EmbeddedFileData &) = delete;
- EmbeddedFileData &operator=(const EmbeddedFileData &) = delete;
+ explicit EmbeddedFileData(std::unique_ptr<FileSpec> &&fs);
EmbFile *embFile() const;
- FileSpec *filespec;
+ std::unique_ptr<FileSpec> filespec;
};
}
diff --git a/qt6/src/poppler-embeddedfile.cc b/qt6/src/poppler-embeddedfile.cc
index f1f3f329..4ab61938 100644
--- a/qt6/src/poppler-embeddedfile.cc
+++ b/qt6/src/poppler-embeddedfile.cc
@@ -1,5 +1,5 @@
/* poppler-document.cc: qt interface to poppler
- * Copyright (C) 2005, 2008, 2009, 2012, 2013, 2018, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2005, 2008, 2009, 2012, 2013, 2018, 2022, Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2005, Brad Hards <bradh at frogmouth.net>
* Copyright (C) 2008, 2011, Pino Toscano <pino at kde.org>
* Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
@@ -27,19 +27,13 @@
#include "Object.h"
#include "Stream.h"
#include "Catalog.h"
-#include "FileSpec.h"
#include "poppler-private.h"
#include "poppler-embeddedfile-private.h"
namespace Poppler {
-EmbeddedFileData::EmbeddedFileData(FileSpec *fs) : filespec(fs) { }
-
-EmbeddedFileData::~EmbeddedFileData()
-{
- delete filespec;
-}
+EmbeddedFileData::EmbeddedFileData(std::unique_ptr<FileSpec> &&fs) : filespec(std::move(fs)) { }
EmbFile *EmbeddedFileData::embFile() const
{
diff --git a/qt6/src/poppler-private.h b/qt6/src/poppler-private.h
index 66ecf431..b2af88cd 100644
--- a/qt6/src/poppler-private.h
+++ b/qt6/src/poppler-private.h
@@ -1,7 +1,7 @@
/* poppler-private.h: qt interface to poppler
* Copyright (C) 2005, Net Integration Technologies, Inc.
* Copyright (C) 2005, 2008, Brad Hards <bradh at frogmouth.net>
- * Copyright (C) 2006-2009, 2011, 2012, 2017-2021 by Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2006-2009, 2011, 2012, 2017-2022 by Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2007-2009, 2011, 2014 by Pino Toscano <pino at kde.org>
* Copyright (C) 2011 Andreas Hartmetz <ahartmetz at gmail.com>
* Copyright (C) 2011 Hib Eris <hib at hiberis.nl>
@@ -53,6 +53,7 @@
#include <poppler-config.h>
#include <GfxState.h>
#include <GlobalParams.h>
+#include <FileSpec.h>
#include <Form.h>
#include <PDFDoc.h>
#include <FontInfo.h>
@@ -155,8 +156,8 @@ public:
if (!(0 == numEmb)) {
// we have some embedded documents, build the list
for (int yalv = 0; yalv < numEmb; ++yalv) {
- FileSpec *fs = doc->getCatalog()->embeddedFile(yalv);
- m_embeddedFiles.append(new EmbeddedFile(*new EmbeddedFileData(fs)));
+ std::unique_ptr<FileSpec> fs = doc->getCatalog()->embeddedFile(yalv);
+ m_embeddedFiles.append(new EmbeddedFile(*new EmbeddedFileData(std::move(fs))));
}
}
}
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
index f5576b38..808263d9 100644
--- a/utils/pdfdetach.cc
+++ b/utils/pdfdetach.cc
@@ -16,7 +16,7 @@
// Copyright (C) 2011 Carlos Garcia Campos <carlosgc at gnome.org>
// Copyright (C) 2013 Yury G. Kudryashov <urkud.urkud at gmail.com>
// Copyright (C) 2014, 2017 Adrian Johnson <ajohnson at redneon.com>
-// Copyright (C) 2018, 2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2018, 2020, 2022 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
// Copyright (C) 2019, 2021 Oliver Sander <oliver.sander at tu-dresden.de>
// Copyright (C) 2020 <r.coeffier at bee-buzziness.com>
@@ -81,10 +81,8 @@ int main(int argc, char *argv[])
char *p;
bool ok;
bool hasSaveFile;
- int exitCode;
- std::vector<FileSpec *> embeddedFiles;
+ std::vector<std::unique_ptr<FileSpec>> embeddedFiles;
int nFiles, nPages, n, i, j;
- FileSpec *fileSpec;
Page *page;
Annots *annots;
Annot *annot;
@@ -93,7 +91,6 @@ int main(int argc, char *argv[])
bool isUnicode;
Win32Console win32Console(&argc, &argv);
- exitCode = 99;
// parse args
ok = parseArgs(argDesc, &argc, argv);
@@ -108,7 +105,7 @@ int main(int argc, char *argv[])
if (!printVersion) {
printUsage("pdfdetach", "<PDF-file>", argDesc);
}
- goto err0;
+ return 99;
}
fileName = new GooString(argv[1]);
@@ -122,7 +119,7 @@ int main(int argc, char *argv[])
if (!(uMap = globalParams->getTextEncoding())) {
error(errConfig, -1, "Couldn't get text encoding");
delete fileName;
- goto err0;
+ return 99;
}
// open PDF file
@@ -146,8 +143,7 @@ int main(int argc, char *argv[])
delete ownerPW;
}
if (!doc->isOk()) {
- exitCode = 1;
- goto err2;
+ return 1;
}
for (i = 0; i < doc->getCatalog()->numEmbeddedFiles(); ++i)
@@ -166,7 +162,7 @@ int main(int argc, char *argv[])
annot = annots->getAnnot(j);
if (annot->getType() != Annot::typeFileAttachment)
continue;
- embeddedFiles.push_back(new FileSpec(static_cast<AnnotFileAttachment *>(annot)->getFile()));
+ embeddedFiles.push_back(std::make_unique<FileSpec>(static_cast<AnnotFileAttachment *>(annot)->getFile()));
}
}
@@ -176,12 +172,11 @@ int main(int argc, char *argv[])
if (doList) {
printf("%d embedded files\n", nFiles);
for (i = 0; i < nFiles; ++i) {
- fileSpec = embeddedFiles[i];
+ const std::unique_ptr<FileSpec> &fileSpec = embeddedFiles[i];
printf("%d: ", i + 1);
s1 = fileSpec->getFileName();
if (!s1) {
- exitCode = 3;
- goto err2;
+ return 3;
}
if (s1->hasUnicodeMarker()) {
isUnicode = true;
@@ -207,7 +202,7 @@ int main(int argc, char *argv[])
// save all embedded files
} else if (saveAll) {
for (i = 0; i < nFiles; ++i) {
- fileSpec = embeddedFiles[i];
+ const std::unique_ptr<FileSpec> &fileSpec = embeddedFiles[i];
if (savePath[0]) {
n = strlen(savePath);
if (n > (int)sizeof(path) - 2) {
@@ -221,8 +216,7 @@ int main(int argc, char *argv[])
}
s1 = fileSpec->getFileName();
if (!s1) {
- exitCode = 3;
- goto err2;
+ return 3;
}
if (s1->hasUnicodeMarker()) {
isUnicode = true;
@@ -249,13 +243,11 @@ int main(int argc, char *argv[])
auto *embFile = fileSpec->getEmbeddedFile();
if (!embFile || !embFile->isOk()) {
- exitCode = 3;
- goto err2;
+ return 3;
}
if (!embFile->save(path)) {
error(errIO, -1, "Error saving embedded file as '{0:s}'", p);
- exitCode = 2;
- goto err2;
+ return 2;
}
}
@@ -263,7 +255,7 @@ int main(int argc, char *argv[])
} else {
if (hasSaveFile) {
for (i = 0; i < nFiles; ++i) {
- fileSpec = embeddedFiles[i];
+ const std::unique_ptr<FileSpec> &fileSpec = embeddedFiles[i];
s1 = fileSpec->getFileName();
if (strcmp(s1->c_str(), saveFile) == 0) {
saveNum = i + 1;
@@ -273,18 +265,17 @@ int main(int argc, char *argv[])
}
if (saveNum < 1 || saveNum > nFiles) {
error(errCommandLine, -1, hasSaveFile ? "Invalid file name" : "Invalid file number");
- goto err2;
+ return 99;
}
- fileSpec = embeddedFiles[saveNum - 1];
+ const std::unique_ptr<FileSpec> &fileSpec = embeddedFiles[saveNum - 1];
if (savePath[0]) {
p = savePath;
} else {
p = path;
s1 = fileSpec->getFileName();
if (!s1) {
- exitCode = 3;
- goto err2;
+ return 3;
}
if (s1->hasUnicodeMarker()) {
isUnicode = true;
@@ -313,23 +304,13 @@ int main(int argc, char *argv[])
auto *embFile = fileSpec->getEmbeddedFile();
if (!embFile || !embFile->isOk()) {
- exitCode = 3;
- goto err2;
+ return 3;
}
if (!embFile->save(p)) {
error(errIO, -1, "Error saving embedded file as '{0:s}'", p);
- exitCode = 2;
- goto err2;
+ return 2;
}
}
- exitCode = 0;
-
- // clean up
-err2:
- for (auto &file : embeddedFiles)
- delete file;
-err0:
-
- return exitCode;
+ return 0;
}
More information about the poppler
mailing list