Bad commit
[scilab.git] / scilab / modules / localization / sci_gateway / c / sci_gettext.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2008 - INRIA - Sylvestre LEDRU
4  * 
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at    
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12 #include <string.h>
13 #include "MALLOC.h"
14 #include "machine.h"
15 #include "stack-c.h"
16 #include "localization.h"
17 #include "gw_localization.h"
18 #include "Scierror.h"
19 #include "strsubst.h"
20 /*--------------------------------------------------------------------------*/
21 int C2F(sci_gettext)(char *fname,unsigned long fname_len)
22 {
23         CheckRhs(1,1);
24         CheckLhs(1,1);
25
26         if ( (GetType(1) == sci_strings) )
27         {
28                 static int l1,n1,m1;
29
30                 char *msgid = NULL;
31                 char *TranslatedString = NULL;
32                         
33                 int revertStrsub = FALSE;
34                         
35                 GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
36                 msgid = cstk(l1);
37
38                 /* This stupid stuff is necessary because scilab is add slashes
39                  * and we need to remove them
40                  * An other solution might be to replace the string "\x" by it
41                  * real code 
42                 */
43                 if (strchr(msgid, '\\')!=NULL)
44                 {
45                         /* There is an \ in the string process to replace */
46                                 
47                         /* We always have something from this functions because gettext
48                          * is returning the same string if it cannot find it */
49
50                         msgid = strsub(msgid, "\\n", "\n"); /* linefeed */
51                         msgid = strsub(msgid, "\\t", "\t"); /* horizontal tab */
52                         msgid = strsub(msgid, "\\r", "\r"); /* carriage return */
53                         msgid = strsub(msgid, "\\v", "\v"); /* vertical tab */
54                         msgid = strsub(msgid, "\\f", "\f"); /* form feed */
55                         msgid = strsub(msgid, "\\\\", "\\"); /* backslash */
56                         msgid = strsub(msgid, "\\\"", "\""); /* double quote */
57
58                         revertStrsub = TRUE;
59                 }
60                 TranslatedString = gettext(msgid);
61
62                 /* Add removed slashes */
63                 if (revertStrsub)
64                 {
65                         TranslatedString = strsub(TranslatedString, "\\", "\\\\"); /* backslash */
66                         TranslatedString = strsub(TranslatedString, "\"", "\\\""); /* double quote */
67                         TranslatedString = strsub(TranslatedString, "\n", "\\n"); /* linefeed */
68                         TranslatedString = strsub(TranslatedString, "\t", "\\t"); /* horizontal tab */
69                         TranslatedString = strsub(TranslatedString, "\r", "\\r"); /* carriage return */
70                         TranslatedString = strsub(TranslatedString, "\v", "\\v"); /* vertical tab */
71                         TranslatedString = strsub(TranslatedString, "\f", "\\f"); /* form feed */
72                 }
73
74                 n1 = 1;
75                 CreateVarFromPtr(Rhs+1,STRING_DATATYPE,(m1=(int)strlen(TranslatedString), &m1),&n1,&TranslatedString);
76                 LhsVar(1) = Rhs+1;
77                 C2F(putlhsvar)();
78         }
79         else
80         {
81                 Scierror(999,_("%s: Wrong type for first input argument: String expected.\n"),fname);
82         }
83         return 0;
84 }
85 /*--------------------------------------------------------------------------*/