1cbd858a9a2534acbf9309218e62575cf65a6144
[scilab.git] / scilab / modules / fileio / sci_gateway / c / sci_chdir.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2006 - INRIA - Allan CORNET
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 <stdio.h>
13 #include "gw_fileio.h"
14 #include "stack-c.h"
15 #include "Scierror.h"
16 #include "scicurdir.h"
17 #include "localization.h"
18 #include "expandPathVariable.h"
19 #include "PATH_MAX.h"
20 #include "MALLOC.h"
21 /*--------------------------------------------------------------------------*/
22 int sci_chdir(char *fname,unsigned long fname_len)
23 {
24         Rhs = Max(0, Rhs);
25         CheckRhs(0,1);
26         CheckLhs(1,1);
27
28         if ( (Rhs == 0) || (GetType(1) == sci_strings) )
29         {
30                 int ierr = 1;
31                 int l1 = 0, n1 = 0,m1 = 0;
32                 char shortpath[PATH_MAX];
33                 char *path = NULL;
34                 int out_n = 0;
35
36                 if (Rhs == 0)
37                 {
38                         strcpy(shortpath, "home/");
39                 }
40                 else
41                 {
42                         GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
43                         strcpy(shortpath,cstk(l1));
44                 }
45
46                 path = expandPathVariable(shortpath);
47                 if (path)
48                 {
49                         scichdir(path, &ierr);
50                         FREE(path);
51                         path = NULL;
52                 }
53
54                 n1=1;
55                 CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
56
57                 if (ierr == 0) *istk(l1)=(int)(TRUE);
58                 else *istk(l1)=(int)(FALSE);
59
60                 LhsVar(1)=Rhs+1;
61                 C2F(putlhsvar)();
62         }
63         else
64         {
65                 Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n"),fname, 1);
66         }
67         return 0;
68 }
69 /*--------------------------------------------------------------------------*/