Beispiel #1
0
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
Beispiel #2
0
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_
        && !yodAdjust_[yodYear].flag_
        && !yodAdjust_[yodMonth].flag_
        && !yodAdjust_[yodDay].flag_) {
        std::cerr << progname() << ": "
                  << _("Adjust action requires at least one -a, -Y, -O or -D option\n");
        rc = 1;
    }
    if (   action_ == Action::modify
        && cmdFiles_.empty() && cmdLines_.empty() && jpegComment_.empty()) {
        std::cerr << progname() << ": "
                  << _("Modify action requires at least one -c, -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 && !cmdFiles_.empty()) {
        // Parse command files
        if (!parseCmdFiles(modifyCmds_, cmdFiles_)) {
            std::cerr << progname() << ": " << _("Error parsing -m option arguments\n");
            rc = 1;
        }
    }
    if (rc == 0 && !cmdLines_.empty()) {
        // 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;
    }
    if (!suffix_.empty() && !(action_ == Action::insert)) {
        std::cerr << progname() << ": "
                  << _("-S option can only be used with insert action\n");
        rc = 1;
    }
    if (timestamp_ && !(action_ == Action::rename)) {
        std::cerr << progname() << ": "
                  << _("-t option can only be used with rename action\n");
        rc = 1;
    }
    if (timestampOnly_ && !(action_ == Action::rename)) {
        std::cerr << progname() << ": "
                  << _("-T option can only be used with rename action\n");
        rc = 1;
    }
    return rc;
} // Params::getopt
Beispiel #3
0
int Params::getopt(int argc, char* const Argv[])
{
	char** argv = new char* [argc+1];
	argv[argc] = NULL;
	long_t longs;

	longs["--adjust"   ] = "-a";
	longs["--binary"   ] = "-b";
	longs["--comment"  ] = "-c";
	longs["--delete"   ] = "-d";
	longs["--days"     ] = "-D";
	longs["--force"    ] = "-f";
	longs["--Force"    ] = "-F";
	longs["--grep"     ] = "-g";
	longs["--help"     ] = "-h";
	longs["--insert"   ] = "-i";
	longs["--keep"     ] = "-k";
	longs["--key"      ] = "-K";
	longs["--location" ] = "-l";
	longs["--modify"   ] = "-m";
	longs["--Modify"   ] = "-M";
	longs["--encode"   ] = "-n";
	longs["--months"   ] = "-O";
	longs["--print"    ] = "-p";
	longs["--Print"    ] = "-P";
	longs["--quiet"    ] = "-q";
	longs["--log"      ] = "-Q";
	longs["--rename"   ] = "-r";
	longs["--suffix"   ] = "-S";
	longs["--timestamp"] = "-t";
	longs["--Timestamp"] = "-T";
	longs["--unknown"  ] = "-u";
	longs["--verbose"  ] = "-v";
	longs["--Version"  ] = "-V";
	longs["--version"  ] = "-V";
	longs["--years"    ] = "-Y";

	for ( int i = 0 ; i < argc ; i++ ) {
		std::string* arg = new std::string(Argv[i]);
		if (longs.find(*arg) != longs.end() ) {
			argv[i] = ::strdup(longs[*arg].c_str());
		} else {
			argv[i] = ::strdup(Argv[i]);
		}
		delete arg;
	}

    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_
        && !yodAdjust_[yodYear].flag_
        && !yodAdjust_[yodMonth].flag_
        && !yodAdjust_[yodDay].flag_) {
        std::cerr << progname() << ": "
                  << _("Adjust action requires at least one -a, -Y, -O or -D option\n");
        rc = 1;
    }
    if (   action_ == Action::modify
        && cmdFiles_.empty() && cmdLines_.empty() && jpegComment_.empty()) {
        std::cerr << progname() << ": "
                  << _("Modify action requires at least one -c, -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 && !cmdFiles_.empty()) {
        // Parse command files
        if (!parseCmdFiles(modifyCmds_, cmdFiles_)) {
            std::cerr << progname() << ": " << _("Error parsing -m option arguments\n");
            rc = 1;
        }
    }
    if (rc == 0 && !cmdLines_.empty()) {
        // Parse command lines
        if (!parseCmdLines(modifyCmds_, cmdLines_)) {
            std::cerr << progname() << ": " << _("Error parsing -M option arguments\n");
            rc = 1;
        }
    }
    if (rc == 0 && (!cmdFiles_.empty() || !cmdLines_.empty())) {
        // We'll set them again, after reading the file
        Exiv2::XmpProperties::unregisterNs();
    }
    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;
    }
    if (!suffix_.empty() && !(action_ == Action::insert)) {
        std::cerr << progname() << ": "
                  << _("-S option can only be used with insert action\n");
        rc = 1;
    }
    if (timestamp_ && !(action_ == Action::rename)) {
        std::cerr << progname() << ": "
                  << _("-t option can only be used with rename action\n");
        rc = 1;
    }
    if (timestampOnly_ && !(action_ == Action::rename)) {
        std::cerr << progname() << ": "
                  << _("-T option can only be used with rename action\n");
        rc = 1;
    }

	// cleanup the argument vector
	for ( int i = 0 ; i < argc ; i++ ) ::free((void*)argv[i]);
    delete [] argv;

    return rc;
} // Params::getopt