#include <exiv2/exiv2.hpp>
#include <iostream>
#include <fstream>
#include <cassert>
#include "getopt.hpp"
#include "metacopy.hpp"
int main(int argc, char* const argv[])
{
try {
#ifdef EXV_ENABLE_BMFF
Exiv2::enableBMFF();
#endif
if (params.
getopt(argc, argv)) {
return 1;
}
return 2;
}
memIo->transfer(*fileIo);
assert(readImg.get() != 0);
readImg->readMetadata();
assert(writeImg.get() != 0);
if (params.
preserve_) writeImg->readMetadata();
if (params.iptc_) {
writeImg->setIptcData(readImg->iptcData());
}
if (params.exif_) {
writeImg->setExifData(readImg->exifData());
}
if (params.comment_) {
writeImg->setComment(readImg->comment());
}
if (params.xmp_) {
writeImg->setXmpData(readImg->xmpData());
}
try {
writeImg->writeMetadata();
}
std::cerr << params.progname() <<
": Could not write metadata to (" << params.write_ << ")\n";
return 8;
}
return 0;
}
std::cerr << "Caught Exiv2 exception '" << e << "'\n";
return 10;
}
}
{
int rc = 0;
switch (opt) {
case 'h': {
help_ =
true;
break;}
case 'i': {iptc_ = true; break;}
case 'e': {exif_ = true; break;}
case 'c': {comment_ = true; break;}
case 'x': {xmp_ = true; break;}
case 'a':{
iptc_ =true;
exif_ =true;
comment_ =true;
xmp_ =true;
break;
}
case ':':{
std::cerr << progname() << ": Option -" << static_cast<char>(optopt)
<< " requires an argument\n";
rc = 1;
break;
}
case '?':{
std::cerr << progname() << ": Unrecognized option -"
<< static_cast<char>(optopt) << "\n";
rc = 1;
break;
}
default:{
std::cerr << progname()
<< ": getopt returned unexpected character code "
<< std::hex << opt << "\n";
rc = 1;
break;
}
}
return rc;
}
{
if (!write_.empty()) {
std::cerr << progname() << ": Unexpected extra argument (" << argv << ")\n";
return 1;
}
if (first_) read_ = argv;
else write_ = argv;
first_ = false;
return 0;
}
{
int rc = Util::Getopt::getopt(argc, argv, optstring_);
if (rc==0 && read_.empty() ) {
std::cerr << progname() << ": Read and write files must be specified\n";
rc = 1;
}
if (rc==0 && write_.empty() ) {
std::cerr << progname() << ": Write file must be specified\n";
rc = 1;
}
if (
preserve_ && iptc_ && exif_ && comment_ && xmp_ ) {
std::cerr << progname() << ": Option -p has no effect when all metadata types are specified.\n";
rc = 1;
}
}
return rc;
}
{
os << "\nReads and writes raw metadata. Use -h option for help.\n"
<< "Usage: " << progname()
<< " [-iecxaph] readfile writefile\n";
}
{
os << "\nOptions:\n"
<< " -i Read Iptc data from readfile and write to writefile.\n"
<< " -e Read Exif data from readfile and write to writefile.\n"
<< " -c Read Jpeg comment from readfile and write to writefile.\n"
<< " -x Read XMP data from readfile and write to writefile.\n"
<< " -a Read all metadata from readfile and write to writefile.\n"
<< " -p Preserve existing metadata in writefile if not replaced.\n"
<< " -h Display this help and exit.\n\n";
}
Error class interface. Allows the definition and use of a hierarchy of error classes which can all be...
Definition: error.hpp:174
std::auto_ptr< BasicIo > AutoPtr
BasicIo auto_ptr type.
Definition: basicio.hpp:58
Provides binary file IO by implementing the BasicIo interface.
Definition: basicio.hpp:296
static Image::AutoPtr open(const std::string &path, bool useCurl=true)
Create an Image subclass of the appropriate type by reading the specified file. Image type is derived...
Definition: image.cpp:924
std::auto_ptr< Image > AutoPtr
Image auto_ptr type.
Definition: image.hpp:81
Provides binary IO on blocks of memory by implementing the BasicIo interface. A copy-on-write impleme...
Definition: basicio.hpp:540
static bool initialize(XmpParser::XmpLockFct xmpLockFct=0, void *pLockData=0)
Initialize the XMP Toolkit.
Definition: xmp.cpp:641
static void terminate()
Terminate the XMP Toolkit and unregister custom namespaces.
Definition: xmp.cpp:703
Implements the command line handling for the program.
Definition: exiv2app.hpp:138
virtual int nonoption(const std::string &argv)
Handle non-option parameters.
Definition: exiv2.cpp:822
void usage(std::ostream &os=std::cout) const
Print a minimal usage note to an output stream.
Definition: exiv2.cpp:241
bool preserve_
Preserve timestamps flag.
Definition: exiv2app.hpp:226
void help(std::ostream &os=std::cout) const
Print further usage explanations to an output stream.
Definition: exiv2.cpp:267
int getopt(int argc, char *const argv[])
Call Getopt::getopt() with optstring, to inititate command line argument parsing, perform consistency...
Definition: exiv2.cpp:1007
virtual int option(int opt, const std::string &optarg, int optopt)
Handle options and their arguments.
Definition: exiv2.cpp:373
bool help_
Help option flag.
Definition: exiv2app.hpp:220