Untitled
unknown
plain_text
2 years ago
1.7 kB
16
Indexable
#include "options.h"
/* Initialize option checks */
int file_option = 0;
int create_option = 0;
int list_option = 0;
int extract_option = 0;
int strict_option = 0;
int verbose_option = 0;
/* Parse the options in the command line */
int parse_options(char *options){
int error, i, option_len;
int character;
error = 0;
/* If options exceed max option space return an error */
if((option_len = strlen(options)) > 3){
error++;
return error;
}
/* Parse through options */
for(i = 0; i < option_len; i++){
character = options[i];
switch (character){
case 'c':
create_option = 1;
/* If list or extract mode is set, update error */
if(list_option == 1 || extract_option == 1){
error++;
}
break;
case 't':
list_option = 1;
/* If create or extract mode is set, update error */
if(create_option == 1 || extract_option == 1){
error++;
}
break;
case 'x':
extract_option = 1;
/* If list or create mode is set, update error */
if(list_option == 1 || create_option == 1){
error++;
}
break;
case 'v':
verbose_option = 1;
break;
case 'S':
strict_option = 1;
break;
case 'f':
file_option = 1;
break;
default:
error++;
}
}
/* If file option is not set, update error */
if(file_option != 1 || options[option_len - 1] != 'f'){
error++;
}
return error;
}Editor is loading...
Leave a Comment