Changeset 5843 in vbox for trunk/src/VBox
- Timestamp:
- Nov 26, 2007 6:45:33 PM (17 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r5760 r5843 208 208 r3/tcp.cpp 209 209 210 #if1of ($(BUILD_TARGET_ARCH),amd64 x86)211 #RuntimeR3_SOURCES += common/time/timesupA.asm212 #else210 if1of ($(BUILD_TARGET_ARCH),amd64 x86) 211 RuntimeR3_SOURCES += common/time/timesupA.asm 212 else 213 213 RuntimeR3_SOURCES += common/time/timesupref.cpp 214 #endif214 endif 215 215 216 216 ifdef IPRT_WITH_KSTUFF … … 666 666 VBox/strformat-vbox.cpp 667 667 668 #if1of ($(BUILD_TARGET_ARCH),amd64 x86)669 #RuntimeR0_SOURCES += common/time/timesupA.asm670 #else668 if1of ($(BUILD_TARGET_ARCH),amd64 x86) 669 RuntimeR0_SOURCES += common/time/timesupA.asm 670 else 671 671 RuntimeR0_SOURCES += common/time/timesupref.cpp 672 #endif672 endif 673 673 674 674 RuntimeR0_SOURCES.win.amd64 = $(RuntimeWin64ASM_SOURCES) … … 997 997 VBox/strformat-vbox.cpp \ 998 998 999 #if1of ($(BUILD_TARGET_ARCH),amd64 x86)1000 #RuntimeGC_SOURCES += common/time/timesupA.asm1001 #else999 if1of ($(BUILD_TARGET_ARCH),amd64 x86) 1000 RuntimeGC_SOURCES += common/time/timesupA.asm 1001 else 1002 1002 RuntimeGC_SOURCES += common/time/timesupref.cpp 1003 #endif1003 endif 1004 1004 1005 1005 RuntimeGC_SOURCES.win.x86 = $(RuntimeWin32ASM_SOURCES) -
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r5766 r5843 1 /* $Id$ */ 1 2 /** @file 2 3 * innotek Portable Runtime - Command Line Parsing … … 21 22 #include <iprt/err.h> 22 23 #include <iprt/string.h> 24 #include <iprt/assert.h> 23 25 24 #include <string.h>25 26 26 /******************************************************************************* 27 * Code * 28 *******************************************************************************/ 29 int RTGetOpt(int argc, 30 char *argv[], 31 const RTOPTIONDEF *paOptions, 32 int cOptions, 33 int *piThis, 34 RTOPTIONUNION *pValueUnion) 27 28 RTDECL(int) RTGetOpt(int argc, char *argv[], PCRTOPTIONDEF paOptions, size_t cOptions, int *piThis, PRTOPTIONUNION pValueUnion) 35 29 { 36 if ( (!piThis) 37 || (*piThis >= argc) 30 pValueUnion->pDef = NULL; 31 32 if ( !piThis 33 || *piThis >= argc 38 34 ) 39 35 return 0; 40 36 41 37 int iThis = (*piThis)++; 42 const char *p cszArgThis = argv[iThis];38 const char *pszArgThis = argv[iThis]; 43 39 44 if (*p cszArgThis == '-')40 if (*pszArgThis == '-') 45 41 { 46 int i; 47 for (i = 0; 48 i < cOptions; 49 ++i) 42 for (size_t i = 0; i < cOptions; i++) 50 43 { 51 44 bool fShort = false; 52 if ( (!strcmp(pcszArgThis, paOptions[i].pcszLong)) 53 || ( ((fShort = (pcszArgThis[1] == paOptions[i].cShort))) 54 && (pcszArgThis[2] == '\0') 45 if ( ( paOptions[i].pszLong 46 && !strcmp(pszArgThis, paOptions[i].pszLong)) 47 || ( (fShort = (pszArgThis[1] == paOptions[i].iShort)) 48 && pszArgThis[2] == '\0' 55 49 ) 56 50 ) 57 51 { 58 if (paOptions[i].fl & RTGETOPT_REQUIRES_ARGUMENT) 52 Assert(!(paOptions[i].fFlags & ~RTGETOPT_REQ_MASK)); 53 pValueUnion->pDef = &paOptions[i]; 54 55 if ((paOptions[i].fFlags & RTGETOPT_REQ_MASK) != RTGETOPT_REQ_NOTHING) 59 56 { 60 57 if (iThis >= argc - 1) 58 return VERR_GETOPT_REQUIRED_ARGUMENT_MISSING; 59 60 int iNext = (*piThis)++; 61 switch (paOptions[i].fFlags & RTGETOPT_REQ_MASK) 61 62 { 62 pValueUnion->pcsz = paOptions[i].pcszLong; 63 return VERR_GETOPT_REQUIRED_ARGUMENT_MISSING; 64 } 65 else 66 { 67 int iNext = (*piThis)++; 68 if (paOptions[i].fl & RTGETOPT_ARG_FORMAT_INT32) 63 case RTGETOPT_REQ_STRING: 64 pValueUnion->psz = argv[iNext]; 65 break; 66 67 case RTGETOPT_REQ_INT32: 69 68 { 70 int32_t i; 71 if (RTStrToInt32Full(argv[iNext], 10, &i)) 72 { 73 pValueUnion->pcsz = paOptions[i].pcszLong; 69 int32_t i32; 70 if (RTStrToInt32Full(argv[iNext], 10, &i32)) 74 71 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 75 }76 72 77 pValueUnion->i = i; 73 pValueUnion->i32 = i32; 74 break; 78 75 } 79 else if (paOptions[i].fl & RTGETOPT_ARG_FORMAT_UINT32) 76 77 case RTGETOPT_REQ_UINT32: 80 78 { 81 uint32_t u; 82 if (RTStrToUInt32Full(argv[iNext], 10, &u)) 83 { 84 pValueUnion->pcsz = paOptions[i].pcszLong; 79 uint32_t u32; 80 if (RTStrToUInt32Full(argv[iNext], 10, &u32)) 85 81 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 86 } 82 83 pValueUnion->u32 = u32; 84 break; 85 } 87 86 88 pValueUnion->u = u; 89 } 90 else 91 pValueUnion->pcsz = argv[iNext]; 87 default: 88 AssertMsgFailed(("i=%d f=%#x\n", i, paOptions[i].fFlags)); 89 return VERR_INTERNAL_ERROR; 92 90 } 93 91 } 94 92 95 return paOptions[i]. cShort;93 return paOptions[i].iShort; 96 94 } 97 95 } 98 96 } 99 97 98 /** @todo Sort options and arguments (i.e. stuff that doesn't start with '-'), stop when 99 * encountering the first argument. */ 100 100 101 return VERR_GETOPT_UNKNOWN_OPTION; 101 102 } -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r4546 r5843 30 30 tstFile \ 31 31 tstFileLock \ 32 tstGetOpt \ 32 33 tstHeapSimple \ 33 34 tstInlineAsm \ … … 234 235 tstErrUnique.cpp_DEPS = $(PATH_TARGET)/../errmsgdata.h 235 236 237 tstGetOpt_SOURCES = tstGetOpt.cpp 238 236 239 tstHeapSimple_SOURCES = tstHeapSimple.cpp 237 240 -
trunk/src/VBox/Runtime/testcase/tstGetOpt.cpp
r5832 r5843 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime Testcase - Native Loader.3 * innotek Portable Runtime Testcase - RTGetOpt 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 200 6-2007 innotek GmbH7 * Copyright (C) 2007 innotek GmbH 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 18 18 19 #include <iprt/ ldr.h>19 #include <iprt/getopt.h> 20 20 #include <iprt/stream.h> 21 #include <iprt/runtime.h> 21 #include <iprt/initterm.h> 22 #include <iprt/string.h> 22 23 #include <iprt/err.h> 23 24 24 int main(int argc, const char * const *argv) 25 26 int main() 25 27 { 26 int rcRet= 0;28 int cErrors = 0; 27 29 RTR3Init(); 28 30 29 /* 30 * If no args, display usage. 31 */ 32 if (argc <= 1) 33 { 34 RTPrintf("Syntax: %s [so/dll [so/dll [..]]\n", argv[0]); 35 return 1; 36 } 31 int i; 32 RTOPTIONUNION Val; 33 #define CHECK(expr) do { if (!(expr)) { RTPrintf("tstGetOpt: error line %d (i=%d): %s\n", __LINE__, i, #expr); cErrors++; } } while (0) 34 35 #define CHECK_GETOPT(expr, chRet, iNext) \ 36 do { \ 37 CHECK((expr) == (chRet)); \ 38 CHECK(i == (iNext)); \ 39 i = (iNext); \ 40 } while (0) 37 41 38 42 /* 39 * Iterate the arguments and treat all of them as so/dll paths.43 * Simple. 40 44 */ 41 for (int i = 1; i < argc; i++)45 static const RTOPTIONDEF s_aOpts2[] = 42 46 { 43 RTLDRMOD hLdrMod = (RTLDRMOD)0xbaadffaa; 44 int rc = RTLdrLoad(argv[i], &hLdrMod); 45 if (RT_SUCCESS(rc)) 46 { 47 RTPrintf("tstLdrLoad: %d - %s\n", i, argv[i]); 48 rc = RTLdrClose(hLdrMod); 49 if (RT_FAILURE(rc)) 50 { 51 RTPrintf("tstLdrLoad: rc=%Rrc RTLdrClose()\n", rc); 52 rcRet++; 53 } 54 } 55 else 56 { 57 RTPrintf("tstLdrLoad: rc=%Rrc RTLdrOpen('%s')\n", rc, argv[i]); 58 rcRet++; 59 } 60 } 47 { "--optwithstring", 's', RTGETOPT_REQ_STRING }, 48 { "--optwithint", 'i', RTGETOPT_REQ_INT32 }, 49 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 50 { NULL, 'q', RTGETOPT_REQ_NOTHING }, 51 { "--quiet", 384, RTGETOPT_REQ_NOTHING }, 52 }; 53 54 char *argv2[] = 55 { 56 "-s", "string1", 57 "--optwithstring", "string2", 58 "-i", "-42", 59 "--optwithint", "42", 60 "-v", 61 "--verbose", 62 "-q", 63 "--quiet", 64 /* "filename1", */ 65 /* "filename2", */ 66 NULL 67 }; 68 int argc2 = (int)RT_ELEMENTS(argv2) - 1; 69 70 i = 0; 71 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 's', 2); 72 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string1")); 73 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 's', 4); 74 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string2")); 75 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 'i', 6); 76 CHECK(Val.i32 == -42); 77 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 'i', 8); 78 CHECK(Val.i32 == 42); 79 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 'v', 9); 80 CHECK(Val.pDef == &s_aOpts2[2]); 81 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 'v', 10); 82 CHECK(Val.pDef == &s_aOpts2[2]); 83 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 'q', 11); 84 CHECK(Val.pDef == &s_aOpts2[3]); 85 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 384, 12); 86 CHECK(Val.pDef == &s_aOpts2[4]); 87 CHECK_GETOPT(RTGetOpt(argc2, argv2, &s_aOpts2[0], RT_ELEMENTS(s_aOpts2), &i, &Val), 0, 12); 88 CHECK(Val.pDef == NULL); 89 CHECK(argc2 == i); 90 61 91 62 92 /* 63 93 * Summary. 64 94 */ 65 if (! rcRet)66 RTPrintf("tst LdrLoad: SUCCESS\n");95 if (!cErrors) 96 RTPrintf("tstGetOpt: SUCCESS\n"); 67 97 else 68 RTPrintf("tst LdrLoad: FAILURE - %d errors\n", rcRet);98 RTPrintf("tstGetOpt: FAILURE - %d errors\n", cErrors); 69 99 70 return !! rcRet;100 return !!cErrors; 71 101 }
Note:
See TracChangeset
for help on using the changeset viewer.