Esempio n. 1
0
void
update_options_from_argv(const char *argv[])
{
	int next, flags_pos;

	for (next = flags_pos = 0; argv[next]; next++) {
		const char *flag = argv[next];
		int value = -1;

		if (map_enum(&value, commit_order_arg_map, flag)) {
			opt_commit_order = value;
			update_commit_order_arg();
			continue;
		}

		if (map_enum(&value, ignore_space_arg_map, flag)) {
			opt_ignore_space = value;
			update_ignore_space_arg();
			continue;
		}

		if (!prefixcmp(flag, "-U")
		    && parse_int(&value, flag + 2, 0, 999999) == SUCCESS) {
			opt_diff_context = value;
			update_diff_context_arg(opt_diff_context);
			continue;
		}

		argv[flags_pos++] = flag;
	}

	argv[flags_pos] = NULL;
}
Esempio n. 2
0
/* Wants: name = value */
static enum status_code
option_set_command(int argc, const char *argv[])
{
	if (argc < 3)
		return ERROR_WRONG_NUMBER_OF_ARGUMENTS;

	if (strcmp(argv[1], "="))
		return ERROR_NO_VALUE_ASSIGNED;

	if (!strcmp(argv[0], "blame-options"))
		return parse_args(&opt_blame_options, argv + 2);

	if (!strcmp(argv[0], "diff-options"))
		return parse_args(&opt_diff_options, argv + 2);

	if (argc != 3)
		return ERROR_WRONG_NUMBER_OF_ARGUMENTS;

	if (!strcmp(argv[0], "show-author"))
		return parse_enum(&opt_show_author, argv[2], author_map);

	if (!strcmp(argv[0], "show-date"))
		return parse_enum(&opt_show_date, argv[2], date_map);

	if (!strcmp(argv[0], "show-rev-graph"))
		return parse_bool(&opt_show_rev_graph, argv[2]);

	if (!strcmp(argv[0], "show-refs"))
		return parse_bool(&opt_show_refs, argv[2]);

	if (!strcmp(argv[0], "show-changes"))
		return parse_bool(&opt_show_changes, argv[2]);

	if (!strcmp(argv[0], "show-notes")) {
		bool matched = FALSE;
		enum status_code res = parse_bool_matched(&opt_show_notes, argv[2], &matched);

		if (res == SUCCESS && matched) {
			update_notes_arg();
			return res;
		}

		opt_show_notes = TRUE;
		strcpy(opt_notes_arg, "--show-notes=");
		res = parse_string(opt_notes_arg + 8, argv[2],
				   sizeof(opt_notes_arg) - 8);
		if (res == SUCCESS && opt_notes_arg[8] == '\0')
			opt_notes_arg[7] = '\0';
		return res;
	}

	if (!strcmp(argv[0], "show-line-numbers"))
		return parse_bool(&opt_show_line_numbers, argv[2]);

	if (!strcmp(argv[0], "line-graphics"))
		return parse_enum(&opt_line_graphics, argv[2], graphic_map);

	if (!strcmp(argv[0], "line-number-interval"))
		return parse_int(&opt_line_number_interval, argv[2], 1, 1024);

	if (!strcmp(argv[0], "author-width"))
		return parse_int(&opt_author_width, argv[2], 0, 1024);

	if (!strcmp(argv[0], "filename-width"))
		return parse_int(&opt_show_filename_width, argv[2], 0, 1024);

	if (!strcmp(argv[0], "show-filename"))
		return parse_enum(&opt_show_filename, argv[2], filename_map);

	if (!strcmp(argv[0], "show-file-size"))
		return parse_enum(&opt_show_file_size, argv[2], file_size_map);

	if (!strcmp(argv[0], "horizontal-scroll"))
		return parse_step(&opt_horizontal_scroll, argv[2]);

	if (!strcmp(argv[0], "split-view-height"))
		return parse_step(&opt_split_view_height, argv[2]);

	if (!strcmp(argv[0], "vertical-split"))
		return parse_enum(&opt_vertical_split, argv[2], vertical_split_map);

	if (!strcmp(argv[0], "tab-size"))
		return parse_int(&opt_tab_size, argv[2], 1, 1024);

	if (!strcmp(argv[0], "diff-context") && !*opt_diff_context_arg) {
		enum status_code code = parse_int(&opt_diff_context, argv[2], 0, 999999);

		if (code == SUCCESS)
			update_diff_context_arg(opt_diff_context);
		return code;
	}

	if (!strcmp(argv[0], "ignore-space") && !*opt_ignore_space_arg) {
		enum status_code code = parse_enum(&opt_ignore_space, argv[2], ignore_space_map);

		if (code == SUCCESS)
			update_ignore_space_arg();
		return code;
	}

	if (!strcmp(argv[0], "commit-order") && !*opt_commit_order_arg) {
		enum status_code code = parse_enum(&opt_commit_order, argv[2], commit_order_map);

		if (code == SUCCESS)
			update_commit_order_arg();
		return code;
	}

	if (!strcmp(argv[0], "status-untracked-dirs"))
		return parse_bool(&opt_status_untracked_dirs, argv[2]);

	if (!strcmp(argv[0], "read-git-colors"))
		return parse_bool(&opt_read_git_colors, argv[2]);

	if (!strcmp(argv[0], "ignore-case"))
		return parse_bool(&opt_ignore_case, argv[2]);

	if (!strcmp(argv[0], "focus-child"))
		return parse_bool(&opt_focus_child, argv[2]);

	if (!strcmp(argv[0], "wrap-lines"))
		return parse_bool(&opt_wrap_lines, argv[2]);

	if (!strcmp(argv[0], "show-id"))
		return parse_bool(&opt_show_id, argv[2]);

	if (!strcmp(argv[0], "id-width"))
		return parse_id(&opt_id_width, argv[2]);

	if (!strcmp(argv[0], "title-overflow")) {
		bool enabled = FALSE;
		bool matched;
		enum status_code code;

		/*
		 * "title-overflow" is considered a boolint.
		 * We try to parse it as a boolean (and set the value to 50 if true),
		 * otherwise we parse it as an integer and use the given value.
		 */
		code = parse_bool_matched(&enabled, argv[2], &matched);
		if (code == SUCCESS && matched) {
			if (enabled)
				opt_title_overflow = 50;
		} else {
			code = parse_int(&opt_title_overflow, argv[2], 2, 1024);
			if (code != SUCCESS)
				opt_title_overflow = 50;
		}

		return code;
	}

	if (!strcmp(argv[0], "editor-line-number"))
		return parse_bool(&opt_editor_line_number, argv[2]);

	if (!strcmp(argv[0], "mouse"))
		return parse_bool(&opt_mouse, argv[2]);

	if (!strcmp(argv[0], "mouse-scroll"))
		return parse_int(&opt_mouse_scroll, argv[2], 0, 1024);

	return ERROR_UNKNOWN_VARIABLE_NAME;
}
Esempio n. 3
0
File: tig.c Progetto: zhez/tig
static enum view_flag
toggle_option(struct view *view, enum request request, char msg[SIZEOF_STR])
{
	const struct {
		enum request request;
		const struct enum_map *map;
		enum view_flag reload_flags;
	} data[] = {
#define DEFINE_TOGGLE_DATA(id, key, help, value, map, vflags) { REQ_TOGGLE_ ## id, map, vflags  }
		TOGGLE_MENU_INFO(DEFINE_TOGGLE_DATA)
	};
	const struct menu_item menu[] = {
#define DEFINE_TOGGLE_MENU(id, key, help, value, map, vflags) { key, help, value }
		TOGGLE_MENU_INFO(DEFINE_TOGGLE_MENU)
		{ 0 }
	};
	int i = 0;

	if (request == REQ_OPTIONS) {
		if (!prompt_menu("Toggle option", menu, &i))
			return VIEW_NO_FLAGS;
	} else {
		while (i < ARRAY_SIZE(data) && data[i].request != request)
			i++;
		if (i >= ARRAY_SIZE(data))
			die("Invalid request (%d)", request);
	}

	if (data[i].map != NULL) {
		unsigned int *opt = menu[i].data;

		*opt = (*opt + 1) % data[i].map->size;
		if (data[i].map == ignore_space_map) {
			update_ignore_space_arg();
			string_format_size(msg, SIZEOF_STR,
				"Ignoring %s %s", enum_name(data[i].map->entries[*opt]), menu[i].text);

		} else if (data[i].map == commit_order_map) {
			update_commit_order_arg();
			string_format_size(msg, SIZEOF_STR,
				"Using %s %s", enum_name(data[i].map->entries[*opt]), menu[i].text);

		} else {
			string_format_size(msg, SIZEOF_STR,
				"Displaying %s %s", enum_name(data[i].map->entries[*opt]), menu[i].text);
		}

	} else if (menu[i].data == &opt_title_overflow) {
		int *option = menu[i].data;

		*option = *option ? -*option : 50;
		string_format_size(msg, SIZEOF_STR,
			"%sabling %s", *option > 0 ? "En" : "Dis", menu[i].text);

	} else {
		bool *option = menu[i].data;

		*option = !*option;
		string_format_size(msg, SIZEOF_STR,
			"%sabling %s", *option ? "En" : "Dis", menu[i].text);
	}

	return data[i].reload_flags;
}