colors-old.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. Skins engine.
  3. Work with colors - backward compability
  4. Copyright (C) 2009, 2010 The Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2009
  7. Egmont Koblinger <egmont@gmail.com>, 2010
  8. This file is part of the Midnight Commander.
  9. The Midnight Commander is free software; you can redistribute it
  10. and/or modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation; either version 2 of the
  12. License, or (at your option) any later version.
  13. The Midnight Commander is distributed in the hope that it will be
  14. useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. MA 02110-1301, USA.
  21. */
  22. #include <config.h>
  23. #include <stdlib.h>
  24. #include <sys/types.h> /* size_t */
  25. #include "internal.h"
  26. #include "lib/tty/color.h"
  27. #include "src/setup.h"
  28. /*** global variables ****************************************************************************/
  29. /*** file scope macro definitions ****************************************************************/
  30. /*** file scope type declarations ****************************************************************/
  31. typedef struct mc_skin_colors_old_struct
  32. {
  33. const char *old_color;
  34. const char *group;
  35. const char *key;
  36. } mc_skin_colors_old_t;
  37. /*** file scope variables ************************************************************************/
  38. static const mc_skin_colors_old_t old_colors[] = {
  39. {"normal", "core", "_default_"},
  40. {"marked", "core", "marked"},
  41. {"selected", "core", "selected"},
  42. {"markselect", "core", "markselect"},
  43. {"disabled", "core", "disabled"},
  44. {"reverse", "core", "reverse"},
  45. {"dnormal", "dialog", "_default_"},
  46. {"dfocus", "dialog", "dfocus"},
  47. {"dhotnormal", "dialog", "dhotnormal"},
  48. {"dhotfocus", "dialog", "dhotfocus"},
  49. {"errors", "error", "_default_"},
  50. {"errdhotnormal", "error", "errdhotnormal"},
  51. {"errdhotfocus", "error", "errdhotfocus"},
  52. {"menunormal", "menu", "_default_"},
  53. {"menuhot", "menu", "menuhot"},
  54. {"menusel", "menu", "menusel"},
  55. {"menuhotsel", "menu", "menuhotsel"},
  56. {"menuinactive", "menu", "menuinactive"},
  57. {"pmenunormal", "popupmenu", "_default_"},
  58. {"pmenusel", "popupmenu", "menusel"},
  59. {"pmenutitle", "popupmenu", "menutitle"},
  60. {"bbarhotkey", "buttonbar", "hotkey"},
  61. {"bbarbutton", "buttonbar", "button"},
  62. {"statusbar", "statusbar", "_default_"},
  63. {"gauge", "core", "gauge"},
  64. {"input", "core", "input"},
  65. {"inputmark", "core", "inputmark"},
  66. {"inputunchanged", "core", "inputunchanged"},
  67. {"commandlinemark", "core", "commandlinemark"},
  68. {"helpnormal", "help", "_default_"},
  69. {"helpitalic", "help", "helpitalic"},
  70. {"helpbold", "help", "helpbold"},
  71. {"helplink", "help", "helplink"},
  72. {"helpslink", "help", "helpslink"},
  73. {"viewunderline", "viewer", "viewunderline"},
  74. {"editnormal", "editor", "_default_"},
  75. {"editbold", "editor", "editbold"},
  76. {"editmarked", "editor", "editmarked"},
  77. {"editwhitespace", "editor", "editwhitespace"},
  78. {"editlinestate", "editor", "editlinestate"},
  79. {NULL, NULL, NULL}
  80. };
  81. /*** file scope functions ************************************************************************/
  82. /* --------------------------------------------------------------------------------------------- */
  83. static gboolean
  84. mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
  85. {
  86. int lc_index;
  87. if (old_color != NULL)
  88. for (lc_index = 0; old_colors[lc_index].old_color; lc_index++)
  89. if (strcasecmp (old_color, old_colors[lc_index].old_color) == 0)
  90. {
  91. if (group != NULL)
  92. *group = old_colors[lc_index].group;
  93. if (key != NULL)
  94. *key = old_colors[lc_index].key;
  95. return TRUE;
  96. }
  97. return FALSE;
  98. }
  99. /* --------------------------------------------------------------------------------------------- */
  100. static void
  101. mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_string)
  102. {
  103. gchar **colors, **orig_colors;
  104. gchar **key_val;
  105. const gchar *skin_group, *skin_key;
  106. gchar *skin_val;
  107. if (the_color_string == NULL)
  108. return;
  109. orig_colors = colors = g_strsplit (the_color_string, ":", -1);
  110. if (colors == NULL)
  111. return;
  112. for (; *colors; colors++)
  113. {
  114. key_val = g_strsplit_set (*colors, "=,", 4);
  115. if (!key_val)
  116. continue;
  117. if (key_val[1] == NULL
  118. || !mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
  119. {
  120. g_strfreev (key_val);
  121. continue;
  122. }
  123. if (key_val[3] != NULL)
  124. skin_val = g_strdup_printf ("%s;%s;%s", key_val[1], key_val[2], key_val[3]);
  125. else if (key_val[2] != NULL)
  126. skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
  127. else
  128. skin_val = g_strdup_printf ("%s;", key_val[1]);
  129. mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
  130. g_free (skin_val);
  131. g_strfreev (key_val);
  132. }
  133. g_strfreev (orig_colors);
  134. }
  135. /* --------------------------------------------------------------------------------------------- */
  136. /*** public functions ****************************************************************************/
  137. /* --------------------------------------------------------------------------------------------- */
  138. void
  139. mc_skin_colors_old_configure (mc_skin_t * mc_skin)
  140. {
  141. mc_skin_colors_old_configure_one (mc_skin, setup_color_string);
  142. mc_skin_colors_old_configure_one (mc_skin, term_color_string);
  143. mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
  144. mc_skin_colors_old_configure_one (mc_skin, command_line_colors);
  145. }
  146. /* --------------------------------------------------------------------------------------------- */