Changeset 8147 in vbox for trunk/include
- Timestamp:
- Apr 18, 2008 1:49:01 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 29853
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/getopt.h
r6000 r8147 38 38 */ 39 39 40 /** @name RTOPTIONDEF::f 40 /** @name RTOPTIONDEF::fFlags 41 * 42 * @remarks When neither of the RTGETOPT_FLAG_HEX, RTGETOPT_FLAG_OCT and RTGETOPT_FLAG_DEC 43 * flags are specified with a integer value format, RTGetOpt will default to 44 * decimal but recognize the 0x prefix when present. RTGetOpt will not look for 45 * for the octal prefix (0). 41 46 * @{ */ 42 43 /** Requires no extra argument. 47 /** Requires no extra argument. 44 48 * (Can be assumed to be 0 for ever.) */ 45 49 #define RTGETOPT_REQ_NOTHING 0 46 50 /** A value is required or error will be returned. */ 47 51 #define RTGETOPT_REQ_STRING 1 52 /** The value must be a valid signed 8-bit integer or an error will be returned. */ 53 #define RTGETOPT_REQ_INT8 2 54 /** The value must be a valid unsigned 8-bit integer or an error will be returned. */ 55 #define RTGETOPT_REQ_UINT8 3 56 /** The value must be a valid signed 16-bit integer or an error will be returned. */ 57 #define RTGETOPT_REQ_INT16 4 58 /** The value must be a valid unsigned 16-bit integer or an error will be returned. */ 59 #define RTGETOPT_REQ_UINT16 5 48 60 /** The value must be a valid signed 32-bit integer or an error will be returned. */ 49 #define RTGETOPT_REQ_INT32 2 50 /** The value must be a valid signed 32-bit integer or an error will be returned. */ 51 #define RTGETOPT_REQ_UINT32 3 61 #define RTGETOPT_REQ_INT32 6 62 /** The value must be a valid unsigned 32-bit integer or an error will be returned. */ 63 #define RTGETOPT_REQ_UINT32 7 64 /** The value must be a valid signed 64-bit integer or an error will be returned. */ 65 #define RTGETOPT_REQ_INT64 8 66 /** The value must be a valid unsigned 64-bit integer or an error will be returned. */ 67 #define RTGETOPT_REQ_UINT64 9 52 68 /** The mask of the valid required types. */ 53 #define RTGETOPT_REQ_MASK 3 69 #define RTGETOPT_REQ_MASK 15 70 /** Treat the value as hexadecimal - only applicable with the RTGETOPT_REQ_*INT*. */ 71 #define RTGETOPT_FLAG_HEX RT_BIT(16) 72 /** Treat the value as octal - only applicable with the RTGETOPT_REQ_*INT*. */ 73 #define RTGETOPT_FLAG_OCT RT_BIT(17) 74 /** Treat the value as decimal - only applicable with the RTGETOPT_REQ_*INT*. */ 75 #define RTGETOPT_FLAG_DEC RT_BIT(18) 76 /** Mask of valid bits - for validation. */ 77 #define RTGETOPT_VALID_MASK ( RTGETOPT_REQ_MASK | RTGETOPT_FLAG_HEX | RTGETOPT_FLAG_OCT | RTGETOPT_FLAG_DEC ) 54 78 /** @} */ 55 79 … … 62 86 * This is optional */ 63 87 const char *pszLong; 64 /** The short option character. 65 * This doesn't have to be a character, it may also be a \#define or enum value if 88 /** The short option character. 89 * This doesn't have to be a character, it may also be a \#define or enum value if 66 90 * there isn't any short version of this option. */ 67 91 int iShort; … … 76 100 /** 77 101 * Option argument union. 78 * 102 * 79 103 * What ends up here depends on argument format in the option definition. 104 * 105 * @remarks Integers will bet put in the \a i and \a u members and sign/zero extended 106 * according to the signedness indicated by the \a fFlags. So, you can choose 107 * use which ever of the integer members for accessing the value regardless 108 * of restrictions indicated in the \a fFlags. 80 109 */ 81 110 typedef union RTOPTIONUNION … … 86 115 /** A RTGETOPT_ARG_FORMAT_STRING option argument. */ 87 116 const char *psz; 88 /** A RTGETOPT_ARG_FORMAT_INT32 option argument. */ 117 118 #if !defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86) 119 # error "PORTME: big-endian systems will need to fix the layout here to get the next two fields working right" 120 #endif 121 122 /** A RTGETOPT_ARG_FORMAT_INT8 option argument. */ 123 int8_t i8; 124 /** A RTGETOPT_ARG_FORMAT_UINT8 option argument . */ 125 uint8_t u8; 126 /** A RTGETOPT_ARG_FORMAT_INT16 option argument. */ 127 int16_t i16; 128 /** A RTGETOPT_ARG_FORMAT_UINT16 option argument . */ 129 uint16_t u16; 130 /** A RTGETOPT_ARG_FORMAT_INT16 option argument. */ 89 131 int32_t i32; 90 132 /** A RTGETOPT_ARG_FORMAT_UINT32 option argument . */ 91 133 uint32_t u32; 134 /** A RTGETOPT_ARG_FORMAT_INT64 option argument. */ 135 int64_t i64; 136 /** A RTGETOPT_ARG_FORMAT_UINT64 option argument. */ 137 uint64_t u64; 138 /** A signed integer value. */ 139 int64_t i; 140 /** An unsigned integer value. */ 141 uint64_t u; 92 142 } RTOPTIONUNION; 93 143 /** Pointer to an option argument union. */ 94 144 typedef RTOPTIONUNION *PRTOPTIONUNION; 145 /** Pointer to a const option argument union. */ 146 typedef RTOPTIONUNION const *PCRTOPTIONUNION; 95 147 96 148 … … 100 152 * 101 153 * This is to be called in a loop until it returns 0 (meaning that all options 102 * were parsed) or a negative value (meaning that an error occured). The passed in 154 * were parsed) or a negative value (meaning that an error occured). The passed in 103 155 * argument vector is sorted into options and non-option arguments, such that when 104 156 * returning 0 the *piThis is the index of the first non-option argument. … … 115 167 * int main(int argc, char *argv[]) 116 168 * { 117 * static const RTOPTIONDEF g_aOptions[] = 169 * static const RTOPTIONDEF g_aOptions[] = 118 170 * { 119 171 * { "--optwithstring", 's', RTGETOPT_REQ_STRING }, … … 145 197 * } 146 198 * } 147 * 199 * 148 200 * while (i < argc) 149 201 * { 150 202 * //do stuff to argv[i]. 151 203 * } 152 * 204 * 153 205 * return 0; 154 206 * } … … 164 216 * that require an argument, this contains the value of that argument, depending on the type that is required. 165 217 */ 166 RTDECL(int) RTGetOpt(int argc, char * argv[], PCRTOPTIONDEF paOptions, size_t cOptions, int *piThis, PRTOPTIONUNION pValueUnion);218 RTDECL(int) RTGetOpt(int argc, char **argv, PCRTOPTIONDEF paOptions, size_t cOptions, int *piThis, PRTOPTIONUNION pValueUnion); 167 219 168 220 /** @} */
Note:
See TracChangeset
for help on using the changeset viewer.