Пример #1
0
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
Пример #2
0
int Params::evalInsert(const std::string& optarg)
{
    int rc = 0;
    switch (action_) {
    case Action::none:
    case Action::modify:
        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
Пример #3
0
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; 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 << "\"\n";
            break;
        default:
            std::cerr << progname() 
                      << ": Option -r is not compatible with a previous option\n";
            rc = 1;
            break;
        }
        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 << "'\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;
        }
        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 << "'\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;
        }
        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;
        default:
            std::cerr << progname() 
                      << ": Option -d is not compatible with a previous option\n";
            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\n";
            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\n";
            rc = 1;
            break;
        }
        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