static int parse_color_pair(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err) { if (! MoreArgs (s)) { strfcpy (err->data, _("color: too few arguments"), err->dsize); return (-1); } mutt_extract_token (buf, s, 0); if (parse_color_name (buf->data, fg, attr, A_BOLD, err) != 0) return (-1); if (! MoreArgs (s)) { strfcpy (err->data, _("color: too few arguments"), err->dsize); return (-1); } mutt_extract_token (buf, s, 0); if (parse_color_name (buf->data, bg, attr, A_BLINK, err) != 0) return (-1); return 0; }
int grub_parse_color_name_pair (grub_uint8_t *color, const char *name) { int result = 1; grub_uint8_t fg, bg; char *fg_name, *bg_name; /* nothing specified by user */ if (name == NULL) return result; fg_name = grub_strdup (name); if (fg_name == NULL) { /* "out of memory" message was printed by grub_strdup() */ grub_wait_after_message (); return result; } bg_name = grub_strchr (fg_name, '/'); if (bg_name == NULL) { grub_printf_ (N_("Warning: syntax error (missing slash) in `%s'\n"), fg_name); grub_wait_after_message (); goto free_and_return; } *(bg_name++) = '\0'; if (parse_color_name (&fg, fg_name) == -1) { grub_printf_ (N_("Warning: invalid foreground color `%s'\n"), fg_name); grub_wait_after_message (); goto free_and_return; } if (parse_color_name (&bg, bg_name) == -1) { grub_printf_ (N_("Warning: invalid background color `%s'\n"), bg_name); grub_wait_after_message (); goto free_and_return; } *color = (bg << 4) | fg; result = 0; free_and_return: grub_free (fg_name); return result; }
/* 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; }
void parse_color_zones(const char *s) { bool fullpage = false; int zones = 0; g().colorzones.empty(); g().colorpalette = ByteStream::create(); // zones while (s[0] == '#') { char rgb[3]; GRect rect; s = parse_color_name(s+1, rgb); if (s[0] == ':') { int c[4]; for (int i=0; i<4; i++) { char *e = 0; c[i] = strtol(s+1, &e, 10); if (e <= s || (i>=2 && c[i]<0) || (i<3 && e[0]!=',')) G_THROW("Invalid coordinates in FGbz chunk specification"); s = e; } rect = GRect(c[0],c[1],c[2],c[3]); } if (rect.isempty()) fullpage = true; g().colorpalette->writall(rgb, 3); g().colorzones.touch(zones); g().colorzones[zones] = rect; zones++; } if (s[0]) G_THROW("Syntax error in FGbz chunk specification"); // add extra black palette entry if (! fullpage) { char rgb[3] = {0,0,0}; g().colorpalette->writall(rgb, 3); } }
static void set_git_color_option(const char *name, char *value) { struct line_info parsed = {}; struct line_info *color = NULL; size_t namelen = strlen(name); int i; if (!opt_git_colors) return; for (i = 0; opt_git_colors[i]; i++) { struct line_rule rule = {}; const char *prefix = NULL; struct line_info *info; const char *alias = opt_git_colors[i]; const char *sep = strchr(alias, '='); if (!sep || namelen != sep - alias || string_enum_compare(name, alias, namelen)) continue; if (!color) { color = parse_git_color_option(&parsed, value); if (!color) return; } if (parse_color_name(sep + 1, &rule, &prefix) == SUCCESS && (info = add_line_rule(prefix, &rule))) { info->fg = parsed.fg; info->bg = parsed.bg; info->attr = parsed.attr; } } }
/* * Parse the sub-options of text color specification * { def$ault | lt <linetype> | pal$ette { cb <val> | frac$tion <val> | z } * The ordering of alternatives shown in the line above is kept in the symbol definitions * TC_DEFAULT TC_LT TC_LINESTYLE TC_RGB TC_CB TC_FRAC TC_Z TC_VARIABLE (0 1 2 3 4 5 6 7) * and the "options" parameter to parse_colorspec limits legal input to the * corresponding point in the series. So TC_LT allows only default or linetype * coloring, while TC_Z allows all coloring options up to and including pal z */ void parse_colorspec(struct t_colorspec *tc, int options) { c_token++; if (END_OF_COMMAND) int_error(c_token, "expected colorspec"); if (almost_equals(c_token,"def$ault")) { c_token++; tc->type = TC_DEFAULT; } else if (equals(c_token,"bgnd")) { c_token++; tc->type = TC_LT; tc->lt = LT_BACKGROUND; } else if (equals(c_token,"lt")) { c_token++; if (END_OF_COMMAND) int_error(c_token, "expected linetype"); tc->type = TC_LT; tc->lt = int_expression()-1; if (tc->lt < LT_BACKGROUND) { tc->type = TC_DEFAULT; int_warn(c_token,"illegal linetype"); } } else if (options <= TC_LT) { tc->type = TC_DEFAULT; int_error(c_token, "only tc lt <n> possible here"); } else if (equals(c_token,"ls") || almost_equals(c_token,"lines$tyle")) { c_token++; tc->type = TC_LINESTYLE; tc->lt = real_expression(); } else if (almost_equals(c_token,"rgb$color")) { c_token++; tc->type = TC_RGB; if (almost_equals(c_token, "var$iable")) { tc->value = -1.0; c_token++; } else { tc->value = 0.0; tc->lt = parse_color_name(); } } else if (almost_equals(c_token,"pal$ette")) { c_token++; if (equals(c_token,"z")) { /* The actual z value is not yet known, fill it in later */ if (options >= TC_Z) { tc->type = TC_Z; } else { tc->type = TC_DEFAULT; int_error(c_token, "palette z not possible here"); } c_token++; } else if (equals(c_token,"cb")) { tc->type = TC_CB; c_token++; if (END_OF_COMMAND) int_error(c_token, "expected cb value"); tc->value = real_expression(); } else if (almost_equals(c_token,"frac$tion")) { tc->type = TC_FRAC; c_token++; if (END_OF_COMMAND) int_error(c_token, "expected palette fraction"); tc->value = real_expression(); if (tc->value < 0. || tc->value > 1.0) int_error(c_token, "palette fraction out of range"); } else { /* END_OF_COMMAND or palette <blank> */ if (options >= TC_Z) tc->type = TC_Z; } } else if (options >= TC_VARIABLE && almost_equals(c_token,"var$iable")) { tc->type = TC_VARIABLE; c_token++; } else { int_error(c_token, "colorspec option not recognized"); } }
/* 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("Invalid color mapping: color area fgcolor bgcolor [attrs]"); code = parse_color_name(argv[0], &rule, &prefix); if (code != SUCCESS) return code; info = add_line_rule(prefix, &rule); if (!info) { static const char *obsolete[][2] = { { "acked", "' Acked-by'" }, { "diff-copy-from", "'copy from '" }, { "diff-copy-to", "'copy to '" }, { "diff-deleted-file-mode", "'deleted file mode '" }, { "diff-dissimilarity", "'dissimilarity '" }, { "diff-rename-from", "'rename from '" }, { "diff-rename-to", "'rename to '" }, { "diff-tree", "'diff-tree '" }, { "filename", "file" }, { "help-keymap", "help.section" }, { "main-revgraph", "" }, { "pp-adate", "'AuthorDate: '" }, { "pp-author", "'Author: '" }, { "pp-cdate", "'CommitDate: '" }, { "pp-commit", "'Commit: '" }, { "pp-date", "'Date: '" }, { "reviewed", "' Reviewed-by'" }, { "signoff", "' Signed-off-by'" }, { "stat-head", "status.header" }, { "stat-section", "status.section" }, { "tested", "' Tested-by'" }, { "tree-dir", "tree.directory" }, { "tree-file", "tree.file" }, { "tree-head", "tree.header" }, }; int index; index = find_remapped(obsolete, ARRAY_SIZE(obsolete), rule.name); if (index != -1) { if (!*obsolete[index][1]) return error("%s is obsolete", argv[0]); /* Keep the initial prefix if defined. */ code = parse_color_name(obsolete[index][1], &rule, prefix ? NULL : &prefix); if (code != SUCCESS) return code; info = add_line_rule(prefix, &rule); } if (!info) return error("Unknown color name: %s", argv[0]); code = error("%s has been replaced by %s", obsolete[index][0], obsolete[index][1]); } if (!set_color(&info->fg, argv[1])) return error("Unknown color: %s", argv[1]); if (!set_color(&info->bg, argv[2])) return error("Unknown color: %s", argv[2]); info->attr = 0; while (argc-- > 3) { int attr; if (!set_attribute(&attr, argv[argc])) return error("Unknown color attribute: %s", argv[argc]); info->attr |= attr; } return code; }
/* * Parse the sub-options of text color specification * { def$ault | lt <linetype> | pal$ette { cb <val> | frac$tion <val> | z } * The ordering of alternatives shown in the line above is kept in the symbol definitions * TC_DEFAULT TC_LT TC_LINESTYLE TC_RGB TC_CB TC_FRAC TC_Z TC_VARIABLE (0 1 2 3 4 5 6 7) * and the "options" parameter to parse_colorspec limits legal input to the * corresponding point in the series. So TC_LT allows only default or linetype * coloring, while TC_Z allows all coloring options up to and including pal z */ void parse_colorspec(struct t_colorspec *tc, int options) { c_token++; if (END_OF_COMMAND) int_error(c_token, "expected colorspec"); if (almost_equals(c_token,"def$ault")) { c_token++; tc->type = TC_DEFAULT; } else if (equals(c_token,"bgnd")) { c_token++; tc->type = TC_LT; tc->lt = LT_BACKGROUND; } else if (equals(c_token,"black")) { c_token++; tc->type = TC_LT; tc->lt = LT_BLACK; } else if (equals(c_token,"lt")) { struct lp_style_type lptemp; c_token++; if (END_OF_COMMAND) int_error(c_token, "expected linetype"); tc->type = TC_LT; tc->lt = int_expression()-1; if (tc->lt < LT_BACKGROUND) { tc->type = TC_DEFAULT; int_warn(c_token,"illegal linetype"); } /* * July 2014 - translate linetype into user-defined linetype color. * This is a CHANGE! * FIXME: calling load_linetype here may obviate the need to call it * many places in the higher level code. They could be removed. */ load_linetype(&lptemp, tc->lt + 1); *tc = lptemp.pm3d_color; } else if (options <= TC_LT) { tc->type = TC_DEFAULT; int_error(c_token, "only tc lt <n> possible here"); } else if (equals(c_token,"ls") || almost_equals(c_token,"lines$tyle")) { c_token++; tc->type = TC_LINESTYLE; tc->lt = real_expression(); } else if (almost_equals(c_token,"rgb$color")) { c_token++; tc->type = TC_RGB; if (almost_equals(c_token, "var$iable")) { tc->value = -1.0; c_token++; } else { tc->value = 0.0; tc->lt = parse_color_name(); } } else if (almost_equals(c_token,"pal$ette")) { c_token++; if (equals(c_token,"z")) { /* The actual z value is not yet known, fill it in later */ if (options >= TC_Z) { tc->type = TC_Z; } else { tc->type = TC_DEFAULT; int_error(c_token, "palette z not possible here"); } c_token++; } else if (equals(c_token,"cb")) { tc->type = TC_CB; c_token++; if (END_OF_COMMAND) int_error(c_token, "expected cb value"); tc->value = real_expression(); } else if (almost_equals(c_token,"frac$tion")) { tc->type = TC_FRAC; c_token++; if (END_OF_COMMAND) int_error(c_token, "expected palette fraction"); tc->value = real_expression(); if (tc->value < 0. || tc->value > 1.0) int_error(c_token, "palette fraction out of range"); } else { /* END_OF_COMMAND or palette <blank> */ if (options >= TC_Z) tc->type = TC_Z; } } else if (options >= TC_VARIABLE && almost_equals(c_token,"var$iable")) { tc->type = TC_VARIABLE; c_token++; /* New: allow to skip the rgb keyword, as in 'plot $foo lc "blue"' */ } else if (isstring(c_token)) { tc->type = TC_RGB; tc->lt = parse_color_name(); } else { int_error(c_token, "colorspec option not recognized"); } }