Skip to content

Commit ee5da11

Browse files
committed
locale/utf8 support (#147)
1 parent 078eb19 commit ee5da11

File tree

10 files changed

+503
-73
lines changed

10 files changed

+503
-73
lines changed

mcsrc/src/args.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ mc_args_add_extended_info_to_help (void)
441441
"Please send any bug reports (including the output of 'mc -V')\n"
442442
"as tickets at www.midnight-commander.org\n")
443443
#if defined(BUILD_NUMBER) //WIN32, build
444-
, "win32, see tickets at https://github/adamyg/mcwin32\n"
444+
, "win32, tickets at https://github/adamyg/mcwin32\n"
445445
#endif
446446
);
447447
mc_args__loc__header_string =
@@ -646,6 +646,15 @@ mc_setup_run_mode (char **argv)
646646

647647
/* --------------------------------------------------------------------------------------------- */
648648

649+
#if defined(WIN32) //WIN32, utf8
650+
static void
651+
print_handler (const gchar *string)
652+
{ // alternative g_printf(), avoids issues with
653+
// tool-chain specific utf8 stream inconsistent behaviour.
654+
tty_oputs (string);
655+
}
656+
#endif
657+
649658
gboolean
650659
mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError **mcerror)
651660
{
@@ -686,9 +695,13 @@ mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError *
686695
g_option_context_add_group (context, color_group);
687696
g_option_group_set_translation_domain (color_group, translation_domain);
688697

698+
#if defined(WIN32)
699+
g_set_print_handler (print_handler);
700+
#endif
701+
689702
if (!g_option_context_parse (context, argc, argv, mcerror))
690703
{
691-
if (*mcerror == NULL)
704+
if (mcerror && *mcerror == NULL)
692705
mc_propagate_error (mcerror, 0, "%s\n", _("Arguments parse error!"));
693706
else
694707
{
@@ -718,6 +731,10 @@ mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError *
718731
g_option_context_free (context);
719732
mc_args_clean_temp_help_strings ();
720733

734+
#if defined(WIN32) //WIN32, utf8
735+
g_set_print_handler (NULL);
736+
#endif
737+
721738
#ifdef ENABLE_NLS
722739
if (!str_isutf8 (_system_codepage))
723740
bind_textdomain_codeset ("mc", _system_codepage);
@@ -728,6 +745,22 @@ mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError *
728745

729746
/* --------------------------------------------------------------------------------------------- */
730747

748+
#if defined(WIN32) //WIN32, utf8
749+
gboolean mc_args_show_info_original (void);
750+
751+
gboolean
752+
mc_args_show_info(void) // replacement
753+
{
754+
#define mc_args_show_info mc_args_show_info_original
755+
int old_utf8_mode, ret;
756+
757+
old_utf8_mode = tty_utf8_mode (1);
758+
ret = mc_args_show_info_original ();
759+
tty_utf8_mode (old_utf8_mode);
760+
return ret;
761+
}
762+
#endif
763+
731764
gboolean
732765
mc_args_show_info (void)
733766
{

mcsrc/src/main.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include <unistd.h> /* getsid() */
4545

4646
#include "lib/global.h"
47-
4847
#include "lib/event.h"
4948
#include "lib/tty/tty.h"
5049
#include "lib/tty/key.h" /* For init_key() */
@@ -269,8 +268,9 @@ main (int argc, char *argv[])
269268
int exit_code = EXIT_FAILURE;
270269
const char *tmpdir = NULL;
271270

272-
#if defined(WIN32)
271+
#if defined(WIN32) //WIN32, config
273272
WIN32_HeapInit ();
273+
argc = WIN32_Arguments (argc, &argv);
274274
#endif
275275

276276
mc_global.run_from_parent_mc = !check_sid ();
@@ -283,30 +283,22 @@ main (int argc, char *argv[])
283283
(void) textdomain (PACKAGE);
284284

285285
#if defined(WIN32) //WIN32, config
286-
WIN32_Setup();
286+
WIN32_Setup ();
287287
#endif
288288

289289
/* do this before args parsing */
290290
str_init_strings (NULL);
291291

292-
#if defined(WIN32)
293-
{ // tool-chain independent wide-char/utf8 conversion command-line parser.
294-
int uargc = 0;
295-
char **uargv;
296-
297-
uargv = GetUTF8Arguments(&uargc);
298-
assert(uargv && uargc == argc);
299-
argv = uargv;
300-
argc = uargc;
301-
}
302-
#endif //WIN32
303-
304292
mc_setup_run_mode (argv); /* are we mc? editor? viewer? etc... */
305293

306294
if (!mc_args_parse (&argc, &argv, "mc", &mcerror))
307295
{
308296
startup_exit_falure:
297+
#if defined(WIN32) //WIN32, utf8
298+
tty_eprintf (_("Failed to run:\n%s\n"), mcerror->message);
299+
#else
309300
fprintf (stderr, _("Failed to run:\n%s\n"), mcerror->message);
301+
#endif
310302
g_error_free (mcerror);
311303
startup_exit_ok:
312304
mc_shell_deinit ();

mcsrc/src/textconf.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,6 @@ show_version (void)
229229
void
230230
show_datadirs_extended (void)
231231
{
232-
#if defined(WIN32)
233-
#ifndef CP_UTF8
234-
#define CP_UTF8 65001 /* UTF-8 translation */
235-
#endif
236-
DWORD codepage;
237-
if (CP_UTF8 != (codepage = GetConsoleOutputCP())) {
238-
(void) SetConsoleOutputCP(CP_UTF8);
239-
}
240-
#endif
241-
242232
(void) printf ("%s %s\n", _("Home directory:"), mc_config_get_home_dir ());
243233
(void) printf ("%s %s\n", _("Profile root directory:"), mc_get_profile_root ());
244234
#if defined(WIN32)
@@ -302,12 +292,6 @@ show_datadirs_extended (void)
302292
#endif //WIN32, conf
303293
#endif
304294
PRINTF_SECTION2 (_("Cache directory:"), mc_config_get_cache_path ());
305-
306-
#if defined(WIN32)
307-
if (CP_UTF8 != codepage) {
308-
(void) SetConsoleOutputCP(codepage);
309-
}
310-
#endif
311295
}
312296

313297
#undef PRINTF

mcwin32/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ directories: $(DIRECTORIES)
869869
artifacts: buildinfo busyboxcmds BUILDNUMBER
870870

871871
%/.created:
872-
-@$(PERL) ./support/mkdir_p.pl $(@D)
872+
-@$(MKDIR_P) $(@D)
873873
@echo "++ do not delete, midnight commander managed content ++" > $@
874874

875875
targets: $(LIBRARIES) $(TARGETS)

mcwin32/config.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const char * mc_EXTHELPERSDIR(void);
9999
#define EXTHELPERSDIR mc_EXTHELPERSDIR() /* ???, 4.8.7 */
100100

101101
extern void WIN32_Setup(void);
102+
extern int WIN32_Arguments(int argc, char ***argv);
103+
102104
extern void WIN32_HeapInit(void);
103105
extern int WIN32_HeapCheck(void);
104106

@@ -124,8 +126,12 @@ extern char * strtok_r(char *s, const char *delim, char **lasts);
124126
extern char * strcasestr(const char *s, const char *find);
125127
#endif
126128

127-
extern char ** GetUTF8Arguments(int *pargc);
129+
extern void tty_oprintf(const char *fmt, ...);
130+
extern void tty_oputs(const char *str);
131+
extern void tty_eprintf(const char *fmt, ...);
132+
extern void tty_eputs(const char *str);
128133

134+
extern int tty_utf8_mode(int state);
129135
extern void tty_set_title(const char *title);
130136

131137
/*

mcwin32/doc/INSTALL.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ To build and install mcwin32, you shall need:
2323
* Git tooling for windows.
2424
* Perl 5 with core modules, see [NOTES-PERL.md](doc/NOTES-PERL.md).
2525
* CoreUtils, includes various text and system utilities.
26+
* Gettext
2627
* Make.
2728
* An ANSI C/C++ compiler.
2829
* A development environment in the form of development libraries and C header files.
@@ -79,7 +80,7 @@ Several alternative profiles are available:
7980
* Open-Watcom (OWC) 1.9 or 2.0; or
8081

8182
* owcconfig - Open Watcom 1.9
82-
* owc20config - Open Watcom 2.0
83+
* owc20config - Open Watcom 2.0
8384

8485
* MingW64, both 32 and 64 bit targets.
8586

@@ -169,10 +170,10 @@ The follow offers a more detailed discussion of the requirements and instruction
169170
- [Native builds using Visual C++](#native-builds-using-visual-c-c)
170171
- [Native builds using MinGW64](#native-builds-using-mingw)
171172

172-
Finally, please review the packaged example alternative configurations as win32 development environments can be problematic, dependent on the host setup:
173+
Finally, please review the packaged example alternative configurations as win32 development environments can be problematic, dependent on the host setup:
173174

174175
- .github/workflows, github build actions for owc, msvc and mingw64 toolchains.
175-
- Appveyor CI integration notes [Appveyor CI](CINotes.md).
176+
- Appveyor CI integration notes [Appveyor CI](CINotes.md).
176177

177178
Native builds using Open-Watcom C/C++
178179
====================================
@@ -226,6 +227,14 @@ Minimal tools required are:
226227

227228
Once installed the required commands should be visible within the path.
228229

230+
* gettext - gettext utilities are a set of tools that provides a framework to help packages produce multi-lingual messages.
231+
232+
Several options are available including:
233+
234+
* msys64 - ```pacman --noconfirm -S mingw-w64-i686-gettext-tools```
235+
236+
* [gettext for windows](https://github.com/mlocati/gettext-iconv-windows)
237+
229238
To support native Windows builds, the make tool ``gmake-42``, web tool ``wget`` and the shell support tool ``busybox`` are bundled within the source repository sub-directory ``win32/``.
230239

231240
- ``gmake`` was built from its original source available from [GNU binutils](https://www.gnu.org/software/binutils/).
@@ -266,7 +275,7 @@ Quick start
266275
From the source root, a suitable environment can be setup using the one of the following dependent on the desired toolchain, were ``C:\Watcom`` is the toolchain installation directory.
267276

268277
* owcconfig- Open Watcom 1.9
269-
* owc20config - Open Watcom 2.0
278+
* owc20config - Open Watcom 2.0
270279

271280
* From the root of the source directory perform the following:
272281

@@ -314,7 +323,7 @@ The resulting work flow could look like the following, inside a Open Watcom 1.9
314323
cd c:\projects
315324
316325
git clone https://github.com/adamyg/mcwin32.git mc
317-
326+
318327
cd c:\projects\mc\mcwin32
319328
320329
git submodule update --init --recursive
@@ -338,18 +347,18 @@ Microsoft Visual is available in several, all are suitable:
338347

339348
* Microsoft Visual C++ 2015 - 2002 Professional -
340349

341-
Standard Microsoft Visual C++ installations.
350+
Standard Microsoft Visual C++ installations.
342351

343352
* Microsoft Visual C++ 2015 - 2022 Community Edition -
344353

345-
These free versions of Visual C++ 2015-2022 Professional contain the same compilers and linkers that ship with the full versions,
354+
These free versions of Visual C++ 2015-2022 Professional contain the same compilers and linkers that ship with the full versions,
346355
and also contain everything necessary to build mcwin32.
347-
348-
* Microsoft C++ Build Tools -
356+
357+
* Microsoft C++ Build Tools -
349358

350359
There's also a standalone (IDE-less) version of the build tools mentioned above containing the MSVC compiler
351360
available for download from https://visualstudio.microsoft.com/visual-cpp-build-tools/.
352-
361+
353362
Note: Since these are proprietary and ever-changing I cannot test them all. Older versions may not work, it is recommended to use a recent version wherever possible.
354363

355364
* Install _Perl_
@@ -393,7 +402,7 @@ The resulting work flow could look like the following, inside a 2019 developer p
393402
cd c:\projects
394403
395404
git clone https://github.com/adamyg/mcwin32.git mc
396-
405+
397406
cd c:\projects\mc\mcwin32
398407
399408
git submodule update --init --recursive
@@ -412,8 +421,8 @@ Native builds using Mingw
412421

413422
Mingw64 (32/64) offers another alternative way to build native __mcwin32__, similar to Open-Watcom C/C++ builds.
414423

415-
MSYS2 provides GNU tools, a Unix-like command prompt, and a UNIX compatibility layer for applications,
416-
available from https://www.mingw-w64.org. However, in this context it is only used for building mcwin32.
424+
MSYS2 provides GNU tools, a Unix-like command prompt, and a UNIX compatibility layer for applications,
425+
available from https://www.mingw-w64.org. However, in this context it is only used for building mcwin32.
417426
The resulting application does not rely on MSYS2 to run and is fully native.
418427

419428
* _MSYS2_ shell, from https://www.msys2.org/
@@ -433,9 +442,14 @@ The resulting application does not rely on MSYS2 to run and is fully native.
433442
$ pacman --noconfirm -S mingw-w64-x86_64-gcc
434443
$ pacman --noconfirm -S mingw-w64-i686-gcc
435444

436-
These compilers must be on your MSYS2 \$PATH, example below assuming the default installation path ``c:/msys64/``.
445+
These compilers must be on your MSYS2 \$PATH, example below assuming the default installation path ``c:/msys64/``.
437446
A common error is to not have these on your \$PATH. The MSYS2 version of gcc will not work correctly here.
438447

448+
finally, any additional components
449+
450+
$ pacman --noconfirm -S mingw-w64-i686-gettext-tools
451+
$ pacman --noconfirm -S zip
452+
439453
* From the root of the source directory perform the following:
440454

441455
* Configure and prime the build system.
@@ -457,7 +471,7 @@ The resulting application does not rely on MSYS2 to run and is fully native.
457471
* Optionally, build the installer.
458472

459473
$ .\support\gmake-42 release package
460-
474+
461475
The resulting work flow could look like the following, inside either a terminal/command or msys prompt:
462476

463477
Install any missing components
@@ -475,7 +489,7 @@ Prime sandbox and build
475489
cd c:\projects
476490
477491
git clone https://github.com/adamyg/mcwin32.git mc
478-
492+
479493
cd c:\projects\mc\mcwin32
480494
481495
git submodule update --init --recursive

0 commit comments

Comments
 (0)