colors-old.c 5.8 KB

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