本文整理汇总了C++中RTGetOptInit函数的典型用法代码示例。如果您正苦于以下问题:C++ RTGetOptInit函数的具体用法?C++ RTGetOptInit怎么用?C++ RTGetOptInit使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTGetOptInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleDebugVM_OSDmesg
/**
* Handles the osdmsg sub-command.
*
* @returns Suitable exit code.
* @param pArgs The handler arguments.
* @param pDebugger Pointer to the debugger interface.
*/
static RTEXITCODE handleDebugVM_OSDmesg(HandlerArg *pArgs, IMachineDebugger *pDebugger)
{
/*
* Parse argument.
*/
uint32_t uMaxMessages = 0;
RTGETOPTSTATE GetState;
RTGETOPTUNION ValueUnion;
static const RTGETOPTDEF s_aOptions[] =
{
{ "--lines", 'n', RTGETOPT_REQ_UINT32 },
};
int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
AssertRCReturn(rc, RTEXITCODE_FAILURE);
while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
switch (rc)
{
case 'n': uMaxMessages = ValueUnion.u32; break;
default: return errorGetOpt(rc, &ValueUnion);
}
/*
* Do it.
*/
com::Bstr bstrDmesg;
CHECK_ERROR2I_RET(pDebugger, QueryOSKernelLog(uMaxMessages, bstrDmesg.asOutParam()), RTEXITCODE_FAILURE);
RTPrintf("%ls\n", bstrDmesg.raw());
return RTEXITCODE_SUCCESS;
}
示例2: supSvcWinDelete
/**
* Handle the 'delete' action.
*
* @returns 0 or 1.
* @param argc The action argument count.
* @param argv The action argument vector.
*/
static int supSvcWinDelete(int argc, char **argv)
{
/*
* Parse the arguments.
*/
bool fVerbose = false;
static const RTGETOPTDEF s_aOptions[] =
{
{ "--verbose", 'v', RTGETOPT_REQ_NOTHING }
};
int ch;
RTGETOPTUNION Value;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
while ((ch = RTGetOpt(&GetState, &Value)))
switch (ch)
{
case 'v':
fVerbose = true;
break;
case VINF_GETOPT_NOT_OPTION:
return supSvcDisplayTooManyArgsError("delete", argc, argv, iArg);
default:
return supSvcDisplayGetOptError("delete", ch, argc, argv, iArg, &Value);
}
/*
* Create the service.
*/
int rc = 1;
SC_HANDLE hSvc = supSvcWinOpenService("delete", SERVICE_CHANGE_CONFIG, DELETE,
1, ERROR_SERVICE_DOES_NOT_EXIST);
if (hSvc)
{
if (DeleteService(hSvc))
{
RTPrintf("Successfully deleted the %s service.\n", SUPSVC_SERVICE_NAME);
rc = 0;
}
else
supSvcDisplayError("delete - DeleteService failed, err=%d.\n", GetLastError());
CloseServiceHandle(hSvc);
}
else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
{
if (fVerbose)
RTPrintf("The service %s was not installed, nothing to be done.", SUPSVC_SERVICE_NAME);
else
RTPrintf("Successfully deleted the %s service.\n", SUPSVC_SERVICE_NAME);
rc = 0;
}
return rc;
}
示例3: handleDebugVM_DumpVMCore
/**
* Handles the inject sub-command.
*
* @returns Suitable exit code.
* @param pArgs The handler arguments.
* @param pDebugger Pointer to the debugger interface.
*/
static RTEXITCODE handleDebugVM_DumpVMCore(HandlerArg *pArgs, IMachineDebugger *pDebugger)
{
/*
* Parse arguments.
*/
const char *pszFilename = NULL;
const char *pszCompression = NULL;
RTGETOPTSTATE GetState;
RTGETOPTUNION ValueUnion;
static const RTGETOPTDEF s_aOptions[] =
{
{ "--filename", 'f', RTGETOPT_REQ_STRING },
{ "--compression", 'c', RTGETOPT_REQ_STRING }
};
int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, 0 /*fFlags*/);
AssertRCReturn(rc, RTEXITCODE_FAILURE);
while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
{
switch (rc)
{
case 'c':
if (pszCompression)
return errorSyntax("The --compression option has already been given");
pszCompression = ValueUnion.psz;
break;
case 'f':
if (pszFilename)
return errorSyntax("The --filename option has already been given");
pszFilename = ValueUnion.psz;
break;
default:
return errorGetOpt(rc, &ValueUnion);
}
}
if (!pszFilename)
return errorSyntax("The --filename option is required");
/*
* Make the filename absolute before handing it on to the API.
*/
char szAbsFilename[RTPATH_MAX];
rc = RTPathAbs(pszFilename, szAbsFilename, sizeof(szAbsFilename));
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAbs failed on '%s': %Rrc", pszFilename, rc);
com::Bstr bstrFilename(szAbsFilename);
com::Bstr bstrCompression(pszCompression);
CHECK_ERROR2I_RET(pDebugger, DumpGuestCore(bstrFilename.raw(), bstrCompression.raw()), RTEXITCODE_FAILURE);
return RTEXITCODE_SUCCESS;
}
示例4: main
int main(int argc, char *argv[])
{
/*
* Init IPRT and globals.
*/
int rc = RTTestInitAndCreate("UsbTest", &g_hTest);
if (rc)
return rc;
/*
* Default values.
*/
const char *pszDevice = NULL;
RTGETOPTUNION ValueUnion;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, g_aCmdOptions, RT_ELEMENTS(g_aCmdOptions), 1, 0 /* fFlags */);
while ((rc = RTGetOpt(&GetState, &ValueUnion)))
{
switch (rc)
{
case 'h':
usbTestUsage(g_pStdOut);
return RTEXITCODE_SUCCESS;
case 'd':
pszDevice = ValueUnion.psz;
break;
default:
return RTGetOptPrintError(rc, &ValueUnion);
}
}
/*
* Start testing.
*/
RTTestBanner(g_hTest);
/* Find the first test device if none was given. */
if (!pszDevice)
pszDevice = usbTestFindDevice();
if (pszDevice)
usbTestExec(pszDevice);
else
{
RTTestPrintf(g_hTest, RTTESTLVL_FAILURE, "Failed to find a test device\n");
RTTestErrorInc(g_hTest);
}
RTEXITCODE rcExit = RTTestSummaryAndDestroy(g_hTest);
return rcExit;
}
示例5: main
int main(int argc, char **argv)
{
int rc = RTTestInitAndCreate("tstIntNetR0", &g_hTest);
if (rc)
return rc;
/*
* Parse the arguments.
*/
static RTGETOPTDEF const s_aOptions[] =
{
{ "--recv-buffer", 'r', RTGETOPT_REQ_UINT32 },
{ "--send-buffer", 's', RTGETOPT_REQ_UINT32 },
{ "--transfer-size", 'l', RTGETOPT_REQ_UINT32 },
};
uint32_t cbSend = 1536*2 + 4;
uint32_t cbRecv = 0x8000;
int ch;
RTGETOPTUNION Value;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
while ((ch = RTGetOpt(&GetState, &Value)))
switch (ch)
{
case 'l':
g_cbTransfer = Value.u32;
break;
case 'r':
cbRecv = Value.u32;
break;
case 's':
cbSend = Value.u32;
break;
default:
return RTGetOptPrintError(ch, &Value);
}
/*
* Do the testing and report summary.
*/
TSTSTATE This;
RT_ZERO(This);
doTest(&This, cbRecv, cbSend);
return RTTestSummaryAndDestroy(g_hTest);
}
示例6: handleDebugVM_Info
/**
* Handles the info sub-command.
*
* @returns Suitable exit code.
* @param pArgs The handler arguments.
* @param pDebugger Pointer to the debugger interface.
*/
static RTEXITCODE handleDebugVM_Info(HandlerArg *pArgs, IMachineDebugger *pDebugger)
{
/*
* Parse arguments.
*/
const char *pszInfo = NULL;
const char *pszArgs = NULL;
RTGETOPTSTATE GetState;
RTGETOPTUNION ValueUnion;
int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, NULL, 0, 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
AssertRCReturn(rc, RTEXITCODE_FAILURE);
while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
{
switch (rc)
{
case VINF_GETOPT_NOT_OPTION:
if (!pszInfo)
pszInfo = ValueUnion.psz;
else if (!pszArgs)
pszArgs = ValueUnion.psz;
else
return errorTooManyParameters(&pArgs->argv[GetState.iNext - 1]);
break;
default:
return errorGetOpt(rc, &ValueUnion);
}
}
if (!pszInfo)
return errorSyntax("Must specify info item to display");
/*
* Do the work.
*/
com::Bstr bstrName(pszInfo);
com::Bstr bstrArgs(pszArgs);
com::Bstr bstrInfo;
CHECK_ERROR2I_RET(pDebugger, Info(bstrName.raw(), bstrArgs.raw(), bstrInfo.asOutParam()), RTEXITCODE_FAILURE);
RTPrintf("%ls", bstrInfo.raw());
return RTEXITCODE_SUCCESS;
}
示例7: main
int main(int argc, char **argv)
{
int rc = RTR3InitExe(argc, &argv, 0);
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Create a HTTP client instance.
*/
RTHTTP hHttp;
rc = RTHttpCreate(&hHttp);
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTHttpCreate failed: %Rrc", rc);
/*
* Parse arguments.
*/
static const RTGETOPTDEF s_aOptions[] =
{
{ "--output", 'o', RTGETOPT_REQ_STRING },
{ "--quiet", 'q', RTGETOPT_REQ_NOTHING },
{ "--verbose", 'v', RTGETOPT_REQ_NOTHING },
};
RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
const char *pszOutput = NULL;
unsigned uVerbosityLevel = 1;
RTGETOPTUNION ValueUnion;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
while ((rc = RTGetOpt(&GetState, &ValueUnion)))
{
switch (rc)
{
case 'o':
pszOutput = ValueUnion.psz;
break;
case 'q':
uVerbosityLevel--;
break;
case 'v':
uVerbosityLevel++;
break;
case 'h':
RTPrintf("Usage: %s [options] URL0 [URL1 [...]]\n"
"\n"
"Options:\n"
" -o,--output=file\n"
" Output file. If not given, the file is displayed on stdout.\n"
" -q, --quiet\n"
" -v, --verbose\n"
" Controls the verbosity level.\n"
" -h, -?, --help\n"
" Display this help text and exit successfully.\n"
" -V, --version\n"
" Display the revision and exit successfully.\n"
, RTPathFilename(argv[0]));
return RTEXITCODE_SUCCESS;
case 'V':
RTPrintf("$Revision: 102641 $\n");
return RTEXITCODE_SUCCESS;
case VINF_GETOPT_NOT_OPTION:
{
int rcHttp;
if (pszOutput && strcmp("-", pszOutput))
{
if (uVerbosityLevel > 0)
RTStrmPrintf(g_pStdErr, "Fetching '%s' into '%s'...\n", ValueUnion.psz, pszOutput);
rcHttp = RTHttpGetFile(hHttp, ValueUnion.psz, pszOutput);
}
else
{
if (uVerbosityLevel > 0)
RTStrmPrintf(g_pStdErr, "Fetching '%s'...\n", ValueUnion.psz);
void *pvResp;
size_t cbResp;
rcHttp = RTHttpGetBinary(hHttp, ValueUnion.psz, &pvResp, &cbResp);
if (RT_SUCCESS(rcHttp))
{
RTVFSIOSTREAM hVfsIos;
rc = RTVfsIoStrmFromStdHandle(RTHANDLESTD_OUTPUT, 0, true /*fLeaveOpen*/, &hVfsIos);
if (RT_SUCCESS(rc))
{
rc = RTVfsIoStrmWrite(hVfsIos, pvResp, cbResp, true /*fBlocking*/, NULL);
if (RT_FAILURE(rc))
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error writing to stdout: %Rrc", rc);
RTVfsIoStrmRelease(hVfsIos);
}
else
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening stdout: %Rrc", rc);
RTHttpFreeResponse(pvResp);
}
}
if (RT_FAILURE(rcHttp))
//.........这里部分代码省略.........
示例8: main
int main(int argc, char **argv)
{
int rc = RTR3InitExe(argc, &argv, 0);
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Create an empty address space that we can load modules and stuff into
* as we parse the parameters.
*/
RTDBGAS hDbgAs;
rc = RTDbgAsCreate(&hDbgAs, 0, RTUINTPTR_MAX, "");
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTDBgAsCreate -> %Rrc", rc);
/*
* Create a debugging configuration instance to work with so that we can
* make use of (i.e. test) path searching and such.
*/
RTDBGCFG hDbgCfg;
rc = RTDbgCfgCreate(&hDbgCfg, "IPRT", true /*fNativePaths*/);
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTDbgCfgCreate -> %Rrc", rc);
/*
* Parse arguments.
*/
static const RTGETOPTDEF s_aOptions[] =
{
{ "--input", 'i', RTGETOPT_REQ_STRING },
{ "--local-file", 'l', RTGETOPT_REQ_NOTHING },
{ "--cache-file", 'c', RTGETOPT_REQ_NOTHING },
{ "--pe-image", 'p', RTGETOPT_REQ_NOTHING },
{ "--verbose", 'v', RTGETOPT_REQ_NOTHING },
{ "--x86", '8', RTGETOPT_REQ_NOTHING },
{ "--amd64", '6', RTGETOPT_REQ_NOTHING },
{ "--whatever", '*', RTGETOPT_REQ_NOTHING },
};
PRTSTREAM pInput = g_pStdIn;
PRTSTREAM pOutput = g_pStdOut;
unsigned cVerbosityLevel = 0;
enum {
kOpenMethod_FromImage,
kOpenMethod_FromPeImage
} enmOpenMethod = kOpenMethod_FromImage;
bool fCacheFile = false;
RTLDRARCH enmArch = RTLDRARCH_WHATEVER;
RTGETOPTUNION ValueUnion;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
while ((rc = RTGetOpt(&GetState, &ValueUnion)))
{
switch (rc)
{
case 'i':
rc = RTStrmOpen(ValueUnion.psz, "r", &pInput);
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to open '%s' for reading: %Rrc", ValueUnion.psz, rc);
break;
case 'c':
fCacheFile = true;
break;
case 'l':
fCacheFile = false;
break;
case 'p':
enmOpenMethod = kOpenMethod_FromPeImage;
break;
case 'v':
cVerbosityLevel++;
break;
case '8':
enmArch = RTLDRARCH_X86_32;
break;
case '6':
enmArch = RTLDRARCH_AMD64;
break;
case '*':
enmArch = RTLDRARCH_WHATEVER;
break;
case 'h':
RTPrintf("Usage: %s [options] <module> <address> [<module> <address> [..]]\n"
"\n"
"Options:\n"
" -i,--input=file\n"
" Specify a input file instead of standard input.\n"
" --pe-image\n"
" Use RTDbgModCreateFromPeImage to open the file."
" -v, --verbose\n"
" Display the address space before doing the filtering.\n"
//.........这里部分代码省略.........
示例9: main
int main(int argc, char **argv)
{
RTR3InitExe(argc, &argv, 0);
enum
{
kDigestType_NotSpecified,
kDigestType_CRC32,
kDigestType_CRC64,
kDigestType_MD5,
kDigestType_SHA1,
kDigestType_SHA256,
kDigestType_SHA512
} enmDigestType = kDigestType_NotSpecified;
enum
{
kMethod_Full,
kMethod_Block,
kMethod_File
} enmMethod = kMethod_Block;
static const RTGETOPTDEF s_aOptions[] =
{
{ "--type", 't', RTGETOPT_REQ_STRING },
{ "--method", 'm', RTGETOPT_REQ_STRING },
{ "--help", 'h', RTGETOPT_REQ_NOTHING },
};
int ch;
RTGETOPTUNION ValueUnion;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
while ((ch = RTGetOpt(&GetState, &ValueUnion)))
{
switch (ch)
{
case 't':
if (!RTStrICmp(ValueUnion.psz, "crc32"))
enmDigestType = kDigestType_CRC32;
else if (!RTStrICmp(ValueUnion.psz, "crc64"))
enmDigestType = kDigestType_CRC64;
else if (!RTStrICmp(ValueUnion.psz, "md5"))
enmDigestType = kDigestType_MD5;
else if (!RTStrICmp(ValueUnion.psz, "sha1"))
enmDigestType = kDigestType_SHA1;
else if (!RTStrICmp(ValueUnion.psz, "sha256"))
enmDigestType = kDigestType_SHA256;
else if (!RTStrICmp(ValueUnion.psz, "sha512"))
enmDigestType = kDigestType_SHA512;
else
{
Error("Invalid digest type: %s\n", ValueUnion.psz);
return 1;
}
break;
case 'm':
if (!RTStrICmp(ValueUnion.psz, "full"))
enmMethod = kMethod_Full;
else if (!RTStrICmp(ValueUnion.psz, "block"))
enmMethod = kMethod_Block;
else if (!RTStrICmp(ValueUnion.psz, "file"))
enmMethod = kMethod_File;
else
{
Error("Invalid digest method: %s\n", ValueUnion.psz);
return 1;
}
break;
case 'h':
RTPrintf("syntax: tstRTDigest -t <digest-type> file [file2 [..]]\n");
return 1;
case VINF_GETOPT_NOT_OPTION:
{
if (enmDigestType == kDigestType_NotSpecified)
return Error("No digest type was specified\n");
switch (enmMethod)
{
case kMethod_Full:
return Error("Full file method is not implemented\n");
case kMethod_File:
switch (enmDigestType)
{
case kDigestType_SHA1:
{
char *pszDigest;
int rc = RTSha1DigestFromFile(ValueUnion.psz, &pszDigest, NULL, NULL);
if (RT_FAILURE(rc))
return Error("RTSha1Digest(%s,) -> %Rrc\n", ValueUnion.psz, rc);
RTPrintf("%s %s\n", pszDigest, ValueUnion.psz);
RTStrFree(pszDigest);
break;
}
case kDigestType_SHA256:
//.........这里部分代码省略.........
示例10: main
int main(int argc, char **argv)
{
int rc = RTR3InitExe(argc, &argv, 0);
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Parse arguments up to the command and pass it on to the command handlers.
*/
typedef enum
{
VCUACTION_ADD_TRUSTED_PUBLISHER = 1000,
VCUACTION_REMOVE_TRUSTED_PUBLISHER,
VCUACTION_DISPLAY_ALL,
VCUACTION_END
} VCUACTION;
static const RTGETOPTDEF s_aOptions[] =
{
{ "--verbose", 'v', RTGETOPT_REQ_NOTHING },
{ "--quiet", 'q', RTGETOPT_REQ_NOTHING },
{ "add-trusted-publisher", VCUACTION_ADD_TRUSTED_PUBLISHER, RTGETOPT_REQ_NOTHING },
{ "remove-trusted-publisher", VCUACTION_REMOVE_TRUSTED_PUBLISHER, RTGETOPT_REQ_NOTHING },
{ "display-all", VCUACTION_DISPLAY_ALL, RTGETOPT_REQ_NOTHING },
};
RTGETOPTUNION ValueUnion;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
while ((rc = RTGetOpt(&GetState, &ValueUnion)))
{
switch (rc)
{
case 'v':
g_cVerbosityLevel++;
break;
case 'q':
if (g_cVerbosityLevel > 0)
g_cVerbosityLevel--;
break;
case 'h':
showUsage(argv[0]);
return RTEXITCODE_SUCCESS;
case 'V':
RTPrintf("%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
return RTEXITCODE_SUCCESS;
case VCUACTION_ADD_TRUSTED_PUBLISHER:
return cmdAddTrustedPublisher(argc - GetState.iNext + 1, argv + GetState.iNext - 1);
case VCUACTION_REMOVE_TRUSTED_PUBLISHER:
return cmdRemoveTrustedPublisher(argc - GetState.iNext + 1, argv + GetState.iNext - 1);
case VCUACTION_DISPLAY_ALL:
return cmdDisplayAll(argc - GetState.iNext + 1, argv + GetState.iNext - 1);
default:
return RTGetOptPrintError(rc, &ValueUnion);
}
}
RTMsgError("Missing command...");
showUsage(argv[0]);
return RTEXITCODE_SYNTAX;
}
示例11: main
//.........这里部分代码省略.........
"--intindex137", "1000",
"--macindex138", "08:0:27:00:ab:f3",
"--indexnovalue1",
"--macindexnegative",
"--twovalues", "firstvalue", "secondvalue",
"--twovalues:firstvalue", "secondvalue",
"--twovaluesindex4", "1", "0xA",
"--twovaluesindex5=2", "0xB",
"--threevalues", "1", "0xC", "thirdvalue",
/* bool on/off */
"--boolean", "on",
"--boolean", "off",
"--boolean", "invalid",
"--booleanindex2", "on",
"--booleanindex7", "off",
"--booleanindex9", "invalid",
/* standard options */
"--help",
"-help",
"-?",
"-h",
"--version",
"-version",
"-V",
/* done */
NULL
};
int argc2 = (int)RT_ELEMENTS(argv2) - 1;
CHECK(RT_SUCCESS(RTGetOptInit(&GetState, argc2, (char **)argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), 0, 0 /* fFlags */)));
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 2);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string1"));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string2"));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string3"));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string4"));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, ""));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, ""));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 2);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string5"));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string6"));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string7"));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, ""));
CHECK(GetState.uIndex == UINT32_MAX);
CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1);
示例12: handleDebugVM_LogXXXX
/**
* Handles the log sub-command.
*
* @returns Suitable exit code.
* @param pArgs The handler arguments.
* @param pDebugger Pointer to the debugger interface.
* @param pszSubCmd The sub command.
*/
static RTEXITCODE handleDebugVM_LogXXXX(HandlerArg *pArgs, IMachineDebugger *pDebugger, const char *pszSubCmd)
{
/*
* Parse arguments.
*/
bool fRelease = false;
com::Utf8Str strSettings;
RTGETOPTSTATE GetState;
RTGETOPTUNION ValueUnion;
/*
* NB: don't use short options to prevent log specifications like
* "-drv_foo" from being interpreted as options.
*/
# define DEBUGVM_LOG_DEBUG (VINF_GETOPT_NOT_OPTION + 'd')
# define DEBUGVM_LOG_RELEASE (VINF_GETOPT_NOT_OPTION + 'r')
static const RTGETOPTDEF s_aOptions[] =
{
{ "--debug", DEBUGVM_LOG_DEBUG, RTGETOPT_REQ_NOTHING },
{ "--release", DEBUGVM_LOG_RELEASE, RTGETOPT_REQ_NOTHING }
};
int rc = RTGetOptInit(&GetState, pArgs->argc, pArgs->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 2, RTGETOPTINIT_FLAGS_OPTS_FIRST);
AssertRCReturn(rc, RTEXITCODE_FAILURE);
while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
{
switch (rc)
{
case DEBUGVM_LOG_RELEASE:
fRelease = true;
break;
case DEBUGVM_LOG_DEBUG:
fRelease = false;
break;
/* Because log strings can start with "-" (like "-all+dev_foo")
* we have to take everything we got as a setting and apply it.
* IPRT will take care of the validation afterwards. */
default:
if (strSettings.length() == 0)
strSettings = ValueUnion.psz;
else
{
strSettings.append(' ');
strSettings.append(ValueUnion.psz);
}
break;
}
}
if (fRelease)
{
com::Utf8Str strTmp(strSettings);
strSettings = "release: ";
strSettings.append(strTmp);
}
com::Bstr bstrSettings(strSettings);
if (!strcmp(pszSubCmd, "log"))
CHECK_ERROR2I_RET(pDebugger, ModifyLogGroups(bstrSettings.raw()), RTEXITCODE_FAILURE);
else if (!strcmp(pszSubCmd, "logdest"))
CHECK_ERROR2I_RET(pDebugger, ModifyLogDestinations(bstrSettings.raw()), RTEXITCODE_FAILURE);
else if (!strcmp(pszSubCmd, "logflags"))
CHECK_ERROR2I_RET(pDebugger, ModifyLogFlags(bstrSettings.raw()), RTEXITCODE_FAILURE);
else
AssertFailedReturn(RTEXITCODE_FAILURE);
return RTEXITCODE_SUCCESS;
}
示例13: RTZipGzipCmd
/**
* A mini GZIP program.
*
* @returns Program exit code.
*
* @param cArgs The number of arguments.
* @param papszArgs The argument vector. (Note that this may be
* reordered, so the memory must be writable.)
*/
RTEXITCODE RTZipGzipCmd(unsigned cArgs, char **papszArgs)
{
/*
* Parse the command line.
*/
static const RTGETOPTDEF s_aOptions[] =
{
{ "--ascii", 'a', RTGETOPT_REQ_NOTHING },
{ "--stdout", 'c', RTGETOPT_REQ_NOTHING },
{ "--to-stdout", 'c', RTGETOPT_REQ_NOTHING },
{ "--decompress", 'd', RTGETOPT_REQ_NOTHING },
{ "--uncompress", 'd', RTGETOPT_REQ_NOTHING },
{ "--force", 'f', RTGETOPT_REQ_NOTHING },
{ "--keep", 'k', RTGETOPT_REQ_NOTHING },
{ "--list", 'l', RTGETOPT_REQ_NOTHING },
{ "--no-name", 'n', RTGETOPT_REQ_NOTHING },
{ "--name", 'N', RTGETOPT_REQ_NOTHING },
{ "--quiet", 'q', RTGETOPT_REQ_NOTHING },
{ "--recursive", 'r', RTGETOPT_REQ_NOTHING },
{ "--suffix", 'S', RTGETOPT_REQ_STRING },
{ "--test", 't', RTGETOPT_REQ_NOTHING },
{ "--verbose", 'v', RTGETOPT_REQ_NOTHING },
{ "--fast", '1', RTGETOPT_REQ_NOTHING },
{ "-1", '1', RTGETOPT_REQ_NOTHING },
{ "-2", '2', RTGETOPT_REQ_NOTHING },
{ "-3", '3', RTGETOPT_REQ_NOTHING },
{ "-4", '4', RTGETOPT_REQ_NOTHING },
{ "-5", '5', RTGETOPT_REQ_NOTHING },
{ "-6", '6', RTGETOPT_REQ_NOTHING },
{ "-7", '7', RTGETOPT_REQ_NOTHING },
{ "-8", '8', RTGETOPT_REQ_NOTHING },
{ "-9", '9', RTGETOPT_REQ_NOTHING },
{ "--best", '9', RTGETOPT_REQ_NOTHING }
};
RTGZIPCMDOPTS Opts;
Opts.fAscii = false;
Opts.fStdOut = false;
Opts.fDecompress = false;
Opts.fForce = false;
Opts.fKeep = false;
Opts.fList = false;
Opts.fName = true;
Opts.fQuiet = false;
Opts.fRecursive = false;
Opts.pszSuff = ".gz";
Opts.fTest = false;
Opts.uLevel = 6;
RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
unsigned cProcessed = 0;
//RTVFSIOSTREAM hVfsStdOut= NIL_RTVFSIOSTREAM;
RTGETOPTSTATE GetState;
int rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
RTGETOPTINIT_FLAGS_OPTS_FIRST);
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_SYNTAX, "RTGetOptInit: %Rrc", rc);
for (;;)
{
RTGETOPTUNION ValueUnion;
int chOpt = RTGetOpt(&GetState, &ValueUnion);
switch (chOpt)
{
case 0:
/*
* If we've processed any files we're done. Otherwise take
* input from stdin and write the output to stdout.
*/
if (cProcessed > 0)
return rcExit;
ValueUnion.psz = "-";
Opts.fStdOut = true;
/* Fall thru. */
case VINF_GETOPT_NOT_OPTION:
{
if (!*Opts.pszSuff && !Opts.fStdOut)
return RTMsgErrorExit(RTEXITCODE_SYNTAX, "The --suffix option specified an empty string");
if (!Opts.fStdOut && RTVfsChainIsSpec(ValueUnion.psz))
return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Must use standard out with VFS chain specifications");
if (Opts.fName)
return RTMsgErrorExit(RTEXITCODE_SYNTAX, "The --name option has not yet been implemented. Use --no-name.");
if (Opts.fAscii)
return RTMsgErrorExit(RTEXITCODE_SYNTAX, "The --ascii option has not yet been implemented.");
if (Opts.fRecursive)
return RTMsgErrorExit(RTEXITCODE_SYNTAX, "The --recursive option has not yet been implemented.");
/* Open the input file. */
RTVFSIOSTREAM hVfsSrc;
//.........这里部分代码省略.........
示例14: vboxNetNATLogInit
static int vboxNetNATLogInit(int argc, char **argv)
{
size_t cch;
int rc;
char szHome[RTPATH_MAX];
rc = com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome), false);
if (RT_FAILURE(rc))
return rc;
const char *pcszNetwork = NULL;
// XXX: This duplicates information from VBoxNetBaseService.cpp.
// Perhaps option definitions should be exported as public static
// member of VBoxNetBaseService?
static const RTGETOPTDEF s_aOptions[] = {
{ "--network", 'n', RTGETOPT_REQ_STRING }
};
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
RTGETOPTINIT_FLAGS_NO_STD_OPTS);
RTGETOPTUNION ValueUnion;
int ch;
while ((ch = RTGetOpt(&GetState, &ValueUnion)))
{
if (ch == 'n')
{
pcszNetwork = ValueUnion.psz;
break;
}
}
if (pcszNetwork == NULL)
return VERR_MISSING;
char szNetwork[RTPATH_MAX];
rc = RTStrCopy(szNetwork, sizeof(szNetwork), pcszNetwork);
if (RT_FAILURE(rc))
return rc;
// sanitize network name to be usable as a path component
for (char *p = szNetwork; *p != '\0'; ++p)
{
if (RTPATH_IS_SEP(*p))
*p = '_';
}
char szLogFile[RTPATH_MAX];
cch = RTStrPrintf(szLogFile, sizeof(szLogFile),
"%s%c%s.log", szHome, RTPATH_DELIMITER, szNetwork);
if (cch >= sizeof(szLogFile))
{
return VERR_BUFFER_OVERFLOW;
}
// sanitize network name some more to be usable as environment variable
for (char *p = szNetwork; *p != '\0'; ++p)
{
if (*p != '_'
&& (*p < '0' || '9' < *p)
&& (*p < 'a' || 'z' < *p)
&& (*p < 'A' || 'Z' < *p))
{
*p = '_';
}
}
char szEnvVarBase[128];
cch = RTStrPrintf(szEnvVarBase, sizeof(szEnvVarBase),
"VBOXNET_%s_RELEASE_LOG", szNetwork);
if (cch >= sizeof(szEnvVarBase))
return VERR_BUFFER_OVERFLOW;
char szError[RTPATH_MAX + 128];
rc = com::VBoxLogRelCreate("NAT Network",
szLogFile,
RTLOGFLAGS_PREFIX_TIME_PROG,
"all all.restrict -default.restrict",
szEnvVarBase,
RTLOGDEST_FILE,
32768 /* cMaxEntriesPerGroup */,
0 /* cHistory */,
0 /* uHistoryFileTime */,
0 /* uHistoryFileSize */,
szError, sizeof(szError));
return rc;
}
示例15: main
int main(int argc, char **argv)
{
RTTEST hTest;
RTEXITCODE rcExit = RTTestInitExAndCreate(argc, &argv, 0 /*fRtInit*/, "tstSupTscDelta", &hTest);
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
/*
* Parse args
*/
static const RTGETOPTDEF g_aOptions[] =
{
{ "--iterations", 'i', RTGETOPT_REQ_INT32 },
{ "--delay", 'd', RTGETOPT_REQ_INT32 },
};
uint32_t cIterations = 0; /* Currently 0 so that it doesn't upset testing. */
uint32_t cMsSleepBetweenIterations = 10;
int ch;
RTGETOPTUNION ValueUnion;
RTGETOPTSTATE GetState;
RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
while ((ch = RTGetOpt(&GetState, &ValueUnion)))
{
switch (ch)
{
case 'd':
cMsSleepBetweenIterations = ValueUnion.u32;
break;
case 'i':
cIterations = ValueUnion.u32;
break;
default:
return RTGetOptPrintError(ch, &ValueUnion);
}
}
if (!cIterations)
return RTTestSkipAndDestroy(hTest, "Nothing to do. The --iterations argument is 0 or not given.");
/*
* Init
*/
PSUPDRVSESSION pSession = NIL_RTR0PTR;
int rc = SUPR3Init(&pSession);
if (RT_SUCCESS(rc))
{
PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
if (pGip)
{
if (pGip->enmUseTscDelta < SUPGIPUSETSCDELTA_PRACTICALLY_ZERO)
return RTTestSkipAndDestroy(hTest, "No deltas to play with: enmUseTscDelta=%d\n", pGip->enmUseTscDelta);
/*
* Init stats.
*/
struct
{
int64_t iLowest;
int64_t iHighest;
int64_t iTotal;
uint64_t uAbsMin;
uint64_t uAbsMax;
uint64_t uAbsTotal;
} aCpuStats[RTCPUSET_MAX_CPUS];
RT_ZERO(aCpuStats);
for (uint32_t i = 0; i < pGip->cCpus; i++)
{
aCpuStats[i].iLowest = INT64_MAX;
aCpuStats[i].iHighest = INT64_MIN;
aCpuStats[i].uAbsMin = UINT64_MAX;
}
/*
* Do the work.
*/
for (uint32_t iIteration = 0; ; iIteration++)
{
/*
* Display the current deltas and gather statistics.
*/
RTPrintf("tstSupTscDelta: Iteration #%u results:", iIteration);
for (uint32_t iCpu = 0; iCpu < pGip->cCpus; iCpu++)
{
int64_t iTscDelta = pGip->aCPUs[iCpu].i64TSCDelta;
/* print */
if ((iCpu % 4) == 0)
RTPrintf("\ntstSupTscDelta:");
if (pGip->aCPUs[iCpu].enmState != SUPGIPCPUSTATE_ONLINE)
RTPrintf(" %02x: offline ", iCpu);
else if (iTscDelta != INT64_MAX)
RTPrintf(" %02x: %-12lld", iCpu, iTscDelta);
else
RTPrintf(" %02x: INT64_MAX ", iCpu);
/* stats */
if ( iTscDelta != INT64_MAX
&& pGip->aCPUs[iCpu].enmState == SUPGIPCPUSTATE_ONLINE)
//.........这里部分代码省略.........