8 /****************************************************************************/
9 void util_cmdline_init( struct util_cmdline_state *cs )
16 for( loop = 0 ; loop < NUMBER_OF_LOWERCASE_LETTERS_IN_LATIN_ALPHABET ; loop++ )
18 cs->args[loop].arg_type = UTIL_CMDLINE_ARG_TYPE_UNSET;
19 cs->args[loop].processed_flag = LOWERED;
29 /****************************************************************************/
30 #pragma warning( disable : 4100 )
32 void util_cmdline_cleanup( struct util_cmdline_state *cs )
39 #pragma warning( default : 4100 )
45 /****************************************************************************/
46 void util_cmdline_add_arg( struct util_cmdline_state *cs, char arg_letter, enum util_cmdline_arg_type arg_type )
52 assert( arg_letter >= 'a' and arg_letter <= 'z' );
53 // TRD : arg_type can be any value in its range
55 index = arg_letter - 'a';
57 cs->args[index].arg_type = arg_type;
59 if( arg_type == UTIL_CMDLINE_ARG_TYPE_FLAG )
60 cs->args[index].arg_data.flag.flag = LOWERED;
69 /****************************************************************************/
70 int util_cmdline_process_args( struct util_cmdline_state *cs, int argc, char **argv )
86 assert( argv != NULL );
88 for( loop = 1 ; loop < argc ; loop++ )
95 arg_letter = tolower( *(arg+1) );
97 if( arg_letter >= 'a' and arg_letter <= 'z' )
99 index = arg_letter - 'a';
101 switch( cs->args[index].arg_type )
103 case UTIL_CMDLINE_ARG_TYPE_INTEGER_RANGE:
109 cc = sscanf( *(argv+loop+1), "%llu-%llu", &cs->args[index].arg_data.integer_range.integer_start, &cs->args[index].arg_data.integer_range.integer_end );
116 cs->args[index].processed_flag = RAISED;
122 case UTIL_CMDLINE_ARG_TYPE_INTEGER:
128 cc = sscanf( *(argv+loop+1), "%llu", &cs->args[index].arg_data.integer.integer );
135 cs->args[index].processed_flag = RAISED;
141 case UTIL_CMDLINE_ARG_TYPE_FLAG:
142 cs->args[index].arg_data.flag.flag = RAISED;
143 cs->args[index].processed_flag = RAISED;
146 case UTIL_CMDLINE_ARG_TYPE_UNSET:
165 /****************************************************************************/
166 void util_cmdline_get_arg_data( struct util_cmdline_state *cs, char arg_letter, union util_cmdline_arg_data **arg_data )
171 assert( cs != NULL );
172 assert( arg_letter >= 'a' and arg_letter <= 'z' );
173 assert( arg_data != NULL );
175 index = arg_letter - 'a';
177 if( cs->args[index].processed_flag == RAISED )
178 *arg_data = &cs->args[index].arg_data;