summaryrefslogtreecommitdiffstats
path: root/lib/libsi18n
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libsi18n')
-rw-r--r--lib/libsi18n/coreres.c141
-rw-r--r--lib/libsi18n/coreres.h52
-rw-r--r--lib/libsi18n/getlang.c330
-rw-r--r--lib/libsi18n/getstrmem.c160
-rw-r--r--lib/libsi18n/getstrprop.c85
-rw-r--r--lib/libsi18n/propset.c442
-rw-r--r--lib/libsi18n/propset.h80
7 files changed, 14 insertions, 1276 deletions
diff --git a/lib/libsi18n/coreres.c b/lib/libsi18n/coreres.c
deleted file mode 100644
index e20d07a6..00000000
--- a/lib/libsi18n/coreres.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include "i18n.h"
-
-#include "propset.h"
-
-#include "coreres.h"
-
-Resource* core_res_init_resource(const char* path, const char* package)
-{
- PropertiesSet *propset;
- char *directory;
- char *filename;
- char *file_path;
- char *p, *q;
- char *filep;
- Resource *hres;
-
- /*********************
- Create full path information
- eg. ./es40/admin and cgi.bin.start ==>
- ./es40/admin/cgi/bin/start.properties
- **********************/
- file_path = (char *) malloc (strlen(path) + strlen(package) + 20);
-
-
- strcpy(file_path, path);
- if (path[strlen(path)-1] != '/')
- strcat(file_path, "/");
-
- p = file_path + strlen(file_path);
- q = (char *) package;
-
- filep = p - 1;
-
- /* Append package to file_path
- p: end positon of path + 1
- q: start position of package
- */
- while (q && *q) {
- if (*q == '.') {
- filep = q;
- *p ++ = '/';
- }
- else
- *p ++ = *q ++;
-
- }
- *p = '\0';
-
- *filep = '\0';
- filename = filep + 1;
- directory = file_path;
-
- propset = PropertiesInit (directory, filename);
-
- if (propset == NULL)
- return NULL;
-
- hres = (Resource *) malloc(sizeof(Resource));
- memset(hres, 0, sizeof(Resource));
-
- hres->path = strdup(file_path);
- hres->propset = propset;
-
- if (file_path)
- free (file_path);
-
- return hres;
-}
-
-const char *core_res_getstring(Resource *hres, char *key, ACCEPT_LANGUAGE_LIST lang)
-{
-
- if (key == NULL)
- return NULL;
-
- if (hres) {
- return PropertiesGetString(hres->propset, key, lang);
- }
-
- return NULL;
-}
-
-void core_res_destroy_resource(Resource *hres)
-{
- if (hres) {
- if (hres->path)
- free(hres->path);
- if (hres->package)
- free(hres->package);
- PropertiesDestroy(hres->propset);
-
- free(hres);
- }
-}
-
diff --git a/lib/libsi18n/coreres.h b/lib/libsi18n/coreres.h
deleted file mode 100644
index 8ad815a4..00000000
--- a/lib/libsi18n/coreres.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifndef CORERES_H
-#define CORERES_H
-
-#include "i18n.h"
-
-Resource* core_res_init_resource(const char* path, const char* package);
-const char *core_res_getstring(Resource *hres, char *key, ACCEPT_LANGUAGE_LIST lang);
-void core_res_destroy_resource(Resource *hres);
-
-#endif
diff --git a/lib/libsi18n/getlang.c b/lib/libsi18n/getlang.c
deleted file mode 100644
index f8cb649b..00000000
--- a/lib/libsi18n/getlang.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "libadmin/libadmin.h"
-
-
-#include "i18n.h"
-
-/*********************************************************************
- strReplace replaces the first instance of from in target with to.
- from can be "": to is inserted at start of target.
- to can be "": from is removed from target.
- if from is not found, 0 is returned; else 1 is returned.
- *********************************************************************/
-
-static int
-strReplace(char* target,char* from,char* to)
-{
- /* replace /from/to/ in target */
-
- char* pFrom;
- char* pOldTail;
- int lenTo;
-
- pFrom = strstr(target,from);
- if (pFrom) {
- pOldTail = pFrom+strlen(from);
- lenTo = strlen(to);
- memmove(pFrom+lenTo,pOldTail,strlen(pOldTail)+1);
- memcpy(pFrom,to,lenTo);
- return 1;
- }
-
- return 0;
-}
-
-/*********************************************************************
- statFileDir is a wrapper to stat() that strips trailing slashes
- because stat() on Windows seems to return -1 otherwise.
-*********************************************************************/
-
-int
-statFileDir(const char *path, struct stat *info) {
- int ret, pathlen;
- char *newpath = strdup(path);
-
- if(newpath == NULL)
- return -1;
-
- for (pathlen = (strlen(newpath) - 1); pathlen >= 0; pathlen--) {
- if (newpath[pathlen] == '/' || newpath[pathlen] == '\\') {
- newpath[pathlen] = '\0';
- } else {
- break;
- }
- }
-
- ret = stat(newpath, info);
-
- if (newpath)
- free(newpath);
-
- return ret;
-}
-
-/*********************************************************************
- GetLanguage is reserved for future use. These APIs are not belong
- to this file. It needs to be moved to somewhere which knows what's
- the current language setting.
- *********************************************************************/
-
-static char emptyString[] = "";
-
-static char client_language[128] = "en";
-static char admin_language[128] = "en";
-static char default_language[128] = "en";
-
-void
-SetLanguage(int type, char *language)
-{
- switch(type) {
- case CLIENT_LANGUAGE:
- if (language)
- strcpy(client_language, language);
- break;
- case ADMIN_LANGUAGE:
- if (language)
- strcpy(admin_language, language);
- break;
- case DEFAULT_LANGUAGE:
- if (language)
- strcpy(default_language, language);
- break;
- }
- return ;
-}
-
-
-
-char*
-GetClientLanguage(void)
-{
- if (client_language)
- return client_language;
- else
- return emptyString;
-}
-
-char*
-GetAdminLanguage(void)
-{
- if (admin_language)
- return admin_language;
- else
- return emptyString;
-}
-
-char*
-GetDefaultLanguage(void)
-{
- if (default_language)
- return default_language;
- else
- return "en";
-}
-
-/*********************************************************************
- GetFileForLanguage looks for a file in the appropriate language.
- *********************************************************************/
-
-NSAPI_PUBLIC
-int
-GetFileForLanguage(char* filePath,char* language,char* existingFilePath)
-{
- /* Input: filePath,language
- * filePath is of the form "/xxx/xxx/$$LANGDIR/xxx/xxx/filename"
- * or of the form "/xxx/xxx/xxx/xxx/filename".
- * filename may or may not have an extension.
- * language is an Accept-Language list; each language-range will be
- * tried as a subdirectory name and possibly as a filename modifier.
- * "*" is ignored - default always provided if needed.
- * "-" is replaced by "_".
- * $$LANGDIR is a special string replaced by language. It is optional.
- * For the default case, $$LANGDIR/ is replaced by nothing
- * (so // is not created).
- *
- * Returned: existingPath
- * existingFilePath is the path of a satisfactory, existing file.
- * if no file is found, an empty string "" is returned.
- *
- * int returned: -1 if no file found (existingFilePath = "")
- * 0 if default file is returned
- * 1 if language file is returned (any in list)
- *
- * Example:
- * filePath = "/path/$$LANGDIR/filename.ext"
- * language = "language"
- * GetDefaultLanguage() --> "default"
- * LANG_DELIMIT = "_"
- *
- * 1. Try: "/path/language/filename.ext"
- * 2. Try: "/path/filename_language.ext"
- * 3. Try: "/path/default/filename.ext"
- * 4. Try: "/path/filename_default.ext"
- * 5. Try: "/path/filename.ext"
- * else: ""
- *
- * Example:
- * language = "en-us;q=0.6,ja;q=0.8,en-ca"
- *
- * 1. Try: "/path/en-ca/filename.ext"
- * 2. Try: "/path/filename_en_ca.ext"
- * 3. Try: "/path/ja/filename.ext"
- * 4. Try: "/path/filename_ja.ext"
- * 5. Try: "/path/en_us/filename.ext"
- * 6. Try: "/path/filename_en_us.ext"
- * 7. Try: "/path/default/filename.ext"
- * 8. Try: "/path/filename_default.ext"
- * 9. Try: "/path/filename.ext"
- * else: ""
- *
- */
-
-#define LANG_DELIMIT '_'
-
- int pattern;
- char* pDot;
- char* pSlash;
-
- /* PRFileInfo info; */
- struct stat info;
-
- char lang_modifier[MAX_ACCEPT_LENGTH+1];
-
- ACCEPT_LANGUAGE_LIST acceptLanguageList;
- int numLang;
- int iLang;
- int iCase;
-
-
- /* escape in case XP_InitStringDatabase has not been called */
- if (filePath==NULL) {
- *existingFilePath = '\0';
- return -1;
- }
-
- pattern = (strstr(filePath,"$$LANGDIR/")!=NULL);
-
- for ( iCase=1 ; iCase>=0 ; iCase-- ) {
- if (iCase==1) { /* iCase=1 tries requested language */
- numLang = XP_AccLangList(language,acceptLanguageList);
- } else { /* iCase=0 tries default language */
- numLang = XP_AccLangList(GetDefaultLanguage(),acceptLanguageList);
- }
-
- for ( iLang=0 ; iLang<numLang ; iLang++ ) {
-
- /* Try: /path/language/filename.ext */
- if (pattern) {
- strcpy(existingFilePath,filePath);
- strReplace(existingFilePath,"$$LANGDIR",acceptLanguageList[iLang]);
-
- if (statFileDir(existingFilePath,&info)==0) {
- return iCase;
- }
-
- /*
- if (PR_GetFileInfo(existingFilePath,&info)==PR_SUCCESS) {
- return iCase;
- }
- */
- }
-
- /* Try: /path/filename_language.ext */
- {
- strcpy(existingFilePath,filePath);
- strReplace(existingFilePath,"$$LANGDIR/",emptyString);
- pDot = strrchr(existingFilePath,'.');
- pSlash = strrchr(existingFilePath,'/');
- if (pSlash>=pDot) {
- pDot = strchr(existingFilePath,'\0');
- }
- sprintf(lang_modifier,"%c%s",LANG_DELIMIT,acceptLanguageList[iLang]);
- strReplace(pDot,emptyString,lang_modifier);
-
- if (statFileDir(existingFilePath,&info)==0) {
- return iCase;
- }
-
- /*
- if (PR_GetFileInfo(existingFilePath,&info)==PR_SUCCESS) {
- return iCase;
- }
- */
- }
- }
- }
-
- /* Try: /path/filename.ext */
- {
- strcpy(existingFilePath,filePath);
- strReplace(existingFilePath,"$$LANGDIR/",emptyString);
-
- if (statFileDir(existingFilePath,&info)==0) {
- return 0;
- }
-
- /*
- if (PR_GetFileInfo(existingFilePath,&info)==PR_SUCCESS) {
- return 0;
- }
- */
- }
-
- /* Else: */
- *existingFilePath = '\0';
- return -1;
-}
-
-
-
-
-
-
diff --git a/lib/libsi18n/getstrmem.c b/lib/libsi18n/getstrmem.c
deleted file mode 100644
index 2beb3472..00000000
--- a/lib/libsi18n/getstrmem.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-
-#include <stdio.h>
-#include <string.h>
-
-#define COMPILE_STRINGS_IN_MEMORY
-
-static char emptyString[] = "";
-
-#ifdef COMPILE_STRINGS_IN_MEMORY
-
-typedef struct DATABIN {
- char* pLibraryName;
- char** pArrayOfLibraryStrings;
- unsigned numberOfStringsInLibrary;
- } DATABIN;
-
-#include "getstrmem.h"
-
-#endif
-
-#if 0 /* Example of getstrmem.h */
- /* It is intended that this header file be generated by program dblink */
-
- #define NUM_BUCKETS 2 /* must be power of 2 */
-
- /* strings in library libalpha */
- static char* libalpha[] = {
- "",
- "libalpha string 1",
- "libalpha string 2",
- "libalpha string 3",
- "libalpha string 4",
- emptyString };
-
- /* strings in library libbeta */
- static char* libbeta[] = {
- "",
- "libbeta string 1",
- "libbeta string 2",
- emptyString };
-
- /* libraries in bucket for hashKey==0 */
- static struct DATABIN bucket0[] = {
- {emptyString, NULL, 0}};
-
- /* libraries in bucket for hashKey==1 */
- static struct DATABIN bucket1[] = {
- {"libalpha", libalpha, 5},
- {"libbeta", libbeta, 3},
- {emptyString, NULL, 0}};
-
- /* array of buckets */
- static struct DATABIN* buckets[NUM_BUCKETS] = {
- bucket0,
- bucket1 };
-
-#endif /* end of example getstrmem.h */
-
-#define BUCKET_MASK NUM_BUCKETS-1
-
-char*
-XP_GetStringFromMemory(char* strLibraryName,int iToken)
-{
- /*
- * In memory model called by XP_GetStringFromDatabase
- * does not use database (nsres, et al.).
- *
- * This function uses hash table for library lookup
- * and direct lookup for string.
- *
- * This function is thread safe.
- */
-
-#ifdef COMPILE_STRINGS_IN_MEMORY
-
- unsigned hashKey;
- int found = 0;
- unsigned uToken = iToken;
- char* cPtr;
- DATABIN* pBucket;
-
- /* calculate hash key */
- hashKey = 0;
- cPtr = strLibraryName;
- while (*cPtr) {
- hashKey += *(cPtr++);
- }
- hashKey &= BUCKET_MASK;
-
- /* get bucket for this hash key */
- pBucket = buckets[hashKey];
-
- /* search overflow buckets */
- while (*(pBucket->pLibraryName)!='\0') {
- if (strcmp(pBucket->pLibraryName,strLibraryName)==0) {
- found = 1;
- break;
- }
- pBucket++;
- }
-
- if (!found) {
- return emptyString;
- }
-
- if (uToken<=pBucket->numberOfStringsInLibrary) {
- return pBucket->pArrayOfLibraryStrings[uToken];
- } else {
- /* string token out of range */
- return emptyString;
- }
-
-#else
-
- return emptyString;
-
-#endif
-}
diff --git a/lib/libsi18n/getstrprop.c b/lib/libsi18n/getstrprop.c
index 4a5ab04b..c63d6ba1 100644
--- a/lib/libsi18n/getstrprop.c
+++ b/lib/libsi18n/getstrprop.c
@@ -49,77 +49,7 @@
#include "getstrmem.h"
-#include "coreres.h"
-
-Resource *hResource = NULL;
-char empty_string[] = "";
-
-char*
-XP_GetStringFromMemory(char* strLibraryName,int iToken);
-
-
-
-void
-XP_InitStringDatabase(char* pathCWD, char* databaseName)
-{
- hResource = core_res_init_resource (pathCWD, databaseName);
-}
-
-char *XP_GetPropertyString(char* strLibraryName,int iToken, ACCEPT_LANGUAGE_LIST lang)
-{
- char *key_name;
- char *result = NULL;
-
- if (hResource == NULL)
- return NULL;
-
- /*creating the key*/
- key_name=(char*)malloc(strlen(strLibraryName) + 10);
- sprintf(key_name, "%s-%d", strLibraryName, iToken);
- if(key_name == NULL)
- return NULL;
-
- result = (char *) core_res_getstring(hResource, key_name, lang) ;
-
- if (key_name)
- free (key_name);
-
- if (result == NULL)
- return empty_string;
- else
- return result ;
-}
-
-char*
-XP_GetStringFromDatabase(char* strLibraryName,
- char* strLanguage,
- int key)
-{
- char *result = NULL;
- ACCEPT_LANGUAGE_LIST alanglist;
- int n;
-
- /*
- * display first choice language if available, otherwise
- * use default which is english in most case
- */
- if (hResource) {
- n = XP_AccLangList (strLanguage, alanglist);
- if (n >= MAX_ACCEPT_LANGUAGE)
- alanglist[MAX_ACCEPT_LANGUAGE-1][0] = '\0';
- else
- alanglist[n][0] = '\0';
- result = XP_GetPropertyString(strLibraryName, key, alanglist);
- }
-
- /* we should never come here. */
- if (result == NULL)
- result = XP_GetStringFromMemory(strLibraryName,key);
- return result;
-}
-
-
-char*
+static char*
XP_GetStringFromMemory(char* strLibraryName,int iToken)
{
/*
@@ -171,3 +101,16 @@ XP_GetStringFromMemory(char* strLibraryName,int iToken)
}
}
+
+char*
+XP_GetStringFromDatabase(char* strLibraryName,
+ char* strLanguage,
+ int key)
+{
+ char *result = NULL;
+
+ /* we use memory strings only in ds. */
+ if (result == NULL)
+ result = XP_GetStringFromMemory(strLibraryName,key);
+ return result;
+}
diff --git a/lib/libsi18n/propset.c b/lib/libsi18n/propset.c
deleted file mode 100644
index 87b98854..00000000
--- a/lib/libsi18n/propset.c
+++ /dev/null
@@ -1,442 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include "i18n.h"
-
-#include "txtfile.h"
-#include "reshash.h"
-#include "propset.h"
-
-int PropertiesLoadFileToHash(PropertiesSet *propset, char *language);
-char *GetProertiesFilename(char *directory, char *file, char *language);
-int PropertiesLanguageStatus(PropertiesSet *propset, char *language);
-int PropertiesSetLangStatus(LanguageStatus *langstatus, char *language, int status);
-int unicode_to_UTF8(unsigned int wch, char *utf8);
-char *decode_ascii(char *src);
-
-
-PropertiesSet * PropertiesInit(char *directory, char *file)
-{
- struct stat buf;
- char * file_path;
- PropertiesSet *propset = NULL;
- PropertiesSet *result = NULL;
- ResHash *reshash;
-
- file_path = (char *) malloc (strlen(directory) + strlen(file) + 20);
-
- strcpy(file_path, directory);
- strcat(file_path, "/");
- strcat(file_path, file);
- strcat(file_path, ".properties");
-
- if (stat(file_path, &buf) == 0) {
- propset = (PropertiesSet *) malloc(sizeof(PropertiesSet));
- memset(propset, 0, sizeof(PropertiesSet));
- reshash = (ResHash *) ResHashCreate(file);
-
- if (reshash) {
- propset->langlist = (LanguageStatus *) malloc(sizeof(LanguageStatus));
- memset(propset->langlist, 0, sizeof(LanguageStatus));
-
- propset->res = reshash;
- propset->directory = strdup(directory);
- propset->filename = strdup(file);
- PropertiesLoadFileToHash(propset, NULL);
- result = propset;
- }
- }
-
- if (file_path)
- free (file_path);
-
- return result;
-}
-
-
-char *GetProertiesFilename(char *directory, char *file, char *language)
-{
- char *filepath;
-
- if (language && *language == '\0')
- filepath = (char *) malloc(strlen(directory) + strlen(file) + strlen(language) + 20);
- else
- filepath = (char *) malloc(strlen(directory) + strlen(file) + 20);
-
- strcpy(filepath, directory);
- if (filepath[strlen(filepath) - 1] != '/')
- strcat(filepath, "/");
- strcat(filepath, file);
- if (language && *language != '\0') {
- strcat(filepath, "_");
- strcat(filepath, language);
- }
- strcat(filepath, ".properties");
-
- return filepath;
-}
-
-/*
- PropertiesLoadToHash
-
- Opens property file and save data to hash table
-
- Input
- propfile: handle
- file: full path with file extension
-
- return:
- 0: SUCCESS
- 1: FAIL
-*/
-
-int PropertiesLoadFileToHash(PropertiesSet *propset, char *language)
-{
- TEXTFILE *hfile;
- char *filepath;
- char *p, *q;
- int n;
- char linebuf[1000];
- int st;
-
- st = PropertiesLanguageStatus(propset, language);
- if (st == LANGUAGE_INVALID)
- return 1;
- else if (st == LANGUAGE_LOAD)
- return 0;
-
- filepath = GetProertiesFilename(propset->directory, propset->filename, language);
-
- if ((hfile = OpenTextFile (filepath, TEXT_OPEN_FOR_READ)) == NULL) {
- PropertiesSetLangStatus(propset->langlist, language, LANGUAGE_INVALID);
- return 1;
- }
-
- while ((n = ReadTextLine(hfile, linebuf)) >= 0) {
- if (n == 0)
- continue;
-
- p = linebuf;
- /* strip leading spaces */
- while (*p == ' ' || *p == '\t')
- p ++;
- /* skip comment line */
- if (*p == '\0' || *p == '#' || *p == '=')
- continue;
-
- q = strchr (linebuf, '=');
- if (q) {
- char *key, *value, *newvalue;
-
- *q = '\0';
- key = p;
- value = q + 1;
- /* strip trailing space for key */
- p = key + strlen(key) - 1;
- while (*p == ' ' || *p == '\t') {
- *p = '\0';
- p --;
- }
-
- /* decode Unicode escape value */
- newvalue = decode_ascii(value);
-
- if (newvalue) {
- ResHashAdd(propset->res, key, newvalue, language);
- free(newvalue);
- }
- else
- ResHashAdd(propset->res, key, value, language);
- }
- }
- PropertiesSetLangStatus(propset->langlist, language, LANGUAGE_LOAD);
- return 0;
-}
-
-/*
- PropertiesIsLoaded
-
- Test if current properties associated with language
- is loaded or not.
-
- return:
- 1: SUCCESS
- 0: FAIL
- */
-
-int PropertiesLanguageStatus(PropertiesSet *propset, char *language)
-{
- LanguageStatus *plang;
-
- plang = propset->langlist;
- if (language == NULL || *language == '\0') {
- return plang->status;
- }
-
- plang = plang->next;
-
- while (plang) {
- if (strcmp(plang->language, language) == 0) {
- return plang->status;
- }
- plang = plang->next;
- }
- return LANGUAGE_NONE;
-}
-
-int PropertiesSetLangStatus(LanguageStatus *langlist, char *language, int status)
-{
- LanguageStatus *plang, *prev;
- LanguageStatus *langstatus;
-
- if (language == NULL || *language == '\0') {
- langlist->status = status;
- return 0;
- }
-
- prev = plang = langlist;
- plang = plang->next;
-
- while (plang) {
- if (strcmp(plang->language, language) == 0) {
- plang->status = status;
- return 0;
- }
- prev = plang;
- plang = plang->next;
- }
-
- langstatus = (LanguageStatus *) malloc(sizeof(LanguageStatus));
- memset (langstatus, 0, sizeof(LanguageStatus));
- langstatus->language = strdup(language);
- langstatus->status = status;
- prev->next = langstatus;
-
- return 0;
-}
-
-
-/***
- PropertiesOpenFile
-
- return 0: loaded
- 1: fail to load file associated with the language
-
-
- */
-int PropertiesOpenFile(PropertiesSet *propset, char *language)
-{
- int status;
- status = PropertiesLanguageStatus(propset, language);
-
- if (status == LANGUAGE_NONE)
- return PropertiesLoadFileToHash (propset, language);
- else if (status == LANGUAGE_INVALID)
- return 1;
- else
- return 0;
-}
-
-const char *PropertiesGetString(PropertiesSet *propset, char *key, ACCEPT_LANGUAGE_LIST acceptlangauge)
-{
- int i;
- char *language = NULL;
-
- i = 0;
- while (acceptlangauge[i][0]) {
- if (PropertiesOpenFile(propset, acceptlangauge[i]) == 0) {
- language = acceptlangauge[i];
- break;
- }
- i ++;
- }
-
- return ResHashSearch(propset->res, key, language);
-}
-void PropertiesDestroy(PropertiesSet *propset)
-{
- LanguageStatus *langattrib, *next;
-
- if (propset) {
- if (propset->path)
- free(propset->path);
- if (propset->directory)
- free(propset->directory);
- if (propset->filename)
- free(propset->filename);
-
- ResHashDestroy(propset->res);
-
- langattrib = propset->langlist;
- while (langattrib) {
- next = langattrib->next;
- if (langattrib->language)
- free(langattrib->language);
- free(langattrib);
- langattrib = next;
- }
- }
-}
-
-
-char *decode_ascii(char *src)
-{
- int i;
- char utf8[10];
- int state = 0;
- int digit = 0;
- int digit_count = 0;
- char *result, *p, *q;
-
- if (src == NULL || *src == '\0')
- return NULL;
-
- if (strchr(src, '\\') == NULL)
- return NULL;
-
- result = (char *) malloc(strlen(src) + 1);
-
- p = src;
- q = result;
-
- for (;*p; p++) {
- char ch;
- int n;
- if (state == BACKSLASH_U) {
- ch = toupper(*p);
- if (ch >= '0' && ch <= '9') {
- digit = digit * 16 + (ch - '0');
- digit_count ++;
- }
- else if (ch >= 'A' && ch <= 'F') {
- digit = digit * 16 + (ch - 'A' + 10);
- digit_count ++;
- }
- else {
- n = unicode_to_UTF8(digit, utf8);
- for (i = 0; i < n; i++)
- *q ++ = utf8[i];
- *q ++ = *p;
- state = 0;
- digit_count = 0;
- }
-
- if (digit_count == 4) {
- n = unicode_to_UTF8(digit, utf8);
- for (i = 0; i < n; i++)
- *q ++ = utf8[i];
- state = 0;
- }
- }
- else if (state == BACKSLASH) {
- if (*p == 'u') {
- state = BACKSLASH_U;
- digit = 0;
- digit_count = 0;
- continue;
- }
- else if (*p == 'n') {
- *q++ = '\n';
- state = 0;
- }
- else if (*p == 'r') {
- *q++ = '\r';
- state = 0;
- }
- else {
- *q++ = '\\';
- *q++ = *p;
- state = 0;
- }
- }
- else if (*p == '\\') {
- state = BACKSLASH;
- continue;
- }
- else {
- *q++ = *p;
- state = 0;
- }
- }
- *q = '\0';
- return result;
-}
-
-
-int unicode_to_UTF8(unsigned int wch, char *utf8)
-{
- unsigned char hibyte, lobyte, mibyte;
-
- if (wch <= 0x7F) {
- /* 0000 007F ==> 0xxxxxxx */
- utf8[0] = (unsigned char) wch ;
- utf8[1] = '\0';
- return 1;
- }
- else if (wch <= 0x7FF) {
- /* 0000 07FF ==> 110xxxxx 10xxxxxx */
- lobyte = wch & 0x3F;
- hibyte = (wch >> 6) & 0x1F;
-
- utf8[0] = 0xC0 | hibyte;
- utf8[1] = 0x80 | lobyte;
- utf8[2] = '\0';
- return 2;
- }
- else {
- /* FFFF ==> 1110xxxx 10xxxxxx 10xxxxxx */
- lobyte = wch & 0x3F;
- mibyte = (wch >> 6) & 0x3F;
- hibyte = (wch >> 12) & 0xF;
-
- utf8[0] = 0xE0 | hibyte;
- utf8[1] = 0x80 | mibyte;
- utf8[2] = 0x80 | lobyte;
- utf8[3] = '\0';
- return 3;
- }
-}
diff --git a/lib/libsi18n/propset.h b/lib/libsi18n/propset.h
deleted file mode 100644
index 8ef0df96..00000000
--- a/lib/libsi18n/propset.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifndef PROPSET_H
-#define PROPSET_H
-
-#include "reshash.h"
-
-
-enum {
- LANGUAGE_NONE = 0,
- LANGUAGE_LOAD,
- LANGUAGE_INVALID
-} ;
-
-enum {
- BACKSLASH = 1,
- BACKSLASH_U
-};
-
-
-typedef struct LanguageStatusS {
- char *language;
- int status;
- struct LanguageStatusS *next;
-} LanguageStatus;
-
-typedef struct PropertiesSet {
- char *path;
- char *directory;
- char *filename;
- LanguageStatus *langlist;
- ResHash *res;
-} PropertiesSet;
-
-
-PropertiesSet * PropertiesInit(char *directory, char *file);
-const char *PropertiesGetString(PropertiesSet *propset, char *key, ACCEPT_LANGUAGE_LIST acceptlangauge);
-void PropertiesDestroy(PropertiesSet *propfile);
-
-#endif