int main(int argc, char* argv[]){ char* taskfilename = "todo.txt"; // char* donefile = "done.txt"; //bool verbose = false; int status = EXIT_SUCCESS; // parse the command line arguments. if (argc < 2){ print_short_help(); exit(status); } int i; //start the loop at 1 because argv[0] refers to the binary file for (i = 1; i < argc; i++){ // Add a new task. if (strings_equal(argv[i], "add", "-a")){ if (add_task(taskfilename, argv[i+1]) != 0){ status = EXIT_FAILURE; // We done goofed. } i++; // Skip the next argument. continue; } // Remove a task. if (strings_equal(argv[i], "rm", "-r")){ int index = atoi(argv[i+1]); if (remove_task(taskfilename, index) != 0){ status = EXIT_FAILURE; } i++; continue; } // Complete a task. if (strings_equal(argv[i], "do", "-d")){ int index = atoi(argv[i+1]); set_complete_task(taskfilename, index, true); i++; continue; } // Uncomplete a task. if (strings_equal(argv[i], "undo", "-u")){ int index = atoi(argv[i+1]); set_complete_task(taskfilename, index, false); i++; continue; } // List the tasks matching the string in the file. if (strings_equal(argv[i], "search", "-s")){ list_tasks_matching(taskfilename, argv[i+1]); i++; continue; } // Show all the tasks in the file. if(strings_equal(argv[i], "ls", "-l")){ list_tasks(taskfilename); continue; } // Show the help dialog. if (strcmp(argv[i], "-h") == 0){ print_help(); } // Set the taskfilename flag. if (strcmp(argv[i], "-f") == 0){ taskfilename = argv[i+1]; i++; continue; } // Set the verbosity flag. if (strcmp(argv[i], "-v") == 0){ // verbose = true; } } return status; }
int main(int argc, char *argv[]) { bool toggle_tasks = true; bool toggle_threads = false; bool toggle_all = false; bool toggle_cpus = false; bool toggle_load = false; bool toggle_uptime = false; task_id_t task_id = 0; int i; for (i = 1; i < argc; i++) { int off; /* Usage */ if ((off = arg_parse_short_long(argv[i], "-h", "--help")) != -1) { usage(argv[0]); return 0; } /* All threads */ if ((off = arg_parse_short_long(argv[i], "-a", "--all")) != -1) { toggle_tasks = false; toggle_threads = true; toggle_all = true; continue; } /* CPUs */ if ((off = arg_parse_short_long(argv[i], "-c", "--cpus")) != -1) { toggle_tasks = false; toggle_cpus = true; continue; } /* Threads */ if ((off = arg_parse_short_long(argv[i], "-t", "--task=")) != -1) { // TODO: Support for 64b range int tmp; int ret = arg_parse_int(argc, argv, &i, &tmp, off); if (ret != EOK) { printf("%s: Malformed task_id '%s'\n", NAME, argv[i]); return -1; } task_id = tmp; toggle_tasks = false; toggle_threads = true; continue; } /* Load */ if ((off = arg_parse_short_long(argv[i], "-l", "--load")) != -1) { toggle_tasks = false; toggle_load = true; continue; } /* Uptime */ if ((off = arg_parse_short_long(argv[i], "-u", "--uptime")) != -1) { toggle_tasks = false; toggle_uptime = true; continue; } } if (toggle_tasks) list_tasks(); if (toggle_threads) list_threads(task_id, toggle_all); if (toggle_cpus) list_cpus(); if (toggle_load) print_load(); if (toggle_uptime) print_uptime(); return 0; }