[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:21 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=0de786b

The following commit has been merged in the master branch:
commit 0de786b863a5daf02130510d2b2c810d802de919
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Sat May 15 16:08:24 2004 +0000

    Less rigid command line argument parsing: try to guess the action from the option given and use print as the default action
---
 src/exiv2.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 169 insertions(+), 45 deletions(-)

diff --git a/src/exiv2.cpp b/src/exiv2.cpp
index a84978a..dcbef7d 100644
--- a/src/exiv2.cpp
+++ b/src/exiv2.cpp
@@ -22,13 +22,13 @@
   Abstract:  Command line program to display and manipulate image %Exif data
 
   File:      exiv2.cpp
-  Version:   $Name:  $ $Revision: 1.7 $
+  Version:   $Name:  $ $Revision: 1.8 $
   Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
   History:   10-Dec-03, ahu: created
  */
 // *****************************************************************************
 #include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.7 $ $RCSfile: exiv2.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.8 $ $RCSfile: exiv2.cpp,v $")
 
 // *****************************************************************************
 // included header files
@@ -42,7 +42,7 @@ EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.7 $ $RCSfile: exiv2.cpp,v $")
 #include <cstring>
 #include <cassert>
 
-// *********************************************************************
+// *****************************************************************************
 // local declarations
 namespace {
 
@@ -115,7 +115,7 @@ void Params::version(std::ostream& os) const
 void Params::usage(std::ostream& os) const
 {
     os << "Usage: " << progname() 
-       << " [ options ] action file ...

"
+       << " [ options ] [ action ] file ...

"
        << "Manipulate the Exif metadata of images.
";
 }
 
@@ -123,14 +123,14 @@ void Params::help(std::ostream& os) const
 {
     usage(os);
     os << "
Actions:
"
-       << "  adjust   Adjust the metadata timestamp by the given time. This action
"
-       << "           requires the option -a time.
"
-       << "  print    Print the Exif (or other) image metadata.
"
-       << "  delete   Delete the Exif section or Exif thumbnail from the files.
"
-       << "  extract  Extract the Exif data or Exif thumbnail to files.
"
-       << "  insert   Insert the Exif data from corresponding *.exv files.
"
-       << "  rename   Rename files according to the metadata create timestamp. The
"
-       << "           filename format can be set with the option -r format.
"
+       << "  ad | adjust   Adjust the metadata timestamp by the given time. This
"
+       << "                action requires the option -a time.
"
+       << "  pr | print    Print the Exif (or other) image metadata.
"
+       << "  rm | delete   Delete the Exif section or thumbnail from the files.
"
+       << "  ex | extract  Extract the Exif data or Exif thumbnail to files.
"
+       << "  in | insert   Insert the Exif data from corresponding *.exv files.
"
+       << "  mv | rename   Rename files according to the Exif create timestamp.
"
+       << "                The filename format can be set with -r format.
"
        << "
Options:
"
        << "   -h      Display this help and exit.
"
        << "   -V      Show the program version and exit.
"
@@ -160,45 +160,119 @@ 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': format_ = optarg; 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;
+        }
+        break;
     case 'a':
-        adjust_ = parseTime(optarg, adjustment_);
-        if (!adjust_) {
-            std::cerr << progname() << ": Error parsing -a option argument `" 
-                      << optarg << "'
";
+        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;
         }
         break;
     case 'p':
-        switch (optarg[0]) {
-        case 's': printMode_ = summary; break;
-        case 'i': printMode_ = interpreted; break;
-        case 'v': printMode_ = values; break;
-        case 'h': printMode_ = hexdump; break;
+        switch (action_) {
+        case Action::none:
+            action_ = Action::print;
+            switch (optarg[0]) {
+            case 's': printMode_ = summary; break;
+            case 'i': printMode_ = interpreted; break;
+            case 'v': printMode_ = values; break;
+            case 'h': printMode_ = hexdump; 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() << ": Unrecognized print mode `"
-                      << optarg << "'
";
+            std::cerr << progname() 
+                      << ": Option -p is not compatible with a previous option
";
             rc = 1;
+            break;
         }
         break;
     case 'd':
-        switch (optarg[0]) {
-        case 'e': delTarget_ = delExif; break;
-        case 't': delTarget_ = delThumb; break;
+        switch (action_) {
+        case Action::none:
+            action_ = Action::erase;
+            switch (optarg[0]) {
+            case 'e': delTarget_ = delExif; break;
+            case 't': delTarget_ = delThumb; break;
+            default:
+                std::cerr << progname() << ": Unrecognized delete target `"
+                          << optarg << "'
";
+                rc = 1;
+                break;
+            }
+            break;
+        case Action::erase:
+            std::cerr << progname() 
+                      << ": Ignoring surplus option -d" << optarg << "
";
+            break;
         default:
-            std::cerr << progname() << ": Unrecognized delete target `"
-                      << optarg << "'
";
+            std::cerr << progname() 
+                      << ": Option -d is not compatible with a previous option
";
             rc = 1;
+            break;
         }
         break;
     case 'e':
-        switch (optarg[0]) {
-        case 'e': extractTarget_ = extExif; break;
-        case 't': extractTarget_ = extThumb; break;
+        switch (action_) {
+        case Action::none:
+            action_ = Action::extract;
+            switch (optarg[0]) {
+            case 'e': extractTarget_ = extExif; break;
+            case 't': extractTarget_ = extThumb; break;
+            default:
+                std::cerr << progname() << ": Unrecognized extract target `"
+                          << optarg << "'
";
+                rc = 1;
+                break;
+            }
+        case Action::extract:
+            std::cerr << progname() 
+                      << ": Ignoring surplus option -e" << optarg << "
";
+            break;
         default:
-            std::cerr << progname() << ": Unrecognized extract target `"
-                      << optarg << "'
";
+            std::cerr << progname() 
+                      << ": Option -e is not compatible with a previous option
";
             rc = 1;
+            break;
         }
         break;
     case ':':
@@ -216,6 +290,7 @@ int Params::option(int opt, const std::string& optarg, int optopt)
                   << ": getopt returned unexpected character code " 
                   << std::hex << opt << "
";
         rc = 1;
+        break;
     }
     return rc;
 } // Params::option
@@ -223,22 +298,70 @@ int Params::option(int opt, const std::string& optarg, int optopt)
 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 == "adjust") action_ = Action::adjust;
-        if (argv == "print") action_ = Action::print;
-        if (argv == "delete") action_ = Action::erase;
-        if (argv == "extract") action_ = Action::extract;
-        if (argv == "insert") action_ = Action::insert;
-        if (argv == "rename") action_ = Action::rename;
+        if (argv == "ad" || argv == "adjust") {
+            if (action_ != Action::none && action_ != Action::adjust) {
+                std::cerr << progname() << ": Action adjust is not "
+                          << "compatible with the given options
";
+                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
";
+                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
";
+                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
";
+                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
";
+                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
";
+                rc = 1;
+            }
+            action = true;
+            action_ = Action::rename;
+        }
         if (action_ == Action::none) {
-            std::cerr << progname() << ": Unrecognized action `" 
-                      << argv << "'
";
-            rc = 1;
+            // if everything else fails, assume print as the default action
+            action_ = Action::print;
         }
     }
-    else {
+    if (!action) {
         files_.push_back(argv);
     }
     return rc;
@@ -250,6 +373,7 @@ int Params::getopt(int argc, char* const argv[])
     // 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
";
         rc = 1;
     }
@@ -265,7 +389,7 @@ int Params::getopt(int argc, char* const argv[])
     return rc;
 } // Params::getopt
 
-// *********************************************************************
+// *****************************************************************************
 // local implementations
 namespace {
 

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list