prompt function corrected.
[scilab.git] / scilab / modules / console / sci_gateway / c / sci_prompt.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Allan CORNET
4  * Copyright (C) 2009 - DIGITEO - Allan CORNET
5  * 
6  * This file must be used under the terms of the CeCILL.
7  * This source file is licensed as described in the file COPYING, which
8  * you should have received as part of this distribution.  The terms
9  * are also available at    
10  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11  *
12  */
13 /*--------------------------------------------------------------------------*/
14 #include "gw_console.h"
15 #include "stack-c.h"
16 #include "prompt.h"
17 #include "Scierror.h"
18 #include "localization.h"
19 /*--------------------------------------------------------------------------*/
20 int sci_prompt(char *fname,unsigned long fname_len)
21 {
22         char currentPrompt[PROMPT_SIZE_MAX];
23         static int n1 = 0, m1 = 0, l1 = 0;
24         int outIndex = 0 ;
25
26         CheckRhs(0,1);
27         CheckLhs(0,2);
28
29         if (Rhs == 0) /* Get current Scilab prompt */
30         {
31                 GetCurrentPrompt(currentPrompt);
32             
33                 m1= (int)strlen(currentPrompt);
34                 n1=1;
35                 CreateVar( Rhs+1,STRING_DATATYPE,&m1,&n1,&outIndex);
36                 strcpy(cstk(outIndex), currentPrompt);
37
38                 if (Lhs == 2)
39                 {
40                         m1 = 1;
41                         n1 = 1;
42                         l1 = 0;
43
44                         CreateVar( Rhs+2, MATRIX_OF_INTEGER_DATATYPE, &m1, &n1, &l1 );
45                         *istk(l1) = (int)C2F(recu).paus ;
46                 }
47             
48                 LhsVar(1) = Rhs+1;
49                 if (Lhs == 2) LhsVar(2) = Rhs+2;
50                 PutLhsVar();
51         }
52         else /* Tempory change of Scilab prompt */
53         {
54                 if (Lhs <=1)
55                 {
56                         if (VarType(1) != sci_strings)
57                         {
58                                 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname,1);
59                                 return FALSE;
60                         }
61
62                         GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
63
64                         if (n1 != 1)
65                         {
66                                 Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname,1);
67                                 return FALSE;
68                         }
69
70                         SetTemporaryPrompt(cstk(l1));
71
72                         LhsVar(1) = 0;
73                         PutLhsVar();
74                 }
75                 else
76                 {
77                         Scierror(999, _("%s: Wrong number of output argument(s).\n"), fname);
78                 }
79         }
80         return 0;
81 }
82 /*--------------------------------------------------------------------------*/