Пример #1
0
void execute_save(char* command, ListT* tasks, TaskT** current_task) {
    char* filename;
    int write_result;

    if (tasks != NULL && tasks->size > 0) {

        char* user_filename = NULL;
        char* input_msg = NULL;

        filename = make_file_name();
        input_msg = malloc(strlen(filename) + strlen(kFilenamePromptFormat) + 1);
        sprintf(input_msg, kFilenamePromptFormat, filename);

        get_user_input_msg(&user_filename, input_msg);

        if (user_filename != NULL && strlen(user_filename) > 0) {
            char* user_filename_with_dir;

            user_filename_with_dir = malloc(6 + 1 + strlen(user_filename));
            sprintf(user_filename_with_dir, "tasks/%s", user_filename);

            free(filename);
            free(user_filename);

            filename = user_filename_with_dir;
        }
        
        write_result = task_write(tasks, filename);

        if (task_write < 0) {
            printf("Failed to write tasks to %s\n", filename);
        }

        free(filename);
    }
}
Пример #2
0
int main(int argc, char **argv)
{
	const char *chip_str, *task, *reg_str;
	int chip;
	unsigned int reg, mask, set, value;
	int err;

	if (argc != 4 && argc != 5 && argc != 6)
		goto err_usage;
	chip_str = argv[1];
	task = argv[2];
	reg_str = argv[3];

	if (strcasecmp(chip_str, "retu") == 0)
		chip = CHIP_RETU;
	else if (strcasecmp(chip_str, "tahvo") == 0)
		chip = CHIP_TAHVO;
	else
		goto err_usage;

	err = str2uint(reg_str, &reg);
	if (err)
		goto err_usage;

	if (strcasecmp(task, "read") == 0) {
		if (argc != 4)
			goto err_usage;
		err = task_read(chip, reg, &value);
		if (err) {
			fprintf(stderr, "Failed to read %s register 0x%02X\n",
				chip2str(chip), reg);
			return 1;
		}
		printf("0x%04X\n", value);
	} else if (strcasecmp(task, "write") == 0) {
		if (argc != 5)
			goto err_usage;
		err = str2uint(argv[4], &value);
		if (err)
			goto err_usage;
		err = task_write(chip, reg, value);
		if (err) {
			fprintf(stderr, "Failed to write %s register 0x%02X\n",
				chip2str(chip), reg);
			return 1;
		}
	} else if (strcasecmp(task, "maskset") == 0) {
		if (argc != 6)
			goto err_usage;
		err = str2uint(argv[4], &mask);
		err |= str2uint(argv[5], &set);
		if (err)
			goto err_usage;
		err = task_maskset(chip, reg, mask, set);
		if (err) {
			fprintf(stderr, "Failed to maskset %s register 0x%02X\n",
				chip2str(chip), reg);
			return 1;
		}
	} else
		goto err_usage;

	return 0;

err_usage:
	usage(stderr, argc, argv);
	return 1;
}