getlanguage('LANGUAGE_DEFAULT') => getdefaultlanguage()
[scilab.git] / scilab / modules / localization / src / c / localization.c
1 /*--------------------------------------------------------------------------*/ 
2 /* INRIA 2006 */
3 /* HUANG Xu */
4 /* Allan CORNET */
5 /*--------------------------------------------------------------------------*/ 
6 #include <stdio.h>
7 #include <string.h>
8 #include "localization.h"
9 #include "MALLOC.h" /* MALLOC */
10 /*--------------------------------------------------------------------------*/ 
11 static struct hashtable *Table_Scilab_Errors=NULL;
12 static struct hashtable *Table_Scilab_Messages=NULL;
13 static struct hashtable *Table_Scilab_Menus=NULL;
14 /*--------------------------------------------------------------------------*/ 
15 static char *QueryString(struct hashtable *Table,char *Tag);
16 /*--------------------------------------------------------------------------*/ 
17 BOOL AppendHashTableLocalization(struct hashtable *Table,char *Tag,char* MsgStr,char *Path)
18 {
19         BOOL bOK=FALSE;
20         struct key_string *k=NULL;
21         struct value_string *v=NULL;
22         char *Key_Tag=NULL;
23         char *Key_Value=NULL;
24         char *Key_Path = NULL;
25
26         k=(struct key_string*)MALLOC(sizeof(struct key_string));
27         v=(struct value_string*)MALLOC(sizeof(struct value_string));
28
29         Key_Tag=(char*)MALLOC(sizeof(char)*(strlen(Tag)+1));
30         Key_Value=(char*)MALLOC(sizeof(char)*(strlen(MsgStr)+1));
31         Key_Path=(char*)MALLOC(sizeof(char)*(strlen(Path)+1));
32
33         if (k && v && Key_Tag && Key_Value && Key_Path)
34         {
35                 strcpy(Key_Tag,Tag);
36                 strcpy(Key_Value,MsgStr);
37                 strcpy(Key_Path,Path);
38
39                 k->Key_String = Key_Tag;
40                 v->Value_String = Key_Value;
41                 v->Path_String = Key_Path;
42
43                 if (InsertHashtable_string(Table,k, v)) bOK=TRUE;
44
45         }
46         return bOK;
47
48 }
49 /*--------------------------------------------------------------------------*/
50 struct hashtable *GetHashTableScilabErrors(void)
51 {
52         return Table_Scilab_Errors;
53 }
54 /*--------------------------------------------------------------------------*/ 
55 struct hashtable *GetHashTableScilabMessages(void)
56 {
57         return Table_Scilab_Messages;
58 }
59 /*--------------------------------------------------------------------------*/ 
60 struct hashtable *GetHashTableScilabMenus(void)
61 {
62         return Table_Scilab_Menus;
63 }
64 /*--------------------------------------------------------------------------*/ 
65 BOOL InitializeHashTableScilabErrors(void)
66 {
67         Table_Scilab_Errors=CreateHashtable_string();
68         if (Table_Scilab_Errors) return TRUE;
69         else return FALSE;
70 }
71 /*--------------------------------------------------------------------------*/ 
72 BOOL InitializeHashTableScilabMessages(void)
73 {
74         Table_Scilab_Messages=CreateHashtable_string();
75         if (Table_Scilab_Messages) return TRUE;
76         else return FALSE;
77 }
78 /*--------------------------------------------------------------------------*/ 
79 BOOL InitializeHashTableScilabMenus(void)
80 {
81         Table_Scilab_Menus=CreateHashtable_string();
82         if (Table_Scilab_Menus) return TRUE;
83         else return FALSE;
84 }
85 /*--------------------------------------------------------------------------*/ 
86 int DisposeHashTableScilabErrors(void)
87 {
88         if (Table_Scilab_Errors)
89         {
90                 hashtable_destroy( Table_Scilab_Errors, 0 ) ;
91                 Table_Scilab_Errors=NULL;
92         }
93         return 0;
94 }
95 /*--------------------------------------------------------------------------*/ 
96 int DisposeHashTableScilabMessages(void)
97 {
98         if (Table_Scilab_Messages)
99         {
100                 hashtable_destroy( Table_Scilab_Messages, 0 ) ;
101                 Table_Scilab_Messages=NULL;
102         }
103         return 0;
104 }
105 /*--------------------------------------------------------------------------*/ 
106 int DisposeHashTableScilabMenus(void)
107 {
108         if (Table_Scilab_Menus)
109         {
110                 hashtable_destroy(Table_Scilab_Menus, 0 ) ;
111                 Table_Scilab_Menus=NULL;
112         }
113         return 0;
114 }
115 /*--------------------------------------------------------------------------*/ 
116 char *QueryStringError(char *Tag)
117 {       
118         return QueryString(Table_Scilab_Errors,Tag);
119 }
120 /*--------------------------------------------------------------------------*/ 
121 char *QueryStringMessage(char *Tag)
122 {
123         return QueryString(Table_Scilab_Messages,Tag);
124 }
125 /*--------------------------------------------------------------------------*/ 
126 char *QueryStringMenu(char *Tag)
127 {
128         return QueryString(Table_Scilab_Menus,Tag);
129 }
130 /*--------------------------------------------------------------------------*/ 
131 static char *QueryString(struct hashtable *Table,char *Tag)
132 {
133         char *RetString=NULL;
134         if (Table==NULL)
135         {
136                 printf("Internal error: localization table empty (looking for %s)!\nAre you sure that the localization files have been loaded ?\n",Tag);
137                 exit(-1);
138         }
139         RetString = SearchHashtable_string(Table,Tag);
140         return RetString;
141 }
142 /*--------------------------------------------------------------------------*/