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; }
static void set_git_color_option(const char *name, char *value) { static const struct enum_map_entry color_option_map[] = { ENUM_MAP_ENTRY("branch.current", LINE_MAIN_HEAD), ENUM_MAP_ENTRY("branch.local", LINE_MAIN_REF), ENUM_MAP_ENTRY("branch.plain", LINE_MAIN_REF), ENUM_MAP_ENTRY("branch.remote", LINE_MAIN_REMOTE), ENUM_MAP_ENTRY("diff.meta", LINE_DIFF_HEADER), ENUM_MAP_ENTRY("diff.meta", LINE_DIFF_INDEX), ENUM_MAP_ENTRY("diff.meta", LINE_DIFF_OLDMODE), ENUM_MAP_ENTRY("diff.meta", LINE_DIFF_NEWMODE), ENUM_MAP_ENTRY("diff.frag", LINE_DIFF_CHUNK), ENUM_MAP_ENTRY("diff.old", LINE_DIFF_DEL), ENUM_MAP_ENTRY("diff.new", LINE_DIFF_ADD), //ENUM_MAP_ENTRY("diff.commit", LINE_DIFF_ADD), ENUM_MAP_ENTRY("status.branch", LINE_STAT_HEAD), //ENUM_MAP_ENTRY("status.nobranch", LINE_STAT_HEAD), ENUM_MAP_ENTRY("status.added", LINE_STAT_STAGED), ENUM_MAP_ENTRY("status.updated", LINE_STAT_STAGED), ENUM_MAP_ENTRY("status.changed", LINE_STAT_UNSTAGED), ENUM_MAP_ENTRY("status.untracked", LINE_STAT_UNTRACKED), }; int type = LINE_NONE; if (opt_read_git_colors && map_enum(&type, color_option_map, name)) { parse_git_color_option(type, value); } }
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; mark_option_seen(&opt_commit_order); continue; } if (map_enum(&value, ignore_space_arg_map, flag)) { opt_ignore_space = value; mark_option_seen(&opt_ignore_space); continue; } if (!strcmp(flag, "--no-notes")) { opt_show_notes = FALSE; mark_option_seen(&opt_show_notes); continue; } if (!prefixcmp(flag, "--show-notes") || !prefixcmp(flag, "--notes")) { opt_show_notes = TRUE; string_ncopy(opt_notes_arg, flag, strlen(flag)); mark_option_seen(&opt_show_notes); continue; } if (!prefixcmp(flag, "-U") && parse_int(&value, flag + 2, 0, 999999) == SUCCESS) { opt_diff_context = value; mark_option_seen(&opt_diff_context); continue; } argv[flags_pos++] = flag; } argv[flags_pos] = NULL; }
static bool set_color(int *color, const char *name) { if (map_enum(color, color_map, name)) return TRUE; if (!prefixcmp(name, "color")) return parse_int(color, name + 5, 0, 255) == SUCCESS; /* Used when reading git colors. Git expects a plain int w/o prefix. */ return parse_int(color, name, 0, 255) == SUCCESS; }
static bool set_color(int *color, const char *name) { if (map_enum(color, color_map, name)) return TRUE; /* Git expects a plain int w/o prefix, however, color<int> is * the preferred Tig color notation. */ if (!prefixcmp(name, "color")) name += 5; return string_isnumber(name) && parse_int(color, name, 0, 255) == SUCCESS; }
/* Wants: object fgcolor bgcolor [attribute] */ static enum status_code option_color_command(int argc, const char *argv[]) { struct line_rule rule = {}; const char *prefix = NULL; struct line_info *info; enum status_code code; if (argc < 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; code = parse_color_name(argv[0], &rule, &prefix); if (code != SUCCESS) return code; info = add_line_rule(prefix, &rule); if (!info) { static const struct enum_map_entry obsolete[] = { ENUM_MAP_ENTRY("main-delim", LINE_DELIMITER), ENUM_MAP_ENTRY("main-date", LINE_DATE), ENUM_MAP_ENTRY("main-author", LINE_AUTHOR), ENUM_MAP_ENTRY("blame-id", LINE_ID), }; int index; if (!map_enum(&index, obsolete, argv[0])) return ERROR_UNKNOWN_COLOR_NAME; info = get_line_info(NULL, index); } if (!set_color(&info->fg, argv[1]) || !set_color(&info->bg, argv[2])) return ERROR_UNKNOWN_COLOR; info->attr = 0; while (argc-- > 3) { int attr; if (!set_attribute(&attr, argv[argc])) return ERROR_UNKNOWN_ATTRIBUTE; info->attr |= attr; } return SUCCESS; }
/* Wants: object fgcolor bgcolor [attribute] */ static enum status_code option_color_command(int argc, const char *argv[]) { struct line_info *info; if (argc < 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; if (*argv[0] == '"' || *argv[0] == '\'') { info = add_custom_color(argv[0]); } else { info = find_line_info(argv[0], strlen(argv[0]), FALSE); } if (!info) { static const struct enum_map_entry obsolete[] = { ENUM_MAP_ENTRY("main-delim", LINE_DELIMITER), ENUM_MAP_ENTRY("main-date", LINE_DATE), ENUM_MAP_ENTRY("main-author", LINE_AUTHOR), ENUM_MAP_ENTRY("blame-id", LINE_ID), }; int index; if (!map_enum(&index, obsolete, argv[0])) return ERROR_UNKNOWN_COLOR_NAME; info = get_line_info(index); } if (!set_color(&info->fg, argv[1]) || !set_color(&info->bg, argv[2])) return ERROR_UNKNOWN_COLOR; info->attr = 0; while (argc-- > 3) { int attr; if (!set_attribute(&attr, argv[argc])) return ERROR_UNKNOWN_ATTRIBUTE; info->attr |= attr; } return SUCCESS; }
/* Wants: mode request key */ static enum status_code option_bind_command(int argc, const char *argv[]) { enum request request; struct keymap *keymap; int key; if (argc < 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; if (!(keymap = get_keymap(argv[0]))) return ERROR_UNKNOWN_KEY_MAP; key = get_key_value(argv[1]); if (key == ERR) return ERROR_UNKNOWN_KEY; request = get_request(argv[2]); if (request == REQ_UNKNOWN) { static const struct enum_map_entry obsolete[] = { ENUM_MAP_ENTRY("cherry-pick", REQ_NONE), ENUM_MAP_ENTRY("screen-resize", REQ_NONE), ENUM_MAP_ENTRY("tree-parent", REQ_PARENT), }; int alias; if (map_enum(&alias, obsolete, argv[2])) { if (alias != REQ_NONE) add_keybinding(keymap, alias, key); return ERROR_OBSOLETE_REQUEST_NAME; } } if (request == REQ_UNKNOWN) { enum run_request_flag flags = RUN_REQUEST_FORCE; if (strchr("!?@<", *argv[2])) { while (*argv[2]) { if (*argv[2] == '@') { flags |= RUN_REQUEST_SILENT; } else if (*argv[2] == '?') { flags |= RUN_REQUEST_CONFIRM; } else if (*argv[2] == '<') { flags |= RUN_REQUEST_EXIT; } else if (*argv[2] != '!') { break; } argv[2]++; } } else if (*argv[2] == ':') { argv[2]++; flags |= RUN_REQUEST_INTERNAL; } else { return ERROR_UNKNOWN_REQUEST_NAME; } return add_run_request(keymap, key, argv + 2, flags) ? SUCCESS : ERROR_OUT_OF_MEMORY; } add_keybinding(keymap, request, key); return SUCCESS; }