root/lib/skin/colors-old.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. old_color_comparator
  2. mc_skin_colors_old_transform
  3. mc_skin_colors_old_configure_one
  4. mc_skin_colors_old_configure

   1 /*
   2    Skins engine.
   3    Work with colors - backward compatibility
   4 
   5    Copyright (C) 2009-2024
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Slava Zanko <slavazanko@gmail.com>, 2009
  10    Egmont Koblinger <egmont@gmail.com>, 2010
  11    Andrew Borodin <aborodin@vmail.ru>, 2012
  12 
  13    This file is part of the Midnight Commander.
  14 
  15    The Midnight Commander is free software: you can redistribute it
  16    and/or modify it under the terms of the GNU General Public License as
  17    published by the Free Software Foundation, either version 3 of the License,
  18    or (at your option) any later version.
  19 
  20    The Midnight Commander is distributed in the hope that it will be useful,
  21    but WITHOUT ANY WARRANTY; without even the implied warranty of
  22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23    GNU General Public License for more details.
  24 
  25    You should have received a copy of the GNU General Public License
  26    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  27  */
  28 
  29 #include <config.h>
  30 #include <stdlib.h>
  31 #include <string.h>             /* strcmp() */
  32 #include <sys/types.h>          /* size_t */
  33 
  34 #include "internal.h"
  35 
  36 #include "lib/tty/color.h"
  37 
  38 /*** global variables ****************************************************************************/
  39 
  40 /*** file scope macro definitions ****************************************************************/
  41 
  42 /*** forward declarations (file scope functions) *************************************************/
  43 
  44 /*** file scope type declarations ****************************************************************/
  45 
  46 typedef struct mc_skin_colors_old_struct
  47 {
  48     const char *old_color;
  49     const char *group;
  50     const char *key;
  51 } mc_skin_colors_old_t;
  52 
  53 /*** file scope variables ************************************************************************/
  54 
  55 /* keep this table alphabetically sorted */
  56 static const mc_skin_colors_old_t old_colors[] = {
  57     {"bbarbutton", "buttonbar", "button"},
  58     {"bbarhotkey", "buttonbar", "hotkey"},
  59     {"commandlinemark", "core", "commandlinemark"},
  60     {"dfocus", "dialog", "dfocus"},
  61     {"dhotfocus", "dialog", "dhotfocus"},
  62     {"dhotnormal", "dialog", "dhotnormal"},
  63     {"disabled", "core", "disabled"},
  64     {"dnormal", "dialog", "_default_"},
  65     {"editbg", "editor", "editbg"},
  66     {"editbold", "editor", "editbold"},
  67     {"editframe", "editor", "editframe"},
  68     {"editframeactive", "editor", "editframeactive"},
  69     {"editframedrag", "editor", "editframedrag"},
  70     {"editlinestate", "editor", "editlinestate"},
  71     {"editmarked", "editor", "editmarked"},
  72     {"editnonprintable", "editor", "editnonprintable"},
  73     {"editnormal", "editor", "_default_"},
  74     {"editwhitespace", "editor", "editwhitespace"},
  75     {"errdhotfocus", "error", "errdhotfocus"},
  76     {"errdhotnormal", "error", "errdhotnormal"},
  77     {"errors", "error", "_default_"},
  78     {"gauge", "core", "gauge"},
  79     {"header", "core", "header"},
  80     {"helpbold", "help", "helpbold"},
  81     {"helpitalic", "help", "helpitalic"},
  82     {"helplink", "help", "helplink"},
  83     {"helpnormal", "help", "_default_"},
  84     {"helpslink", "help", "helpslink"},
  85     {"input", "core", "input"},
  86     {"inputmark", "core", "inputmark"},
  87     {"inputunchanged", "core", "inputunchanged"},
  88     {"marked", "core", "marked"},
  89     {"markselect", "core", "markselect"},
  90     {"menuhot", "menu", "menuhot"},
  91     {"menuhotsel", "menu", "menuhotsel"},
  92     {"menuinactive", "menu", "menuinactive"},
  93     {"menunormal", "menu", "_default_"},
  94     {"menusel", "menu", "menusel"},
  95     {"normal", "core", "_default_"},
  96     {"pmenunormal", "popupmenu", "_default_"},
  97     {"pmenusel", "popupmenu", "menusel"},
  98     {"pmenutitle", "popupmenu", "menutitle"},
  99     {"reverse", "core", "reverse"},
 100     {"selected", "core", "selected"},
 101     {"statusbar", "statusbar", "_default_"},
 102     {"viewbold", "viewer", "viewbold"},
 103     {"viewnormal", "viewer", "_default_"},
 104     {"viewselected", "viewer", "viewselected"},
 105     {"viewunderline", "viewer", "viewunderline"}
 106 };
 107 
 108 static const size_t num_old_colors = G_N_ELEMENTS (old_colors);
 109 
 110 /* --------------------------------------------------------------------------------------------- */
 111 /*** file scope functions ************************************************************************/
 112 /* --------------------------------------------------------------------------------------------- */
 113 
 114 static int
 115 old_color_comparator (const void *p1, const void *p2)
     /* [previous][next][first][last][top][bottom][index][help]  */
 116 {
 117     const mc_skin_colors_old_t *m1 = (const mc_skin_colors_old_t *) p1;
 118     const mc_skin_colors_old_t *m2 = (const mc_skin_colors_old_t *) p2;
 119 
 120     return strcmp (m1->old_color, m2->old_color);
 121 }
 122 
 123 /* --------------------------------------------------------------------------------------------- */
 124 
 125 static gboolean
 126 mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
     /* [previous][next][first][last][top][bottom][index][help]  */
 127 {
 128     const mc_skin_colors_old_t oc = { old_color, NULL, NULL };
 129     mc_skin_colors_old_t *res;
 130 
 131     if (old_color == NULL)
 132         return FALSE;
 133 
 134     res = (mc_skin_colors_old_t *) bsearch (&oc, old_colors, num_old_colors,
 135                                             sizeof (old_colors[0]), old_color_comparator);
 136 
 137     if (res == NULL)
 138         return FALSE;
 139 
 140     if (group != NULL)
 141         *group = res->group;
 142     if (key != NULL)
 143         *key = res->key;
 144     return TRUE;
 145 }
 146 
 147 /* --------------------------------------------------------------------------------------------- */
 148 
 149 static void
 150 mc_skin_colors_old_configure_one (mc_skin_t *mc_skin, const char *the_color_string)
     /* [previous][next][first][last][top][bottom][index][help]  */
 151 {
 152     gchar **colors, **orig_colors;
 153 
 154     if (the_color_string == NULL)
 155         return;
 156 
 157     orig_colors = g_strsplit (the_color_string, ":", -1);
 158     if (orig_colors == NULL)
 159         return;
 160 
 161     for (colors = orig_colors; *colors != NULL; colors++)
 162     {
 163         gchar **key_val;
 164         const gchar *skin_group, *skin_key;
 165 
 166         key_val = g_strsplit_set (*colors, "=,", 4);
 167 
 168         if (key_val == NULL)
 169             continue;
 170 
 171         if (key_val[1] != NULL && mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
 172         {
 173             gchar *skin_val;
 174 
 175             if (key_val[2] == NULL)
 176                 skin_val = g_strdup_printf ("%s;", key_val[1]);
 177             else if (key_val[3] == NULL)
 178                 skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
 179             else
 180                 skin_val = g_strdup_printf ("%s;%s;%s", key_val[1], key_val[2], key_val[3]);
 181 
 182             mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
 183             g_free (skin_val);
 184         }
 185 
 186         g_strfreev (key_val);
 187     }
 188     g_strfreev (orig_colors);
 189 }
 190 
 191 /* --------------------------------------------------------------------------------------------- */
 192 /*** public functions ****************************************************************************/
 193 /* --------------------------------------------------------------------------------------------- */
 194 
 195 void
 196 mc_skin_colors_old_configure (mc_skin_t *mc_skin)
     /* [previous][next][first][last][top][bottom][index][help]  */
 197 {
 198     mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.setup_color_string);
 199     mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.term_color_string);
 200     mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
 201     mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.command_line_colors);
 202 }
 203 
 204 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */