1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include "uti/sge_mtutil.h"
#include "uti/sge_rmon.h"
#include "uti/sge_language.h"
#include "uti/sge_prog.h"
#include "uti/sge_htable.h"
#include "basis_types.h"
#ifdef __SGE_COMPILE_WITH_GETTEXT__
/* MT-NOTE: language_mutex guards all language module function calls */
static pthread_mutex_t language_mutex = PTHREAD_MUTEX_INITIALIZER;
# define LANGUAGE_LOCK() sge_mutex_lock("language_mutex", SGE_FUNC, __LINE__, &language_mutex)
# define LANGUAGE_UNLOCK() sge_mutex_unlock("language_mutex", SGE_FUNC, __LINE__, &language_mutex)
/*
* environment variable "SGE_ENABLE_MSG_ID"
* supported values: 0 - off
* 1 - on for error messages
* 2 - on for every message
*/
#define SGE_ENABLE_MSG_ID "SGE_ENABLE_MSG_ID"
#define PACKAGE "GRIDPACKAGE"
#define LOCALEDIR "GRIDLOCALEDIR"
#define SGE_DEFAULT_PACKAGE "gridengine"
#define SGE_DEFAULT_LOCALEDIR "locale"
/* this is to define the functions for the internationalization
tools */
typedef struct {
gettext_func_type gettext_func ;
setlocale_func_type setlocale_func ;
bindtextdomain_func_type bindtextdomain_func ;
textdomain_func_type textdomain_func ;
} language_functions_struct;
typedef struct {
int id; /* message identification number */
int category; /* message category: 0 = common */
u_long32 counter; /* number of calls */
const char* message; /* message string */
const char* local_message; /* local translated message */
} sge_error_message_t;
static pthread_once_t message_id_once = PTHREAD_ONCE_INIT;
static void message_id_once_init(void);
static pthread_key_t message_id_key;
static void message_id_destroy(void* theState);
static language_functions_struct sge_language_functions;
static int sge_enable_msg_id = 0; /* used to enable/disable message ids */
static int sge_enable_msg_id_to_every_message = 0;
static htable sge_message_hash_table = NULL;
/* this is to find out if the sge_init_language_func() was called */
static bool sge_are_language_functions_installed = false;
static int sge_get_message_id_output_implementation(void);
/****** uti/language/sge_init_language() **************************************
* NAME
* sge_init_language() -- initialize language package for gettext()
*
* SYNOPSIS
* int sge_init_language(char* package, char* localeDir)
*
*
* FUNCTION
* starts up the language initialization for gettext(). This
* function should be called nearly after the main() function.
*
* sge_init_language_func() must be called first to install the
* correct function pointers for gettext() setlocale() etc. etc.
*
* INPUTS
* char* package - package name like "gridengine" of binary
* package *.mo file.
* (if package is NULL sge_init_language tries
* to get the package name from the invironment
* variable "GRIDPACKAGE").
* char* localeDir - path to the localisazion directory
* (if localeDir is NULL sge_init_language
* tries to get the localization directory path
* from the invironment variable
* "GRIDLOCALEDIR").
*
* RESULT
* int state - true for seccess, false on error.
*
* NOTES
* MT-NOTE: sge_init_languagefunc() is guarded by language_mutex
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
******************************************************************************/
int sge_init_languagefunc(char *package, char *localeDir)
{
char* packName = NULL;
char* locDir = NULL;
char* language = NULL;
char* language_var = NULL;
char* pathName = NULL;
char* sge_enable_msg_id_string = NULL;
int success = false;
int back;
int stop = 0;
DENTER_(TOP_LAYER, "sge_init_language");
LANGUAGE_LOCK();
DPRINTF_(("****** starting localization procedure ... **********\n"));
while ( stop <= 2 ) {
/* free memory for evt. second run */
sge_free(&packName);
sge_free(&locDir);
sge_free(&language);
sge_free(&language_var);
sge_free(&pathName);
/* try to get the package name */
if (package != NULL) {
packName = strdup(package);
} else if (getenv(PACKAGE) != NULL) {
packName = strdup(getenv(PACKAGE));
DPRINTF_(("try to get language package name from environment "SFQ"\n",PACKAGE));
} else {
DPRINTF_(("could not get environment variable "SFQ"\n", PACKAGE));
}
/* no package name given, using default one */
if (packName == NULL) {
packName = malloc(sizeof(char)*(strlen(SGE_DEFAULT_PACKAGE)+strlen(sge_get_arch()) + 2));
/* RATS: ignore */
sprintf(packName, "%s/%s", sge_get_arch(), SGE_DEFAULT_PACKAGE);
}
/* try to get the localization directory */
if (localeDir != NULL) {
locDir = strdup(localeDir);
} else if ( getenv(LOCALEDIR) != NULL ) {
if (stop != 0) {
DPRINTF_(("ignoring environment "SFQ"\n",LOCALEDIR ));
} else {
locDir = strdup(getenv(LOCALEDIR)); /* only the first time */
stop++;
DPRINTF_(("try to get language package directory path from environment "SFQ"\n",LOCALEDIR));
}
} else {
DPRINTF_(("could not get environment variable "SFQ"\n", LOCALEDIR));
}
/* no directory given, using default one */
if (locDir == NULL) {
const char *sge_root = sge_get_root_dir(0, NULL, 0, 0);
char* root = NULL;
if (sge_root != NULL) {
root = strdup(sge_root);
}
if ( root == NULL ) {
locDir = strdup("/usr/lib/locale");
} else {
locDir = malloc(sizeof(char)*(strlen(root)+strlen(SGE_DEFAULT_LOCALEDIR) + 100));
/* RATS: ignore */
sprintf(locDir, "%s/%s", root, SGE_DEFAULT_LOCALEDIR);
}
sge_free(&root);
}
/* try to get a language stylename (only for output of package path) */
if (getenv("LANGUAGE") != NULL) {
language_var = strdup(getenv("LANGUAGE"));
} else {
if (getenv("LANG") != NULL) {
language_var = strdup(getenv("LANG"));
}
}
if (language_var == NULL) {
DPRINTF_(("environment LANGUAGE or LANG is not set; no language selected - using defaults\n"));
language_var = strdup("C");
}
/* get correct language value */
if ( sge_language_functions.setlocale_func != NULL ) {
char* help1 = NULL;
help1 = sge_language_functions.setlocale_func(LC_MESSAGES, "");
if (help1 != NULL) {
char* slash_pos = NULL;
DPRINTF_(("setlocale() returns \"%s\"\n",help1));
slash_pos = strstr(help1,"_");
if (slash_pos != NULL) {
char* tmp_lang = NULL;
DPRINTF_(("cutting of language string after \"_\":\n"));
tmp_lang = strdup(help1);
slash_pos = strstr(tmp_lang,"_");
*slash_pos = 0; /* cut off "_" */
language = strdup(tmp_lang);
sge_free(&tmp_lang);
} else {
language = strdup(help1);
}
} else {
DPRINTF_(("setlocale() returns NULL"));
language = strdup(language_var);
}
}
/* packName, locDir and language strings are now surely not NULL,
so we can now try to setup the choosen language package (*.mo - file) */
pathName = malloc(sizeof(char)*(strlen(locDir)+strlen(language)+strlen(packName)+100));
/* RATS: ignore */
sprintf(pathName,"%s/%s/LC_MESSAGES/%s.mo",locDir,language,packName);
DPRINTF_(("locale directory: >%s<\n",locDir));
DPRINTF_(("package file: >%s.mo<\n",packName));
DPRINTF_(("language (LANG): >%s<\n",language));
DPRINTF_(("loading message file: %s\n",pathName ));
/* is the package file allright */
back = open (pathName, O_RDONLY);
if (back >= 0) {
DPRINTF_(("found message file - ok\n"));
success = true;
close(back);
stop = 2;
} else {
DPRINTF_(("could not open message file - error\n"));
success = false;
}
if(stop==0) {
stop = 2; /* only when stop = 1: Try to repeat without LOCALEDIR environment variable */
}
stop++;
}
/* now startup the language package for gettext */
/* setlocale(LC_ALL, ""); */
if ( (sge_language_functions.setlocale_func != NULL ) &&
(sge_language_functions.bindtextdomain_func != NULL) &&
(sge_language_functions.textdomain_func != NULL ) &&
(sge_are_language_functions_installed == true ) ) {
char* help1 = NULL;
help1 = sge_language_functions.setlocale_func(LC_MESSAGES, "");
if (help1 != NULL) {
DPRINTF_(("setlocale() returns \"%s\"\n",help1));
} else {
DPRINTF_(("setlocale() returns NULL\n"));
}
help1 = sge_language_functions.bindtextdomain_func(packName, locDir );
if (help1 != NULL) {
DPRINTF_(("bindtextdomain() returns \"%s\"\n",help1));
}else {
DPRINTF_(("bindtextdomain() returns NULL\n"));
}
help1 = sge_language_functions.textdomain_func(packName);
if (help1 != NULL) {
DPRINTF_(("textdomain() returns \"%s\"\n",help1));
}else {
DPRINTF_(("textdomain() returns NULL\n"));
}
} else {
DPRINTF_(("sge_init_language() called without valid sge_language_functions pointer!\n"));
success = false;
}
sge_free(&packName);
sge_free(&locDir);
sge_free(&language);
sge_free(&language_var);
sge_free(&pathName);
if (success == true) {
sge_enable_msg_id = 1;
}
sge_enable_msg_id_string = getenv(SGE_ENABLE_MSG_ID);
if (sge_enable_msg_id_string != NULL) {
int env_value = 0;
DPRINTF_(("SGE_ENABLE_MSG_ID is set to \"%s\"\n", sge_enable_msg_id_string));
env_value = atoi(sge_enable_msg_id_string);
if (env_value == 0) {
sge_enable_msg_id = 0;
} else {
sge_enable_msg_id = 1;
}
if (env_value == 2) {
sge_enable_msg_id_to_every_message = 1;
}
}
if (sge_enable_msg_id == 0) {
DPRINTF_(("error id output : disabled\n"));
} else {
DPRINTF_(("error id output : enabled\n"));
}
if (success == true) {
DPRINTF_(("****** starting localization procedure ... success **\n"));
} else {
DPRINTF_(("****** starting localization procedure ... failed **\n"));
}
LANGUAGE_UNLOCK();
DRETURN_(success);
}
/****** uti/language/sge_init_language_func() **********************************
* NAME
* sge_init_language() -- install language functions
*
* SYNOPSIS
* void sge_init_language_func(gettext_func_type new_gettext,
* setlocale_func_type new_setlocale,
* bindtextdomain_func_type new_bindtextdomain,
* textdomain_func_type new_textdomain);
*
* FUNCTION
* set the function pointer for the gettext(), setlocale(),
* bindtextdomain() and textdomain() function calls. This function
* must called before any call to sge_init_language() and
* sge_gettext().
*
* INPUTS
* gettext_func_type - pointer for gettext()
* setlocale_func_type - pointer for setlocale()
* bindtextdomain_func_type - pointer for bindtextdomain()
* textdomain_func_type - pointer for textdomain()
*
* NOTES
* MT-NOTE: sge_init_language_func() is guarded by language_mutex
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
******************************************************************************/
void sge_init_language_func(gettext_func_type new_gettext,
setlocale_func_type new_setlocale,
bindtextdomain_func_type new_bindtextdomain,
textdomain_func_type new_textdomain)
{
DENTER_(TOP_LAYER, "sge_init_language_func");
LANGUAGE_LOCK();
/* initialize the functions pointer to NULL */
sge_language_functions.gettext_func = NULL;
sge_language_functions.setlocale_func = NULL;
sge_language_functions.bindtextdomain_func = NULL;
sge_language_functions.textdomain_func = NULL;
/* ok, the functions have now NULL pointer */
sge_are_language_functions_installed = true;
/* set the new functions */
if (new_gettext != NULL) {
sge_language_functions.gettext_func = new_gettext;
}
if (new_setlocale != NULL) {
sge_language_functions.setlocale_func = new_setlocale;
}
if (new_bindtextdomain != NULL) {
sge_language_functions.bindtextdomain_func = new_bindtextdomain;
}
if (new_textdomain != NULL) {
sge_language_functions.textdomain_func = new_textdomain;
}
LANGUAGE_UNLOCK();
DRETURN_VOID_;
}
/****** uti/language/sge_set_message_id_output() *******************************
* NAME
* sge_set_message_id_output() -- enable message id number adding
*
* SYNOPSIS
* void sge_set_message_id_output(int flag)
*
* FUNCTION
* This procedure is used to enable the adding of message id's when
* showing error messages. This function is used in the macro
* SGE_ADD_MSG_ID(x) to enable the message id for errors.
*
* INPUTS
* int flag - 0 = off ; 1 = on
*
* NOTES
* MT-NOTE: sge_set_message_id_output() is guarded by language_mutex
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
*******************************************************************************/
void sge_set_message_id_output(int flag) {
int *buf = NULL;
DENTER_(CULL_LAYER, "sge_set_message_id_output");
pthread_once(&message_id_once, message_id_once_init);
buf = (int*) pthread_getspecific(message_id_key);
if (buf != NULL) {
*buf = flag;
}
DRETURN_VOID_;
}
/****** uti/language/sge_get_message_id_output() *******************************
* NAME
* sge_get_message_id_output() -- check if message id should be added
*
* SYNOPSIS
* int sge_get_message_id_output(void)
*
* FUNCTION
* This function returns the value stored in the static global
* variable sge_message_id_view_flag.
*
* RESULT
* int - value of sge_message_id_view_flag
*
* NOTES
* MT-NOTE: sge_get_message_id_output() is guarded by language_mutex
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
* uti/language/sge_get_message_id_output_implementation()
*******************************************************************************/
int sge_get_message_id_output(void)
{
int ret;
DENTER_(TOP_LAYER, "sge_get_message_id_output");
LANGUAGE_LOCK();
ret = sge_get_message_id_output_implementation();
LANGUAGE_UNLOCK();
DRETURN_(ret);
}
/****** uti/language/sge_get_message_id_output_implementation() ***************
* NAME
* sge_get_message_id_output_implementation() -- pure implementation of
* sge_get_message_id_output_implementation() that does not lock
* language_mutex
*
* SYNOPSIS
* int sge_get_message_id_output_implementation(void)
*
* FUNCTION
* When the sge_get_message_id_output() functionality is needed from within
* the language modules the language_mutex may not be obtained because this
* mutex is already owned by the same thread.
*
* RESULT
* int - value of sge_message_id_view_flag
*
* NOTES
* MT-NOTE: The caller of sge_get_message_id_output_implementation() must
* MT-NOTE: have obtained the language_mutex mutex due to access to
* MT-NOTE: 'sge_enable_msg_id' and 'sge_enable_msg_id_to_every_message'.
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
*******************************************************************************/
static int sge_get_message_id_output_implementation(void)
{
int *buf;
DENTER_(CULL_LAYER, "sge_get_message_id_output_implementation");
if (sge_enable_msg_id_to_every_message == 1) {
DRETURN_(1);
}
if (sge_enable_msg_id == 0) {
DRETURN_(0);
}
pthread_once(&message_id_once, message_id_once_init);
buf = (int*) pthread_getspecific(message_id_key);
if (buf == NULL) {
DRETURN_(0);
} else {
DRETURN_(*buf);
}
}
/****** uti/language/sge_gettext() *********************************************
* NAME
* sge_gettext() -- dummy gettext() function
*
* SYNOPSIS
* const char* sge_gettext(char *x)
*
* FUNCTION
* This function returns the given argument
*
* INPUTS
* char *x - string
*
* RESULT
* const char* - input string
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
*******************************************************************************/
const char *sge_gettext(char *x) {
return x;
}
/****** uti/language/sge_gettext_() ********************************************
* NAME
* sge_gettext_() -- add error id to message
*
* SYNOPSIS
* const char* sge_gettext_(int msg_id, const char *msg_str)
*
* FUNCTION
* This function is used for adding the message id to the translated
* gettext message string. The message id is only added when the
* function sge_get_message_id_output() returns not "0" and the
* message string contains at least one SPACE character.
*
* INPUTS
* int msg_id - message id
* const char *msg_str - message to translate
*
* RESULT
* const char* - translated (L10N) message with message id
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
*******************************************************************************/
const char *sge_gettext_(int msg_id, const char *msg_str)
{
/* extern */
#ifndef __SGE_COMPILE_WITH_GETTEXT__
return msg_str;
#else
union {
sge_error_message_t *l;
void *p;
} message_p;
long key;
DENTER_(CULL_LAYER, "sge_gettext_");
message_p.l = NULL;
if (msg_str == NULL) {
DRETURN_(NULL);
}
key = msg_id;
/* check if message is not just one word (strstr) */
if ( (sge_get_message_id_output_implementation() != 0) &&
(strstr(msg_str, " ") != NULL) ) {
if (sge_message_hash_table == NULL) {
sge_message_hash_table = sge_htable_create(8, /* 2^8 = 256 table start size */
dup_func_long,
hash_func_long,
hash_compare_long);
}
if (sge_htable_lookup(sge_message_hash_table, &key, (const void**)&message_p.p) == False) {
/* add element */
sge_error_message_t* new_mp = NULL;
char* org_message = NULL;
char* trans_message = NULL;
const char* gettext_return_string = NULL;
size_t len;
gettext_return_string = sge_gettext__((char*)msg_str);
org_message = malloc(strlen(msg_str)+1);
len = strlen(gettext_return_string)+1+8; /* max "(99999) "*/
trans_message = malloc(len);
new_mp = malloc(sizeof(sge_error_message_t));
if (new_mp != NULL && org_message != NULL && trans_message != NULL) {
DPRINTF_(("add new hash table entry for message id: %d\n",msg_id));
new_mp->id = msg_id;
new_mp->category = 0;
new_mp->counter = 1;
strcpy(org_message, msg_str); /* RATS: ignore */
new_mp->message = org_message;
if (msg_id <= 99999) {
/* RATS: ignore */
snprintf(trans_message, len, "[%d] %s", msg_id, gettext_return_string);
} else {
snprintf(trans_message, len, "%s", gettext_return_string);
}
new_mp->local_message = trans_message;
sge_htable_store(sge_message_hash_table, &key, new_mp);
DRETURN_(new_mp->local_message);
}
} else {
/* check element */
DPRINTF_(("using old hash entry for message id: %d\n",msg_id));
if (strcmp(msg_str,message_p.l->message) != 0) {
DPRINTF_(("duplicate message id error: returning gettext() message"));
DPRINTF_(("msg in : \"%s\"\n",msg_str));
DPRINTF_(("msg out: \"%s\"\n",message_p.l->message));
DRETURN_(sge_gettext__((char*)msg_str));
} else {
message_p.l->counter = (message_p.l->counter) + 1;
DPRINTF_(("message count: "sge_U32CFormat"\n", sge_u32c(message_p.l->counter)));
DRETURN_(message_p.l->local_message);
}
}
}
DRETURN_(sge_gettext__((char*)msg_str));
#endif
}
/****** uti/language/sge_gettext__() *******************************************
* NAME
* sge_gettext__() -- get translated message from message file
*
* SYNOPSIS
* char *sge_gettext__(char *x)
*
* FUNCTION
* makes a call to sge_language_functions.gettext_func(x) if
* gettext_func is not NULL, otherwise it returns the input
* string.
*
* INPUTS
* char *x - pointer to message which should be internationalizied
*
* RESULT
* char* - pointer internationalized message
*
* NOTE
* MT-NOTE: not guarded b/c sge_gettext__() is used only in infotext utility
*
* SEE ALSO
* uti/language/sge_init_language()
* uti/language/sge_init_language_func()
* uti/language/sge_gettext()
* uti/language/sge_gettext_()
* uti/language/sge_gettext__()
* uti/language/sge_get_message_id_output()
* uti/language/sge_set_message_id_output()
*******************************************************************************/
const char *sge_gettext__(char *x)
{
char *z;
DENTER_(BASIS_LAYER, "sge_gettext__");
if ( (sge_language_functions.gettext_func != NULL) &&
(sge_are_language_functions_installed == true) ) {
z = sge_language_functions.gettext_func(x);
} else {
z = x;
DPRINTF_(("sge_gettext() called without valid gettext function pointer!\n"));
}
/*z = gettext(x);*/
/*DPRINTF_(("gettext: '%s' -> '%s'\n", x ? x : "", z ? z : ""));*/
DRETURN_(z);
}
static void message_id_destroy(void* theState)
{
sge_free(&theState);
}
static void message_id_once_init(void)
{
int *buf;
int res;
pthread_key_create(&message_id_key, &message_id_destroy);
buf = (int*) sge_malloc(sizeof(int));
*buf = 0;
res = pthread_setspecific(message_id_key, (const void*)buf);
if (0 != res) {
fprintf(stderr, "pthread_set_specific(%s) failed: %s\n", "log_buffer_getspecific", strerror(res));
abort();
}
}
#endif
|