Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef enum {
- OP_APPEND,
- OP_READ,
- OP_DELETE,
- OP_LIST,
- OP_REFORMAT,
- OP_CREATE_FS
- } operation_t;
- int main(int argc, char** argv) {
- char file[PATH_MAX];
- bool file_arg_set = false;
- operation_t operation = OP_LIST;
- if (argc > 1) {
- int i = 1;
- // iterate over all args
- for (; i < argc; i++) {
- const size_t length = strlen(argv[i]);
- const char *arg = argv[i];
- // it's a flag
- if (arg[0] == '-') {
- // long-name flag
- if (arg[1] == '-') {
- // we can't use switch-case for strings
- if (strcmp(arg, "--append") == 0) operation = OP_APPEND;
- if (strcmp(arg, "--read") == 0) operation = OP_READ;
- if (strcmp(arg, "--delete") == 0) operation = OP_DELETE;
- if (strcmp(arg, "--list") == 0) operation = OP_LIST;
- if (strcmp(arg, "--reformat") == 0) operation = OP_REFORMAT;
- if (strcmp(arg, "--create") == 0) operation = OP_CREATE_FS;
- }
- // short-name flag
- else {
- int k = 1;
- for (; k < length; k++) {
- switch (arg[k]) {
- case 'a':
- operation = OP_APPEND;
- break;
- case 'r':
- operation = OP_READ;
- break;
- case 'd':
- operation = OP_DELETE;
- break;
- case 'l':
- operation = OP_LIST;
- break;
- case 'R':
- operation = OP_REFORMAT;
- break;
- case 'C':
- operation = OP_CREATE_FS;
- break;
- }
- }
- }
- } else {
- memcpy(file, arg, length + 1);
- file_arg_set = true;
- }
- }
- }
- switch (operation) {
- case OP_APPEND: {
- /* */
- break;
- }
- case OP_LIST: {
- /* */
- break;
- }
- case OP_READ: {
- /* */
- break;
- }
- case OP_DELETE: {
- /* */
- break;
- }
- case OP_REFORMAT: {
- /* */
- break;
- }
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement