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:
Lev Kujawski
2021-01-30 20:05:13 -07:00
committed by Jon Trulson
parent 3379999106
commit a6ea2a2d52
241 changed files with 3154 additions and 3498 deletions

View File

@@ -33,7 +33,7 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <nl_types.h>
#include <Dt/MsgCatP.h>
#include <ab_private/AB.h>
#include <ab/util_types.h>
#include <ab_private/util.h>

View File

@@ -48,7 +48,7 @@
#include <time.h>
#include <limits.h>
#include <ctype.h>
#include <nl_types.h>
#include <Dt/MsgCatP.h>
#include <ab_private/util.h>
#include <ab_private/obj.h>
#include <ab_private/objxm.h>
@@ -226,7 +226,7 @@ main(int argc, STRING *argv)
/*
* Open the standard message catalog for the project.
*/
Dtb_project_catd = catopen("dtcodegen", NL_CAT_LOCALE);
Dtb_project_catd = CATOPEN("dtcodegen", NL_CAT_LOCALE);
if (Dtb_project_catd == (nl_catd)-1)
{
fprintf(stderr,
@@ -268,14 +268,14 @@ main(int argc, STRING *argv)
if (!util_be_silent())
{
util_printf(
catgets(Dtb_project_catd, 1, 1,
CATGETS(Dtb_project_catd, 1, 1,
"No project file that references module(s) - using defaults\n"));
}
}
else if (numProjFiles == 0)
{
util_printf(
catgets(Dtb_project_catd, 1, 2,
CATGETS(Dtb_project_catd, 1, 2,
"No files specified, and no project file found\n"));
abmf_usage();
}
@@ -344,7 +344,7 @@ main(int argc, STRING *argv)
{
char *proj_file_name = istr_string_safe(cmdline->proj_file);
util_printf(
catgets(Dtb_project_catd, 1, 3, "Reading project %s.\n"),
CATGETS(Dtb_project_catd, 1, 3, "Reading project %s.\n"),
proj_file_name);
}
@@ -443,7 +443,7 @@ main(int argc, STRING *argv)
char *prog_name_string = util_get_program_name();
fprintf(stderr,
catgets(Dtb_project_catd, 1, 4,
CATGETS(Dtb_project_catd, 1, 4,
"%s: exiting due to error loading project.\n"),
prog_name_string);
exit(1);
@@ -461,7 +461,7 @@ main(int argc, STRING *argv)
char *prog_name_string = util_get_program_name();
fprintf(stderr,
catgets(Dtb_project_catd, 1, 5,
CATGETS(Dtb_project_catd, 1, 5,
"%s: Nothing to do!\n"), prog_name_string);
exit(1);
}
@@ -667,7 +667,7 @@ parse_args(int argc, char *argv[], CmdlineArgs cmdline)
{
if ((argCount + 1) >= argc)
{
util_error( catgets(Dtb_project_catd, 1, 6,
util_error( CATGETS(Dtb_project_catd, 1, 6,
"Missing project name for -p option"));
abmf_usage();
}
@@ -762,7 +762,7 @@ parse_args(int argc, char *argv[], CmdlineArgs cmdline)
{
char *prog_name_string = util_get_program_name();
fprintf(stderr, catgets(Dtb_project_catd, 1, 7,
fprintf(stderr, CATGETS(Dtb_project_catd, 1, 7,
"%s: Illegal option \"%s\"\n\n"), prog_name_string, arg);
abmf_usage();
}
@@ -780,7 +780,7 @@ parse_args(int argc, char *argv[], CmdlineArgs cmdline)
if (cmdline->proj_file != NULL)
{
util_error(
catgets(Dtb_project_catd, 1, 8,
CATGETS(Dtb_project_catd, 1, 8,
"Only one project file may be specified."));
abmf_usage();
}
@@ -818,7 +818,7 @@ parse_args(int argc, char *argv[], CmdlineArgs cmdline)
char *proj_file_name = istr_string_safe(cmdline->proj_file);
util_printf_err(
catgets(Dtb_project_catd, 1, 9,
CATGETS(Dtb_project_catd, 1, 9,
"ignoring -noproject (-np) because project file was specified: %s\n"),
proj_file_name);
cmdline->use_default_project = FALSE;
@@ -1107,7 +1107,7 @@ load_module(ABObj module)
else if (newProject != project)
{
util_printf_err(
catgets(Dtb_project_catd, 1, 10,
CATGETS(Dtb_project_catd, 1, 10,
"Unexpected project in file %s. Aborting\n"), fileName);
exit(1);
}
@@ -1116,7 +1116,7 @@ load_module(ABObj module)
char *module_name_string = obj_get_name(module);
util_printf_err(
catgets(Dtb_project_catd, 1, 11,
CATGETS(Dtb_project_catd, 1, 11,
"Module %s not found in file %s. Aborting\n"),
module_name_string, fileName);
exit(1);
@@ -1136,49 +1136,49 @@ abmf_usage(void)
fprintf(stderr,"\n");
fprintf(stderr,
catgets(Dtb_project_catd, 1, 12,
CATGETS(Dtb_project_catd, 1, 12,
"Usage: %s [options] [project-file] [module-file [module-file] ...]\n\n"),
program_name_string);
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 13,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 13,
"Code is generated for each module specified on the command line, or for\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 14,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 14,
"all modules in the project, if no modules are specified. If no project\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 15,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 15,
"file is specified, a project file containing the specified module(s) is\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 16,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 16,
"searched for in the current directory.\n\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 17,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 17,
"Files with extension .bip are assumend to be BIL project files, files with\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 18,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 18,
".bix extension are assumed to be encapsulated BIL files, and files\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 19,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 19,
"With a .bil extension are assumed to be BIL module files.\n\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 20,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 20,
"Options (* = default, + = default with no project file):\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 21,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 21,
" -help (-h) Print out this help message\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 22,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 22,
" -main Write file containing main()\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 23,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 23,
" -changed Only generate files that have changed\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 24,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 24,
"* -merge Merge generated _stubs.c files with previous version\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 25,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 25,
" -nomerge Don't merge existing and new stubs file\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 26,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 26,
"* -project (-p) Specify a project to generate code for\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 27,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 27,
" -noproject (-np) Use default project settings, ignore project file\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 28,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 28,
"+ -showall Application shows (maps) all windows at startup\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 29,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 29,
"* -noshowall Application shows (maps) only initially-visible windows\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 30,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 30,
" -silent (-s) Silent mode, no messages written\n"));
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 31,
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 31,
" -verbose (-v) Verbose mode, detailed progress messages\n\n"));
@@ -1211,7 +1211,7 @@ find_proj_file(CmdlineArgs cmdline)
dir= opendir(".");
if (dir == NULL)
{
perror(catgets(Dtb_project_catd,1,32,"Couldn't open '.'"));
perror(CATGETS(Dtb_project_catd,1,32,"Couldn't open '.'"));
return -1;
}
@@ -1251,17 +1251,17 @@ find_proj_file(CmdlineArgs cmdline)
int i = 0;
char *prog_name_string = util_get_program_name();
fprintf(stderr, catgets(Dtb_project_catd, 1, 33,
fprintf(stderr, CATGETS(Dtb_project_catd, 1, 33,
"%s: Please specify project file (e.g."), prog_name_string);
for (i = 0; i < strlist_get_num_strs(&projFiles); ++i)
{
fprintf(stderr, ", %s", strlist_get_str(&projFiles, i, NULL));
}
fprintf(stderr, "%s", catgets(Dtb_project_catd, 1, 34, ")\n"));
fprintf(stderr, "%s", CATGETS(Dtb_project_catd, 1, 34, ")\n"));
if (!strlist_is_empty(cmdline->files))
{
fprintf(stderr,
catgets(Dtb_project_catd, 1, 35,
CATGETS(Dtb_project_catd, 1, 35,
"%s: More than one project contains specified module(s)\n"),
prog_name_string);
}
@@ -2088,7 +2088,7 @@ abmfP_create_obj_data_for_module(ABObj objInModule)
memset(objData, 0, objDataBytes);
if (objData == NULL)
{
util_printf_err(catgets(Dtb_project_catd, 1, 36,
util_printf_err(CATGETS(Dtb_project_catd, 1, 36,
"Could not allocate cgen data\n"));
return -1;
}

View File

@@ -51,7 +51,7 @@
#include <stdio.h> /* FILE*, BUFSIZ */
#include <stdint.h>
#include <sys/param.h> /* MAXPATHLEN, ... */
#include <nl_types.h>
#include <Dt/MsgCatP.h>
#include <X11/Intrinsic.h>
#include <ab_private/obj.h>
#include <ab_private/trav.h>

View File

@@ -252,7 +252,7 @@ static int update_msg_set(MsgFile msgFile, ABObj obj);
#define print_writing_message(_fname) \
{STRING progress_msg; \
progress_msg=XtNewString(catgets(Dtb_project_catd, 1, 52, "writing"));\
progress_msg=XtNewString(CATGETS(Dtb_project_catd, 1, 52, "writing"));\
print_progress_message(1,progress_msg,_fname);\
XtFree(progress_msg);}
@@ -486,7 +486,7 @@ epilogue:
if (return_value < 0)
{
util_puts_err("\n");
util_puts_err(catgets(Dtb_project_catd, 1, 53,
util_puts_err(CATGETS(Dtb_project_catd, 1, 53,
"** Aborting due to errors **\n"));
}
abmfP_res_file_close(genCodeInfo->resource_file); /* NULL OK */
@@ -544,13 +544,13 @@ write_module_files(
char *prog_name_string = util_get_program_name();
char *module_name_string = obj_get_name(module);
fprintf(stderr, catgets(Dtb_project_catd, 1, 54,
fprintf(stderr, CATGETS(Dtb_project_catd, 1, 54,
"%s: module filename must contain only letters\n"),
prog_name_string);
fprintf(stderr, catgets(Dtb_project_catd, 1, 55,
fprintf(stderr, CATGETS(Dtb_project_catd, 1, 55,
"and digits. %s will generate C variables based\n"),
prog_name_string);
fprintf(stderr, catgets(Dtb_project_catd, 1, 56,
fprintf(stderr, CATGETS(Dtb_project_catd, 1, 56,
"on the module filename. Please rename %s\n"), module_name_string);
exit(1);
}
@@ -628,7 +628,7 @@ write_module_files(
if ((genCodeInfo->resource_file != NULL) && (resFileName != NULL))
{
char *prog_name_string = util_get_program_name();
fprintf(stderr, catgets(Dtb_project_catd, 1, 57,
fprintf(stderr, CATGETS(Dtb_project_catd, 1, 57,
"%s: writing resources for %s into %s\n"),
prog_name_string,
uiCFileName,
@@ -888,7 +888,7 @@ write_project_files(
{
if (check_dates && force_write_c_file)
{
util_printf(catgets(Dtb_project_catd, 1, 58,
util_printf(CATGETS(Dtb_project_catd, 1, 58,
"generating %s because of changes in modules\n"),
stubsFileName);
}
@@ -1014,7 +1014,7 @@ write_make_file(
if (util_be_verbose())
{
char *prog_name_string = util_get_program_name();
fprintf(stderr, catgets(Dtb_project_catd, 1, 59,
fprintf(stderr, CATGETS(Dtb_project_catd, 1, 59,
"%s: Skipping user-defined %s\n"),
prog_name_string, curMakeFileName);
}
@@ -1037,7 +1037,7 @@ write_make_file(
if (actualOSType == AB_OS_UNDEF)
{
util_printf_err(catgets(Dtb_project_catd, 1, 60,
util_printf_err(CATGETS(Dtb_project_catd, 1, 60,
"Could not determine OS type of this machine\n"));
goto epilogue;
}
@@ -1049,7 +1049,7 @@ write_make_file(
/* The user has modified this file since we wrote it last */
if (util_be_verbose())
{
util_printf(catgets(Dtb_project_catd, 1, 61,
util_printf(CATGETS(Dtb_project_catd, 1, 61,
"Skipping user-defined %s\n"), actualMakeFileName);
}
}
@@ -1057,20 +1057,20 @@ write_make_file(
{
if (!util_be_silent())
{
util_printf(catgets(Dtb_project_catd, 1, 62,
util_printf(CATGETS(Dtb_project_catd, 1, 62,
"linking %s => %s\n"), curMakeFileName, actualMakeFileName);
}
rc = unlink(actualMakeFileName);
if (util_file_exists(actualMakeFileName))
{
util_printf_err(catgets(Dtb_project_catd, 1, 63,
util_printf_err(CATGETS(Dtb_project_catd, 1, 63,
"Could not remove %s\n"), actualMakeFileName);
return_code(-1);
}
rc = link(curMakeFileName, actualMakeFileName);
if (rc != 0)
{
util_printf_err(catgets(Dtb_project_catd, 1, 64,
util_printf_err(CATGETS(Dtb_project_catd, 1, 64,
"Could not create link to %s\n"), curMakeFileName);
return_code(-1);
}
@@ -1647,7 +1647,7 @@ check_and_replace_file(
if (orgFile == NULL)
{
fileSkippedReasonOut = ABMF_SKIP_ERR_OCCURRED;
util_printf_err(catgets(Dtb_project_catd, 1, 65, "%s: %s\n"),
util_printf_err(CATGETS(Dtb_project_catd, 1, 65, "%s: %s\n"),
fileName, strerror(errno));
return_code(-1);
}
@@ -1673,7 +1673,7 @@ check_and_replace_file(
if (file == NULL)
{
fileSkippedReasonOut = ABMF_SKIP_ERR_OCCURRED;
util_printf_err(catgets(Dtb_project_catd, 1, 65, "%s: %s\n"),
util_printf_err(CATGETS(Dtb_project_catd, 1, 65, "%s: %s\n"),
fileName, strerror(errno));
return_code(ERR_OPEN);
}
@@ -1767,7 +1767,7 @@ replace_file(STRING fileName, File fromFile, BOOL rewindFiles)
toFile = util_fopen_locked(fileName, "w");
if (toFile == NULL)
{
util_printf_err(catgets(Dtb_project_catd, 1, 65, "%s: %s\n"),
util_printf_err(CATGETS(Dtb_project_catd, 1, 65, "%s: %s\n"),
fileName, strerror(errno));
return ERR_OPEN;
}
@@ -1787,7 +1787,7 @@ print_progress_message(int verbosity, STRING message, STRING fileName)
{
if (util_get_verbosity() >= verbosity)
{
util_printf_err(catgets(Dtb_project_catd, 1, 67, "%s %s\n"),
util_printf_err(CATGETS(Dtb_project_catd, 1, 67, "%s %s\n"),
message, fileName);
}
return 0;
@@ -1802,15 +1802,15 @@ print_skipping_message(STRING fileName, ABMF_SKIP_WHY why)
switch (why)
{
case ABMF_SKIP_NO_CHANGES:
util_printf(catgets(Dtb_project_catd, 1, 68,
util_printf(CATGETS(Dtb_project_catd, 1, 68,
"skipping (no changes) %s\n"), fileName);
break;
case ABMF_SKIP_UP_TO_DATE:
util_printf(catgets(Dtb_project_catd, 1, 69,
util_printf(CATGETS(Dtb_project_catd, 1, 69,
"skipping (up-to-date) %s\n"), fileName);
break;
case ABMF_SKIP_ERR_OCCURRED:
util_printf(catgets(Dtb_project_catd, 1, 70,
util_printf(CATGETS(Dtb_project_catd, 1, 70,
"skipping due to errors %s\n"), fileName);
break;
}
@@ -1824,7 +1824,7 @@ print_backing_up_message(STRING fileFromName, STRING fileToName)
{
if (util_be_verbose())
{
util_printf(catgets(Dtb_project_catd, 1, 71,
util_printf(CATGETS(Dtb_project_catd, 1, 71,
"saving previous %s to %s\n"), fileFromName, fileToName);
}
return 0;

View File

@@ -931,12 +931,12 @@ abmfP_write_add_callbacks_and_actions(
util_strsafe(util_when_to_string(when));
if(src_obj_name == NULL) {
util_printf_err(catgets(Dtb_project_catd, 1, 74,
util_printf_err(CATGETS(Dtb_project_catd, 1, 74,
"Ignoring unsupported WHEN - obj:<unnamed> when:%s\n"),
when_string);
}
else {
util_printf_err(catgets(Dtb_project_catd, 1, 75,
util_printf_err(CATGETS(Dtb_project_catd, 1, 75,
"Ignoring unsupported WHEN - obj:%s when:%s\n"),
src_obj_name, when_string);
}

View File

@@ -116,7 +116,7 @@ abmfP_catgets_prefix_str(
goto cret;
MsgSet_set_msg_is_referenced(msg_set, msg_num, TRUE);
sprintf(str_catg, "catgets(Dtb_project_catd, %d, %d, ",
sprintf(str_catg, "CATGETS(Dtb_project_catd, %d, %d, ",
MsgSet_get_number(msg_set),
msg_num);

View File

@@ -136,7 +136,7 @@ static char *Session_Includes[] =
*/
static char *I18n_Includes[] =
{
"<nl_types.h>",
"<Dt/MsgCatP.h>",
NULL,
};
@@ -997,7 +997,7 @@ write_main_msg_i18n(
abio_puts(codeFile, abmfP_comment_end);
abio_puts(codeFile,
"Dtb_project_catd = catopen(DTB_PROJECT_CATALOG, NL_CAT_LOCALE);\n");
"Dtb_project_catd = CATOPEN(DTB_PROJECT_CATALOG, NL_CAT_LOCALE);\n");
abio_puts(codeFile, "if (Dtb_project_catd == (nl_catd)-1)\n");
abmfP_write_c_block_begin(genCodeInfo);
abio_puts(codeFile,

View File

@@ -81,7 +81,7 @@ static int write_i18n_declarations(GenCodeInfo genCodeInfo, ABObj project);
*/
static char *I18n_Includes[] =
{
"<nl_types.h>",
"<Dt/MsgCatP.h>",
NULL,
};

View File

@@ -1192,7 +1192,7 @@ abmfP_write_action_function(
default:
{
char *obj_name_string = obj_get_name(fromObj);
util_printf_err(catgets(Dtb_project_catd, 1, 78,
util_printf_err(CATGETS(Dtb_project_catd, 1, 78,
"unknown function type for action from object, %s"),
obj_name_string);
return_code(ERR);
@@ -1469,13 +1469,13 @@ write_builtin_action(
if (obj_get_name(action) != NULL)
{
char *action_name = obj_get_name(action);
sprintf(msg, catgets(Dtb_project_catd, 1, 76,
sprintf(msg, CATGETS(Dtb_project_catd, 1, 76,
"Unknown action name, %s"), action_name);
}
else
{
int action_type = obj_get_func_builtin(action);
sprintf(msg, catgets(Dtb_project_catd, 1, 77,
sprintf(msg, CATGETS(Dtb_project_catd, 1, 77,
"Unknown action type, %d"), action_type);
}
util_error(msg);

View File

@@ -380,7 +380,7 @@ abmfP_calloc(size_t n, size_t size)
if (p = (STRING) calloc(n, size))
return p;
util_error(catgets(Dtb_project_catd, 1, 83, "calloc: out of memory"));
util_error(CATGETS(Dtb_project_catd, 1, 83, "calloc: out of memory"));
return NULL;
}
@@ -394,7 +394,7 @@ abmfP_malloc(size_t size)
if (p = malloc(size))
return p;
util_error(catgets(Dtb_project_catd, 1, 84, "malloc: out of memory"));
util_error(CATGETS(Dtb_project_catd, 1, 84, "malloc: out of memory"));
return NULL;
}
@@ -408,7 +408,7 @@ abmfP_realloc(void *buf, unsigned int size)
if (p = realloc(buf, size))
return p;
util_error(catgets(Dtb_project_catd, 1, 85, "realloc: out of memory"));
util_error(CATGETS(Dtb_project_catd, 1, 85, "realloc: out of memory"));
return NULL;
}