[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a
Maximiliano Curia
maxy at moszumanska.debian.org
Thu Jul 13 17:36:56 UTC 2017
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=1075ce0
The following commit has been merged in the master branch:
commit 1075ce06e48a45a213be1d4b55748f2d345806ee
Author: Andreas Huggel <ahuggel at gmx.net>
Date: Sat Feb 12 10:12:54 2005 +0000
Merged revisions 499:500 from Exiv2-0_6_041212 branch
---
src/cmd.txt | 14 +-
src/exiv2.cpp | 430 ++++++++++++++++++++++++++++++++++------------------------
src/exiv2.hpp | 27 +++-
3 files changed, 287 insertions(+), 184 deletions(-)
diff --git a/src/cmd.txt b/src/cmd.txt
index 8b1b44f..b4bce14 100644
--- a/src/cmd.txt
+++ b/src/cmd.txt
@@ -1,8 +1,17 @@
# Sample Exiv2 command file
-# Run exiv2 -m cmd.txt file ...
-# to apply the commands to each file.
+# -------------------------
#
+# $ exiv2 -m cmd.txt file ...
+#
+# to apply the commands in cmd.txt to each file. Alternatively, commands can be
+# run from the command line directly, without a command file:
+#
+# $ exiv2 -M'add Iptc.Application2.Credit String mee too!' file ...
+#
+# Note the quotes. Multiple -m and -M options are allowed and can be combined.
+#
# Command file format
+# -------------------
# Empty lines and lines starting with # are ignored
# Each remaining line is a command. The format for command lines is
# <cmd> <key> [[<type>] <value>]
@@ -20,6 +29,7 @@
# value
# The remaining text on the line is the value. It can optionally be enclosed in
# double quotes ("value")
+#
add Iptc.Application2.Credit String "mee too! (1)"
add Iptc.Application2.Credit mee too! (2)
diff --git a/src/exiv2.cpp b/src/exiv2.cpp
index c140db5..bb45f28 100644
--- a/src/exiv2.cpp
+++ b/src/exiv2.cpp
@@ -80,12 +80,20 @@ namespace {
const std::string& action);
/*!
- @brief Parse metadata modification commands from a file
+ @brief Parse metadata modification commands from multiple files
@param modifyCmds Reference to a structure to store the parsed commands
- @param filename Name of the command file
+ @param cmdFiles Container with the file names
*/
- bool parseCommands(ModifyCmds& modifyCmds,
- const std::string& filename);
+ 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
@@ -180,7 +188,7 @@ void Params::help(std::ostream& os) const
<< " mv | rename Rename files according to the Exif create timestamp.
"
<< " The filename format can be set with -r format.
"
<< " mo | modify Apply commands to modify (add, set, delete) the Exif
"
- << " and Iptc metadata of image files. Requires option -m
"
+ << " and Iptc metadata of image files. Requires option -m or -M
"
<< "
Options:
"
<< " -h Display this help and exit.
"
<< " -V Show the program version and exit.
"
@@ -209,8 +217,10 @@ void Params::help(std::ostream& os) const
<< " -r fmt Filename format for the `rename' action. The format string
"
<< " follows strftime(3). Default filename format is "
<< format_ << ".
"
- << " -m file Command file for the modify action. The format for the commands
"
- << " set|add|del <key> [[<Type>] <value>].
";
+ << " -m file Command file for the modify action. The format for commands is
"
+ << " set|add|del <key> [[<type>] <value>].
"
+ << " -M cmd One command line for the modify action. The format for the
"
+ << " commands is the same as that of the lines of a command file.
";
} // Params::help
int Params::option(int opt, const std::string& optarg, int optopt)
@@ -221,179 +231,215 @@ int Params::option(int opt, const std::string& optarg, int optopt)
case 'V': version_ = true; break;
case 'v': verbose_ = true; break;
case 'f': force_ = true; break;
- case 'r':
- switch (action_) {
- case Action::none:
- action_ = Action::rename;
- format_ = optarg;
- break;
- case Action::rename:
- std::cerr << progname()
- << ": Ignoring surplus option -r \"" << optarg << "\"
";
- break;
- default:
- std::cerr << progname()
- << ": Option -r is not compatible with a previous option
";
- rc = 1;
- 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 ':':
+ std::cerr << progname() << ": Option -" << static_cast<char>(optopt)
+ << " requires an argument
";
+ rc = 1;
break;
- case 'a':
- switch (action_) {
- case Action::none:
- action_ = Action::adjust;
- adjust_ = parseTime(optarg, adjustment_);
- if (!adjust_) {
- std::cerr << progname() << ": Error parsing -a option argument `"
- << optarg << "'
";
- rc = 1;
- }
- break;
- case Action::adjust:
- std::cerr << progname()
- << ": Ignoring surplus option -a " << optarg << "
";
- break;
- default:
- std::cerr << progname()
- << ": Option -a is not compatible with a previous option
";
- rc = 1;
- break;
- }
+ case '?':
+ std::cerr << progname() << ": Unrecognized option -"
+ << static_cast<char>(optopt) << "
";
+ rc = 1;
break;
- case 'p':
- 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 << "'
";
- rc = 1;
- break;
- }
- break;
- case Action::print:
- std::cerr << progname()
- << ": Ignoring surplus option -p" << optarg << "
";
- break;
- default:
- std::cerr << progname()
- << ": Option -p is not compatible with a previous option
";
+ default:
+ std::cerr << progname()
+ << ": getopt returned unexpected character code "
+ << std::hex << opt << "
";
+ 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 << "\"
";
+ break;
+ default:
+ std::cerr << progname()
+ << ": Option -r is not compatible with a previous option
";
+ 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 << "'
";
rc = 1;
- break;
}
break;
- case 'd':
- 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;
+ case Action::adjust:
+ std::cerr << progname()
+ << ": Ignoring surplus option -a " << optarg << "
";
+ break;
+ default:
+ std::cerr << progname()
+ << ": Option -a is not compatible with a previous option
";
+ 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()
- << ": Option -d is not compatible with a previous option
";
+ std::cerr << progname() << ": Unrecognized print mode `"
+ << optarg << "'
";
rc = 1;
break;
}
break;
- case 'e':
- 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
";
+ case Action::print:
+ std::cerr << progname()
+ << ": Ignoring surplus option -p" << optarg << "
";
+ break;
+ default:
+ std::cerr << progname()
+ << ": Option -p is not compatible with a previous option
";
+ 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;
}
break;
- case 'i':
- 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
";
+ default:
+ std::cerr << progname()
+ << ": Option -d is not compatible with a previous option
";
+ 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;
}
break;
- case 'm':
- switch (action_) {
- case Action::none:
- action_ = Action::modify;
- cmdFile_ = optarg; // parse the file later
- break;
- case Action::modify:
- std::cerr << progname()
- << ": Ignoring surplus option -m " << optarg << "
";
- break;
- default:
- std::cerr << progname()
- << ": Option -m is not compatible with a previous option
";
+ default:
+ std::cerr << progname()
+ << ": Option -e is not compatible with a previous option
";
+ 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;
}
break;
- case ':':
- std::cerr << progname() << ": Option -" << static_cast<char>(optopt)
- << " requires an argument
";
+ default:
+ std::cerr << progname()
+ << ": Option -i is not compatible with a previous option
";
rc = 1;
break;
- case '?':
- std::cerr << progname() << ": Unrecognized option -"
- << static_cast<char>(optopt) << "
";
- rc = 1;
+ }
+ 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()
- << ": getopt returned unexpected character code "
- << std::hex << opt << "
";
+ << ": Option -" << (char)opt
+ << " is not compatible with a previous option
";
rc = 1;
break;
}
return rc;
-} // Params::option
+} // Params::evalModify
int Params::nonoption(const std::string& argv)
{
@@ -491,9 +537,9 @@ int Params::getopt(int argc, char* const argv[])
<< ": Adjust action requires option -a time
";
rc = 1;
}
- if (action_ == Action::modify && cmdFile_.empty()) {
+ if (action_ == Action::modify && cmdFiles_.empty() && cmdLines_.empty()) {
std::cerr << progname()
- << ": Modify action requires option -m file
";
+ << ": Modify action requires at least one -m or -M option
";
rc = 1;
}
if (0 == files_.size()) {
@@ -501,9 +547,16 @@ int Params::getopt(int argc, char* const argv[])
rc = 1;
}
if (rc == 0 && action_ == Action::modify) {
- if (!parseCommands(modifyCmds_, cmdFile_)) {
- std::cerr << progname() << ": Error parsing -m option argument `"
- << cmdFile_ << "'
";
+ // Parse command files
+ if (!parseCmdFiles(modifyCmds_, cmdFiles_)) {
+ std::cerr << progname() << ": Error parsing -m option arguments
";
+ rc = 1;
+ }
+ }
+ if (rc ==0 && action_ == Action::modify) {
+ // Parse command lines
+ if (!parseCmdLines(modifyCmds_, cmdLines_)) {
+ std::cerr << progname() << ": Error parsing -M option arguments
";
rc = 1;
}
}
@@ -578,31 +631,56 @@ namespace {
return rc ? rc : target;
} // parseCommonTargets
- bool parseCommands(ModifyCmds& modifyCmds,
- const std::string& filename)
+ bool parseCmdFiles(ModifyCmds& modifyCmds,
+ const Params::CmdFiles& cmdFiles)
{
- try {
- std::ifstream file(filename.c_str());
- if (!file) {
- std::cerr << filename
- << ": Failed to open command file for reading
";
+ 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
";
+ 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::Error& error) {
+ std::cerr << *filename << ", line " << error << "
";
return false;
}
+ }
+ return true;
+ } // parseCmdFile
+
+ bool parseCmdLines(ModifyCmds& modifyCmds,
+ const Params::CmdLines& cmdLines)
+ {
+ try {
int num = 0;
- std::string line;
- while (std::getline(file, line)) {
+ 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)) {
+ if (parseLine(modifyCmd, *line, ++num)) {
modifyCmds.push_back(modifyCmd);
}
}
return true;
}
catch (const Exiv2::Error& error) {
- std::cerr << filename << ", " << error << "
";
+ std::cerr << "-M option " << error << "
";
return false;
}
- } // parseCommands
+ } // parseCmdLines
bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num)
{
@@ -619,14 +697,14 @@ namespace {
if ( cmdStart == std::string::npos
|| cmdEnd == std::string::npos
|| keyStart == std::string::npos) {
- throw Exiv2::Error("line " + Exiv2::toString(num)
+ throw Exiv2::Error(Exiv2::toString(num)
+ ": Invalid command line");
}
std::string cmd(line.substr(cmdStart, cmdEnd-cmdStart));
CmdId cmdId = commandId(cmd);
if (cmdId == invalidCmdId) {
- throw Exiv2::Error("line " + Exiv2::toString(num)
+ throw Exiv2::Error(Exiv2::toString(num)
+ ": Invalid command `" + cmd + "'");
}
@@ -649,7 +727,7 @@ namespace {
catch (const Exiv2::Error&) {}
}
if (metadataId == invalidMetadataId) {
- throw Exiv2::Error("line " + Exiv2::toString(num)
+ throw Exiv2::Error(Exiv2::toString(num)
+ ": Invalid key `" + key + "'");
}
@@ -669,7 +747,7 @@ namespace {
|| typeStart == std::string::npos
|| typeEnd == std::string::npos
|| valStart == std::string::npos) {
- throw Exiv2::Error("line " + Exiv2::toString(num)
+ throw Exiv2::Error(Exiv2::toString(num)
+ ": Invalid command line");
}
@@ -678,7 +756,7 @@ namespace {
if (type != Exiv2::invalidTypeId) {
valStart = line.find_first_not_of(delim, typeEnd+1);
if (valStart == std::string::npos) {
- throw Exiv2::Error("line " + Exiv2::toString(num)
+ throw Exiv2::Error(Exiv2::toString(num)
+ ": Invalid command line");
}
}
@@ -687,7 +765,7 @@ namespace {
explicitType = false;
}
if (type == Exiv2::invalidTypeId) {
- throw Exiv2::Error("line " + Exiv2::toString(num)
+ throw Exiv2::Error(Exiv2::toString(num)
+ ": Invalid type");
}
@@ -695,7 +773,7 @@ namespace {
std::string::size_type last = value.length()-1;
if ( (value[0] == '"' || value[last] == '"')
&& value[0] != value[last]) {
- throw Exiv2::Error("line " + Exiv2::toString(num)
+ throw Exiv2::Error(Exiv2::toString(num)
+ ": Unbalanced quotes");
}
if (value[0] == '"') {
diff --git a/src/exiv2.hpp b/src/exiv2.hpp
index 7c323ec..982029c 100644
--- a/src/exiv2.hpp
+++ b/src/exiv2.hpp
@@ -107,6 +107,13 @@ 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.
@@ -131,12 +138,9 @@ public:
long adjustment_; //!< Adjustment in seconds.
std::string format_; //!< Filename format (-r option arg).
- std::string cmdFile_; //!< Name of the modification command file
+ CmdFiles cmdFiles_; //!< Names of the modification command files
+ CmdLines cmdLines_; //!< Commands from the command line
ModifyCmds modifyCmds_; //!< Parsed modification commands
-
- //! Container to store filenames.
- typedef std::vector<std::string> Files;
-
Files files_; //!< List of non-option arguments.
private:
@@ -144,7 +148,7 @@ private:
@brief Default constructor. Note that optstring_ is initialized here.
The c'tor is private to force instantiation through instance().
*/
- Params() : optstring_(":hVvfa:r:p:d:e:i:m:"),
+ Params() : optstring_(":hVvfa:r:p:d:e:i:m:M:"),
help_(false),
version_(false),
verbose_(false),
@@ -160,6 +164,17 @@ private:
//! 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_;
--
exiv2 packaging
More information about the pkg-kde-commits
mailing list