Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    r1b9d3cc r0697f09  
    407407}
    408408
    409 /* These are in order of their value in owl.h */
    410 static const struct {
    411   int number;
    412   const char *name;
    413 } color_map[] = {
    414   {OWL_COLOR_INVALID, "invalid"},
    415   {OWL_COLOR_DEFAULT, "default"},
    416   {OWL_COLOR_BLACK, "black"},
    417   {OWL_COLOR_RED, "red"},
    418   {OWL_COLOR_GREEN, "green"},
    419   {OWL_COLOR_YELLOW,"yellow"},
    420   {OWL_COLOR_BLUE, "blue"},
    421   {OWL_COLOR_MAGENTA, "magenta"},
    422   {OWL_COLOR_CYAN, "cyan"},
    423   {OWL_COLOR_WHITE, "white"},
    424 };
    425409
    426410/* Return the owl color associated with the named color.  Return -1
     
    429413int owl_util_string_to_color(const char *color)
    430414{
    431   int c, i;
    432   char *p;
    433 
    434   for (i = 0; i < (sizeof(color_map)/sizeof(color_map[0])); i++)
    435     if (strcasecmp(color, color_map[i].name) == 0)
    436       return color_map[i].number;
    437 
    438   c = strtol(color, &p, 10);
    439   if (p != color && c >= -1 && c < COLORS) {
     415  int c;
     416  if (!strcasecmp(color, "black")) {
     417    return(OWL_COLOR_BLACK);
     418  } else if (!strcasecmp(color, "red")) {
     419    return(OWL_COLOR_RED);
     420  } else if (!strcasecmp(color, "green")) {
     421    return(OWL_COLOR_GREEN);
     422  } else if (!strcasecmp(color, "yellow")) {
     423    return(OWL_COLOR_YELLOW);
     424  } else if (!strcasecmp(color, "blue")) {
     425    return(OWL_COLOR_BLUE);
     426  } else if (!strcasecmp(color, "magenta")) {
     427    return(OWL_COLOR_MAGENTA);
     428  } else if (!strcasecmp(color, "cyan")) {
     429    return(OWL_COLOR_CYAN);
     430  } else if (!strcasecmp(color, "white")) {
     431    return(OWL_COLOR_WHITE);
     432  } else if (!strcasecmp(color, "default")) {
     433    return(OWL_COLOR_DEFAULT);
     434  }
     435  c = atoi(color);
     436  if (c >= -1 && c < COLORS) {
    440437    return(c);
    441438  }
     
    446443const char *owl_util_color_to_string(int color)
    447444{
    448   if (color >= OWL_COLOR_INVALID && color <= OWL_COLOR_WHITE)
    449     return color_map[color - OWL_COLOR_INVALID].name;
     445  if (color==OWL_COLOR_BLACK)   return("black");
     446  if (color==OWL_COLOR_RED)     return("red");
     447  if (color==OWL_COLOR_GREEN)   return("green");
     448  if (color==OWL_COLOR_YELLOW)  return("yellow");
     449  if (color==OWL_COLOR_BLUE)    return("blue");
     450  if (color==OWL_COLOR_MAGENTA) return("magenta");
     451  if (color==OWL_COLOR_CYAN)    return("cyan");
     452  if (color==OWL_COLOR_WHITE)   return("white");
     453  if (color==OWL_COLOR_DEFAULT) return("default");
    450454  return("Unknown color");
    451455}
Note: See TracChangeset for help on using the changeset viewer.