Exemplo n.º 1
0
/* Wants: name = value */
static enum status_code
option_set_command(int argc, const char *argv[])
{
	struct option_info *option;

	if (argc < 3)
		return error("Invalid set command: set option = value");

	if (strcmp(argv[1], "="))
		return error("No value assigned to %s", argv[0]);

	if (!strcmp(argv[0], "reference-format"))
		return parse_ref_formats(argv + 2);

	option = find_option_info(option_info, ARRAY_SIZE(option_info), argv[0]);
	if (option) {
		enum status_code code;

		if (option->seen)
			return SUCCESS;

		if (!strcmp(option->type, "const char **")) {
			code = check_view_config(option, argv + 2);
			if (code != SUCCESS)
				return code;
			return parse_args(option->value, argv + 2);
		}

		code = parse_option(option, "", argv[2]);
		if (code == SUCCESS && argc != 3)
			return error("Option %s only takes one value", argv[0]);

		return code;

	}

	{
		const char *obsolete[][2] = {
			{ "author-width",		"author" },
			{ "filename-width",		"file-name" },
			{ "line-number-interval",	"line-number" },
			{ "show-author",		"author" },
			{ "show-date",			"date" },
			{ "show-file-size",		"file-size" },
			{ "show-filename",		"file-name" },
			{ "show-id",			"id" },
			{ "show-line-numbers",		"line-number" },
			{ "show-refs",			"commit-title" },
			{ "show-rev-graph",		"commit-title" },
			{ "title-overflow",		"commit-title and text" },
		};
		int index = find_remapped(obsolete, ARRAY_SIZE(obsolete), argv[0]);

		if (index != -1)
			return error("%s is obsolete; see tigrc(5) for how to set the %s column option",
				     obsolete[index][0], obsolete[index][1]);

		if (!strcmp(argv[0], "read-git-colors"))
			return error("read-git-colors has been obsoleted by the git-colors option");
	}

	return error("Unknown option name: %s", argv[0]);
}
Exemplo n.º 2
0
Arquivo: options.c Projeto: bbolli/tig
/* Wants: name = value */
static enum status_code
option_set_command(int argc, const char *argv[])
{
	if (argc < 3)
		return error("Invalid set command: set option = value");

	if (strcmp(argv[1], "="))
		return error("No value assigned to %s", argv[0]);

	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 (!strcmp(argv[0], "reference-format"))
		return parse_ref_formats(argv + 2);

	if (argc != 3)
		return error("Option %s expects only one value", argv[0]);

	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)
			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"))
		return seen_diff_context_arg ? SUCCESS
			: parse_int(&opt_diff_context, argv[2], 0, 999999);

	if (!strcmp(argv[0], "ignore-space"))
		return seen_ignore_space_arg ? SUCCESS
			: parse_enum(&opt_ignore_space, argv[2], ignore_space_map);

	if (!strcmp(argv[0], "commit-order"))
		return seen_commit_order_arg ? SUCCESS
			: parse_enum(&opt_commit_order, argv[2], commit_order_map);

	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 option name: %s", argv[0]);
}