colors-old.c 5.5 KB

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