#include "arg.ih"

Arg__::Arg__(char const *accept, char const *opts,
         LongOption const *const begin, LongOption const *const end,
         int argc, char **argv)
:
    d_optStr(opts),
    d_nLongOptions(0),
    d_beyondDashes(string::npos),
    d_end(argv + argc),
    d_unspecOK(d_optStr.front() == '+'),
    d_nOptions(0),
    d_argv0(argv[0]),
    d_optionType(OK)
{
    setBasename(argv[0]);

    --argc;                 // skip the program name
    ++argv;

    d_optStr.push_back(0);  // allow value checking for the last option char

    if (d_unspecOK)
        d_optStr.erase(0, 1);

    if (not fillLongMap(begin, end))
        return;
                                            // process all arguments
    for (d_arg = argv; d_arg != d_end; ++d_arg)
    {
        if (not optionArg())            // set the option variables
            continue;                   // no option if a mere '-' char

        if (dashes())                   // accept all from "--"
            break;                      // or set d_nextChar

        if (d_short)                        // at a short option
        {
            if (acceptOption(accept))           // 'accept' option: accept
                break;                          //  all arguments from here

            if (not shortOption())
                return;

            continue;                       // or continue
        }

        if (not longOption())
            return;
    }

    if (d_beyondDashes == string::npos)
        d_beyondDashes = d_argv.size();
}











