00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include "localization.h"
00009 #include "MALLOC.h"
00010
00011 static int count=0;
00012 static char *Key_String=NULL;
00013 static char *Key_Value=NULL;
00014
00015 static struct hashtable *Table_Scilab_Errors=NULL;
00016 static struct hashtable *Table_Scilab_Messages=NULL;
00017 static struct hashtable *Table_Scilab_Menus=NULL;
00018
00019 static char *ReplaceChars(char *s1, char *s2, char *s3);
00020 static char *QueryString(struct hashtable *Table,char *Tag);
00021
00022 BOOL AppendHashTableLocalization(struct hashtable *Table,char *Tag,char* MsgStr)
00023 {
00024 BOOL bOK=FALSE;
00025 struct key_string *k=NULL;
00026 struct value_string *v=NULL;
00027 char *Key_Tag=NULL;
00028 char *Key_Value=NULL;
00029
00030 k=(struct key_string*)MALLOC(sizeof(struct key_string));
00031 v=(struct value_string*)MALLOC(sizeof(struct value_string));
00032
00033 Key_Tag=(char*)MALLOC(sizeof(char)*(strlen(Tag)+1));
00034 Key_Value=(char*)MALLOC(sizeof(char)*(strlen(MsgStr)+1));
00035
00036 if (k && v && Key_Tag && Key_Value)
00037 {
00038 strcpy(Key_Tag,Tag);
00039 strcpy(Key_Value,MsgStr);
00040
00041 k->Key_String=Key_Tag;
00042 v->Value_String=Key_Value;
00043
00044 if (InsertHashtable_string(Table,k, v)) bOK=TRUE;
00045
00046 }
00047 return bOK;
00048
00049 }
00050
00051 struct hashtable *GetHashTableScilabErrors(void)
00052 {
00053 return Table_Scilab_Errors;
00054 }
00055
00056 struct hashtable *GetHashTableScilabMessages(void)
00057 {
00058 return Table_Scilab_Messages;
00059 }
00060
00061 struct hashtable *GetHashTableScilabMenus(void)
00062 {
00063 return Table_Scilab_Menus;
00064 }
00065
00066 BOOL InitializeHashTableScilabErrors(void)
00067 {
00068 BOOL bOK=FALSE;
00069
00070 Table_Scilab_Errors=CreateHashtable_string();
00071 if (Table_Scilab_Errors) bOK=TRUE;
00072 else bOK=FALSE;
00073
00074 return bOK;
00075 }
00076
00077 BOOL InitializeHashTableScilabMessages(void)
00078 {
00079 BOOL bOK=FALSE;
00080
00081 Table_Scilab_Messages=CreateHashtable_string();
00082 if (Table_Scilab_Messages) bOK=TRUE;
00083 else bOK=FALSE;
00084
00085 return bOK;
00086 }
00087
00088 BOOL InitializeHashTableScilabMenus(void)
00089 {
00090 BOOL bOK=FALSE;
00091
00092 Table_Scilab_Menus=CreateHashtable_string();
00093 if (Table_Scilab_Menus) bOK=TRUE;
00094 else bOK=FALSE;
00095
00096 return bOK;
00097 }
00098
00099 int DisposeHashTableScilabErrors(void)
00100 {
00101 if (Table_Scilab_Errors)
00102 {
00103 hashtable_destroy( Table_Scilab_Errors, 0 ) ;
00104 Table_Scilab_Errors=NULL;
00105 }
00106 return 0;
00107 }
00108
00109 int DisposeHashTableScilabMessages(void)
00110 {
00111 if (Table_Scilab_Messages)
00112 {
00113 hashtable_destroy( Table_Scilab_Messages, 0 ) ;
00114 Table_Scilab_Messages=NULL;
00115 }
00116 return 0;
00117 }
00118
00119 int DisposeHashTableScilabMenus(void)
00120 {
00121 if (Table_Scilab_Menus)
00122 {
00123 hashtable_destroy(Table_Scilab_Menus, 0 ) ;
00124 Table_Scilab_Menus=NULL;
00125 }
00126 return 0;
00127 }
00128
00129 IMPORT_EXPORT_LOCALIZATION_DLL char *QueryStringError(char *Tag)
00130 {
00131 return QueryString(Table_Scilab_Errors,Tag);
00132 }
00133
00134 IMPORT_EXPORT_LOCALIZATION_DLL char *QueryStringMessage(char *Tag)
00135 {
00136 return QueryString(Table_Scilab_Messages,Tag);
00137 }
00138
00139 IMPORT_EXPORT_LOCALIZATION_DLL char *QueryStringMenu(char *Tag)
00140 {
00141 return QueryString(Table_Scilab_Menus,Tag);
00142 }
00143
00144 static char *ReplaceChars(char *S1, char *S2, char *S3)
00145 {
00146 char *buffer=NULL;
00147
00148 if ( (S1) && (strlen(S1)>0) )
00149 {
00150 char *p=NULL;
00151 buffer = (char*)MALLOC((strlen(S1)*2)*sizeof(char));
00152 if(!(p = strstr(S1, S2)))
00153 {
00154 sprintf(buffer,"%s",S1);
00155 return buffer;
00156 }
00157
00158 strncpy(buffer, S1, p-S1);
00159 buffer[p-S1] = '\0';
00160
00161 sprintf(buffer+(p-S1), "%s%s", S3, p+strlen(S2));
00162 }
00163 return buffer;
00164 }
00165
00166 static char *QueryString(struct hashtable *Table,char *Tag)
00167 {
00168 char oldpiece[8];
00169 char newpiece[8];
00170 char *RetString=NULL;
00171 char *StringWithoutSomeChars=NULL;
00172
00173 if (strcmp(Tag,"\r\n"))
00174 {
00175
00176 strcpy(oldpiece,"\r\n");
00177 strcpy(newpiece,"\\r\\n");
00178 StringWithoutSomeChars=ReplaceChars( Tag,oldpiece,newpiece);
00179
00180 if (StringWithoutSomeChars)
00181 {
00182 RetString=SearchHashtable_string(Table,StringWithoutSomeChars);
00183 if (StringWithoutSomeChars) FREE(StringWithoutSomeChars);
00184
00185 if (RetString)
00186 {
00187
00188 strcpy(oldpiece,"\\r\\n");
00189 strcpy(newpiece,"\r\n");
00190 StringWithoutSomeChars=ReplaceChars(RetString,oldpiece,newpiece);
00191 if (RetString) FREE(RetString);
00192 RetString = StringWithoutSomeChars;
00193 }
00194 }
00195 }
00196 return RetString;
00197 }
00198