colors-old.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 "lib/tty/color.h"
  25. #include "internal.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. {"reverse", "core", "reverse"},
  43. {"dnormal", "dialog", "_default_"},
  44. {"dfocus", "dialog", "dfocus"},
  45. {"dhotnormal", "dialog", "dhotnormal"},
  46. {"dhotfocus", "dialog", "dhotfocus"},
  47. {"errors", "error", "_default_"},
  48. {"errdhotnormal", "error", "errdhotnormal"},
  49. {"errdhotfocus", "error", "errdhotfocus"},
  50. {"menunormal", "menu", "_default_"},
  51. {"menuhot", "menu", "menuhot"},
  52. {"menusel", "menu", "menusel"},
  53. {"menuhotsel", "menu", "menuhotsel"},
  54. {"menuinactive", "menu", "menuinactive"},
  55. {"gauge", "core", "gauge"},
  56. {"input", "core", "input"},
  57. {"helpnormal", "help", "_default_"},
  58. {"helpitalic", "help", "helpitalic"},
  59. {"helpbold", "help", "helpbold"},
  60. {"helplink", "help", "helplink"},
  61. {"helpslink", "help", "helpslink"},
  62. {"viewunderline", "viewer", "viewunderline"},
  63. {"editnormal", "editor", "_default_"},
  64. {"editbold", "editor", "editbold"},
  65. {"editmarked", "editor", "editmarked"},
  66. {"editwhitespace", "editor", "editwhitespace"},
  67. {"editlinestate", "editor", "editlinestate"},
  68. {NULL, NULL, NULL}
  69. };
  70. /*** file scope functions ************************************************************************/
  71. /* --------------------------------------------------------------------------------------------- */
  72. static gboolean
  73. mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
  74. {
  75. int lc_index;
  76. if (old_color != NULL)
  77. for (lc_index = 0; old_colors[lc_index].old_color; lc_index++)
  78. if (strcasecmp (old_color, old_colors[lc_index].old_color) == 0)
  79. {
  80. if (group != NULL)
  81. *group = old_colors[lc_index].group;
  82. if (key != NULL)
  83. *key = old_colors[lc_index].key;
  84. return TRUE;
  85. }
  86. return FALSE;
  87. }
  88. /* --------------------------------------------------------------------------------------------- */
  89. static void
  90. mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_string)
  91. {
  92. gchar **colors, **orig_colors;
  93. gchar **key_val;
  94. const gchar *skin_group, *skin_key;
  95. gchar *skin_val;
  96. if (the_color_string == NULL)
  97. return;
  98. orig_colors = colors = g_strsplit (the_color_string, ":", -1);
  99. if (colors == NULL)
  100. return;
  101. for (; *colors; colors++)
  102. {
  103. key_val = g_strsplit_set (*colors, "=,", 3);
  104. if (!key_val)
  105. continue;
  106. if (key_val[1] == NULL
  107. || !mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
  108. {
  109. g_strfreev (key_val);
  110. continue;
  111. }
  112. if (key_val[2] != NULL)
  113. skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
  114. else
  115. skin_val = g_strdup_printf ("%s;", key_val[1]);
  116. mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
  117. g_free (skin_val);
  118. g_strfreev (key_val);
  119. }
  120. g_strfreev (orig_colors);
  121. }
  122. /* --------------------------------------------------------------------------------------------- */
  123. /*** public functions ****************************************************************************/
  124. /* --------------------------------------------------------------------------------------------- */
  125. void
  126. mc_skin_colors_old_configure (mc_skin_t * mc_skin)
  127. {
  128. mc_skin_colors_old_configure_one (mc_skin, setup_color_string);
  129. mc_skin_colors_old_configure_one (mc_skin, term_color_string);
  130. mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
  131. mc_skin_colors_old_configure_one (mc_skin, command_line_colors);
  132. }
  133. /* --------------------------------------------------------------------------------------------- */