ed8d67e839d4bba55c0156d78b34be5d4619b808
[scilab.git] / scilab / modules / fileio / sci_gateway / c / sci_getshortpathname.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Allan CORNET
4  * ...
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 <string.h>
15 #include "gw_fileio.h"
16 #include "stack-c.h"
17 #include "getshortpathname.h"
18 #include "MALLOC.h"
19 #include "Scierror.h"
20 #include "localization.h"
21 /*--------------------------------------------------------------------------*/
22 int C2F(sci_getshortpathname)(char *fname,unsigned long l)
23 {
24         static int l1,n1,m1;
25         int bOK=FALSE;
26
27         CheckRhs(0,1);
28         CheckLhs(1,2);
29
30         if (GetType(1) == sci_strings)
31         {
32                 char *LongName=NULL;
33                 char *ShortName=NULL;
34
35                 GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
36                 LongName=cstk(l1);
37
38                 ShortName = getshortpathname(LongName,&bOK);
39
40                 n1=1;
41                 CreateVarFromPtr( Rhs+1,STRING_DATATYPE,(m1=(int)strlen(ShortName), &m1),&n1,&ShortName);
42                 LhsVar(1)=Rhs+1;
43
44                 if (ShortName) {FREE(ShortName);ShortName=NULL;}
45
46                 if (Lhs != 1) /* Lhs == 2 */
47                 {
48                         int *bOkOutINT=(int*)MALLOC(sizeof(int));
49
50                         *bOkOutINT=bOK;
51                         n1=1;
52                         CreateVarFromPtr(Rhs+2,MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &bOkOutINT);
53                         LhsVar(2)=Rhs+2;
54                         if (bOkOutINT) {FREE(bOkOutINT);bOkOutINT=NULL;}
55                 }
56
57                 C2F(putlhsvar)();
58         }
59         else
60         {
61                 Scierror(999,_("%s: Wrong type for first input argument: String expected.\n"),fname);
62         }
63         return 0;
64 }
65 /*--------------------------------------------------------------------------*/