* global.h: Include unix.h under "classical" QNX.
[midnight-commander.git] / src / selcodepage.c
blob60f7660e5c789f34ac5b11535e1110b138dfd5bf
1 #include <config.h>
3 #ifdef HAVE_CHARSET
4 #include <stdlib.h>
5 #include <stdio.h>
7 #include "global.h"
8 #include "dlg.h"
9 #include "dialog.h"
10 #include "widget.h"
11 #include "wtools.h"
12 #include "charsets.h"
13 #include "selcodepage.h"
14 #include "main.h"
16 #define ENTRY_LEN 35
18 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
19 int source_codepage = -1;
20 int display_codepage = -1;
22 static unsigned char get_hotkey( int n )
24 return (n <= 9) ? '0' + n : 'a' + n - 10;
27 int select_charset( int current_charset, int seldisplay )
29 int i, menu_lines = n_codepages + 1;
31 /* Create listbox */
32 Listbox* listbox =
33 create_listbox_window ( ENTRY_LEN + 2, menu_lines,
34 _(" Choose input codepage "),
35 "[Codepages Translation]");
37 if (!seldisplay)
38 LISTBOX_APPEND_TEXT( listbox, '-', _("- < No translation >"), NULL );
40 /* insert all the items found */
41 for (i = 0; i < n_codepages; i++) {
42 struct codepage_desc cpdesc = codepages[i];
43 char buffer[255];
44 sprintf( buffer, "%c %s", get_hotkey(i), cpdesc.name );
45 LISTBOX_APPEND_TEXT( listbox, get_hotkey(i), buffer, NULL );
47 if (seldisplay) {
48 char buffer[255];
49 sprintf( buffer, "%c %s", get_hotkey(n_codepages), _("Other 8 bit"));
50 LISTBOX_APPEND_TEXT( listbox, get_hotkey(n_codepages), buffer, NULL );
53 /* Select the default entry */
54 i = (seldisplay)
56 ( (current_charset < 0) ? n_codepages : current_charset )
58 ( current_charset + 1 );
60 listbox_select_by_number( listbox->list, i );
62 i = run_listbox( listbox );
64 return (seldisplay) ? ( (i >= n_codepages) ? -1 : i )
65 : ( i - 1 );
68 /* Helper functions for codepages support */
71 int do_select_codepage(void)
73 #ifndef HAVE_ICONV
75 message( 1, _(" Warning "),
76 _("Midnight Commander was compiled without iconv support,\n"
77 "so charsets recoding feature is not available!" ));
78 return -1;
80 #else
82 char *errmsg;
84 if (display_codepage > 0) {
85 source_codepage = select_charset( source_codepage, 0 );
86 errmsg = init_translation_table( source_codepage, display_codepage );
87 if (errmsg) {
88 message( 1, MSG_ERROR, "%s", errmsg );
89 return -1;
91 } else {
92 message( 1, _(" Warning "),
93 _("To use this feature select your codepage in\n"
94 "Setup / Display Bits dialog!\n"
95 "Do not forget to save options." ));
96 return -1;
98 return 0;
100 #endif /* HAVE_ICONV */
103 #endif /* HAVE_CHARSET */