Some fixups with wrongly highlighted words
[midnight-commander.git] / src / selcodepage.c
blob753c9c19ae690404e3b3e667074507cf268a679d
1 /* User interface for charset selection.
3 Copyright (C) 2001 Walery Studennikov <despair@sama.ru>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /** \file selcodepage.c
21 * \brief Source: user %interface for charset %selection
24 #include <config.h>
26 #ifdef HAVE_CHARSET
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include "global.h"
32 #include "dialog.h"
33 #include "widget.h"
34 #include "wtools.h"
35 #include "charsets.h"
36 #include "selcodepage.h"
37 #include "main.h"
39 #define ENTRY_LEN 35
41 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
42 int source_codepage = -1;
43 int display_codepage = -1;
45 static unsigned char
46 get_hotkey (int n)
48 return (n <= 9) ? '0' + n : 'a' + n - 10;
51 int
52 select_charset (int current_charset, int seldisplay)
54 int i, menu_lines = n_codepages + 1;
55 char buffer[255];
57 /* Create listbox */
58 Listbox *listbox = create_listbox_window (ENTRY_LEN + 2, menu_lines,
59 _(" Choose input codepage "),
60 "[Codepages Translation]");
62 if (!seldisplay)
63 LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"),
64 NULL);
66 /* insert all the items found */
67 for (i = 0; i < n_codepages; i++) {
68 char *name = codepages[i].name;
69 g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i),
70 name);
71 LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL);
73 if (seldisplay) {
74 g_snprintf (buffer, sizeof (buffer), "%c %s",
75 get_hotkey (n_codepages), _("Other 8 bit"));
76 LISTBOX_APPEND_TEXT (listbox, get_hotkey (n_codepages), buffer,
77 NULL);
80 /* Select the default entry */
81 i = (seldisplay)
82 ? ((current_charset < 0) ? n_codepages : current_charset)
83 : (current_charset + 1);
85 listbox_select_by_number (listbox->list, i);
87 i = run_listbox (listbox);
89 return (seldisplay) ? ((i >= n_codepages) ? -1 : i)
90 : (i - 1);
93 /* Helper functions for codepages support */
96 int
97 do_select_codepage (void)
99 const char *errmsg;
101 if (display_codepage > 0) {
102 source_codepage = select_charset (source_codepage, 0);
103 errmsg =
104 init_translation_table (source_codepage, display_codepage);
105 if (errmsg) {
106 message (D_ERROR, MSG_ERROR, "%s", errmsg);
107 return -1;
109 } else {
110 message (D_ERROR, _("Warning"),
111 _("To use this feature select your codepage in\n"
112 "Setup / Display Bits dialog!\n"
113 "Do not forget to save options."));
114 return -1;
116 return 0;
119 #endif /* HAVE_CHARSET */