dthelp: use system locales.

This commit is contained in:
Liang Chang
2022-01-19 07:17:46 +08:00
parent f3965ed394
commit b239c00ae8
7 changed files with 39 additions and 588 deletions

View File

@@ -15,28 +15,9 @@ SDLBUILDSRC = $(HTAG2)/build
SDLUTILLIB = $(HTAG2)/util/libutil.a
SDLIFFILE = $(HTAG2SRC)/help.if
XLATESRCS = XlationSvc.c LocaleXlate.c
XLATESRCDIR = ${top_srcdir}/lib/DtSvc/DtUtil2
$(XLATESRCS): XDONE
XDONE: $(XLATESRCDIR)/XlationSvc.c $(XLATESRCDIR)/LocaleXlate.c
$(RM) $(XLATESRCS)
$(CP) $(XLATESRCDIR)/XlationSvc.c XlationSvc.c
$(CP) $(XLATESRCDIR)/LocaleXlate.c LocaleXlate.c
cd ../parser; $(MAKE) CDONE
touch XDONE
BUILT_SOURCES = $(XLATESRCS)
CLEANFILES = $(BUILT_SOURCES) XDONE
AM_CPPFLAGS = -I$(SDLPARSERSRC) -I$(SDLUTILSRC) \
-I$(SDLELTDEFSRC) -I$(XLATESRCDIR) $(DT_INCDIR)
-I$(SDLELTDEFSRC) $(DT_INCDIR)
# needed by parser/
noinst_LIBRARIES = libhelptag.a
libhelptag_a_SOURCES = custom.c sdl.c option.c \
out.c $(XLATESRCS) \
global.c ../parser/delim.h
libhelptag_a_SOURCES = custom.c sdl.c option.c out.c global.c ../parser/delim.h

View File

@@ -39,9 +39,6 @@
#include "userinc.h"
#include "globdec.h"
#include "LocaleXlate.h"
#include "XlationSvc.h"
static char *operantLocale;
static char openLoids[] = "<LOIDS COUNT=\"%d\">\n";
@@ -6536,27 +6533,16 @@ while (name = CycleEnt(FALSE, &type, &content, &wheredef));
}
/* A function that takes a language/charset pair and:
* if they are standard, leave them unchanged but get local
* versions and setlocale(3) using those
* if they are local, setlocale(3) with them and replace them with
* standard versions.
/* A function that takes a language/charset pair and setlocale(3) using those.
*/
void
SetLocale(M_WCHAR *pLang, M_WCHAR *pCharset)
{
const char cString[] = "C";
_DtXlateDb myDb = NULL;
char myPlatform[_DtPLATFORM_MAX_LEN+1];
char myLocale[256]; /* arbitrarily large */
char *mb_lang;
char *mb_charset;
char *locale;
char *lang;
char *charset;
int execVer;
int compVer;
int isStd;
if (!pLang && !pCharset)
return;
@@ -6576,76 +6562,15 @@ if (mb_charset && *mb_charset)
strcat(myLocale, mb_charset);
}
if ((_DtLcxOpenAllDbs(&myDb) != 0) ||
(_DtXlateGetXlateEnv(myDb,myPlatform,&execVer,&compVer) != 0))
{
fprintf(stderr,
"Warning: could not open locale translation database.\n");
if (m_errfile != stderr)
fprintf(m_errfile,
"Warning: could not open locale translation database.\n");
if (mb_lang != cString)
mb_free(&mb_lang);
if (mb_charset)
mb_free(&mb_charset);
if (myDb != 0)
_DtLcxCloseDb(&myDb);
return;
}
isStd = !_DtLcxXlateOpToStd(myDb,
"CDE",
0,
DtLCX_OPER_STD,
myLocale,
NULL,
NULL,
NULL,
NULL);
if (isStd)
{ /* already standard - get local versions and set locale */
if (_DtLcxXlateStdToOp(myDb,
myPlatform,
compVer,
DtLCX_OPER_SETLOCALE,
myLocale,
NULL,
NULL,
NULL,
&locale))
{
fprintf(stderr,
"Warning: could not translate CDE locale to local\n");
if (m_errfile != stderr)
fprintf(m_errfile,
"Warning: could not translate CDE locale to local\n");
_DtLcxCloseDb(&myDb);
if (mb_lang != cString)
mb_free(&mb_lang);
if (mb_charset)
mb_free(&mb_charset);
return;
}
else
{
setlocale(LC_CTYPE, locale);
operantLocale = mb_malloc(strlen(locale)+1);
strcpy(operantLocale, locale);
}
}
else
{ /* already local - just set locale */
setlocale(LC_CTYPE, myLocale);
operantLocale = mb_malloc(strlen(myLocale)+1);
strcpy(operantLocale, myLocale);
}
setlocale(LC_CTYPE, myLocale);
mb_free(&operantLocale);
operantLocale = mb_malloc(strlen(myLocale)+1);
strcpy(operantLocale, myLocale);
if (mb_lang != cString)
mb_free(&mb_lang);
if (mb_charset)
mb_free(&mb_charset);
_DtLcxCloseDb(&myDb);
}