setgetlanguage.c File Reference

#include <string.h>
#include <stdlib.h>
#include "setgetlanguage.h"
#include "MALLOC.h"
#include "tableslanguages.h"
#include "loadsavelanguage.h"
#include "loadhashtableslocalization.h"

Include dependency graph for setgetlanguage.c:

Go to the source code of this file.

Defines

#define UPDATESCILABHELPMACRO   "try update_scilab_help();catch end;"

Functions

static BOOL LanguageIsOK (char *lang)
static int FindLanguageCode (char *lang)
static BOOL setlanguagecode (char *lang)
static char * FindAlias (char *lang)
static char * GetLanguageFromAlias (char *langAlias)
int C2F() syncexec (char *str, int *ns, int *ierr, int *seq, long int str_len)
BOOL setlanguage (char *lang, BOOL updateHelpIndex, BOOL updateMenus)
char * getlanguage (void)
int getcurrentlanguagecode (void)
char * getlanguagefromcode (int code)
int getcodefromlanguage (char *language)
char * getlanguagealias (void)
int comparelanguages (char *language1, char *language2)
BOOL needtochangelanguage (char *language)
char * convertlanguagealias (char *strlanguage)

Variables

static char CURRENTLANGUAGESTRING [LengthAlphacode] = SCILABDEFAULTLANGUAGE
static int CURRENTLANGUAGECODE = SCILABDEFAULTLANGUAGECODE


Define Documentation

#define UPDATESCILABHELPMACRO   "try update_scilab_help();catch end;"

Referenced by setlanguage().


Function Documentation

int comparelanguages ( char *  language1,
char *  language2 
)

TODO compare 2 languages same or not ?

Parameters:
language 
Returns:

Definition at line 185 of file setgetlanguage.c.

Referenced by needtochangelanguage().

00186 {
00187         return strcmp(language1,language2);
00188 }

Here is the caller graph for this function:

char* convertlanguagealias ( char *  strlanguage  ) 

TODO try to convert strlanguage (alias) to a good language string

Parameters:
language 
Returns:

Definition at line 204 of file setgetlanguage.c.

References GetLanguageFromAlias(), and NULL.

Referenced by C2F().

00205 {
00206         char *correctlanguage=NULL;
00207 
00208         if (strlen(strlanguage)==2)
00209         {
00210                 correctlanguage=GetLanguageFromAlias(strlanguage);
00211         }
00212         else if (strcmp(strlanguage,"eng")==0) /* compatibility previous scilab */
00213         {
00214                 correctlanguage=GetLanguageFromAlias("en");
00215         }
00216         return correctlanguage;
00217 }

Here is the call graph for this function:

Here is the caller graph for this function:

static char * FindAlias ( char *  lang  )  [static]

Definition at line 148 of file setgetlanguage.c.

References i, LANGUAGE_LOCALE_ALIAS, MALLOC, NULL, and NumberLanguagesAlias.

Referenced by getlanguagealias().

00149 {
00150         char *RetAlias=NULL;
00151         int i=0;
00152         for(i=0;i<NumberLanguagesAlias;i++)
00153         {
00154                 if (strcmp(LANGUAGE_LOCALE_ALIAS[i].alphacode,lang)==0)
00155                 {
00156                         RetAlias=(char*)MALLOC(sizeof(char)*(strlen(LANGUAGE_LOCALE_ALIAS[i].alias)+1));
00157                         strcpy(RetAlias,LANGUAGE_LOCALE_ALIAS[i].alias);
00158                         return RetAlias;
00159                 }
00160         }
00161         return RetAlias;
00162 }

Here is the caller graph for this function:

static int FindLanguageCode ( char *  lang  )  [static]

Definition at line 119 of file setgetlanguage.c.

References code, i, LANGUAGE_COUNTRY_TAB, and NumberLanguages.

Referenced by getcodefromlanguage(), and setlanguagecode().

00120 {
00121         int Code=-1;
00122         int i=0;
00123 
00124         for (i=0;i<NumberLanguages;i++)
00125         {
00126                 if (strcmp(lang,LANGUAGE_COUNTRY_TAB[i].alphacode)==0)
00127                 {
00128                         Code=LANGUAGE_COUNTRY_TAB[i].code;
00129                         return Code;
00130                 }
00131         }
00132         return Code;
00133 }

Here is the caller graph for this function:

int getcodefromlanguage ( char *  language  ) 

TODO get code of a language

Parameters:
language 
Returns:

Definition at line 98 of file setgetlanguage.c.

References FindLanguageCode().

00099 {
00100         return FindLanguageCode(language);
00101 }

Here is the call graph for this function:

int getcurrentlanguagecode ( void   ) 

TODO return internal code associated with a language

Returns:

Definition at line 76 of file setgetlanguage.c.

References CURRENTLANGUAGECODE.

00077 {
00078         return CURRENTLANGUAGECODE;
00079 }

char* getlanguage ( void   ) 

TODO returns current language

Returns:

Definition at line 66 of file setgetlanguage.c.

References CURRENTLANGUAGESTRING, MALLOC, and NULL.

Referenced by C2F(), needtochangelanguage(), and savelanguagepref_linux().

00067 {
00068         char *RetLanguage=NULL;
00069 
00070         RetLanguage=(char*)MALLOC(sizeof(char)*(strlen(CURRENTLANGUAGESTRING)+1));
00071         strcpy(RetLanguage,CURRENTLANGUAGESTRING);
00072 
00073         return RetLanguage;
00074 }

Here is the caller graph for this function:

char* getlanguagealias ( void   ) 

TODO returns current alias example : en_US --> en

Returns:

Definition at line 180 of file setgetlanguage.c.

References CURRENTLANGUAGESTRING, and FindAlias().

Referenced by C2F().

00181 {
00182         return FindAlias(CURRENTLANGUAGESTRING);
00183 }

Here is the call graph for this function:

Here is the caller graph for this function:

static char * GetLanguageFromAlias ( char *  langAlias  )  [static]

Definition at line 164 of file setgetlanguage.c.

References i, LANGUAGE_LOCALE_ALIAS, MALLOC, NULL, and NumberLanguagesAlias.

Referenced by convertlanguagealias().

00165 {
00166         char *RetLanguage=NULL;
00167         int i=0;
00168         for(i=0;i<NumberLanguagesAlias;i++)
00169         {
00170                 if (strcmp(LANGUAGE_LOCALE_ALIAS[i].alias,langAlias)==0)
00171                 {
00172                         RetLanguage=(char*)MALLOC(sizeof(char)*(strlen(LANGUAGE_LOCALE_ALIAS[i].alphacode)+1));
00173                         strcpy(RetLanguage,LANGUAGE_LOCALE_ALIAS[i].alphacode);
00174                         return RetLanguage;
00175                 }
00176         }
00177         return RetLanguage;
00178 }

Here is the caller graph for this function:

char* getlanguagefromcode ( int  code  ) 

TODO returns language of code

Parameters:
code 
Returns:

Definition at line 81 of file setgetlanguage.c.

References i, LANGUAGE_COUNTRY_TAB, MALLOC, NULL, and NumberLanguages.

00082 {
00083         char *RetLanguage=NULL;
00084         int i=0;
00085 
00086         for (i=0;i<NumberLanguages;i++)
00087         {
00088                 if (LANGUAGE_COUNTRY_TAB[i].code == code)
00089                 {
00090                         RetLanguage=(char*)MALLOC(sizeof(char)*(strlen(LANGUAGE_COUNTRY_TAB[i].alphacode)+1));
00091                         strcpy(RetLanguage,LANGUAGE_COUNTRY_TAB[i].alphacode);
00092                         return RetLanguage;
00093                 }
00094         }
00095         return RetLanguage;
00096 }

static BOOL LanguageIsOK ( char *  lang  )  [static]

Definition at line 103 of file setgetlanguage.c.

References FALSE, i, LANGUAGE_COUNTRY_TAB, NumberLanguages, and TRUE.

Referenced by setlanguage().

00104 {
00105         BOOL bOK=FALSE;
00106         int i=0;
00107 
00108         for (i=0;i<NumberLanguages;i++)
00109         {
00110                 if (strcmp(lang,LANGUAGE_COUNTRY_TAB[i].alphacode)==0)
00111                 {
00112                         bOK=TRUE;
00113                         return bOK;
00114                 }
00115         }
00116         return bOK;
00117 }

Here is the caller graph for this function:

BOOL needtochangelanguage ( char *  language  ) 

TODO test if we need to change language

Parameters:
language 
Returns:

Definition at line 190 of file setgetlanguage.c.

References comparelanguages(), FALSE, FREE, getlanguage(), NULL, and TRUE.

Referenced by C2F(), and setlanguage().

00191 {
00192         BOOL bOK=FALSE;
00193         char *currentlanguage=NULL;
00194 
00195         currentlanguage=getlanguage();
00196 
00197         if (comparelanguages(language,currentlanguage)) bOK=TRUE;
00198 
00199         if (currentlanguage) {FREE(currentlanguage);currentlanguage=NULL;}
00200 
00201         return bOK;
00202 }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL setlanguage ( char *  lang,
BOOL  updateHelpIndex,
BOOL  updateMenus 
)

TODO change language

Parameters:
lang 

Definition at line 24 of file setgetlanguage.c.

References C2F, CURRENTLANGUAGESTRING, FALSE, ierr, int, LanguageIsOK(), LoadHashTablesLocalization(), needtochangelanguage(), savelanguagepref(), setlanguagecode(), syncexec(), TRUE, and UPDATESCILABHELPMACRO.

Referenced by C2F(), and loadlanguagepref_linux().

00025 {
00026         BOOL bOK=FALSE;
00027         if (lang)
00028         {
00029                 if ( LanguageIsOK(lang) )
00030                 {
00031                         if (needtochangelanguage(lang))
00032                         {
00033                                 /* change language */
00034                                 strcpy(CURRENTLANGUAGESTRING,lang);
00035                                 setlanguagecode(lang);
00036 
00037                                 if (updateHelpIndex)
00038                                 {
00039                                         #define UPDATESCILABHELPMACRO "try update_scilab_help();catch end;" 
00040                                         integer ierr ;
00041                                         integer seq = 1 ;
00042                                         int macroCallLength=0;
00043 
00044                                         /* update help index */
00045                                         macroCallLength = (int)strlen(UPDATESCILABHELPMACRO);
00046                                         C2F(syncexec)(UPDATESCILABHELPMACRO,&macroCallLength,&ierr,&seq, macroCallLength);
00047                                 }
00048 
00049                                 /* save language pref. */
00050                                 savelanguagepref();
00051 
00052                                 /* update hash tables messages , errors , menus */
00053                                 LoadHashTablesLocalization(lang);
00054 
00055                                 if (updateMenus)
00056                                 {
00057                                         /* changes menus : to do after */
00058                                 }
00059                                 bOK=TRUE;
00060                         }
00061                 }
00062         }
00063         return bOK;
00064 }

Here is the call graph for this function:

Here is the caller graph for this function:

static BOOL setlanguagecode ( char *  lang  )  [static]

Definition at line 135 of file setgetlanguage.c.

References CURRENTLANGUAGECODE, FALSE, FindLanguageCode(), and TRUE.

Referenced by setlanguage().

00136 {
00137         BOOL bOK=FALSE;
00138         int tmpCode=FindLanguageCode(lang);
00139         
00140         if (tmpCode>0) 
00141         {
00142                 CURRENTLANGUAGECODE=tmpCode;
00143                 bOK=TRUE;
00144         }
00145         return bOK;
00146 }

Here is the call graph for this function:

Here is the caller graph for this function:

int C2F() syncexec ( char *  str,
int ns,
int ierr,
int seq,
long int  str_len 
)

Definition at line 1525 of file parse.c.

References allowptr(), basbrk, bexec(), bot, C2F, c__0, c__1, callinterf(), Eptover(), Err, err, fin, fun, funs(), Infstk, ir, iset(), krec, Lhs, Lstk, max, nsiz, parse(), Pt, ref2val(), Rhs, SciError(), Top, and TRUE_.

01526 {
01527 
01528   /* Local variables */
01529   int Pts, Tops;
01530   extern int C2F(iset)();
01531   extern int C2F(callinterf)(), C2F(ref2val)();
01532   static int iflagint;
01533   static int k;
01534   static int ir;
01535 
01536   static int *Ids  = C2F(recu).ids-nsiz-1;
01537   static int *Rstk = C2F(recu).rstk-1;
01538   static int *Lstk = C2F(vstk).lstk-1;
01539   static int *Infstk  = C2F(vstk).infstk-1;
01540 
01541   Pt = max(Pt,0);Pts=Pt;
01542   Top = max(Top,0);Tops=Top;
01543   C2F(basbrk).interruptible = *seq != 0;
01544   C2F(bexec)(str, ns, ierr, (*ns));
01545   if (*ierr != 0) {
01546     goto L9998;
01547   }
01548   /* + */
01549   if (Eptover(1)) {
01550     goto L9998;
01551   }
01552   Ids[1 + Pt * nsiz] = Lhs;
01553   Ids[2 + Pt * nsiz] = Rhs;
01554   Ids[3 + Pt * nsiz] = C2F(com).sym;
01555   Rstk[Pt] = 1002;
01556   ++C2F(recu).niv;
01557   C2F(com).fun = 0;
01558   C2F(recu).icall = 5;
01559 
01560   /* code translated from callinterf.h */
01561  L60:
01562 
01563    C2F(parse)();
01564   if (C2F(iop).err > 0) {
01565     goto L9999;
01566   }
01567 
01568   if (C2F(com).fun == 99) {
01569     C2F(com).fun = 0;
01570     goto L200;
01571   }
01572 
01573   if (Rstk[Pt] / 100 == 9) {
01574     ir = Rstk[Pt] - 900;
01575     if (ir == 1) {
01576       /* back to matsys */
01577       k = 13;
01578     } else if (ir >= 2 && ir <= 9) {
01579       /* back to matio */
01580       k = 5;
01581     } else if (ir == 10) {
01582       /* end of overloaded function */
01583       goto L96;
01584     } else if (ir > 40) {
01585       /* back to gw_user2 */
01586       k = 24;
01587     } else if (ir > 20) {
01588       /* back to gw_user */
01589       k = 14;
01590     } else {
01591       goto L89;
01592     }
01593     iflagint = 0;
01594     goto L95;
01595   }
01596 
01597  L89:
01598   if (Top < Rhs) {
01599     SciError(22);
01600     goto L9999;
01601   }
01602   if (Top - Rhs + Lhs + 1 >= C2F(vstk).bot) {
01603     SciError(18);
01604     goto L9999;
01605   }
01606   goto L91;
01607 
01608  L90:
01609   if (C2F(iop).err > 0) {
01610     goto L9999;
01611   }
01612  L91:
01613   k = C2F(com).fun;
01614   C2F(com).fun = 0;
01615   if (k == C2F(recu).krec) {
01616     C2F(recu).krec = -1;
01617     SciError(22);
01618     goto L9999;
01619   }
01620   C2F(recu).krec = -1;
01621   if (k == 0) {
01622     goto L60;
01623   }
01624  L95:
01625   if (! C2F(allowptr)(&k)) {
01626     C2F(ref2val)();
01627   }
01628   C2F(recu).krec = k;
01629   C2F(callinterf)(&k, &iflagint);
01630   /*      if (k.eq.krec) krec=99999 */
01631   C2F(recu).krec = -1;
01632   if (C2F(com).fun >= 0) {
01633     if (Top - Lhs + 1 > 0) {
01634       C2F(iset)(&Rhs, &c__0, &Infstk[Top - Lhs+1], &c__1);
01635     }
01636     goto L90;
01637   }
01638   /*     called interface ask for a scilab function to perform the function (fun=-1) */
01639   /*     the function name is given in ids(1,pt+1) */
01640   C2F(ref2val)();
01641   C2F(com).fun = 0;
01642   C2F(funs)(&Ids[1 + (Pt + 1) * nsiz]);
01643   if (C2F(iop).err > 0) {
01644     goto L9999;
01645   }
01646   if (C2F(com).fun > 0) {
01647     goto L91;
01648   }
01649   if (C2F(com).fin == 0) {
01650     SciError(246);
01651     if (C2F(iop).err > 0) {
01652       goto L9999;
01653     }
01654     goto L90;
01655   }
01656   ++Pt;
01657   C2F(com).fin = Lstk[C2F(com).fin];
01658   Rstk[Pt] = 910;
01659   C2F(recu).icall = 5;
01660   C2F(com).fun = 0;
01661   /*     *call*  macro */
01662   goto L60;
01663  L96:
01664   --Pt;
01665   goto L90;
01666   /* End of callinterf.h code */
01667 
01668  L200:
01669   Lhs = Ids[1 + Pt * nsiz];
01670   Rhs = Ids[2 + Pt * nsiz];
01671   C2F(com).sym = Ids[3 + Pt * nsiz];
01672   --Pt;
01673   --Top;
01674   /* + */
01675   --C2F(recu).niv;
01676   *ierr = 0;
01677   C2F(recu).icall = 0;
01678   C2F(com).fin = 3;
01679   C2F(basbrk).interruptible = TRUE_;
01680   return 0;
01681  L9998:
01682   *ierr = 1;
01683   Pt=Pts;Top=Tops;
01684   C2F(basbrk).interruptible = TRUE_;
01685 
01686   return 0;
01687  L9999:
01688   /* Err == 9999999 arises if abort has been used to terminate the callback execution */
01689   if (Err != 9999999) *ierr = 1;
01690   --Top;
01691   --C2F(recu).niv;
01692   Pt=Pts;Top=Tops;
01693   C2F(basbrk).interruptible = TRUE_;
01694   return 0;
01695 } /* syncexec */

Here is the call graph for this function:


Variable Documentation

int CURRENTLANGUAGECODE = SCILABDEFAULTLANGUAGECODE [static]

Definition at line 14 of file setgetlanguage.c.

Referenced by getcurrentlanguagecode(), and setlanguagecode().

char CURRENTLANGUAGESTRING[LengthAlphacode] = SCILABDEFAULTLANGUAGE [static]

Definition at line 13 of file setgetlanguage.c.

Referenced by getlanguage(), getlanguagealias(), and setlanguage().


Generated on Sun Mar 4 16:10:20 2007 for Scilab [trunk] by  doxygen 1.5.1