Centralize catgets() calls through MsgCat
CDE has relied upon catgets() implementations following a relaxed interpretation of the XPG internationalization standard that ignored -1, the standard error value returned by catopen, as the catalog argument. However, this same behavior causes segmentation faults with the musl C library. This patch: - Centralizes (with the exception of ToolTalk) all calls to catopen(), catgets(), and catclose() through MsgCat within the DtSvc library. - Prevents calls to catgets() and catclose() that rely upon undefined behavior. - Eliminates a number of bespoke catgets() wrappers, including multiple redundant caching implementations designed to work around a design peculiarity in HP/UX. - Eases building CDE without XPG internationalization support by providing the appropriate macros.
This commit is contained in:
committed by
Jon Trulson
parent
8278e0eae3
commit
7010b2c11b
@@ -70,7 +70,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "EUSDebug.hh"
|
||||
@@ -98,34 +98,6 @@ Application::_appResources[] = {
|
||||
#define NL_CAT_LOCALE 0
|
||||
#endif
|
||||
|
||||
#ifdef hpV4
|
||||
/*
|
||||
* Wrapper around catgets -- this makes sure the message string is saved
|
||||
* in a safe location; so repeated calls to catgets() do not overwrite
|
||||
* the catgets() internal buffer. This has been a problem on HP systems.
|
||||
*/
|
||||
char *catgets_cache2(nl_catd catd, int set, int num, char *dflt)
|
||||
{
|
||||
|
||||
#define MSGS_PER_SET_MAX 12
|
||||
#define NUM_SETS_MAX 2
|
||||
|
||||
/* array to hold messages from catalog */
|
||||
static char *MsgCat[NUM_SETS_MAX][MSGS_PER_SET_MAX];
|
||||
|
||||
/* convert to a zero based index */
|
||||
int setIdx = set - 1;
|
||||
int numIdx = num - 1;
|
||||
|
||||
if ( ! MsgCat[setIdx][numIdx] ) {
|
||||
MsgCat[setIdx][numIdx] = strdup( catgets(catd, set, num, dflt));
|
||||
}
|
||||
|
||||
return MsgCat[setIdx][numIdx];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Application *theApplication = NULL;
|
||||
|
||||
nl_catd catd = (nl_catd) -1; // catgets file descriptor
|
||||
@@ -261,7 +233,7 @@ Application::~Application()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
catclose(catd);
|
||||
CATCLOSE(catd);
|
||||
|
||||
// In an MT environment, calling exit() causes threads to
|
||||
// hang and a deadlock results.
|
||||
@@ -387,7 +359,7 @@ void
|
||||
Application::open_catalog()
|
||||
{
|
||||
// open message catalog file
|
||||
catd = catopen("MotifApp", NL_CAT_LOCALE);
|
||||
catd = CATOPEN("MotifApp", NL_CAT_LOCALE);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -65,11 +65,9 @@
|
||||
#include "QuestionDialogManager.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
extern nl_catd catd;
|
||||
|
||||
#include "NLS.hh"
|
||||
|
||||
AskFirstCmd::AskFirstCmd ( char *name,
|
||||
char *label,
|
||||
int active ) : Cmd ( name, label, active )
|
||||
@@ -77,7 +75,7 @@ AskFirstCmd::AskFirstCmd ( char *name,
|
||||
_dialog = NULL;
|
||||
_question = NULL;
|
||||
_dialogParentWidget = NULL;
|
||||
setQuestion ( GETMSG(catd, 1, 1,
|
||||
setQuestion ( CATGETS(catd, 1, 1,
|
||||
"Do you really want to execute this command?"));
|
||||
}
|
||||
|
||||
|
||||
@@ -69,11 +69,9 @@
|
||||
#include <Xm/MessageB.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
extern nl_catd catd;
|
||||
|
||||
#include "NLS.hh"
|
||||
|
||||
DialogManager::DialogManager ( char *name ): UIComponent ( name )
|
||||
{
|
||||
// Empty
|
||||
@@ -468,8 +466,8 @@ DialogManager::post_and_return(
|
||||
// They may have been set via the overloaded post_and_return()
|
||||
// method before. Reset them to their default values...
|
||||
|
||||
okLabel = XmStringCreateLocalized(GETMSG(catd, 1, 2, "OK"));
|
||||
cancelLabel = XmStringCreateLocalized(GETMSG(catd, 1, 3, "Cancel"));
|
||||
okLabel = XmStringCreateLocalized(CATGETS(catd, 1, 2, "OK"));
|
||||
cancelLabel = XmStringCreateLocalized(CATGETS(catd, 1, 3, "Cancel"));
|
||||
|
||||
Widget dlg = this->getDialog(wid);
|
||||
|
||||
|
||||
@@ -50,11 +50,9 @@
|
||||
#include <Dt/Editor.h>
|
||||
#include "Help.hh"
|
||||
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
extern nl_catd catd;
|
||||
|
||||
#include "NLS.hh"
|
||||
|
||||
void DisplayMain( Widget, char *, char *);
|
||||
static Widget helpMain = NULL;
|
||||
static Widget helpError = NULL;
|
||||
@@ -126,7 +124,7 @@ DisplayVersion (
|
||||
|
||||
if (versionMain != NULL) {
|
||||
n = 0;
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 4,
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 4,
|
||||
"DtMail Version Dialog")); n++;
|
||||
if (helpVolume != NULL) {
|
||||
XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
|
||||
@@ -141,7 +139,7 @@ DisplayVersion (
|
||||
|
||||
// Build a new one in our cached list
|
||||
n = 0;
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 5,
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 5,
|
||||
"DtMail Version Dialog")); n++;
|
||||
if (helpVolume != NULL) {
|
||||
XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
|
||||
@@ -190,7 +188,7 @@ HelpMenuCB (
|
||||
|
||||
switch ((int) status) {
|
||||
case DtHELP_SELECT_ERROR:
|
||||
printf(GETMSG(catd, 2, 1, "Selection Error, cannot continue\n"));
|
||||
printf(CATGETS(catd, 2, 1, "Selection Error, cannot continue\n"));
|
||||
break;
|
||||
case DtHELP_SELECT_VALID:
|
||||
while (selWidget != NULL) {
|
||||
@@ -205,10 +203,10 @@ HelpMenuCB (
|
||||
}
|
||||
break;
|
||||
case DtHELP_SELECT_ABORT:
|
||||
printf(GETMSG(catd, 2, 2, "Selection aborted by user.\n"));
|
||||
printf(CATGETS(catd, 2, 2, "Selection aborted by user.\n"));
|
||||
break;
|
||||
case DtHELP_SELECT_INVALID:
|
||||
printf(GETMSG(catd, 1, 6,
|
||||
printf(CATGETS(catd, 1, 6,
|
||||
"You must select a component withing your app.\n"));
|
||||
break;
|
||||
}
|
||||
@@ -260,9 +258,9 @@ DisplayMain(
|
||||
if (helpMain != NULL) {
|
||||
n = 0;
|
||||
#ifdef undef
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 7, "DtMail Help")); n++;
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 7, "DtMail Help")); n++;
|
||||
#endif
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 12, "Mailer : Help")); n++;
|
||||
if (helpVolume != NULL) {
|
||||
XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
|
||||
}
|
||||
@@ -277,7 +275,7 @@ DisplayMain(
|
||||
|
||||
// Build a new one in our cached list
|
||||
n = 0;
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 12, "Mailer : Help")); n++;
|
||||
if (helpVolume != NULL) {
|
||||
XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
|
||||
}
|
||||
@@ -306,9 +304,9 @@ DisplayErrorHelp(
|
||||
if (helpError) {
|
||||
n = 0;
|
||||
#ifdef undef
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 7, "DtMail Help")); n++;
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 7, "DtMail Help")); n++;
|
||||
#endif
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 12, "Mailer : Help")); n++;
|
||||
if (helpVolume != NULL) {
|
||||
XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
|
||||
}
|
||||
@@ -323,9 +321,9 @@ DisplayErrorHelp(
|
||||
// when done.
|
||||
n = 0;
|
||||
#ifdef undef
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 8, "DtMail Help")); n++;
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 8, "DtMail Help")); n++;
|
||||
#endif
|
||||
XtSetArg (args[n], XmNtitle, GETMSG(catd, 1, 12, "Mailer : Help")); n++;
|
||||
XtSetArg (args[n], XmNtitle, CATGETS(catd, 1, 12, "Mailer : Help")); n++;
|
||||
if (helpVolume != NULL) {
|
||||
XtSetArg (args[n], DtNhelpVolume, helpVolume); n++;
|
||||
}
|
||||
|
||||
@@ -66,17 +66,15 @@
|
||||
#include "MainWindow.h"
|
||||
#include "Application.h"
|
||||
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
extern nl_catd catd;
|
||||
|
||||
#include "NLS.hh"
|
||||
|
||||
QuitCmd::QuitCmd ( char *name, char *label, int active, MainWindow *mywindow) :
|
||||
WarnNoUndoCmd ( name, label, active )
|
||||
{
|
||||
_mywindow = mywindow;
|
||||
_dialogParentWidget = _mywindow->baseWidget();
|
||||
setQuestion ( GETMSG(catd, 1, 9, "Close this folder?") );
|
||||
setQuestion ( CATGETS(catd, 1, 9, "Close this folder?") );
|
||||
}
|
||||
|
||||
void QuitCmd::doit()
|
||||
|
||||
@@ -70,11 +70,9 @@
|
||||
#include <X11/Intrinsic.h>
|
||||
#include "Help.hh"
|
||||
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
extern nl_catd catd;
|
||||
|
||||
#include "NLS.hh"
|
||||
|
||||
extern "C" {
|
||||
#include <Dt/HourGlass.h>
|
||||
}
|
||||
@@ -184,7 +182,7 @@ void SelectFileCmd::doit()
|
||||
XmStringFree(title);
|
||||
XmStringFree(ok_str);
|
||||
XmString hidden_str = XmStringCreateLocalized(
|
||||
GETMSG(catd, 1, 11, "Show hidden folders and files"));
|
||||
CATGETS(catd, 1, 11, "Show hidden folders and files"));
|
||||
_hidden_button = XtVaCreateManagedWidget(
|
||||
"hidden", xmToggleButtonWidgetClass,
|
||||
_fileBrowser,
|
||||
|
||||
@@ -63,17 +63,15 @@
|
||||
//////////////////////////////////////////////////////////
|
||||
#include "WarnNoUndoCmd.h"
|
||||
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
extern nl_catd catd;
|
||||
|
||||
#include "NLS.hh"
|
||||
|
||||
WarnNoUndoCmd::WarnNoUndoCmd ( char *name, char *label, int active) :
|
||||
AskFirstCmd ( name, label, active )
|
||||
{
|
||||
_hasUndo = 0; // Specify that there is no undo
|
||||
|
||||
setQuestion ( GETMSG(catd, 1, 10,
|
||||
setQuestion ( CATGETS(catd, 1, 10,
|
||||
"This command cannot be undone. Proceed anyway?") );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user