Changeset 17087 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Feb 24, 2009 6:28:29 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r17083 r17087 37 37 #include <iprt/assert.h> 38 38 #include <iprt/ctype.h> 39 #include <limits.h> 39 40 40 41 … … 56 57 { 57 58 Assert(!(paOptions[i].fFlags & ~RTGETOPT_VALID_MASK)); 58 59 bool fShort = ( *pszArgThis == '-' 60 && (uint32_t)pszArgThis[1] == paOptions[i].uShort 61 ); 59 Assert(paOptions[i].uShort > 0 && paOptions[i].uShort <= (unsigned)INT_MAX); 60 61 bool fShort = *pszArgThis == '-' 62 && (uint32_t)pszArgThis[1] == paOptions[i].uShort 63 && paOptions[i].uShort; 62 64 63 65 if ((paOptions[i].fFlags & RTGETOPT_REQ_MASK) != RTGETOPT_REQ_NOTHING) 64 66 { 65 67 /* 66 * A value is required with the argument. We're trying tovery67 68 69 70 71 68 * A value is required with the argument. We're trying to be very 69 * understanding here and will permit any of the following: 70 * -svalue, -s:value, -s=value, 71 * -s value, -s: value, -s= value 72 * (Ditto for long options.) 73 */ 72 74 size_t cchLong = 2; 73 if ( ( 74 75 76 77 75 if ( ( paOptions[i].pszLong 76 && !strncmp(pszArgThis, paOptions[i].pszLong, (cchLong = strlen(paOptions[i].pszLong))) 77 && ( pszArgThis[cchLong] == '\0' 78 || pszArgThis[cchLong] == ':' 79 || pszArgThis[cchLong] == '=') 78 80 ) 79 ||fShort81 || fShort 80 82 ) 81 83 { … … 83 85 84 86 /* 85 86 87 * Find the argument value 88 */ 87 89 const char *pszValue; 88 90 if ( fShort 89 ?pszArgThis[2] == '\0'90 || ((pszArgThis[2] == ':' || pszArgThis[2] == '=') && pszArgThis[3] == '\0')91 :pszArgThis[cchLong] == '\0' || pszArgThis[cchLong + 1] == '\0')91 ? pszArgThis[2] == '\0' 92 || ((pszArgThis[2] == ':' || pszArgThis[2] == '=') && pszArgThis[3] == '\0') 93 : pszArgThis[cchLong] == '\0' || pszArgThis[cchLong + 1] == '\0') 92 94 { 93 95 if (iThis + 1 >= argc) … … 98 100 else /* same argument. */ 99 101 pszValue = fShort 100 101 102 ? &pszArgThis[2 + (pszArgThis[2] == ':' || pszArgThis[2] == '=')] 103 : &pszArgThis[cchLong + 1]; 102 104 103 105 /* 104 105 106 107 108 106 * Transform into a option value as requested. 107 * If decimal conversion fails, we'll check for "0x<xdigit>" and 108 * try a 16 based conversion. We will not interpret any of the 109 * generic ints as octals. 110 */ 109 111 switch (paOptions[i].fFlags & (RTGETOPT_REQ_MASK | RTGETOPT_FLAG_HEX | RTGETOPT_FLAG_OCT | RTGETOPT_FLAG_DEC)) 110 112 { … … 182 184 } 183 185 else if ( ( paOptions[i].pszLong 184 185 186 186 && !strcmp(pszArgThis, paOptions[i].pszLong)) 187 || ( fShort 188 && pszArgThis[2] == '\0') /** @todo implement support for ls -lsR like stuff? */ 187 189 ) 188 190 { … … 192 194 } 193 195 194 return VERR_GETOPT_UNKNOWN_OPTION; 196 /* Option or not? */ 197 if (*pszArgThis == '-') 198 return VERR_GETOPT_UNKNOWN_OPTION; 199 200 /* 201 * Not an option. 202 */ 203 (*piThis)--; 204 /** @todo Sort options and arguments (i.e. stuff that doesn't start with '-'), stop when 205 * encountering the first argument. */ 206 207 return 0; 195 208 } 196 209
Note:
See TracChangeset
for help on using the changeset viewer.