Exemple #1
0
void print_help(){
    print_short_help();
    puts("Manage tasks in a todo.txt file.\n");
    puts("Options:\n"
         " -f file \t\tSet the file used.\n"
         " -h \t\t\tShow the extended help.\n\n"
         "Commands:\n"
         " -a|add 'task'\t\tadds the task to the list\n"
         " -d|do index\t\tmarks the task at the index as done\n"
         " -u|undo index\t\tmarks the task at the index as incomplete\n"
         " -r|remove index\tremoves the task at the index\n"
         " -s|search 'query'\tsearches for the text in the tasklist\n"
         " -l|list\t\tshows all the tasks\n");
}
Exemple #2
0
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;
}
Exemple #3
0
int main(int argc, char *argv[])
{
    int c, i, err, do_bus_list;
    const char *config_file_name = NULL;

    struct option long_opts[] =  {
        { "help", no_argument, NULL, 'h' },
        { "set", no_argument, NULL, 's' },
        { "version", no_argument, NULL, 'v'},
        { "fahrenheit", no_argument, NULL, 'f' },
        { "no-adapter", no_argument, NULL, 'A' },
        { "config-file", required_argument, NULL, 'c' },
        { "bus-list", no_argument, NULL, 'B' },
        { 0, 0, 0, 0 }
    };

    setlocale(LC_CTYPE, "");

    do_raw = 0;
    do_sets = 0;
    do_bus_list = 0;
    hide_adapter = 0;
    while (1) {
        c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL);
        if (c == EOF)
            break;
        switch(c) {
        case ':':
        case '?':
            print_short_help();
            exit(1);
        case 'h':
            print_long_help();
            exit(0);
        case 'v':
            print_version();
            exit(0);
        case 'c':
            config_file_name = optarg;
            break;
        case 's':
            do_sets = 1;
            break;
        case 'f':
            fahrenheit = 1;
            break;
        case 'A':
            hide_adapter = 1;
            break;
        case 'u':
            do_raw = 1;
            break;
        case 'B':
            do_bus_list = 1;
            break;
        default:
            fprintf(stderr,
                    "Internal error while parsing options!\n");
            exit(1);
        }
    }

    err = read_config_file(config_file_name);
    if (err)
        exit(err);

    /* build the degrees string */
    set_degstr();

    if (do_bus_list) {
        print_bus_list();
    } else if (optind == argc) { /* No chip name on command line */
        if (!do_the_real_work(NULL, &err)) {
            fprintf(stderr,
                    "No sensors found!\n"
                    "Make sure you loaded all the kernel drivers you need.\n"
                    "Try sensors-detect to find out which these are.\n");
            err = 1;
        }
    } else {
        int cnt = 0;
        sensors_chip_name chip;

        for (i = optind; i < argc; i++) {
            if (sensors_parse_chip_name(argv[i], &chip)) {
                fprintf(stderr,
                        "Parse error in chip name `%s'\n",
                        argv[i]);
                print_short_help();
                err = 1;
                goto exit;
            }
            cnt += do_the_real_work(&chip, &err);
            sensors_free_chip_name(&chip);
        }

        if (!cnt) {
            fprintf(stderr, "Specified sensor(s) not found!\n");
            err = 1;
        }
    }

exit:
    sensors_cleanup();
    exit(err);
}