colors-old.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. {"inputmark", "core", "inputmark"},
  58. {"inputunchanged", "core", "inputunchanged"},
  59. {"commandlinemark", "core", "commandlinemark"},
  60. {"helpnormal", "help", "_default_"},
  61. {"helpitalic", "help", "helpitalic"},
  62. {"helpbold", "help", "helpbold"},
  63. {"helplink", "help", "helplink"},
  64. {"helpslink", "help", "helpslink"},
  65. {"viewunderline", "viewer", "viewunderline"},
  66. {"editnormal", "editor", "_default_"},
  67. {"editbold", "editor", "editbold"},
  68. {"editmarked", "editor", "editmarked"},
  69. {"editwhitespace", "editor", "editwhitespace"},
  70. {"editlinestate", "editor", "editlinestate"},
  71. {NULL, NULL, NULL}
  72. };
  73. /*** file scope functions ************************************************************************/
  74. /* --------------------------------------------------------------------------------------------- */
  75. static gboolean
  76. mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
  77. {
  78. int lc_index;
  79. if (old_color != NULL)
  80. for (lc_index = 0; old_colors[lc_index].old_color; lc_index++)
  81. if (strcasecmp (old_color, old_colors[lc_index].old_color) == 0)
  82. {
  83. if (group != NULL)
  84. *group = old_colors[lc_index].group;
  85. if (key != NULL)
  86. *key = old_colors[lc_index].key;
  87. return TRUE;
  88. }
  89. return FALSE;
  90. }
  91. /* --------------------------------------------------------------------------------------------- */
  92. static void
  93. mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_string)
  94. {
  95. gchar **colors, **orig_colors;
  96. gchar **key_val;
  97. const gchar *skin_group, *skin_key;
  98. gchar *skin_val;
  99. if (the_color_string == NULL)
  100. return;
  101. orig_colors = colors = g_strsplit (the_color_string, ":", -1);
  102. if (colors == NULL)
  103. return;
  104. for (; *colors; colors++)
  105. {
  106. key_val = g_strsplit_set (*colors, "=,", 3);
  107. if (!key_val)
  108. continue;
  109. if (key_val[1] == NULL
  110. || !mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
  111. {
  112. g_strfreev (key_val);
  113. continue;
  114. }
  115. if (key_val[2] != NULL)
  116. skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
  117. else
  118. skin_val = g_strdup_printf ("%s;", key_val[1]);
  119. mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
  120. g_free (skin_val);
  121. g_strfreev (key_val);
  122. }
  123. g_strfreev (orig_colors);
  124. }
  125. /* --------------------------------------------------------------------------------------------- */
  126. /*** public functions ****************************************************************************/
  127. /* --------------------------------------------------------------------------------------------- */
  128. void
  129. mc_skin_colors_old_configure (mc_skin_t * mc_skin)
  130. {
  131. mc_skin_colors_old_configure_one (mc_skin, setup_color_string);
  132. mc_skin_colors_old_configure_one (mc_skin, term_color_string);
  133. mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
  134. mc_skin_colors_old_configure_one (mc_skin, command_line_colors);
  135. }
  136. /* --------------------------------------------------------------------------------------------- */