Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

RTDECL ( int   ) 

Initialize the RTGetOpt state.

The passed in argument vector may be sorted if fFlags indicates that this is desired (to be implemented).

Returns:
VINF_SUCCESS, VERR_INVALID_PARAMETER or VERR_INVALID_POINTER.
Parameters:
pState The state.
argc Argument count, to be copied from what comes in with main().
argv Argument array, to be copied from what comes in with main(). This may end up being modified by the option/argument sorting.
paOptions Array of RTGETOPTDEF structures, which must specify what options are understood by the program.
cOptions Number of array items passed in with paOptions.
iFirst The argument to start with (in argv).
fFlags The flags. MBZ for now.
Command line argument parser, handling both long and short options and checking argument formats, if desired.

This is to be called in a loop until it returns 0 (meaning that all options were parsed) or a negative value (meaning that an error occured). How non-option arguments are dealt with depends on the flags passed to RTGetOptInit. The default (fFlags = 0) is to return VINF_GETOPT_NOT_OPTION with pValueUnion->psz pointing to the argument string.

For example, for a program which takes the following options:

--optwithstring (or -s) and a string argument; --optwithint (or -i) and a 32-bit signed integer argument; --verbose (or -v) with no arguments,

code would look something like this:

int main(int argc, char **argv)
{
     RTR3Init();

     static const RTGETOPTDEF s_aOptions[] =
     {
         { "--optwithstring",    's', RTGETOPT_REQ_STRING },
         { "--optwithint",       'i', RTGETOPT_REQ_INT32 },
         { "--verbose",          'v', 0 },
     };

     int ch;
     RTGETOPTUNION ValueUnion;
     RTGETOPTSTATE GetState;
     RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
     while ((ch = RTGetOpt(&GetState, &ValueUnion)))
     {
         // for options that require an argument, ValueUnion has received the value
         switch (ch)
         {
             case 's': // --optwithstring or -s
                 // string argument, copy ValueUnion.psz
                 break;

             case 'i': // --optwithint or -i
                 // integer argument, copy ValueUnion.i32
                 break;

             case 'v': // --verbose or -v
                 g_fOptVerbose = true;
                 break;

             case VINF_GETOPT_NOT_OPTION:
                 // handle non-option argument in ValueUnion.psz.
                 break;

             default:
                 if (ch > 0)
                 {
                     if (RT_C_IS_GRAPH(ch))
                         Error("unhandled option: -%c\n", ch);
                     else
                         Error("unhandled option: %i\n", ch);
                 }
                 else if (ch == VERR_GETOPT_UNKNOWN_OPTION)
                     Error("unknown option: %s\n", ValueUnion.psz);
                 else if (ValueUnion.pDef)
                     Error("%s: %Rrs\n", ValueUnion.pDef->pszLong, ch);
                 else
                     Error("%Rrs\n", ch);
                 return 1;
         }
     }

     return 0;
}

Returns:
0 when done parsing.

the iShort value of the option. pState->pDef points to the option definition which matched.

IPRT error status on parse error.

VINF_GETOPT_NOT_OPTION when encountering a non-option argument and RTGETOPT_FLAG_SORT was not specified. pValueUnion->psz points to the argument string.

VERR_GETOPT_UNKNOWN_OPTION when encountering an unknown option. pValueUnion->psz points to the option string.

VERR_GETOPT_REQUIRED_ARGUMENT_MISSING and pValueUnion->pDef if a required argument (aka value) was missing for an option.

VERR_GETOPT_INVALID_ARGUMENT_FORMAT and pValueUnion->pDef if argument (aka value) conversion failed.

Parameters:
pState The state previously initialized with RTGetOptInit.
pValueUnion Union with value; in the event of an error, psz member points to erroneous parameter; otherwise, for options that require an argument, this contains the value of that argument, depending on the type that is required.
Fetch an additional value.

This is used for special cases where an option have more than one value.

Returns:
VINF_SUCCESS on success.

IPRT error status on parse error.

VERR_INVALID_PARAMETER if the flags are wrong.

VERR_GETOPT_UNKNOWN_OPTION when pState->pDef is null.

VERR_GETOPT_REQUIRED_ARGUMENT_MISSING if there are no more available arguments. pValueUnion->pDef is NULL.

VERR_GETOPT_INVALID_ARGUMENT_FORMAT and pValueUnion->pDef if value conversion failed.

Parameters:
pState The state previously initialized with RTGetOptInit.
pValueUnion Union with value; in the event of an error, psz member points to erroneous parameter; otherwise, for options that require an argument, this contains the value of that argument, depending on the type that is required.
fFlags The flags.
Print error messages for a RTGetOpt default case.

Uses RTMsgError.

Returns:
Suitable exit code.
Parameters:
ch The RTGetOpt return value.
pValueUnion The value union returned by RTGetOpt.

If the critical section has already been destroyed, then inform the caller.

Definition at line 145 of file ldr.cpp.

{
    LogFlow(("RTLdrClose: hLdrMod=%RTldrm\n", hLdrMod));

    /*
     * Validate input.
     */
    AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
    PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
    //AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);

    /*
     * Do it.
     */
    int rc = pMod->pOps->pfnClose(pMod);
    AssertRC(rc);
    pMod->eState = LDR_STATE_INVALID;
    pMod->u32Magic++;
    RTMemFree(pMod);

    LogFlow(("RTLdrClose: returns VINF_SUCCESS\n"));
    return VINF_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index