From f12f3e0641430b9011e21e2ba7781035d545b4ed Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 1 Feb 2008 15:09:59 +0000 Subject: [PATCH] Factor out the str attribute in the ecolors array to its own array. This way ecolors can be marked const. --- src/libeinfo/libeinfo.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libeinfo/libeinfo.c b/src/libeinfo/libeinfo.c index eec7798f..15e54d60 100644 --- a/src/libeinfo/libeinfo.c +++ b/src/libeinfo/libeinfo.c @@ -122,18 +122,18 @@ struct ecolor { einfo_color_t color; int def; const char *name; - char *str; }; static char nullstr = '\0'; -static struct ecolor ecolors[] = { - { ECOLOR_GOOD, GOOD, "good", NULL }, - { ECOLOR_WARN, WARN, "warn", NULL }, - { ECOLOR_BAD, BAD, "bad", NULL }, - { ECOLOR_HILITE, HILITE, "hilite", NULL }, - { ECOLOR_BRACKET, BRACKET, "bracket", NULL }, - { ECOLOR_NORMAL, 0, NULL, NULL }, +static const struct ecolor ecolors[] = { + { ECOLOR_GOOD, GOOD, "good" }, + { ECOLOR_WARN, WARN, "warn" }, + { ECOLOR_BAD, BAD, "bad" }, + { ECOLOR_HILITE, HILITE, "hilite" }, + { ECOLOR_BRACKET, BRACKET, "bracket" }, + { ECOLOR_NORMAL, 0, NULL }, }; +static const char *ecolors_str[sizeof(ecolors)/sizeof(ecolors[0])]; static char *flush = NULL; static char *up = NULL; @@ -442,9 +442,9 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f) _GET_CAP (tmp, _me); if (tmp[0]) - _ASSIGN_CAP (ecolors[i].str) + _ASSIGN_CAP (ecolors_str[i]) else - ecolors[i].str = &nullstr; + ecolors_str[i] = &nullstr; } _GET_CAP (tmp, _ce) @@ -540,7 +540,7 @@ static const char *_ecolor (FILE * __EINFO_RESTRICT f, einfo_color_t color) for (i = 0; i < sizeof (ecolors) / sizeof (ecolors[0]); i++) { if (ecolors[i].color == color) - return (ecolors[i].str); + return (ecolors_str[i]); } return ("");