[1856] in BarnOwl Developers
Re: [PATCH] Rewrite color name<->number mapping code
daemon@ATHENA.MIT.EDU (=?UTF-8?B?IkFsZWphbmRybyBSLiBTZWRl)
Thu Oct 29 18:23:17 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@lunatique.mit.edu
Date: Sat, 24 Oct 2009 14:31:51 -0400
From: =?UTF-8?B?IkFsZWphbmRybyBSLiBTZWRlw7FvIg==?= <asedeno@MIT.EDU>
To: David A Benjamin <davidben@mit.edu>
CC: Karl Ramm <kcr@1ts.org>, barnowl-dev@mit.edu
In-Reply-To: <alpine.DEB.1.10.0910241409320.5476@dr-wily.mit.edu>
David A Benjamin wrote:
> On Sat, 24 Oct 2009, Karl Ramm wrote:
>> @@ -442,15 +444,8 @@ int owl_util_string_to_color(const char *color)
>> /* Return a string name of the given owl color */
>> const char *owl_util_color_to_string(int color)
>> {
>> - if (color==OWL_COLOR_BLACK) return("black");
>> - if (color==OWL_COLOR_RED) return("red");
>> - if (color==OWL_COLOR_GREEN) return("green");
>> - if (color==OWL_COLOR_YELLOW) return("yellow");
>> - if (color==OWL_COLOR_BLUE) return("blue");
>> - if (color==OWL_COLOR_MAGENTA) return("magenta");
>> - if (color==OWL_COLOR_CYAN) return("cyan");
>> - if (color==OWL_COLOR_WHITE) return("white");
>> - if (color==OWL_COLOR_DEFAULT) return("default");
>> + if (color >= OWL_COLOR_INVALID && color <= OWL_COLOR_WHITE)
>> + return color_map[color - OWL_COLOR_INVALID].name;
>> return("Unknown color");
>> }
>
> Perhaps sizeof(color_map) / sizeof(color_map[0]) or a OWL_NUM_COLORS
> or something along those lines?
You're assuming we start at 0, but as per owl.h
…
#define OWL_COLOR_DEFAULT -1
#define OWL_COLOR_INVALID -2
…
Also, OWL_NUM_COLORS would be ambiguous, since this only refers to named
colors; there may be others. Run barnowl in a 256-color terminal for
examples.
-Alejandro