commit fc815e7fcaea40f751a36b0dc1d00e87b3aac520 parent 7fa7e6534ce4978b09c09977c7085012358014b4 Author: Christian Grothoff <christian@grothoff.org> Date: Thu, 14 Jul 2005 16:53:13 +0000 dead code elimination, thanks to Andreas Huggel Diffstat:
| M | src/plugins/exiv2/Makefile.am | | | 5 | ----- |
| D | src/plugins/exiv2/doxygen.hpp | | | 133 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/exifprint.cpp | | | 49 | ------------------------------------------------- |
| D | src/plugins/exiv2/exiv2.cpp | | | 814 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/exiv2.hpp | | | 219 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/getopt_win32.h | | | 140 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/iptceasy.cpp | | | 49 | ------------------------------------------------- |
| D | src/plugins/exiv2/iptcprint.cpp | | | 50 | -------------------------------------------------- |
| D | src/plugins/exiv2/metacopy.cpp | | | 182 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/metacopy.hpp | | | 86 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/private.h | | | 235 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/taglist.cpp | | | 69 | --------------------------------------------------------------------- |
| D | src/plugins/exiv2/timegm.h | | | 88 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/tzfile.h | | | 193 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/utils.cpp | | | 141 | ------------------------------------------------------------------------------- |
| D | src/plugins/exiv2/utils.hpp | | | 165 | ------------------------------------------------------------------------------- |
16 files changed, 0 insertions(+), 2618 deletions(-)
diff --git a/src/plugins/exiv2/Makefile.am b/src/plugins/exiv2/Makefile.am @@ -28,7 +28,6 @@ canonmn.cpp \ canonmn.hpp \ datasets.cpp \ datasets.hpp \ -doxygen.hpp \ error.cpp \ error.hpp \ exif.cpp \ @@ -47,8 +46,6 @@ jpgimage.cpp \ jpgimage.hpp \ makernote.cpp \ makernote.hpp \ -metacopy.cpp \ -metacopy.hpp \ metadatum.cpp \ metadatum.hpp \ mn.hpp \ @@ -67,8 +64,6 @@ tags.cpp \ tags.hpp \ types.cpp \ types.hpp \ -utils.cpp \ -utils.hpp \ value.cpp \ value.hpp diff --git a/src/plugins/exiv2/doxygen.hpp b/src/plugins/exiv2/doxygen.hpp @@ -1,133 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/*! - @file doxygen.hpp - @brief Additional documentation, this file contains no source code - @version $Rev: 581 $ - @author Andreas Huggel (ahu) - <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> - @date 07-Feb-04, ahu: created - */ -/*! - @mainpage Exif and Iptc metadata manipulation library and tools v0.7 - - @section overview Exiv2 Overview - - %Exiv2 comprises of a C++ library and a command line utility to access image - metadata. %Exiv2 is free software. The homepage of %Exiv2 is at - <A HREF="http://home.arcor.de/ahuggel/exiv2">http://home.arcor.de/ahuggel/exiv2</A>. - - The %Exiv2 library provides - - full read and write access to the Exif and Iptc metadata of an image through - %Exiv2 keys and standard C++ iterators - - a smart Iptc implementation that does not effect data that programs like - Photoshop store in the same image segment - - Exif %MakerNote support: - - %MakerNote tags can be accessed just like any other Exif metadata - - a sophisticated write algorithm avoids corrupting the %MakerNote: - <br> 1) the %MakerNote is not re-located if possible at all, and - <br> 2) %MakerNote %Ifd offsets are re-calculated if the - %MakerNote needs to be moved (for known %Ifd %MakerNotes) - - new camera make/model specific %MakerNotes can be added to the library with - minimum effort in OO-fashion (by subclassing %MakerNote or %IfdMakerNote) - - extract and delete methods for Exif thumbnails (both, Jpeg and Tiff thumbnails) - - set methods for Exif thumbnails (Jpeg only, Tiff thumbnails can be set from - individual tags) - - complete API documentation (by Doxygen) - - generic lower-level classes to access %Ifd (%Image File Directory) data - structures - - @section getting-started Getting started - - <A HREF="getting-started.html">A few pointers</A> to get you started with - the %Exiv2 library without delay. - - @section metadata Supported Exif and MakerNote tags and Iptc datasets - - - <A HREF="tags-exif.html">Standard Exif tags</A> - - <A HREF="tags-canon.html">Canon MakerNote tags</A> - - <A HREF="tags-fujifilm.html">Fujifilm MakerNote tags</A> - - <A HREF="tags-nikon.html">Nikon MakerNote tags</A> - - <A HREF="tags-olympus.html">Olympus MakerNote tags</A> - - <A HREF="tags-panasonic.html">Panasonic MakerNote tags</A> - - <A HREF="tags-sigma.html">Sigma/Foveon MakerNote tags</A> - - <A HREF="tags-sony.html">Sony MakerNote tags</A> - - <A HREF="tags-iptc.html">Iptc datasets</A> - - @section makernote MakerNote Formats and Specifications - - A summary of <A HREF="makernote.html">MakerNote structures</A> with links to - publicly available specifications. - - @section supp Support - - <p>There is now a - <a title="Exiv2 forum" href="http://uk.groups.yahoo.com/group/exiv2">Yahoo! group for Exiv2 help and discussions</a>.</p> - <p><a title="Join the Exiv2 forum" href="http://uk.groups.yahoo.com/group/exiv2/join">Join the group</a> to post and receive messages or use <em><a title="Post to the Exiv2 forum" href="http://uk.groups.yahoo.com/group/exiv2/post">exiv2user/password</a></em> to post anonymously. Bug reports can be submitted directly to the -<a title="Issue tracker" href="http://dev.robotbattle.com/bugs/main_page.php" - onclick="document.images['tracker'].src='http://www.whatcounter.com/dlcount.php?id=ahu&url='+this.href"> -bug tracking system</a>.</p> - - @section devel Development - - <p>%Exiv2 is maintained in a publicly available subversion repository. - There is a <a title="Last 50 commits" href="http://dev.robotbattle.com/cmtinfo_svn.php?r=10"> - live list with the latest commits</a> to the repository, and you can - <a title="Online source code repository" href="http://dev.robotbattle.com/~cvsuser/cgi-bin/ns_viewcvs.cgi/exiv2/trunk/"> - browse the source code</a> online. - </p> - <p>To check-out the current source code from the repository, you need a - <a title="Get Subversion!" - href="http://subversion.tigris.org/project_packages.html">subversion client</a>. - If you use a command line client, change to the directory where you want to keep - the source code and type:</p> - - @verbatim $ svn checkout svn://dev.robotbattle.com/exiv2/trunk . @endverbatim - - <p>To download the test data and test drivers for version 0.7 from - the repository, change to your local exiv2-0.7 directory and use the - following command: - </p> - - @verbatim $ svn export svn://dev.robotbattle.com/exiv2/tags/0.7/test @endverbatim - - <P>If you'd like to contribute code, please <A HREF="mailto:ahuggel@gmx.net">contact me</A>. - - @section license License - - <P>Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net></P> - - <P>%Exiv2 is free software; you can redistribute it and/or modify it under the - terms of the <a href="gpl-license.html">GNU General Public License</a> as - published by the Free Software Foundation; either version 2 of the License, or - (at your option) any later version.</P> - - <P>%Exiv2 is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more - details.</P> - - <P>You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., 59 - Temple Place - Suite 330, Boston, MA 02111-1307, USA.</P> - -*/ -/*! - @example addmoddel.cpp - Sample usage of high-level metadata operations. - */ -/*! - @example exifprint.cpp - Sample program to print Exif data from an image. - */ -/*! - @example exifcomment.cpp - Sample program showing how to set the Exif comment of an image. - */ -/*! - @example iptcprint.cpp - Sample program to print the Iptc metadata of an image - */ -/*! - @example iptceasy.cpp - The quickest way to access, set or modify Iptc metadata - */ diff --git a/src/plugins/exiv2/exifprint.cpp b/src/plugins/exiv2/exifprint.cpp @@ -1,49 +0,0 @@ -// ***************************************************************** -*- C++ -*- -// exifprint.cpp, $Rev: 578 $ -// Sample program to print the Exif metadata of an image - -#include "image.hpp" -#include "exif.hpp" -#include <iostream> -#include <iomanip> -#include <cassert> - -int main(int argc, char* const argv[]) -try { - - if (argc != 2) { - std::cout << "Usage: " << argv[0] << " file\n"; - return 1; - } - - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]); - assert(image.get() != 0); - image->readMetadata(); - - Exiv2::ExifData &exifData = image->exifData(); - if (exifData.empty()) { - std::string error(argv[1]); - error += ": No Exif data found in the file"; - throw Exiv2::Error(1, error); - } - Exiv2::ExifData::const_iterator end = exifData.end(); - for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { - std::cout << std::setw(44) << std::setfill(' ') << std::left - << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right - << std::hex << i->tag() << " " - << std::setw(9) << std::setfill(' ') << std::left - << i->typeName() << " " - << std::dec << std::setw(3) - << std::setfill(' ') << std::right - << i->count() << " " - << std::dec << i->value() - << "\n"; - } - - return 0; -} -catch (Exiv2::AnyError& e) { - std::cout << "Caught Exiv2 exception '" << e << "'\n"; - return -1; -} diff --git a/src/plugins/exiv2/exiv2.cpp b/src/plugins/exiv2/exiv2.cpp @@ -1,814 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> - * - * This program is part of the Exiv2 distribution. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -/* - Abstract: Command line program to display and manipulate image %Exif data - - File: exiv2.cpp - Version: $Rev: 598 $ - Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net> - History: 10-Dec-03, ahu: created - */ -// ***************************************************************************** -#include "rcsid.hpp" -EXIV2_RCSID("@(#) $Id: exiv2.cpp 598 2005-07-08 15:29:11Z ahuggel $"); - -// ***************************************************************************** -// included header files -#ifdef _MSC_VER -# include "exv_msvc.h" -#else -# include "exv_conf.h" -#endif - -#include "exiv2.hpp" -#include "actions.hpp" -#include "utils.hpp" - -#include <string> -#include <iostream> -#include <fstream> -#include <iomanip> -#include <cstring> -#include <cassert> - -// ***************************************************************************** -// local declarations -namespace { - - //! List of all command identifiers and corresponding strings - static const CmdIdAndString cmdIdAndString[] = { - { add, "add" }, - { set, "set" }, - { del, "del" }, - { invalidCmdId, "invalidCmd" } // End of list marker - }; - - // Return a command Id for a command string - CmdId commandId(const std::string& cmdString); - - // Evaluate [-]HH[:MM[:SS]], returns true and sets time to the value - // in seconds if successful, else returns false. - bool parseTime(const std::string& ts, long& time); - - /*! - @brief Parse the oparg string into a bitmap of common targets. - @param optarg Option arguments - @param action Action being processed - @return A bitmap of common targets or -1 in case of a parse error - */ - int parseCommonTargets(const std::string& optarg, - const std::string& action); - - /*! - @brief Parse metadata modification commands from multiple files - @param modifyCmds Reference to a structure to store the parsed commands - @param cmdFiles Container with the file names - */ - bool parseCmdFiles(ModifyCmds& modifyCmds, - const Params::CmdFiles& cmdFiles); - - /*! - @brief Parse metadata modification commands from a container of commands - @param modifyCmds Reference to a structure to store the parsed commands - @param cmdLines Container with the commands - */ - bool parseCmdLines(ModifyCmds& modifyCmds, - const Params::CmdLines& cmdLines); - - /*! - @brief Parse one line of the command file - @param modifyCmd Reference to a command structure to store the parsed - command - @param line Input line - @param num Line number (used for error output) - */ - bool parseLine(ModifyCmd& modifyCmd, - const std::string& line, int num); - -} - -// ***************************************************************************** -// Main -int main(int argc, char* const argv[]) -{ - // Handle command line arguments - Params& params = Params::instance(); - if (params.getopt(argc, argv)) { - params.usage(); - return 1; - } - if (params.help_) { - params.help(); - return 0; - } - if (params.version_) { - params.version(); - return 0; - } - - // Create the required action class - Action::TaskFactory& taskFactory = Action::TaskFactory::instance(); - Action::Task::AutoPtr task - = taskFactory.create(Action::TaskType(params.action_)); - assert(task.get()); - - // Process all files - int n = 1; - int s = static_cast<int>(params.files_.size()); - int w = s > 9 ? s > 99 ? 3 : 2 : 1; - Params::Files::const_iterator e = params.files_.end(); - for (Params::Files::const_iterator i = params.files_.begin(); i != e; ++i) { - if (params.verbose_) { - std::cout << "File " << std::setw(w) << n++ << "/" << s << ": " - << *i << std::endl; - } - task->run(*i); - } - - taskFactory.cleanup(); - params.cleanup(); - - return 0; -} // main - -// ***************************************************************************** -// class Params -Params* Params::instance_ = 0; - -Params& Params::instance() -{ - if (0 == instance_) { - instance_ = new Params; - } - return *instance_; -} - -void Params::cleanup() -{ - delete instance_; - instance_ = 0; -} - -void Params::version(std::ostream& os) const -{ - os << EXV_PACKAGE_STRING << ", " - << "Copyright (C) 2004, 2005 Andreas Huggel.\n\n" - << "This is free software; see the source for copying conditions. " - << "There is NO \nwarranty; not even for MERCHANTABILITY or FITNESS FOR " - << "A PARTICULAR PURPOSE.\n"; -} - -void Params::usage(std::ostream& os) const -{ - os << "Usage: " << progname() - << " [ options ] [ action ] file ...\n\n" - << "Manipulate the Exif metadata of images.\n"; -} - -void Params::help(std::ostream& os) const -{ - usage(os); - os << "\nActions:\n" - << " ad | adjust Adjust Exif timestamps by the given time. This\n" - << " action requires the option -a time.\n" - << " pr | print Print image metadata.\n" - << " rm | delete Delete image metadata from the files.\n" - << " in | insert Insert metadata from corresponding *.exv files.\n" - << " ex | extract Extract metadata to *.exv and thumbnail image files.\n" - << " mv | rename Rename files according to the Exif create timestamp.\n" - << " The filename format can be set with -r format.\n" - << " mo | modify Apply commands to modify (add, set, delete) the Exif\n" - << " and Iptc metadata of image files. Requires option -m or -M\n" - << "\nOptions:\n" - << " -h Display this help and exit.\n" - << " -V Show the program version and exit.\n" - << " -v Be verbose during the program run.\n" - << " -f Do not prompt before overwriting existing files (force).\n" - << " -F Do not prompt before renaming existing files (Force).\n" - << " -a time Time adjustment in the format [-]HH[:MM[:SS]]. This option\n" - << " is only used with the `adjust' action.\n" - << " -p mode Print mode for the `print' action. Possible modes are:\n" - << " s : print a summary of the Exif metadata (the default)\n" - << " t : interpreted (translated) Exif data\n" - << " v : plain Exif data values\n" - << " h : hexdump of the Exif data\n" - << " i : Iptc data values\n" - << " c : Jpeg comment\n" - << " -d tgt Delete target(s) for the `delete' action. Possible targets are:\n" - << " a : all supported metadata (the default)\n" - << " e : Exif section\n" - << " t : Exif thumbnail only\n" - << " i : Iptc data\n" - << " c : Jpeg comment\n" - << " -i tgt Insert target(s) for the `insert' action. Possible targets are\n" - << " the same as those for the -d option. Only Jpeg thumbnails can\n" - << " be inserted, they need to be named <file>-thumb.jpg\n" - << " -e tgt Extract target(s) for the `extract' action. Possible targets\n" - << " are the same as those for the -d option.\n" - << " -r fmt Filename format for the `rename' action. The format string\n" - << " follows strftime(3). Default filename format is " - << format_ << ".\n" - << " -m file Command file for the modify action. The format for commands is\n" - << " set|add|del <key> [[<type>] <value>].\n" - << " -M cmd Command line for the modify action. The format for the\n" - << " commands is the same as that of the lines of a command file.\n" - << " -l dir Location (directory) for files to be inserted or extracted.\n\n"; -} // Params::help - -int Params::option(int opt, const std::string& optarg, int optopt) -{ - int rc = 0; - switch (opt) { - case 'h': help_ = true; break; - case 'V': version_ = true; break; - case 'v': verbose_ = true; break; - case 'f': force_ = true; fileExistsPolicy_ = overwritePolicy; break; - case 'F': force_ = true; fileExistsPolicy_ = renamePolicy; break; - case 'r': rc = evalRename(optarg); break; - case 'a': rc = evalAdjust(optarg); break; - case 'p': rc = evalPrint(optarg); break; - case 'd': rc = evalDelete(optarg); break; - case 'e': rc = evalExtract(optarg); break; - case 'i': rc = evalInsert(optarg); break; - case 'm': rc = evalModify(opt, optarg); break; - case 'M': rc = evalModify(opt, optarg); break; - case 'l': directory_ = optarg; 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; -} // Params::option - -int Params::evalRename(const std::string& optarg) -{ - int rc = 0; - switch (action_) { - case Action::none: - action_ = Action::rename; - format_ = optarg; - break; - case Action::rename: - std::cerr << progname() - << ": Ignoring surplus option -r \"" << optarg << "\"\n"; - break; - default: - std::cerr << progname() - << ": Option -r is not compatible with a previous option\n"; - rc = 1; - break; - } - return rc; -} // Params::evalRename - -int Params::evalAdjust(const std::string& optarg) -{ - int rc = 0; - switch (action_) { - case Action::none: - action_ = Action::adjust; - adjust_ = parseTime(optarg, adjustment_); - if (!adjust_) { - std::cerr << progname() << ": Error parsing -a option argument `" - << optarg << "'\n"; - rc = 1; - } - break; - case Action::adjust: - std::cerr << progname() - << ": Ignoring surplus option -a " << optarg << "\n"; - break; - default: - std::cerr << progname() - << ": Option -a is not compatible with a previous option\n"; - rc = 1; - break; - } - return rc; -} // Params::evalAdjust - -int Params::evalPrint(const std::string& optarg) -{ - int rc = 0; - switch (action_) { - case Action::none: - action_ = Action::print; - switch (optarg[0]) { - case 's': printMode_ = pmSummary; break; - case 't': printMode_ = pmInterpreted; break; - case 'v': printMode_ = pmValues; break; - case 'h': printMode_ = pmHexdump; break; - case 'i': printMode_ = pmIptc; break; - case 'c': printMode_ = pmComment; break; - default: - std::cerr << progname() << ": Unrecognized print mode `" - << optarg << "'\n"; - rc = 1; - break; - } - break; - case Action::print: - std::cerr << progname() - << ": Ignoring surplus option -p" << optarg << "\n"; - break; - default: - std::cerr << progname() - << ": Option -p is not compatible with a previous option\n"; - rc = 1; - break; - } - return rc; -} // Params::evalPrint - -int Params::evalDelete(const std::string& optarg) -{ - int rc = 0; - switch (action_) { - case Action::none: - action_ = Action::erase; - target_ = 0; - // fallthrough - case Action::erase: - rc = parseCommonTargets(optarg, "erase"); - if (rc > 0) { - target_ |= rc; - rc = 0; - } - else { - rc = 1; - } - break; - default: - std::cerr << progname() - << ": Option -d is not compatible with a previous option\n"; - rc = 1; - break; - } - return rc; -} // Params::evalDelete - -int Params::evalExtract(const std::string& optarg) -{ - int rc = 0; - switch (action_) { - case Action::none: - action_ = Action::extract; - target_ = 0; - // fallthrough - case Action::extract: - rc = parseCommonTargets(optarg, "extract"); - if (rc > 0) { - target_ |= rc; - rc = 0; - } - else { - rc = 1; - } - break; - default: - std::cerr << progname() - << ": Option -e is not compatible with a previous option\n"; - rc = 1; - break; - } - return rc; -} // Params::evalExtract - -int Params::evalInsert(const std::string& optarg) -{ - int rc = 0; - switch (action_) { - case Action::none: - action_ = Action::insert; - target_ = 0; - // fallthrough - case Action::insert: - rc = parseCommonTargets(optarg, "insert"); - if (rc > 0) { - target_ |= rc; - rc = 0; - } - else { - rc = 1; - } - break; - default: - std::cerr << progname() - << ": Option -i is not compatible with a previous option\n"; - rc = 1; - break; - } - return rc; -} // Params::evalInsert - -int Params::evalModify(int opt, const std::string& optarg) -{ - int rc = 0; - switch (action_) { - case Action::none: - action_ = Action::modify; - // fallthrough - case Action::modify: - if (opt == 'm') cmdFiles_.push_back(optarg); // parse the files later - if (opt == 'M') cmdLines_.push_back(optarg); // parse the commands later - break; - default: - std::cerr << progname() - << ": Option -" << (char)opt - << " is not compatible with a previous option\n"; - rc = 1; - break; - } - return rc; -} // Params::evalModify - -int Params::nonoption(const std::string& argv) -{ - int rc = 0; - bool action = false; - if (first_) { - // The first non-option argument must be the action - first_ = false; - if (argv == "ad" || argv == "adjust") { - if (action_ != Action::none && action_ != Action::adjust) { - std::cerr << progname() << ": Action adjust is not " - << "compatible with the given options\n"; - rc = 1; - } - action = true; - action_ = Action::adjust; - } - if (argv == "pr" || argv == "print") { - if (action_ != Action::none && action_ != Action::print) { - std::cerr << progname() << ": Action print is not " - << "compatible with the given options\n"; - rc = 1; - } - action = true; - action_ = Action::print; - } - if (argv == "rm" || argv == "delete") { - if (action_ != Action::none && action_ != Action::erase) { - std::cerr << progname() << ": Action delete is not " - << "compatible with the given options\n"; - rc = 1; - } - action = true; - action_ = Action::erase; - } - if (argv == "ex" || argv == "extract") { - if (action_ != Action::none && action_ != Action::extract) { - std::cerr << progname() << ": Action extract is not " - << "compatible with the given options\n"; - rc = 1; - } - action = true; - action_ = Action::extract; - } - if (argv == "in" || argv == "insert") { - if (action_ != Action::none && action_ != Action::insert) { - std::cerr << progname() << ": Action insert is not " - << "compatible with the given options\n"; - rc = 1; - } - action = true; - action_ = Action::insert; - } - if (argv == "mv" || argv == "rename") { - if (action_ != Action::none && action_ != Action::rename) { - std::cerr << progname() << ": Action rename is not " - << "compatible with the given options\n"; - rc = 1; - } - action = true; - action_ = Action::rename; - } - if (argv == "mo" || argv == "modify") { - if (action_ != Action::none && action_ != Action::modify) { - std::cerr << progname() << ": Action modify is not " - << "compatible with the given options\n"; - rc = 1; - } - action = true; - action_ = Action::modify; - } - if (action_ == Action::none) { - // if everything else fails, assume print as the default action - action_ = Action::print; - } - } - if (!action) { - files_.push_back(argv); - } - return rc; -} // Params::nonoption - -int Params::getopt(int argc, char* const argv[]) -{ - int rc = Util::Getopt::getopt(argc, argv, optstring_); - // Further consistency checks - if (help_ || version_) return 0; - if (action_ == Action::none) { - // This shouldn't happen since print is taken as default action - std::cerr << progname() << ": An action must be specified\n"; - rc = 1; - } - if (action_ == Action::adjust && !adjust_) { - std::cerr << progname() - << ": Adjust action requires option -a time\n"; - rc = 1; - } - if (action_ == Action::modify && cmdFiles_.empty() && cmdLines_.empty()) { - std::cerr << progname() - << ": Modify action requires at least one -m or -M option\n"; - rc = 1; - } - if (0 == files_.size()) { - std::cerr << progname() << ": At least one file is required\n"; - rc = 1; - } - if (rc == 0 && action_ == Action::modify) { - // Parse command files - if (!parseCmdFiles(modifyCmds_, cmdFiles_)) { - std::cerr << progname() << ": Error parsing -m option arguments\n"; - rc = 1; - } - } - if (rc ==0 && action_ == Action::modify) { - // Parse command lines - if (!parseCmdLines(modifyCmds_, cmdLines_)) { - std::cerr << progname() << ": Error parsing -M option arguments\n"; - rc = 1; - } - } - if (!directory_.empty() && !(action_ == Action::insert || action_ == Action::extract)) { - std::cerr << progname() << ": -l option can only be used with extract or insert actions\n"; - rc = 1; - } - return rc; -} // Params::getopt - -// ***************************************************************************** -// local implementations -namespace { - - bool parseTime(const std::string& ts, long& time) - { - std::string hstr, mstr, sstr; - char *cts = new char[ts.length() + 1]; - strcpy(cts, ts.c_str()); - char *tmp = ::strtok(cts, ":"); - if (tmp) hstr = tmp; - tmp = ::strtok(0, ":"); - if (tmp) mstr = tmp; - tmp = ::strtok(0, ":"); - if (tmp) sstr = tmp; - delete[] cts; - - int sign = 1; - long hh(0), mm(0), ss(0); - // [-]HH part - if (!Util::strtol(hstr.c_str(), hh)) return false; - if (hh < 0) { - sign = -1; - hh *= -1; - } - // check for the -0 special case - if (hh == 0 && hstr.find('-') != std::string::npos) sign = -1; - // MM part, if there is one - if (mstr != "") { - if (!Util::strtol(mstr.c_str(), mm)) return false; - if (mm > 59) return false; - if (mm < 0) return false; - } - // SS part, if there is one - if (sstr != "") { - if (!Util::strtol(sstr.c_str(), ss)) return false; - if (ss > 59) return false; - if (ss < 0) return false; - } - - time = sign * (hh * 3600 + mm * 60 + ss); - return true; - } // parseTime - - int parseCommonTargets(const std::string& optarg, - const std::string& action) - { - int rc = 0; - int target = 0; - for (size_t i = 0; rc == 0 && i < optarg.size(); ++i) { - switch (optarg[i]) { - case 'e': target |= Params::ctExif; break; - case 'i': target |= Params::ctIptc; break; - case 'c': target |= Params::ctComment; break; - case 't': target |= Params::ctThumb; break; - case 'a': target |= Params::ctExif - | Params::ctIptc - | Params::ctComment; break; - default: - std::cerr << Params::instance().progname() << ": Unrecognized " - << action << " target `" << optarg[i] << "'\n"; - rc = -1; - break; - } - } - return rc ? rc : target; - } // parseCommonTargets - - bool parseCmdFiles(ModifyCmds& modifyCmds, - const Params::CmdFiles& cmdFiles) - { - Params::CmdFiles::const_iterator end = cmdFiles.end(); - Params::CmdFiles::const_iterator filename = cmdFiles.begin(); - for ( ; filename != end; ++filename) { - try { - std::ifstream file(filename->c_str()); - if (!file) { - std::cerr << *filename - << ": Failed to open command file for reading\n"; - return false; - } - int num = 0; - std::string line; - while (std::getline(file, line)) { - ModifyCmd modifyCmd; - if (parseLine(modifyCmd, line, ++num)) { - modifyCmds.push_back(modifyCmd); - } - } - } - catch (const Exiv2::AnyError& error) { - std::cerr << *filename << ", line " << error << "\n"; - return false; - } - } - return true; - } // parseCmdFile - - bool parseCmdLines(ModifyCmds& modifyCmds, - const Params::CmdLines& cmdLines) - { - try { - int num = 0; - Params::CmdLines::const_iterator end = cmdLines.end(); - Params::CmdLines::const_iterator line = cmdLines.begin(); - for ( ; line != end; ++line) { - ModifyCmd modifyCmd; - if (parseLine(modifyCmd, *line, ++num)) { - modifyCmds.push_back(modifyCmd); - } - } - return true; - } - catch (const Exiv2::AnyError& error) { - std::cerr << "-M option " << error << "\n"; - return false; - } - } // parseCmdLines - - bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num) - { - const std::string delim = " \t"; - - // Skip empty lines and comments - std::string::size_type cmdStart = line.find_first_not_of(delim); - if (cmdStart == std::string::npos || line[cmdStart] == '#') return false; - - // Get command and key - std::string::size_type cmdEnd = line.find_first_of(delim, cmdStart+1); - std::string::size_type keyStart = line.find_first_not_of(delim, cmdEnd+1); - std::string::size_type keyEnd = line.find_first_of(delim, keyStart+1); - if ( cmdStart == std::string::npos - || cmdEnd == std::string::npos - || keyStart == std::string::npos) { - throw Exiv2::Error(1, Exiv2::toString(num) - + ": Invalid command line"); - } - - std::string cmd(line.substr(cmdStart, cmdEnd-cmdStart)); - CmdId cmdId = commandId(cmd); - if (cmdId == invalidCmdId) { - throw Exiv2::Error(1, Exiv2::toString(num) - + ": Invalid command `" + cmd + "'"); - } - - Exiv2::TypeId defaultType = Exiv2::invalidTypeId; - std::string key(line.substr(keyStart, keyEnd-keyStart)); - MetadataId metadataId = invalidMetadataId; - try { - Exiv2::IptcKey iptcKey(key); - metadataId = iptc; - defaultType = Exiv2::IptcDataSets::dataSetType(iptcKey.tag(), - iptcKey.record()); - } - catch (const Exiv2::AnyError&) {} - if (metadataId == invalidMetadataId) { - try { - Exiv2::ExifKey exifKey(key); - metadataId = exif; - defaultType = Exiv2::ExifTags::tagType(exifKey.tag(), - exifKey.ifdId()); - } - catch (const Exiv2::AnyError&) {} - } - if (metadataId == invalidMetadataId) { - throw Exiv2::Error(1, Exiv2::toString(num) - + ": Invalid key `" + key + "'"); - } - - std::string value; - Exiv2::TypeId type = defaultType; - bool explicitType = false; - if (cmdId != del) { - // Get type and value - std::string::size_type typeStart - = line.find_first_not_of(delim, keyEnd+1); - std::string::size_type typeEnd - = line.find_first_of(delim, typeStart+1); - std::string::size_type valStart = typeStart; - std::string::size_type valEnd = line.find_last_not_of(delim); - - if ( keyEnd == std::string::npos - || typeStart == std::string::npos - || valStart == std::string::npos) { - throw Exiv2::Error(1, Exiv2::toString(num) - + ": Invalid command line "); - } - - if (typeEnd != std::string::npos) { - std::string typeStr(line.substr(typeStart, typeEnd-typeStart)); - Exiv2::TypeId tmpType = Exiv2::TypeInfo::typeId(typeStr); - if (tmpType != Exiv2::invalidTypeId) { - valStart = line.find_first_not_of(delim, typeEnd+1); - if (valStart == std::string::npos) { - throw Exiv2::Error(1, Exiv2::toString(num) - + ": Invalid command line "); - } - type = tmpType; - explicitType = true; - } - } - - value = line.substr(valStart, valEnd+1-valStart); - std::string::size_type last = value.length()-1; - if ( (value[0] == '"' || value[last] == '"') - && value[0] != value[last]) { - throw Exiv2::Error(1, Exiv2::toString(num) - + ": Unbalanced quotes"); - } - if (value[0] == '"') { - value = value.substr(1, value.length()-2); - } - } - - modifyCmd.cmdId_ = cmdId; - modifyCmd.key_ = key; - modifyCmd.metadataId_ = metadataId; - modifyCmd.typeId_ = type; - modifyCmd.explicitType_ = explicitType; - modifyCmd.value_ = value; - - return true; - } // parseLine - - CmdId commandId(const std::string& cmdString) - { - int i = 0; - for (; cmdIdAndString[i].cmdId_ != invalidCmdId - && cmdIdAndString[i].cmdString_ != cmdString; ++i) {} - return cmdIdAndString[i].cmdId_; - } - -} diff --git a/src/plugins/exiv2/exiv2.hpp b/src/plugins/exiv2/exiv2.hpp @@ -1,219 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> - * - * This program is part of the Exiv2 distribution. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -/*! - @file exiv2.hpp - @brief Defines class Params, used for the command line handling of exiv2 - @version $Rev: 598 $ - @author Andreas Huggel (ahu) - <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> - @date 08-Dec-03, ahu: created - */ -#ifndef EXIV2_HPP_ -#define EXIV2_HPP_ - -// ***************************************************************************** -// included header files -#include "utils.hpp" -#include "types.hpp" - -// + standard includes -#include <string> -#include <vector> -#include <iostream> - -// ***************************************************************************** -// class definitions - -//! Command identifiers -enum CmdId { invalidCmdId, add, set, del }; -//! Metadata identifiers -enum MetadataId { invalidMetadataId, iptc, exif }; -//! Structure for one parsed modification command -struct ModifyCmd { - //! C'tor - ModifyCmd() : - cmdId_(invalidCmdId), metadataId_(invalidMetadataId), - typeId_(Exiv2::invalidTypeId), explicitType_(false) {} - CmdId cmdId_; //!< Command identifier - std::string key_; //!< Exiv2 key string - MetadataId metadataId_; //!< Metadata identifier - Exiv2::TypeId typeId_; //!< Exiv2 type identifier - //! Flag to indicate if the type was explicitely specified (true) - bool explicitType_; - std::string value_; //!< Data -}; -//! Container for modification commands -typedef std::vector<ModifyCmd> ModifyCmds; -//! Structure to link command identifiers to strings -struct CmdIdAndString { - CmdId cmdId_; //!< Commands identifier - std::string cmdString_; //!< Command string -}; - -/*! - @brief Implements the command line handling for the program. - - Derives from Util::Getopt to use the command line argument parsing - functionalty provided there. This class is implemented as a Singleton, - i.e., there is only one global instance of it, which can be accessed - from everywhere. - - <b>Usage example:</b> <br> - @code - #include "params.h" - - int main(int argc, char* const argv[]) - { - Params& params = Params::instance(); - if (params.getopt(argc, argv)) { - params.usage(); - return 1; - } - if (params.help_) { - params.help(); - return 0; - } - if (params.version_) { - params.version(); - return 0; - } - - // do something useful here... - - return 0; - } - @endcode - */ -class Params : public Util::Getopt { -private: - std::string optstring_; - -public: - //! Container for command files - typedef std::vector<std::string> CmdFiles; - //! Container for commands from the command line - typedef std::vector<std::string> CmdLines; - //! Container to store filenames. - typedef std::vector<std::string> Files; - - /*! - @brief Controls all access to the global Params instance. - @return Reference to the global Params instance. - */ - static Params& instance(); - //! Destructor - void cleanup(); - - //! Enumerates print modes - enum PrintMode { pmSummary, pmInterpreted, pmValues, pmHexdump, pmIptc, - pmComment }; - //! Enumerates common targets, bitmap - enum CommonTarget { ctExif = 1, ctIptc = 2, ctComment = 4, ctThumb = 8 }; - //! Enumerates the policies to handle existing files in rename action - enum FileExistsPolicy { overwritePolicy, renamePolicy, askPolicy }; - - bool help_; //!< Help option flag. - bool version_; //!< Version option flag. - bool verbose_; //!< Verbose (talkative) option flag. - bool force_; //!< Force overwrites flag. - FileExistsPolicy fileExistsPolicy_; //!< What to do if file to rename exists. - bool adjust_; //!< Adjustment flag. - PrintMode printMode_; //!< Print mode. - //! %Action (integer rather than TaskType to avoid dependency). - int action_; - int target_; //!< What common target to process. - - long adjustment_; //!< Adjustment in seconds. - std::string format_; //!< Filename format (-r option arg). - CmdFiles cmdFiles_; //!< Names of the modification command files - CmdLines cmdLines_; //!< Commands from the command line - ModifyCmds modifyCmds_; //!< Parsed modification commands - std::string directory_; //!< Location for files to extract/insert - Files files_; //!< List of non-option arguments. - -private: - /*! - @brief Default constructor. Note that optstring_ is initialized here. - The c'tor is private to force instantiation through instance(). - */ - Params() : optstring_(":hVvfFa:r:p:d:e:i:m:M:l:"), - help_(false), - version_(false), - verbose_(false), - force_(false), - fileExistsPolicy_(askPolicy), - adjust_(false), - printMode_(pmSummary), - action_(0), - target_(ctExif|ctIptc|ctComment), - adjustment_(0), - format_("%Y%m%d_%H%M%S"), - first_(true) {} - - //! Prevent copy-construction: not implemented. - Params(const Params& rhs); - - //! @name Helpers - //@{ - int evalRename(const std::string& optarg); - int evalAdjust(const std::string& optarg); - int evalPrint(const std::string& optarg); - int evalDelete(const std::string& optarg); - int evalExtract(const std::string& optarg); - int evalInsert(const std::string& optarg); - int evalModify(int opt, const std::string& optarg); - //@} - - //! Pointer to the global Params object. - static Params* instance_; - - bool first_; - -public: - /*! - @brief Call Getopt::getopt() with optstring, to inititate command line - argument parsing, perform consistency checks after all command line - arguments are parsed. - - @param argc Argument count as passed to main() on program invocation. - @param argv Argument array as passed to main() on program invocation. - - @return 0 if successful, >0 in case of errors. - */ - int getopt(int argc, char* const argv[]); - - //! Handle options and their arguments. - virtual int option(int opt, const std::string& optarg, int optopt); - - //! Handle non-option parameters. - virtual int nonoption(const std::string& argv); - - //! Print a minimal usage note to an output stream. - void usage(std::ostream& os =std::cout) const; - - //! Print further usage explanations to an output stream. - void help(std::ostream& os =std::cout) const; - - //! Print version information to an output stream. - void version(std::ostream& os =std::cout) const; -}; // class Params - -#endif // #ifndef EXIV2_HPP_ diff --git a/src/plugins/exiv2/getopt_win32.h b/src/plugins/exiv2/getopt_win32.h @@ -1,140 +0,0 @@ -/* Declarations for getopt. - Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. - - 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 the - Free Software Foundation; either version 2, or (at your option) any - later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef _GETOPT_H -#define _GETOPT_H 1 - -#ifdef _MSC_VER - -#if defined(_MSC_VER) && !defined(BUILD_GETOPT) -# ifdef _DEBUG -# pragma comment(lib,"getopt_debug.lib") -# else -# pragma comment(lib,"getopt.lib") -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -extern char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns EOF, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -extern int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -extern int opterr; - -/* Set to an option character which was unrecognized. */ - -extern int optopt; - -/* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector - of `struct option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -struct option -{ -#if __STDC__ || _MSC_VER || defined(XP_OS2_VACPP) - const char *name; -#else - char *name; -#endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* Names for the values of the `has_arg' field of `struct option'. */ - -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 - -#if __STDC__ || _MSC_VER || defined( XP_OS2_VACPP ) -#if defined(__GNU_LIBRARY__) || defined( XP_OS2_VACPP ) || defined(_MSC_VER) -/* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ -extern int getopt (int argc, char *const *argv, const char *shortopts); -#else /* not __GNU_LIBRARY__ */ -extern int getopt (); -#endif /* not __GNU_LIBRARY__ */ -extern int getopt_long (int argc, char *const *argv, const char *shortopts, - const struct option *longopts, int *longind); -extern int getopt_long_only (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind); - -/* Internal only. Users should not call this directly. */ -extern int _getopt_internal (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind, - int long_only); -#else /* not __STDC__ */ -extern int getopt (); -extern int getopt_long (); -extern int getopt_long_only (); - -extern int _getopt_internal (); -#endif /* not __STDC__ */ - -#ifdef __cplusplus -} -#endif - -#endif /* _MSC_VER */ -#endif /* _GETOPT_H */ diff --git a/src/plugins/exiv2/iptceasy.cpp b/src/plugins/exiv2/iptceasy.cpp @@ -1,49 +0,0 @@ -// ***************************************************************** -*- C++ -*- -// iptceasy.cpp, $Rev: 560 $ -// The quickest way to access, set or modify Iptc metadata. - -#include "iptc.hpp" -#include "image.hpp" -#include <iostream> -#include <iomanip> -#include <cassert> - -int main(int argc, char* const argv[]) -try { - if (argc != 2) { - std::cout << "Usage: " << argv[0] << " file\n"; - return 1; - } - std::string file(argv[1]); - - Exiv2::IptcData iptcData; - - iptcData["Iptc.Application2.Headline"] = "The headline I am"; - iptcData["Iptc.Application2.Keywords"] = "Yet another keyword"; - iptcData["Iptc.Application2.DateCreated"] = "2004-8-3"; - iptcData["Iptc.Application2.Urgency"] = uint16_t(1); - iptcData["Iptc.Envelope.ModelVersion"] = 42; - iptcData["Iptc.Envelope.TimeSent"] = "14:41:0-05:00"; - iptcData["Iptc.Application2.RasterizedCaption"] = "230 42 34 2 90 84 23 146"; - iptcData["Iptc.0x0009.0x0001"] = "Who am I?"; - - Exiv2::StringValue value; - value.read("very!"); - iptcData["Iptc.Application2.Urgency"] = value; - - std::cout << "Time sent: " << iptcData["Iptc.Envelope.TimeSent"] << "\n"; - - // Open image file - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file); - assert (image.get() != 0); - - // Set Iptc data and write it to the file - image->setIptcData(iptcData); - image->writeMetadata(); - - return 0; -} -catch (Exiv2::AnyError& e) { - std::cout << "Caught Exiv2 exception '" << e << "'\n"; - return -1; -} diff --git a/src/plugins/exiv2/iptcprint.cpp b/src/plugins/exiv2/iptcprint.cpp @@ -1,50 +0,0 @@ -// ***************************************************************** -*- C++ -*- -// iptcprint.cpp, $Rev: 578 $ -// Sample program to print the Iptc metadata of an image - -#include "image.hpp" -#include "iptc.hpp" -#include <iostream> -#include <iomanip> -#include <cassert> - -int main(int argc, char* const argv[]) -try { - - if (argc != 2) { - std::cout << "Usage: " << argv[0] << " file\n"; - return 1; - } - - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]); - assert (image.get() != 0); - image->readMetadata(); - - Exiv2::IptcData &iptcData = image->iptcData(); - if (iptcData.empty()) { - std::string error(argv[1]); - error += ": No Iptc data found in the file"; - throw Exiv2::Error(1, error); - } - - Exiv2::IptcData::iterator end = iptcData.end(); - for (Exiv2::IptcData::iterator md = iptcData.begin(); md != end; ++md) { - std::cout << std::setw(44) << std::setfill(' ') << std::left - << md->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right - << std::hex << md->tag() << " " - << std::setw(9) << std::setfill(' ') << std::left - << md->typeName() << " " - << std::dec << std::setw(3) - << std::setfill(' ') << std::right - << md->count() << " " - << std::dec << md->value() - << std::endl; - } - - return 0; -} -catch (Exiv2::AnyError& e) { - std::cout << "Caught Exiv2 exception '" << e << "'\n"; - return -1; -} diff --git a/src/plugins/exiv2/metacopy.cpp b/src/plugins/exiv2/metacopy.cpp @@ -1,182 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> - * - * This program is part of the Exiv2 distribution. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -/* - Abstract : Tester application for image file handling - - File : metacopy.cpp - Version : $Rev: 560 $ - Author(s): Brad Schick (brad) <brad@robotbattle.com> - History : 13-Jul-04, brad: created - */ -// ***************************************************************************** -// included header files -#include "image.hpp" -#include "iptc.hpp" -#include "exif.hpp" -#include "types.hpp" -#include "metacopy.hpp" -#include <iostream> -#include <fstream> -#include <cassert> - -// ***************************************************************************** -// Main -int main(int argc, char* const argv[]) -{ -try { - // Handle command line arguments - Params params; - if (params.getopt(argc, argv)) { - params.usage(); - return 1; - } - if (params.help_) { - params.help(); - return 2; - } - - // Use MemIo to increase test coverage. - Exiv2::BasicIo::AutoPtr fileIo(new Exiv2::FileIo(params.read_)); - Exiv2::BasicIo::AutoPtr memIo(new Exiv2::MemIo); - memIo->transfer(*fileIo); - - Exiv2::Image::AutoPtr readImg = Exiv2::ImageFactory::open(memIo); - assert(readImg.get() != 0); - readImg->readMetadata(); - - Exiv2::Image::AutoPtr writeImg = Exiv2::ImageFactory::open(params.write_); - 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()); - } - - try { - writeImg->writeMetadata(); - } - catch (const Exiv2::AnyError&) { - std::cerr << params.progname() << - ": Could not write metadata to (" << params.write_ << ")\n"; - return 8; - } - - return 0; -} -catch (Exiv2::AnyError& e) { - std::cerr << "Caught Exiv2 exception '" << e << "'\n"; - return 10; -} -} - -int Params::option(int opt, const std::string& optarg, int optopt) -{ - 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 'p': preserve_ = true; break; - case 'a': - iptc_ =true; - exif_ =true; - comment_ =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; -} - -int Params::nonoption(const std::string& argv) -{ - 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 Params::getopt(int argc, char* const argv[]) -{ - int rc = Util::Getopt::getopt(argc, argv, optstring_); - // Further consistency checks - if (help_==false) { - 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_ ) { - std::cerr << progname() << ": Option -p has no effect when all metadata types are specified.\n"; - rc = 1; - } - } - return rc; -} // Params::getopt - - -void Params::usage(std::ostream& os) const -{ - os << "\nReads and writes raw metadata. Use -h option for help.\n" - << "Usage: " << progname() - << " [-iecaph] readfile writefile\n"; -} - -void Params::help(std::ostream& os) const -{ - usage(os); - 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" - << " -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"; -} // Params::help - diff --git a/src/plugins/exiv2/metacopy.hpp b/src/plugins/exiv2/metacopy.hpp @@ -1,86 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> - * - * This program is part of the Exiv2 distribution. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -/*! - @file metacopy.hpp - @brief Defines class Params, used for the command line handling - @version $Rev: 538 $ - @author Brad Schick (brad) <brad@robotbattle.com> - @date 13-Jul-04, brad: created - */ -#ifndef METACOPY_HPP_ -#define METACOPY_HPP_ - -#include "utils.hpp" - -class Params : public Util::Getopt { -private: - std::string optstring_; - bool first_; - -public: - bool help_; //!< Help option flag. - bool iptc_; //!< Iptc option flag. - bool exif_; //!< Exif option flag. - bool comment_; //!< JPEG comment option flag. - bool preserve_; //!< Preserve existing metadata option flag. - std::string read_; //!< Source file - std::string write_; //!< Destination file - -public: - /*! - @brief Default constructor. Note that optstring_ is initialized here. - */ - Params() : optstring_(":iecaph"), - first_(true), - help_(false), - iptc_(false), - exif_(false), - comment_(false), - preserve_(false) - {} - - /*! - @brief Call Getopt::getopt() with optstring, to initiate command line - argument parsing, perform consistency checks after all command line - arguments are parsed. - - @param argc Argument count as passed to main() on program invocation. - @param argv Argument array as passed to main() on program invocation. - - @return 0 if successful, >0 in case of errors. - */ - int getopt(int argc, char* const argv[]); - - //! Handle options and their arguments. - virtual int option(int opt, const std::string& optarg, int optopt); - - //! Handle non-option parameters. - virtual int nonoption(const std::string& argv); - - //! Print a minimal usage note to an output stream. - void usage(std::ostream& os =std::cout) const; - - //! Print further usage explanations to an output stream. - void help(std::ostream& os =std::cout) const; - -}; // class Params - -#endif // METACOPY_HPP_ diff --git a/src/plugins/exiv2/private.h b/src/plugins/exiv2/private.h @@ -1,235 +0,0 @@ -/*! - @file private.h - @brief This file is from the tz distribution at ftp://elsie.nci.nih.gov/pub/ - @version $Rev: 544 $ -*/ -#ifndef PRIVATE_H - -#define PRIVATE_H - -/* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). -*/ - -/* -** This header is for use ONLY with the time conversion code. -** There is no guarantee that it will remain unchanged, -** or that it will remain at all. -** Do NOT copy it to any system include directory. -** Thank you! -*/ - -/* -** ID -*/ - -#ifndef lint -#ifndef NOID -static char privatehid[] = "@(#)private.h 7.53"; -#endif /* !defined NOID */ -#endif /* !defined lint */ - -/* ahu: moved required preprocessor symbols to config.h */ - -/* ahu: disable warnings */ -#ifdef _MSC_VER -// disable warning 'uses old-style declarator' C4131 -#pragma warning (disable: 4131) -#endif - -/* -** Nested includes -*/ - -#include "sys/types.h" /* for time_t */ -#include "stdio.h" -#include "errno.h" -#include "string.h" -#include "limits.h" /* for CHAR_BIT */ -#include "time.h" -#include "stdlib.h" - -/* ahu: added io.h for MSVC */ -#ifdef _MSC_VER -# include "io.h" -#endif - -/* ahu: deleted include libintl.h */ - -/* ahu: deleted include sys/wait.h and WIFEXITED, WEXITSTATUS macros */ - -#if EXV_HAVE_UNISTD_H - 0 -#include "unistd.h" /* for F_OK and R_OK */ -#endif /* EXV_HAVE_UNISTD_H - 0 */ - -#if !(EXV_HAVE_UNISTD_H - 0) -#ifndef F_OK -#define F_OK 0 -#endif /* !defined F_OK */ -#ifndef R_OK -#define R_OK 4 -#endif /* !defined R_OK */ -#endif /* !(EXV_HAVE_UNISTD_H - 0) */ - -/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */ -#define is_digit(c) ((unsigned)(c) - '0' <= 9) - -/* -** Workarounds for compilers/systems. -*/ - -/* -** SunOS 4.1.1 cc lacks prototypes. -*/ - -#ifndef P -#ifdef __STDC__ -#define P(x) x -#endif /* defined __STDC__ */ -#ifndef __STDC__ -#define P(x) () -#endif /* !defined __STDC__ */ -#endif /* !defined P */ - -/* -** SunOS 4.1.1 headers lack EXIT_SUCCESS. -*/ - -#ifndef EXIT_SUCCESS -#define EXIT_SUCCESS 0 -#endif /* !defined EXIT_SUCCESS */ - -/* -** SunOS 4.1.1 headers lack EXIT_FAILURE. -*/ - -#ifndef EXIT_FAILURE -#define EXIT_FAILURE 1 -#endif /* !defined EXIT_FAILURE */ - -/* -** SunOS 4.1.1 headers lack FILENAME_MAX. -*/ - -#ifndef FILENAME_MAX - -#ifndef MAXPATHLEN -#ifdef unix -#include "sys/param.h" -#endif /* defined unix */ -#endif /* !defined MAXPATHLEN */ - -#ifdef MAXPATHLEN -#define FILENAME_MAX MAXPATHLEN -#endif /* defined MAXPATHLEN */ -#ifndef MAXPATHLEN -#define FILENAME_MAX 1024 /* Pure guesswork */ -#endif /* !defined MAXPATHLEN */ - -#endif /* !defined FILENAME_MAX */ - -/* -** SunOS 4.1.1 libraries lack remove. -*/ - -#ifndef remove -extern int unlink P((const char * filename)); -#define remove unlink -#endif /* !defined remove */ - -/* -** Some ancient errno.h implementations don't declare errno. -** But some newer errno.h implementations define it as a macro. -** Fix the former without affecting the latter. -*/ -#ifndef errno -extern int errno; -#endif /* !defined errno */ - -/* -** Private function declarations. -*/ -char * icalloc P((int nelem, int elsize)); -char * icatalloc P((char * old, const char * new)); -char * icpyalloc P((const char * string)); -char * imalloc P((int n)); -void * irealloc P((void * pointer, int size)); -void icfree P((char * pointer)); -void ifree P((char * pointer)); -char * scheck P((const char *string, const char *format)); - - -/* -** Finally, some convenience items. -*/ - -#ifndef TRUE -#define TRUE 1 -#endif /* !defined TRUE */ - -#ifndef FALSE -#define FALSE 0 -#endif /* !defined FALSE */ - -#ifndef TYPE_BIT -#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) -#endif /* !defined TYPE_BIT */ - -#ifndef TYPE_SIGNED -#define TYPE_SIGNED(type) (((type) -1) < 0) -#endif /* !defined TYPE_SIGNED */ - -#ifndef INT_STRLEN_MAXIMUM -/* -** 302 / 1000 is log10(2.0) rounded up. -** Subtract one for the sign bit if the type is signed; -** add one for integer division truncation; -** add one more for a minus sign if the type is signed. -*/ -#define INT_STRLEN_MAXIMUM(type) \ - ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type)) -#endif /* !defined INT_STRLEN_MAXIMUM */ - -/* -** INITIALIZE(x) -*/ - -#ifndef GNUC_or_lint -#ifdef lint -#define GNUC_or_lint -#endif /* defined lint */ -#ifndef lint -#ifdef __GNUC__ -#define GNUC_or_lint -#endif /* defined __GNUC__ */ -#endif /* !defined lint */ -#endif /* !defined GNUC_or_lint */ - -#ifndef INITIALIZE -#ifdef GNUC_or_lint -#define INITIALIZE(x) ((x) = 0) -#endif /* defined GNUC_or_lint */ -#ifndef GNUC_or_lint -#define INITIALIZE(x) -#endif /* !defined GNUC_or_lint */ -#endif /* !defined INITIALIZE */ - -/* ahu: deleted definition of _(msgid) macro */ - -#ifndef TZ_DOMAIN -#define TZ_DOMAIN "tz" -#endif /* !defined TZ_DOMAIN */ - -#if HAVE_INCOMPATIBLE_CTIME_R -#undef asctime_r -#undef ctime_r -char *asctime_r P((struct tm const *, char *)); -char *ctime_r P((time_t const *, char *)); -#endif /* HAVE_INCOMPATIBLE_CTIME_R */ - -/* -** UNIX was a registered trademark of The Open Group in 2003. -*/ - -#endif /* !defined PRIVATE_H */ diff --git a/src/plugins/exiv2/taglist.cpp b/src/plugins/exiv2/taglist.cpp @@ -1,69 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - Abstract: Print a simple comma separated list of tags defined in Exiv2 - - File: taglist.cpp - Version: $Rev: 570 $ - Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net> - History: 07-Jan-04, ahu: created - */ -// ***************************************************************************** -#include "rcsid.hpp" -EXIV2_RCSID("@(#) $Id: taglist.cpp 570 2005-05-28 15:35:08Z ahuggel $"); - -#include "makernote.hpp" -#include "tags.hpp" -#include "datasets.hpp" -#include "error.hpp" - -#include <string> -#include <iostream> - -using namespace Exiv2; - -int main(int argc, char* argv[]) -try { - int rc = 0; - - switch (argc) { - case 2: - { - std::string item(argv[1]); - - if (item == "Exif") { - ExifTags::taglist(std::cout); - break; - } - - if (item == "Iptc") { - IptcDataSets::dataSetList(std::cout); - break; - } - - IfdId ifdId = ExifTags::ifdIdByIfdItem(item); - if (ExifTags::isMakerIfd(ifdId)) { - ExifTags::makerTaglist(std::cout, ifdId); - } - else { - rc = 2; - } - break; - } - case 1: - ExifTags::taglist(std::cout); - break; - default: - rc = 1; - break; - } - if (rc) { - std::cout << "Usage: " << argv[0] - << " [Exif|Canon|CanonCs1|CanonCs2|CanonCf|Fujifilm|Nikon1|Nikon2|Nikon3|Olympus|Sigma|Sony|Iptc]\n" - << "Print Exif tags, MakerNote tags, or Iptc datasets\n"; - } - return rc; -} -catch (AnyError& e) { - std::cout << "Caught Exiv2 exception '" << e << "'\n"; - return 1; -} diff --git a/src/plugins/exiv2/timegm.h b/src/plugins/exiv2/timegm.h @@ -1,88 +0,0 @@ -/*! - @file timegm.h - @brief Declaration of timegm(). The implementation is in localtime.c - @version $Rev: 392 $ -*/ -#ifndef TIMEGM_H_ -#define TIMEGM_H_ - -#include <time.h> - -/* - The following comments are copied from the Makefile of the tz distribution, - available at ftp://elsie.nci.nih.gov/pub/: - - NIST-PCTS:151-2, Version 1.4, (1993-12-03) is a test suite put - out by the National Institute of Standards and Technology - which claims to test C and Posix conformance. If you want to pass PCTS, add - -DPCTS - to the end of the "CFLAGS=" line. - - If your system has a "zone abbreviation" field in its "struct tm"s - (or if you decide to add such a field in your system's "time.h" file), - add the name to a define such as - -DTM_ZONE=tm_zone - or - -DTM_ZONE=_tm_zone - to the end of the "CFLAGS=" line. - - If you want functions that were inspired by early versions of X3J11's work, - add - -DSTD_INSPIRED - to the end of the "CFLAGS=" line. - - If you want to allocate state structures in localtime, add - -DALL_STATE - to the end of the "CFLAGS=" line. Storage is obtained by calling malloc. - - If you want Source Code Control System ID's left out of object modules, add - -DNOID - - Add the following to the end of the "CFLAGS=" line as needed. - -DTZDEFRULESTRING=\",date/time,date/time\" to default to the specified - DST transitions if the time zone files cannot be accessed - - If you want to use System V compatibility code, add - -DUSG_COMPAT - to the end of the "CFLAGS=" line. This arrange for "timezone" and "daylight" - variables to be kept up-to-date by the time conversion functions. Neither - "timezone" nor "daylight" is described in X3J11's work. - - If you want an "altzone" variable (a la System V Release 3.1), add - -DALTZONE - to the end of the "CFLAGS=" line. - This variable is not described in X3J11's work. - - If your system has a "GMT offset" field in its "struct tm"s - (or if you decide to add such a field in your system's "time.h" file), - add the name to a define such as - -DTM_GMTOFF=tm_gmtoff - or - -DTM_GMTOFF=_tm_gmtoff - to the end of the "CFLAGS=" line. - Neither tm_gmtoff nor _tm_gmtoff is described in X3J11's work; - in its work, use of "tm_gmtoff" is described as non-conforming. - Both Linux and BSD have done the equivalent of defining TM_GMTOFF in - their recent releases. - - If you want a "gtime" function (a la MACH), add - -DCMUCS - to the end of the "CFLAGS=" line - This function is not described in X3J11's work. -*/ - -#define STD_INSPIRED -#define NOID - -#ifdef __cplusplus -extern "C" { -#endif - -// The UTC version of mktime -time_t timegm(struct tm * const tmp); - -#ifdef __cplusplus -} -#endif - -#endif // #ifndef TIMEGM_H_ diff --git a/src/plugins/exiv2/tzfile.h b/src/plugins/exiv2/tzfile.h @@ -1,193 +0,0 @@ -/*! - @file tzfile.h - @brief This file is from the tz distribution at ftp://elsie.nci.nih.gov/pub/ - @version $Rev: 392 $ -*/ -#ifndef TZFILE_H - -#define TZFILE_H - -/* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). -*/ - -/* -** This header is for use ONLY with the time conversion code. -** There is no guarantee that it will remain unchanged, -** or that it will remain at all. -** Do NOT copy it to any system include directory. -** Thank you! -*/ - -/* -** ID -*/ - -#ifndef lint -#ifndef NOID -static char tzfilehid[] = "@(#)tzfile.h 7.14"; -#endif /* !defined NOID */ -#endif /* !defined lint */ - -/* -** Information about time zone files. -*/ - -#ifndef TZDIR -#define TZDIR "/usr/local/etc/zoneinfo" /* Time zone object file directory */ -#endif /* !defined TZDIR */ - -#ifndef TZDEFAULT -#define TZDEFAULT "localtime" -#endif /* !defined TZDEFAULT */ - -#ifndef TZDEFRULES -#define TZDEFRULES "posixrules" -#endif /* !defined TZDEFRULES */ - -/* -** Each file begins with. . . -*/ - -#define TZ_MAGIC "TZif" - -struct tzhead { - char tzh_magic[4]; /* TZ_MAGIC */ - char tzh_reserved[16]; /* reserved for future use */ - char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ - char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ - char tzh_leapcnt[4]; /* coded number of leap seconds */ - char tzh_timecnt[4]; /* coded number of transition times */ - char tzh_typecnt[4]; /* coded number of local time types */ - char tzh_charcnt[4]; /* coded number of abbr. chars */ -}; - -/* -** . . .followed by. . . -** -** tzh_timecnt (char [4])s coded transition times a la time(2) -** tzh_timecnt (unsigned char)s types of local time starting at above -** tzh_typecnt repetitions of -** one (char [4]) coded UTC offset in seconds -** one (unsigned char) used to set tm_isdst -** one (unsigned char) that's an abbreviation list index -** tzh_charcnt (char)s '\0'-terminated zone abbreviations -** tzh_leapcnt repetitions of -** one (char [4]) coded leap second transition times -** one (char [4]) total correction after above -** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition -** time is standard time, if FALSE, -** transition time is wall clock time -** if absent, transition times are -** assumed to be wall clock time -** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition -** time is UTC, if FALSE, -** transition time is local time -** if absent, transition times are -** assumed to be local time -*/ - -/* -** In the current implementation, "tzset()" refuses to deal with files that -** exceed any of the limits below. -*/ - -#ifndef TZ_MAX_TIMES -/* -** The TZ_MAX_TIMES value below is enough to handle a bit more than a -** year's worth of solar time (corrected daily to the nearest second) or -** 138 years of Pacific Presidential Election time -** (where there are three time zone transitions every fourth year). -*/ -#define TZ_MAX_TIMES 370 -#endif /* !defined TZ_MAX_TIMES */ - -#ifndef TZ_MAX_TYPES -#ifndef NOSOLAR -#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ -#endif /* !defined NOSOLAR */ -#ifdef NOSOLAR -/* -** Must be at least 14 for Europe/Riga as of Jan 12 1995, -** as noted by Earl Chew <earl@hpato.aus.hp.com>. -*/ -#define TZ_MAX_TYPES 20 /* Maximum number of local time types */ -#endif /* !defined NOSOLAR */ -#endif /* !defined TZ_MAX_TYPES */ - -#ifndef TZ_MAX_CHARS -#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ - /* (limited by what unsigned chars can hold) */ -#endif /* !defined TZ_MAX_CHARS */ - -#ifndef TZ_MAX_LEAPS -#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ -#endif /* !defined TZ_MAX_LEAPS */ - -#define SECSPERMIN 60 -#define MINSPERHOUR 60 -#define HOURSPERDAY 24 -#define DAYSPERWEEK 7 -#define DAYSPERNYEAR 365 -#define DAYSPERLYEAR 366 -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) -#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) -#define MONSPERYEAR 12 - -#define TM_SUNDAY 0 -#define TM_MONDAY 1 -#define TM_TUESDAY 2 -#define TM_WEDNESDAY 3 -#define TM_THURSDAY 4 -#define TM_FRIDAY 5 -#define TM_SATURDAY 6 - -#define TM_JANUARY 0 -#define TM_FEBRUARY 1 -#define TM_MARCH 2 -#define TM_APRIL 3 -#define TM_MAY 4 -#define TM_JUNE 5 -#define TM_JULY 6 -#define TM_AUGUST 7 -#define TM_SEPTEMBER 8 -#define TM_OCTOBER 9 -#define TM_NOVEMBER 10 -#define TM_DECEMBER 11 - -#define TM_YEAR_BASE 1900 - -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY TM_THURSDAY - -/* -** Accurate only for the past couple of centuries; -** that will probably do. -*/ - -#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) - -#ifndef USG - -/* -** Use of the underscored variants may cause problems if you move your code to -** certain System-V-based systems; for maximum portability, use the -** underscore-free variants. The underscored variants are provided for -** backward compatibility only; they may disappear from future versions of -** this file. -*/ - -#define SECS_PER_MIN SECSPERMIN -#define MINS_PER_HOUR MINSPERHOUR -#define HOURS_PER_DAY HOURSPERDAY -#define DAYS_PER_WEEK DAYSPERWEEK -#define DAYS_PER_NYEAR DAYSPERNYEAR -#define DAYS_PER_LYEAR DAYSPERLYEAR -#define SECS_PER_HOUR SECSPERHOUR -#define SECS_PER_DAY SECSPERDAY -#define MONS_PER_YEAR MONSPERYEAR - -#endif /* !defined USG */ - -#endif /* !defined TZFILE_H */ diff --git a/src/plugins/exiv2/utils.cpp b/src/plugins/exiv2/utils.cpp @@ -1,141 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> - * - * This program is part of the Exiv2 distribution. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -/* - File: utils.cpp - Version: $Rev: 560 $ - Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net> - History: 08-Dec-03, ahu: created - */ -// ***************************************************************************** -#include "rcsid.hpp" -EXIV2_RCSID("@(#) $Id: utils.cpp 560 2005-04-17 11:51:32Z ahuggel $"); - -// ***************************************************************************** -// included header files -#ifdef _MSC_VER -# include "exv_msvc.h" -#else -# include "exv_conf.h" -#endif - -#include "utils.hpp" - -// + standard includes -#include <sys/types.h> -#include <sys/stat.h> -#ifdef _MSC_VER -# include "getopt_win32.h" -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif -#ifdef EXV_HAVE_UNISTD_H -# include <unistd.h> // for getopt(), stat() -#endif - -#include <cerrno> -#include <cstdlib> -#include <cstring> -#include <string> -#include <iostream> -#include <sstream> - -namespace Util { - -// ***************************************************************************** -// class Getopt -int Getopt::getopt(int argc, char* const argv[], const std::string& optstring) -{ - progname_ = Util::basename(argv[0]); - - for (;;) { - int c = ::getopt(argc, argv, optstring.c_str()); - if (c == -1) break; - errcnt_ += option(c, ::optarg == 0 ? "" : ::optarg, ::optopt); - } - for (int i = ::optind; i < argc; i++) { - errcnt_ += nonoption(argv[i]); - } - return errcnt_; -} - -// ***************************************************************************** -// free functions - - std::string dirname(const std::string& path) - { - if (path == "") return "."; - // Strip trailing slashes or backslashes - std::string p = path; - while ( p.length() > 1 - && (p[p.length()-1] == '\\' || p[p.length()-1] == '/')) { - p = p.substr(0, p.length()-1); - } - if (p == "\\" || p == "/") return p; - if (p.length() == 2 && p[1] == ':') return p; // For Windows paths - std::string::size_type idx = p.find_last_of("\\/"); - if (idx == std::string::npos) return "."; - if (idx == 1 && p[0] == '\\' && p[1] == '\\') return p; // For Windows paths - p = p.substr(0, idx == 0 ? 1 : idx); - while ( p.length() > 1 - && (p[p.length()-1] == '\\' || p[p.length()-1] == '/')) { - p = p.substr(0, p.length()-1); - } - return p; - } - - std::string basename(const std::string& path, bool delsuffix) - { - if (path == "") return "."; - // Strip trailing slashes or backslashes - std::string p = path; - while ( p.length() > 1 - && (p[p.length()-1] == '\\' || p[p.length()-1] == '/')) { - p = p.substr(0, p.length()-1); - } - if (p.length() == 2 && p[1] == ':') return ""; // For Windows paths - std::string::size_type idx = p.find_last_of("\\/"); - if (idx == 1 && p[0] == '\\' && p[1] == '\\') return ""; // For Windows paths - if (idx != std::string::npos) p = p.substr(idx+1); - if (delsuffix) p = p.substr(0, p.length() - suffix(p).length()); - return p; - } - - std::string suffix(const std::string& path) - { - std::string b = basename(path); - std::string::size_type idx = b.rfind('.'); - if (idx == std::string::npos || idx == 0 || idx == b.length()-1) { - return ""; - } - return b.substr(idx); - } - - bool strtol(const char* nptr, long& n) - { - if (!nptr || *nptr == '\0') return false; - char* endptr = 0; - long tmp = ::strtol(nptr, &endptr, 10); - if (*endptr != '\0') return false; - if (tmp == LONG_MAX || tmp == LONG_MIN) return false; - n = tmp; - return true; - } - -} // namespace Util diff --git a/src/plugins/exiv2/utils.hpp b/src/plugins/exiv2/utils.hpp @@ -1,165 +0,0 @@ -// ********************************************************* -*- C++ -*- -/* - * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> - * - * This program is part of the Exiv2 distribution. - * - * 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 the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -/*! - @file utils.hpp - @brief A collection of utility functions - @version $Rev: 560 $ - @author Andreas Huggel (ahu) - <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> - @date 12-Dec-03, ahu: created - */ -#ifndef UTILS_HPP_ -#define UTILS_HPP_ - -// ********************************************************************* -// included header files -// + standard includes -#include <string> - -// ********************************************************************* -// namespace extensions -/*! - @brief Contains utility classes and functions. Most of these are - wrappers for common C functions that do not require pointers - and memory considerations. -*/ -namespace Util { - -// ********************************************************************* -// class definitions - -/*! - @brief Parse the command line options of a program. - - A wrapper around the POSIX %getopt(3) function. Parses the command line - options and passes each option to virtual option(). A derived class - implements this method to handle options as needed. Similarly, - remaining non-option parameters are passed to the virtual nonoption() - method. - */ -class Getopt { -public: - //! Default constructor. - Getopt() : errcnt_(0) {} - - //! Destructor. - virtual ~Getopt() {} - - /*! - @brief Parse command line arguments. - - Parses the command line arguments. Calls option() with the - character value of the option and its argument (if any) for each - recognized option and with ':' or '?' for unrecognized options. - See the manual pages for %getopt(3) for details. In addition, - nonoption() is invoked for each remaining non-option parameter on - the command line. - - @param argc Argument count as passed to main() on program invocation. - @param argv Argument array as passed to main() on program invocation. - @param optstring String containing the legitimate option characters. - - @return Number of errors (the sum of the return values from option() - and nonoption()). - */ - int getopt(int argc, char* const argv[], const std::string& optstring); - - /*! - @brief Callback used by getopt() to pass on each option and its - argument (if any). - - Implement this method in a derived class to handle the options as - needed. See the manual pages for %getopt(3) for further details, in - particular, the semantics of optarg and optopt. - - @param opt Value of the option character as returned by %getopt(3). - @param optarg The corresponding option argument. - @param optopt The actual option character in case of an unrecognized - option or a missing option argument (opt is '?' or ':'). - - @return 0 if successful, 1 in case of an error. - */ - virtual int option(int opt, const std::string& optarg, int optopt) = 0; - - /*! - @brief Callback used by getopt() to pass on each non-option parameter - found on the command line. - - Implement this method in a derived class to handle the non-option - parameters as needed. The default implementation ignores all non-option - parameters. - - @param argv The non-option parameter from the command line. - - @return 0 if successful, 1 in case of an error. - */ - virtual int nonoption(const std::string& argv) { return 0; } - - //! Program name (argv[0]) - const std::string& progname() const { return progname_; } - - //! Total number of errors returned by calls to option() - int errcnt() const { return errcnt_; } - -private: - std::string progname_; - int errcnt_; -}; - -// ********************************************************************* -// free functions - - /*! - @brief Get the directory component from the \em path string. - See %dirname(3). - - This function can handle Windows paths to some extent: c:\\bar should - be fine, \\\\bigsrv\\foo also, but \\\\bigsrv alone doesn't work. - */ - std::string dirname(const std::string& path); - - /*! - @brief Get the filename component from the \em path string. - See %basename(3). If the \em delsuffix parameter is true, - the suffix will be removed. - - This function can handle Windows paths to some extent: c:\\bar should - be fine, \\\\bigsrv\\foo also, but \\\\bigsrv alone doesn't work. - */ - std::string basename(const std::string& path, bool delsuffix =false); - - /*! - @brief Get the suffix from the path string. Normally, the suffix - is the substring of the basename of path from the last '.' - to the end of the string. - */ - std::string suffix(const std::string& path); - - /*! - @brief Convert a C string to a long value, which is returned in n. - Returns true if the conversion is successful, else false. - n is not modified if the conversion is unsuccessful. See strtol(2). - */ - bool strtol(const char* nptr, long& n); - -} // namespace Util - -#endif // #ifndef UTILS_HPP_