aboutsummaryrefslogtreecommitdiffstats
path: root/src/colors.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-03 12:57:30 +0200
committerMax Kellermann <max@duempel.org>2008-10-03 12:57:30 +0200
commitf81333daa0bb652a5c1296941057eef82a12e12f (patch)
treeb616f9bfc73941e0c570cbebab9949ae5b483621 /src/colors.c
parent547b0c5f28be1e830c00ac167806ffba641855c6 (diff)
downloadmpd-f81333daa0bb652a5c1296941057eef82a12e12f.tar.gz
mpd-f81333daa0bb652a5c1296941057eef82a12e12f.tar.xz
mpd-f81333daa0bb652a5c1296941057eef82a12e12f.zip
code style, indent with tabs XI
Follow the same code style als MPD itself.
Diffstat (limited to 'src/colors.c')
-rw-r--r--src/colors.c397
1 files changed, 186 insertions, 211 deletions
diff --git a/src/colors.c b/src/colors.c
index 67f3319ca..507be48ca 100644
--- a/src/colors.c
+++ b/src/colors.c
@@ -1,6 +1,4 @@
-/*
- * $Id$
- *
+/*
* (c) 2004 by Kalle Wallin <kaw@linux.se>
*
* This program is free software; you can redistribute it and/or modify
@@ -27,32 +25,32 @@
#include <string.h>
#include <glib.h>
-#define COLOR_BRIGHT_MASK (1<<7)
+#define COLOR_BRIGHT_MASK (1<<7)
-#define COLOR_BRIGHT_BLACK (COLOR_BLACK | COLOR_BRIGHT_MASK)
-#define COLOR_BRIGHT_RED (COLOR_RED | COLOR_BRIGHT_MASK)
-#define COLOR_BRIGHT_GREEN (COLOR_GREEN | COLOR_BRIGHT_MASK)
-#define COLOR_BRIGHT_YELLOW (COLOR_YELLOW | COLOR_BRIGHT_MASK)
-#define COLOR_BRIGHT_BLUE (COLOR_BLUE | COLOR_BRIGHT_MASK)
-#define COLOR_BRIGHT_MAGENTA (COLOR_MAGENTA | COLOR_BRIGHT_MASK)
-#define COLOR_BRIGHT_CYAN (COLOR_CYAN | COLOR_BRIGHT_MASK)
-#define COLOR_BRIGHT_WHITE (COLOR_WHITE | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_BLACK (COLOR_BLACK | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_RED (COLOR_RED | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_GREEN (COLOR_GREEN | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_YELLOW (COLOR_YELLOW | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_BLUE (COLOR_BLUE | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_MAGENTA (COLOR_MAGENTA | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_CYAN (COLOR_CYAN | COLOR_BRIGHT_MASK)
+#define COLOR_BRIGHT_WHITE (COLOR_WHITE | COLOR_BRIGHT_MASK)
#define IS_BRIGHT(color) (color & COLOR_BRIGHT_MASK)
/* name of the color fields */
-#define NAME_TITLE "title"
-#define NAME_TITLE_BOLD "title-bold"
-#define NAME_LINE "line"
-#define NAME_LINE_BOLD "line-flags"
-#define NAME_LIST "list"
-#define NAME_LIST_BOLD "list-bold"
-#define NAME_PROGRESS "progressbar"
-#define NAME_STATUS "status-song"
-#define NAME_STATUS_BOLD "status-state"
-#define NAME_STATUS_TIME "status-time"
-#define NAME_ALERT "alert"
-#define NAME_BGCOLOR "background"
+#define NAME_TITLE "title"
+#define NAME_TITLE_BOLD "title-bold"
+#define NAME_LINE "line"
+#define NAME_LINE_BOLD "line-flags"
+#define NAME_LIST "list"
+#define NAME_LIST_BOLD "list-bold"
+#define NAME_PROGRESS "progressbar"
+#define NAME_STATUS "status-song"
+#define NAME_STATUS_BOLD "status-state"
+#define NAME_STATUS_TIME "status-time"
+#define NAME_ALERT "alert"
+#define NAME_BGCOLOR "background"
typedef struct {
short color;
@@ -67,8 +65,7 @@ typedef struct {
} color_entry_t;
static color_entry_t colors[] = {
- /* color pair, field name, color, mono attribute */
- /*-------------------------------------------------------------------------*/
+ /* color pair, field name, color, mono attribute */
{ COLOR_TITLE, NAME_TITLE, COLOR_YELLOW, A_NORMAL },
{ COLOR_TITLE_BOLD, NAME_TITLE_BOLD, COLOR_BRIGHT_YELLOW, A_BOLD },
{ COLOR_LINE, NAME_LINE, COLOR_WHITE, A_NORMAL },
@@ -91,239 +88,217 @@ static GList *color_definition_list = NULL;
static color_entry_t *
colors_lookup(int id)
{
- int i;
-
- i=0;
- while( colors[i].name != NULL )
- {
- if( colors[i].id == id )
- return &colors[i];
- i++;
- }
- return NULL;
+ int i = 0;
+
+ while (colors[i].name != NULL) {
+ if (colors[i].id == id)
+ return &colors[i];
+ i++;
+ }
+
+ return NULL;
}
static color_entry_t *
colors_lookup_by_name(const char *name)
{
- int i;
-
- i=0;
- while( colors[i].name != NULL )
- {
- if( !strcasecmp(colors[i].name, name) )
- return &colors[i];
- i++;
- }
- return NULL;
+ int i = 0;
+
+ while (colors[i].name != NULL) {
+ if (!strcasecmp(colors[i].name, name))
+ return &colors[i];
+ i++;
+ }
+
+ return NULL;
}
static int
colors_update_pair(int id)
{
- color_entry_t *entry = colors_lookup(id);
- short fg = -1;
-
- if( !entry )
- return -1;
-
- if( IS_BRIGHT(entry->fg) )
- {
- entry->attrs = A_BOLD;
- fg = entry->fg & ~COLOR_BRIGHT_MASK;
- }
- else
- {
- entry->attrs = A_NORMAL;
- fg = entry->fg;
- }
-
- init_pair(entry->id, fg, bg);
-
- return 0;
+ color_entry_t *entry = colors_lookup(id);
+ short fg = -1;
+
+ if (!entry)
+ return -1;
+
+ if (IS_BRIGHT(entry->fg)) {
+ entry->attrs = A_BOLD;
+ fg = entry->fg & ~COLOR_BRIGHT_MASK;
+ } else {
+ entry->attrs = A_NORMAL;
+ fg = entry->fg;
+ }
+
+ init_pair(entry->id, fg, bg);
+ return 0;
}
short
colors_str2color(const char *str)
{
- if( !strcasecmp(str,"black") )
- return COLOR_BLACK;
- else if( !strcasecmp(str,"red") )
- return COLOR_RED;
- else if( !strcasecmp(str,"green") )
- return COLOR_GREEN;
- else if( !strcasecmp(str,"yellow") )
- return COLOR_YELLOW;
- else if( !strcasecmp(str,"blue") )
- return COLOR_BLUE;
- else if( !strcasecmp(str,"magenta") )
- return COLOR_MAGENTA;
- else if( !strcasecmp(str,"cyan") )
- return COLOR_CYAN;
- else if( !strcasecmp(str,"white") )
- return COLOR_WHITE;
- else if( !strcasecmp(str,"brightred") )
- return COLOR_BRIGHT_RED;
- else if( !strcasecmp(str,"brightgreen") )
- return COLOR_BRIGHT_GREEN;
- else if( !strcasecmp(str,"brightyellow") )
- return COLOR_BRIGHT_YELLOW;
- else if( !strcasecmp(str,"brightblue") )
- return COLOR_BRIGHT_BLUE;
- else if( !strcasecmp(str,"brightmagenta") )
- return COLOR_BRIGHT_MAGENTA;
- else if( !strcasecmp(str,"brightcyan") )
- return COLOR_BRIGHT_CYAN;
- else if( !strcasecmp(str,"brightwhite") )
- return COLOR_BRIGHT_WHITE;
- else if( !strcasecmp(str,"grey") || !strcasecmp(str,"gray") )
- return COLOR_BRIGHT_BLACK;
- else if( !strcasecmp(str,"none") )
- return -1;
- fprintf(stderr,_("Warning: Unknown color - %s\n"), str);
- return -2;
+ if (!strcasecmp(str, "black"))
+ return COLOR_BLACK;
+ else if (!strcasecmp(str, "red"))
+ return COLOR_RED;
+ else if (!strcasecmp(str, "green"))
+ return COLOR_GREEN;
+ else if (!strcasecmp(str, "yellow"))
+ return COLOR_YELLOW;
+ else if (!strcasecmp(str, "blue"))
+ return COLOR_BLUE;
+ else if (!strcasecmp(str, "magenta"))
+ return COLOR_MAGENTA;
+ else if (!strcasecmp(str, "cyan"))
+ return COLOR_CYAN;
+ else if (!strcasecmp(str, "white"))
+ return COLOR_WHITE;
+ else if (!strcasecmp(str, "brightred"))
+ return COLOR_BRIGHT_RED;
+ else if (!strcasecmp(str, "brightgreen"))
+ return COLOR_BRIGHT_GREEN;
+ else if (!strcasecmp(str, "brightyellow"))
+ return COLOR_BRIGHT_YELLOW;
+ else if (!strcasecmp(str, "brightblue"))
+ return COLOR_BRIGHT_BLUE;
+ else if (!strcasecmp(str, "brightmagenta"))
+ return COLOR_BRIGHT_MAGENTA;
+ else if (!strcasecmp(str, "brightcyan"))
+ return COLOR_BRIGHT_CYAN;
+ else if (!strcasecmp(str, "brightwhite"))
+ return COLOR_BRIGHT_WHITE;
+ else if (!strcasecmp(str, "grey") || !strcasecmp(str, "gray"))
+ return COLOR_BRIGHT_BLACK;
+ else if (!strcasecmp(str, "none"))
+ return -1;
+
+ fprintf(stderr,_("Warning: Unknown color - %s\n"), str);
+ return -2;
}
/* This function is called from conf.c before curses have been started,
- * it adds the definition to the color_definition_list and init_color() is
+ * it adds the definition to the color_definition_list and init_color() is
* done in colors_start() */
int
colors_define(const char *name, short r, short g, short b)
{
- color_definition_entry_t *entry;
- short color = colors_str2color(name);
+ color_definition_entry_t *entry;
+ short color = colors_str2color(name);
- if( color<0 )
- return -1;
+ if (color < 0)
+ return -1;
- entry = g_malloc(sizeof(color_definition_entry_t));
- entry->color = color;
- entry->r = r;
- entry->g = g;
- entry->b = b;
+ entry = g_malloc(sizeof(color_definition_entry_t));
+ entry->color = color;
+ entry->r = r;
+ entry->g = g;
+ entry->b = b;
- color_definition_list = g_list_append(color_definition_list, entry);
+ color_definition_list = g_list_append(color_definition_list, entry);
- return 0;
+ return 0;
}
-
int
colors_assign(const char *name, const char *value)
{
- color_entry_t *entry = colors_lookup_by_name(name);
- short color;
-
- if( !entry )
- {
- if( !strcasecmp(NAME_BGCOLOR, name) )
- {
- if( (color=colors_str2color(value)) < -1 )
- return -1;
- if( color > COLORS )
- color = color & ~COLOR_BRIGHT_MASK;
- bg = color;
- return 0;
+ color_entry_t *entry = colors_lookup_by_name(name);
+ short color;
+
+ if (!entry) {
+ if (!strcasecmp(NAME_BGCOLOR, name)) {
+ if ((color = colors_str2color(value)) < -1)
+ return -1;
+ if (color > COLORS)
+ color = color & ~COLOR_BRIGHT_MASK;
+ bg = color;
+ return 0;
+ }
+
+ fprintf(stderr,_("Warning: Unknown color field - %s\n"), name);
+ return -1;
}
- fprintf(stderr,_("Warning: Unknown color field - %s\n"), name);
- return -1;
- }
- if( (color=colors_str2color(value)) < -1 )
- return -1;
- entry->fg = color;
+ if ((color = colors_str2color(value)) < -1)
+ return -1;
- return 0;
+ entry->fg = color;
+ return 0;
}
-
int
colors_start(void)
{
- if( has_colors() )
- {
- /* initialize color support */
- start_color();
- use_default_colors();
- /* define any custom colors defined in the configuration file */
- if( color_definition_list && can_change_color() )
- {
- GList *list = color_definition_list;
-
- while( list )
- {
- color_definition_entry_t *entry = list->data;
-
- if( entry->color <= COLORS )
- init_color(entry->color, entry->r, entry->g, entry->b);
- list=list->next;
- }
+ if (has_colors()) {
+ /* initialize color support */
+ start_color();
+ use_default_colors();
+ /* define any custom colors defined in the configuration file */
+ if (color_definition_list && can_change_color()) {
+ GList *list = color_definition_list;
+
+ while (list) {
+ color_definition_entry_t *entry = list->data;
+
+ if (entry->color <= COLORS)
+ init_color(entry->color, entry->r,
+ entry->g, entry->b);
+ list = list->next;
+ }
+ } else if (color_definition_list && !can_change_color())
+ fprintf(stderr, _("Terminal lacks support for changing colors!\n"));
+
+ if (options.enable_colors) {
+ int i = 0;
+
+ while (colors[i].name) {
+ /* update the color pairs */
+ colors_update_pair(colors[i].id);
+ i++;
+ }
+ }
+ } else if (options.enable_colors) {
+ fprintf(stderr, _("Terminal lacks color capabilities!\n"));
+ options.enable_colors = 0;
}
- else if( color_definition_list && !can_change_color() )
- fprintf(stderr, _("Terminal lacks support for changing colors!\n"));
- if( options.enable_colors )
- {
- int i = 0;
+ /* free the color_definition_list */
+ if (color_definition_list) {
+ GList *list = color_definition_list;
- while(colors[i].name)
- {
- /* update the color pairs */
- colors_update_pair(colors[i].id);
- i++;
- }
+ while (list) {
+ g_free(list->data);
+ list=list->next;
+ }
+ g_list_free(color_definition_list);
+ color_definition_list = NULL;
}
- }
- else if( options.enable_colors )
- {
- fprintf(stderr, _("Terminal lacks color capabilities!\n"));
- options.enable_colors = 0;
- }
-
- /* free the color_definition_list */
- if( color_definition_list )
- {
- GList *list = color_definition_list;
-
- while( list )
- {
- g_free(list->data);
- list=list->next;
- }
- g_list_free(color_definition_list);
- color_definition_list = NULL;
- }
- return 0;
+ return 0;
}
-
int
colors_use(WINDOW *w, int id)
{
- color_entry_t *entry = colors_lookup(id);
- short pair;
- attr_t attrs;
-
- if( !entry )
- return -1;
-
- wattr_get(w, &attrs, &pair, NULL);
-
- if( options.enable_colors )
- {
- /* color mode */
- if( attrs != entry->attrs || id!=pair )
- wattr_set(w, entry->attrs, id, NULL);
- }
- else
- {
- /* mono mode */
- if( attrs != entry->attrs )
- wattrset(w, entry->attrs);
- }
-
- return 0;
-}
+ color_entry_t *entry = colors_lookup(id);
+ short pair;
+ attr_t attrs;
+ if (!entry)
+ return -1;
+
+ wattr_get(w, &attrs, &pair, NULL);
+
+ if (options.enable_colors) {
+ /* color mode */
+ if (attrs != entry->attrs || id != pair)
+ wattr_set(w, entry->attrs, id, NULL);
+ } else {
+ /* mono mode */
+ if (attrs != entry->attrs)
+ wattrset(w, entry->attrs);
+ }
+
+ return 0;
+}