mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-15 04:32:24 +00:00
dthelp: use system locales.
This commit is contained in:
parent
f3965ed394
commit
b239c00ae8
7 changed files with 39 additions and 588 deletions
|
@ -72,7 +72,6 @@ $COPYRIGHT$:
|
||||||
#include "DtI/HelpTermP.h" /* from libDtHelp */
|
#include "DtI/HelpTermP.h" /* from libDtHelp */
|
||||||
#include "Dt/CanvasP.h" /* from libDtHelp */
|
#include "Dt/CanvasP.h" /* from libDtHelp */
|
||||||
#include "StringFuncsI.h" /* from libDtHelp */
|
#include "StringFuncsI.h" /* from libDtHelp */
|
||||||
#include "Dt/LocaleXlate.h" /* from libDtHelp */
|
|
||||||
#include "DtI/bufioI.h" /* from libDtHelp; required for AccessI.h */
|
#include "DtI/bufioI.h" /* from libDtHelp; required for AccessI.h */
|
||||||
#include "DtI/FileUtilsI.h" /* from libDtHelp */
|
#include "DtI/FileUtilsI.h" /* from libDtHelp */
|
||||||
#include "DtI/Access.h" /* from libDtHelp */
|
#include "DtI/Access.h" /* from libDtHelp */
|
||||||
|
@ -468,9 +467,7 @@ int IconvFile(
|
||||||
for (i=0; i<NUMSTRS; i++) loc[i] = NULL;
|
for (i=0; i<NUMSTRS; i++) loc[i] = NULL;
|
||||||
|
|
||||||
/* get the normalized current codeset */
|
/* get the normalized current codeset */
|
||||||
_DtHelpCeXlateOpToStdLocale (
|
_DtHelpCeGetLcCtype(&loc[CUR_LOCALE], NULL, &loc[CUR_CODESET]);
|
||||||
DtLCX_OPER_SETLOCALE, setlocale(LC_CTYPE,NULL),
|
|
||||||
&loc[CUR_LOCALE], NULL, &loc[CUR_CODESET]);
|
|
||||||
|
|
||||||
/* get the normalized volume codeset */
|
/* get the normalized volume codeset */
|
||||||
loc[VOL_LOCALE] = _DtHelpCeGetVolumeLocale(helpVolumeHandle);
|
loc[VOL_LOCALE] = _DtHelpCeGetVolumeLocale(helpVolumeHandle);
|
||||||
|
@ -495,14 +492,10 @@ int IconvFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the source codeset */
|
/* get the source codeset */
|
||||||
_DtHelpCeXlateStdToOpLocale (
|
loc[FROM_CODESET] = strdup(loc[VOL_LOCALE]);
|
||||||
DtLCX_OPER_ICONV1, loc[VOL_LOCALE],
|
|
||||||
"iso8859_1", &loc[FROM_CODESET]);
|
|
||||||
|
|
||||||
/* get the target codeset */
|
/* get the target codeset */
|
||||||
_DtHelpCeXlateStdToOpLocale (
|
loc[TO_CODESET] = strdup(loc[CUR_LOCALE]);
|
||||||
DtLCX_OPER_ICONV1, loc[CUR_LOCALE],
|
|
||||||
"iso8859_1", &loc[TO_CODESET]);
|
|
||||||
|
|
||||||
/* construct the command line */
|
/* construct the command line */
|
||||||
destFile = _DtHPrCreateTmpFile(TMPFILE_PREFIX,TMPFILE_SUFFIX);
|
destFile = _DtHPrCreateTmpFile(TMPFILE_PREFIX,TMPFILE_SUFFIX);
|
||||||
|
@ -742,9 +735,7 @@ int IconvBuffer(
|
||||||
for (i=0; i<NUMSTRS; i++) loc[i] = NULL;
|
for (i=0; i<NUMSTRS; i++) loc[i] = NULL;
|
||||||
|
|
||||||
/* get the normalized current codeset */
|
/* get the normalized current codeset */
|
||||||
_DtHelpCeXlateOpToStdLocale (
|
_DtHelpCeGetLcCtype(&loc[CUR_LOCALE], NULL, &loc[CUR_CODESET]);
|
||||||
DtLCX_OPER_SETLOCALE, setlocale(LC_CTYPE,NULL),
|
|
||||||
&loc[CUR_LOCALE], NULL, &loc[CUR_CODESET]);
|
|
||||||
|
|
||||||
/* get the normalized volume codeset */
|
/* get the normalized volume codeset */
|
||||||
loc[VOL_LOCALE] = _DtHelpCeGetVolumeLocale(helpVolumeHandle);
|
loc[VOL_LOCALE] = _DtHelpCeGetVolumeLocale(helpVolumeHandle);
|
||||||
|
@ -769,14 +760,10 @@ int IconvBuffer(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the source codeset */
|
/* get the source codeset */
|
||||||
_DtHelpCeXlateStdToOpLocale (
|
loc[FROM_CODESET] = strdup(loc[VOL_LOCALE]);
|
||||||
DtLCX_OPER_ICONV1, loc[VOL_LOCALE],
|
|
||||||
"iso8859_1", &loc[FROM_CODESET]);
|
|
||||||
|
|
||||||
/* get the target codeset */
|
/* get the target codeset */
|
||||||
_DtHelpCeXlateStdToOpLocale (
|
loc[TO_CODESET] = strdup(loc[CUR_LOCALE]);
|
||||||
DtLCX_OPER_ICONV1, loc[CUR_LOCALE],
|
|
||||||
"iso8859_1", &loc[TO_CODESET]);
|
|
||||||
|
|
||||||
if ( isFirst ) {
|
if ( isFirst ) {
|
||||||
CD = iconv_open( loc[TO_CODESET], loc[FROM_CODESET] );
|
CD = iconv_open( loc[TO_CODESET], loc[FROM_CODESET] );
|
||||||
|
|
|
@ -16,28 +16,17 @@ HELPUTILLIB = $(HELPTAG)/util/libutil.a
|
||||||
HELPIFFILE = $(HELPTAGSRC)/help.if
|
HELPIFFILE = $(HELPTAGSRC)/help.if
|
||||||
HELPTSSFILE = $(HELPTAGSRC)/htag.tss
|
HELPTSSFILE = $(HELPTAGSRC)/htag.tss
|
||||||
|
|
||||||
XLATESRCS = XlationSvc.c LocaleXlate.c
|
XDONE:
|
||||||
|
|
||||||
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
|
cd ../parser; $(MAKE) CDONE
|
||||||
touch XDONE
|
touch XDONE
|
||||||
|
|
||||||
BUILT_SOURCES = $(XLATESRCS)
|
BUILT_SOURCES = XDONE
|
||||||
CLEANFILES = $(BUILT_SOURCES) XDONE
|
CLEANFILES = $(BUILT_SOURCES)
|
||||||
|
|
||||||
AM_CPPFLAGS = -I$(HELPPARSERSRC) -I$(HELPUTILSRC) \
|
AM_CPPFLAGS = -I$(HELPPARSERSRC) -I$(HELPUTILSRC) \
|
||||||
-I$(HELPELTDEFSRC) -I$(XLATESRCDIR) $(DT_INCDIR)
|
-I$(HELPELTDEFSRC) $(DT_INCDIR)
|
||||||
|
|
||||||
# needed by parser/
|
# needed by parser/
|
||||||
noinst_LIBRARIES = libhelptag.a
|
noinst_LIBRARIES = libhelptag.a
|
||||||
libhelptag_a_SOURCES = custom.c default.c help.c make.c option.c \
|
libhelptag_a_SOURCES = custom.c default.c help.c make.c option.c \
|
||||||
special.c out.c xref.c $(XLATESRCS) \
|
special.c out.c xref.c global.c ../parser/delim.h
|
||||||
global.c ../parser/delim.h
|
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,6 @@
|
||||||
#include "userinc.h"
|
#include "userinc.h"
|
||||||
#include "globdec.h"
|
#include "globdec.h"
|
||||||
|
|
||||||
#include "LocaleXlate.h"
|
|
||||||
#include "XlationSvc.h"
|
|
||||||
|
|
||||||
void m_mberr1(char *text, const char *arg);
|
void m_mberr1(char *text, const char *arg);
|
||||||
|
|
||||||
void assert_hometopic_exists(void)
|
void assert_hometopic_exists(void)
|
||||||
|
@ -1444,220 +1441,11 @@ return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 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.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
SetStdLocale(char *pLang, char *pCharset)
|
|
||||||
{
|
|
||||||
static const char *cString = "C";
|
|
||||||
static const char *isoString = "ISO-8859-1";
|
|
||||||
_DtXlateDb myDb = NULL;
|
|
||||||
char myPlatform[_DtPLATFORM_MAX_LEN+1];
|
|
||||||
char myLocale[256]; /* arbitrarily large */
|
|
||||||
char *locale;
|
|
||||||
char *lang = NULL;
|
|
||||||
char *charset = NULL;
|
|
||||||
int execVer;
|
|
||||||
int compVer;
|
|
||||||
int isStd;
|
|
||||||
|
|
||||||
if (*pCharset)
|
|
||||||
{
|
|
||||||
snprintf(myLocale, sizeof(myLocale), "%s.%s", pLang, pCharset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(myLocale, sizeof(myLocale), "%s", pLang);
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
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");
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setlocale(LC_CTYPE, locale);
|
|
||||||
mb_free(&locale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ /* already local - set locale and get standard versions */
|
|
||||||
if (_DtLcxXlateOpToStd(myDb,
|
|
||||||
myPlatform,
|
|
||||||
compVer,
|
|
||||||
DtLCX_OPER_SETLOCALE,
|
|
||||||
myLocale,
|
|
||||||
NULL,
|
|
||||||
&lang,
|
|
||||||
&charset,
|
|
||||||
NULL))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
if (m_errfile != stderr)
|
|
||||||
fprintf(m_errfile,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setlocale(LC_CTYPE, myLocale);
|
|
||||||
|
|
||||||
if (*lang)
|
|
||||||
{
|
|
||||||
strcpy(pLang, lang);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
|
|
||||||
if (*charset)
|
|
||||||
{
|
|
||||||
strcpy(pCharset, charset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
}
|
|
||||||
|
|
||||||
mb_free(&lang);
|
|
||||||
mb_free(&charset);
|
|
||||||
free(charset);
|
|
||||||
|
|
||||||
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* A function that takes the return value from a call to setlocale()
|
|
||||||
* and extracts the langterr.charset data from it in a vendor neutral
|
|
||||||
* fashion.
|
|
||||||
*/
|
|
||||||
static char *
|
|
||||||
GetStdLocale(void)
|
|
||||||
{
|
|
||||||
static char buffer[256];
|
|
||||||
static char *cString = "C";
|
|
||||||
_DtXlateDb myDb = NULL;
|
|
||||||
char myPlatform[_DtPLATFORM_MAX_LEN+1];
|
|
||||||
char *opLocale;
|
|
||||||
char *stdLocale;
|
|
||||||
int execVer;
|
|
||||||
int compVer;
|
|
||||||
|
|
||||||
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");
|
|
||||||
return cString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_DtLcxXlateOpToStd(myDb,
|
|
||||||
myPlatform,
|
|
||||||
compVer,
|
|
||||||
DtLCX_OPER_SETLOCALE,
|
|
||||||
setlocale(LC_ALL, NULL),
|
|
||||||
&stdLocale,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
if (m_errfile != stderr)
|
|
||||||
fprintf(m_errfile,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return cString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_DtLcxXlateStdToOp(myDb,
|
|
||||||
myPlatform,
|
|
||||||
compVer,
|
|
||||||
DtLCX_OPER_SETLOCALE,
|
|
||||||
stdLocale,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&opLocale))
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
mb_free(&stdLocale);
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return cString;
|
|
||||||
}
|
|
||||||
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
|
|
||||||
strcpy(buffer, opLocale);
|
|
||||||
mb_free(&stdLocale);
|
|
||||||
mb_free(&opLocale);
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for a entities by the name of "LanguageElementDefaultLocale".
|
* Look for a entities by the name of "LanguageElementDefaultLocale".
|
||||||
* and "LanguageElementDefaultCharset". If not found, get the user's
|
* and "LanguageElementDefaultCharset". If not found, get the user's
|
||||||
* locale. If LanguageElementDefaultCharset was set, use that in
|
* locale. If LanguageElementDefaultCharset was set, use that in
|
||||||
* place of the charset of the local (if any). Call SetStdLocale()
|
* place of the charset of the local (if any).
|
||||||
* to insure the language and charset are in the normalized form.
|
|
||||||
* SetStdLocale() will also set the current locale to the local
|
|
||||||
* versions of the language and charset.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
SetDefaultLocale(void)
|
SetDefaultLocale(void)
|
||||||
|
@ -1690,7 +1478,7 @@ m_free(elementName,"wide character string");
|
||||||
|
|
||||||
if (!locale)
|
if (!locale)
|
||||||
{
|
{
|
||||||
tmpStr = GetStdLocale();
|
if ((tmpStr = setlocale(LC_CTYPE, NULL)) == NULL) tmpStr = "C.UTF-8";
|
||||||
locale = mb_malloc(strlen(tmpStr)+1);
|
locale = mb_malloc(strlen(tmpStr)+1);
|
||||||
strcpy(locale, tmpStr);
|
strcpy(locale, tmpStr);
|
||||||
}
|
}
|
||||||
|
@ -1724,10 +1512,11 @@ if (!charset)
|
||||||
if (dotPtr)
|
if (dotPtr)
|
||||||
*dotPtr = 0;
|
*dotPtr = 0;
|
||||||
|
|
||||||
snprintf(stdLang, sizeof(stdLang), "%s", locale);
|
if (charset) snprintf(stdCharset, sizeof(stdCharset), "%s", charset);
|
||||||
if (charset)
|
else snprintf(stdCharset, sizeof(stdCharset), "UTF-8");
|
||||||
snprintf(stdCharset, sizeof(stdCharset), "%s", charset);
|
|
||||||
SetStdLocale(stdLang, stdCharset);
|
snprintf(stdLang, sizeof(stdLang), "%s.%s", locale, stdCharset);
|
||||||
|
setlocale(LC_CTYPE, stdLang);
|
||||||
|
|
||||||
if (*stdCharset)
|
if (*stdCharset)
|
||||||
helpcharset = MakeWideCharString(stdCharset);
|
helpcharset = MakeWideCharString(stdCharset);
|
||||||
|
|
|
@ -16,28 +16,17 @@ HELPUTILLIB = $(HELPTAG)/util/libutil.a
|
||||||
HELPIFFILE = $(HELPTAGSRC)/help.if
|
HELPIFFILE = $(HELPTAGSRC)/help.if
|
||||||
HELPTSSFILE = $(HELPTAGSRC)/htag.tss
|
HELPTSSFILE = $(HELPTAGSRC)/htag.tss
|
||||||
|
|
||||||
XLATESRCS = XlationSvc.c LocaleXlate.c
|
XDONE:
|
||||||
|
|
||||||
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
|
cd ../parser; $(MAKE) CDONE
|
||||||
touch XDONE
|
touch XDONE
|
||||||
|
|
||||||
BUILT_SOURCES = $(XLATESRCS)
|
BUILT_SOURCES = XDONE
|
||||||
CLEANFILES = $(BUILT_SOURCES) XDONE
|
CLEANFILES = $(BUILT_SOURCES)
|
||||||
|
|
||||||
AM_CPPFLAGS = -I. -I$(HELPPARSERSRC) -I$(HELPUTILSRC) \
|
AM_CPPFLAGS = -I. -I$(HELPPARSERSRC) -I$(HELPUTILSRC) \
|
||||||
-I$(HELPELTDEFSRC) -I$(XLATESRCDIR) $(DT_INCDIR)
|
-I$(HELPELTDEFSRC) $(DT_INCDIR)
|
||||||
|
|
||||||
# needed by parser/
|
# needed by parser/
|
||||||
noinst_LIBRARIES = libhelptag.a
|
noinst_LIBRARIES = libhelptag.a
|
||||||
libhelptag_a_SOURCES = custom.c default.c help.c make.c option.c \
|
libhelptag_a_SOURCES = custom.c default.c help.c make.c option.c \
|
||||||
special.c out.c xref.c $(XLATESRCS) \
|
special.c out.c xref.c global.c ../parser/delim.h
|
||||||
global.c ../parser/delim.h
|
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,6 @@
|
||||||
#include "globdec.h"
|
#include "globdec.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
|
|
||||||
#include "LocaleXlate.h"
|
|
||||||
#include "XlationSvc.h"
|
|
||||||
|
|
||||||
void m_mberr1(char *text, const char *arg);
|
void m_mberr1(char *text, const char *arg);
|
||||||
|
|
||||||
void assert_hometopic_exists(void)
|
void assert_hometopic_exists(void)
|
||||||
|
@ -1436,218 +1433,11 @@ return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 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.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
SetStdLocale(char *pLang, char *pCharset)
|
|
||||||
{
|
|
||||||
static const char *cString = "C";
|
|
||||||
static const char *isoString = "ISO-8859-1";
|
|
||||||
_DtXlateDb myDb = NULL;
|
|
||||||
char myPlatform[_DtPLATFORM_MAX_LEN+1];
|
|
||||||
char myLocale[256]; /* arbitrarily large */
|
|
||||||
char myLocaleTemp[sizeof(myLocale)]; /* non-arbitrarily the same */
|
|
||||||
char *locale;
|
|
||||||
char *lang;
|
|
||||||
char *charset;
|
|
||||||
int execVer;
|
|
||||||
int compVer;
|
|
||||||
int isStd;
|
|
||||||
|
|
||||||
snprintf(myLocale, sizeof(myLocale), "%s", pLang);
|
|
||||||
if (*pCharset)
|
|
||||||
{
|
|
||||||
snprintf(myLocaleTemp, sizeof(myLocaleTemp), "%s.%s", myLocale, pCharset);
|
|
||||||
strcpy(myLocale, myLocaleTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
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");
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setlocale(LC_CTYPE, locale);
|
|
||||||
mb_free(&locale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ /* already local - set locale and get standard versions */
|
|
||||||
if (_DtLcxXlateOpToStd(myDb,
|
|
||||||
myPlatform,
|
|
||||||
compVer,
|
|
||||||
DtLCX_OPER_SETLOCALE,
|
|
||||||
myLocale,
|
|
||||||
NULL,
|
|
||||||
&lang,
|
|
||||||
&charset,
|
|
||||||
NULL))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
if (m_errfile != stderr)
|
|
||||||
fprintf(m_errfile,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setlocale(LC_CTYPE, myLocale);
|
|
||||||
|
|
||||||
if (*lang)
|
|
||||||
{
|
|
||||||
strcpy(pLang, lang);
|
|
||||||
mb_free(&lang);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy(pLang, cString);
|
|
||||||
|
|
||||||
if ( *charset)
|
|
||||||
{
|
|
||||||
strcpy(pCharset, charset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy(pCharset, isoString);
|
|
||||||
}
|
|
||||||
mb_free(&charset);
|
|
||||||
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
free(charset);
|
|
||||||
free(lang);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* A function that takes the return value from a call to setlocale()
|
|
||||||
* and extracts the langterr.charset data from it in a vendor neutral
|
|
||||||
* fashion.
|
|
||||||
*/
|
|
||||||
static char *
|
|
||||||
GetStdLocale(void)
|
|
||||||
{
|
|
||||||
static char buffer[256];
|
|
||||||
static char *cString = "C";
|
|
||||||
_DtXlateDb myDb = NULL;
|
|
||||||
char myPlatform[_DtPLATFORM_MAX_LEN+1];
|
|
||||||
char *opLocale;
|
|
||||||
char *stdLocale;
|
|
||||||
int execVer;
|
|
||||||
int compVer;
|
|
||||||
|
|
||||||
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");
|
|
||||||
return cString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_DtLcxXlateOpToStd(myDb,
|
|
||||||
myPlatform,
|
|
||||||
compVer,
|
|
||||||
DtLCX_OPER_SETLOCALE,
|
|
||||||
setlocale(LC_ALL, NULL),
|
|
||||||
&stdLocale,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
if (m_errfile != stderr)
|
|
||||||
fprintf(m_errfile,
|
|
||||||
"Warning: could not translate local locale to CDE\n");
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return cString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_DtLcxXlateStdToOp(myDb,
|
|
||||||
myPlatform,
|
|
||||||
compVer,
|
|
||||||
DtLCX_OPER_SETLOCALE,
|
|
||||||
stdLocale,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&opLocale))
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
mb_free(&stdLocale);
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
return cString;
|
|
||||||
}
|
|
||||||
|
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
|
|
||||||
strcpy(buffer, opLocale);
|
|
||||||
mb_free(&stdLocale);
|
|
||||||
mb_free(&opLocale);
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for a entities by the name of "LanguageElementDefaultLocale".
|
* Look for a entities by the name of "LanguageElementDefaultLocale".
|
||||||
* and "LanguageElementDefaultCharset". If not found, get the user's
|
* and "LanguageElementDefaultCharset". If not found, get the user's
|
||||||
* locale. If LanguageElementDefaultCharset was set, use that in
|
* locale. If LanguageElementDefaultCharset was set, use that in
|
||||||
* place of the charset of the local (if any). Call SetStdLocale()
|
* place of the charset of the local (if any).
|
||||||
* to insure the language and charset are in the normalized form.
|
|
||||||
* SetStdLocale() will also set the current locale to the local
|
|
||||||
* versions of the language and charset.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
SetDefaultLocale(void)
|
SetDefaultLocale(void)
|
||||||
|
@ -1680,7 +1470,7 @@ m_free(elementName,"wide character string");
|
||||||
|
|
||||||
if (!locale)
|
if (!locale)
|
||||||
{
|
{
|
||||||
tmpStr = GetStdLocale();
|
if ((tmpStr = setlocale(LC_CTYPE, NULL)) == NULL) tmpStr = "C.UTF-8";
|
||||||
locale = mb_malloc(strlen(tmpStr)+1);
|
locale = mb_malloc(strlen(tmpStr)+1);
|
||||||
strcpy(locale, tmpStr);
|
strcpy(locale, tmpStr);
|
||||||
}
|
}
|
||||||
|
@ -1714,10 +1504,11 @@ if (!charset)
|
||||||
if (dotPtr)
|
if (dotPtr)
|
||||||
*dotPtr = '\0';
|
*dotPtr = '\0';
|
||||||
|
|
||||||
snprintf(stdLang, sizeof(stdLang), "%s", locale);
|
if (charset) snprintf(stdCharset, sizeof(stdCharset), "%s", charset);
|
||||||
if (charset)
|
else snprintf(stdCharset, sizeof(stdCharset), "UTF-8");
|
||||||
snprintf(stdCharset, sizeof(stdCharset), "%s", charset);
|
|
||||||
SetStdLocale(stdLang, stdCharset);
|
snprintf(stdLang, sizeof(stdLang), "%s.%s", locale, stdCharset);
|
||||||
|
setlocale(LC_CTYPE, stdLang);
|
||||||
|
|
||||||
if (*stdCharset)
|
if (*stdCharset)
|
||||||
helpcharset = MakeWideCharString(stdCharset);
|
helpcharset = MakeWideCharString(stdCharset);
|
||||||
|
|
|
@ -15,28 +15,9 @@ SDLBUILDSRC = $(HTAG2)/build
|
||||||
SDLUTILLIB = $(HTAG2)/util/libutil.a
|
SDLUTILLIB = $(HTAG2)/util/libutil.a
|
||||||
SDLIFFILE = $(HTAG2SRC)/help.if
|
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) \
|
AM_CPPFLAGS = -I$(SDLPARSERSRC) -I$(SDLUTILSRC) \
|
||||||
-I$(SDLELTDEFSRC) -I$(XLATESRCDIR) $(DT_INCDIR)
|
-I$(SDLELTDEFSRC) $(DT_INCDIR)
|
||||||
|
|
||||||
# needed by parser/
|
# needed by parser/
|
||||||
noinst_LIBRARIES = libhelptag.a
|
noinst_LIBRARIES = libhelptag.a
|
||||||
libhelptag_a_SOURCES = custom.c sdl.c option.c \
|
libhelptag_a_SOURCES = custom.c sdl.c option.c out.c global.c ../parser/delim.h
|
||||||
out.c $(XLATESRCS) \
|
|
||||||
global.c ../parser/delim.h
|
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,6 @@
|
||||||
#include "userinc.h"
|
#include "userinc.h"
|
||||||
#include "globdec.h"
|
#include "globdec.h"
|
||||||
|
|
||||||
#include "LocaleXlate.h"
|
|
||||||
#include "XlationSvc.h"
|
|
||||||
|
|
||||||
static char *operantLocale;
|
static char *operantLocale;
|
||||||
|
|
||||||
static char openLoids[] = "<LOIDS COUNT=\"%d\">\n";
|
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:
|
/* A function that takes a language/charset pair and setlocale(3) using those.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
SetLocale(M_WCHAR *pLang, M_WCHAR *pCharset)
|
SetLocale(M_WCHAR *pLang, M_WCHAR *pCharset)
|
||||||
{
|
{
|
||||||
const char cString[] = "C";
|
const char cString[] = "C";
|
||||||
_DtXlateDb myDb = NULL;
|
|
||||||
char myPlatform[_DtPLATFORM_MAX_LEN+1];
|
|
||||||
char myLocale[256]; /* arbitrarily large */
|
char myLocale[256]; /* arbitrarily large */
|
||||||
char *mb_lang;
|
char *mb_lang;
|
||||||
char *mb_charset;
|
char *mb_charset;
|
||||||
char *locale;
|
|
||||||
char *lang;
|
|
||||||
char *charset;
|
char *charset;
|
||||||
int execVer;
|
|
||||||
int compVer;
|
|
||||||
int isStd;
|
|
||||||
|
|
||||||
if (!pLang && !pCharset)
|
if (!pLang && !pCharset)
|
||||||
return;
|
return;
|
||||||
|
@ -6576,76 +6562,15 @@ if (mb_charset && *mb_charset)
|
||||||
strcat(myLocale, mb_charset);
|
strcat(myLocale, mb_charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_DtLcxOpenAllDbs(&myDb) != 0) ||
|
setlocale(LC_CTYPE, myLocale);
|
||||||
(_DtXlateGetXlateEnv(myDb,myPlatform,&execVer,&compVer) != 0))
|
mb_free(&operantLocale);
|
||||||
{
|
operantLocale = mb_malloc(strlen(myLocale)+1);
|
||||||
fprintf(stderr,
|
strcpy(operantLocale, myLocale);
|
||||||
"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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mb_lang != cString)
|
if (mb_lang != cString)
|
||||||
mb_free(&mb_lang);
|
mb_free(&mb_lang);
|
||||||
if (mb_charset)
|
if (mb_charset)
|
||||||
mb_free(&mb_charset);
|
mb_free(&mb_charset);
|
||||||
_DtLcxCloseDb(&myDb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue