~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/fileio/sci_gateway/c/sci_getrelativefilename.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
3
 * Copyright (C) 2006 - INRIA - Pierre MARECHAL
4
 
 * 
 
4
 *
5
5
 * This file must be used under the terms of the CeCILL.
6
6
 * This source file is licensed as described in the file COPYING, which
7
7
 * you should have received as part of this distribution.  The terms
8
 
 * are also available at    
 
8
 * are also available at
9
9
 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10
10
 *
11
11
 */
19
19
#include "Scierror.h"
20
20
#include "localization.h"
21
21
#include "freeArrayOfString.h"
22
 
 /*--------------------------------------------------------------------------*/
 
22
/*--------------------------------------------------------------------------*/
23
23
/* ================================================================================== */
24
24
// sci_getrelativefilename
25
25
//
27
27
/* ================================================================================== */
28
28
int sci_getrelativefilename(char *fname, unsigned long l)
29
29
{
30
 
        static int n1 = 0,m1 = 0,n2 = 0,m2 = 0;
31
 
 
32
 
        CheckRhs(2,2);
33
 
        CheckLhs(1,1);
34
 
 
35
 
        if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) )
36
 
        {
37
 
                char **param1=NULL;
38
 
                char **param2=NULL;
39
 
                char *result=(char*)MALLOC(PATH_MAX*sizeof(char));
40
 
                
41
 
                GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&m1,&n1,&param1);
42
 
                
43
 
                if ( (n1*m1) != 1 )
44
 
                {
45
 
                        freeArrayOfString(param1,m1*n1);
46
 
                        Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
47
 
                        return 0;
48
 
                }
49
 
                
50
 
                GetRhsVar(2,MATRIX_OF_STRING_DATATYPE,&m2,&n2,&param2);
51
 
                if ( (n2*m2) !=1 )
52
 
                {
53
 
                        freeArrayOfString(param1,m1*n1);
54
 
                        freeArrayOfString(param2,m2*n2);
55
 
                        Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,2);
56
 
                        return 0;
57
 
                }
58
 
                
59
 
                // make sure the names are not too long
60
 
                
61
 
                if( strlen(param1[0]) > PATH_MAX )
62
 
                {
63
 
                        Scierror(999,_("%s: Wrong size for input argument #%d: Must be less than %d characters.\n"),fname,1,PATH_MAX);
64
 
                }
65
 
                
66
 
                if( strlen(param2[0]) > PATH_MAX )
67
 
                {
68
 
                        Scierror(999,_("%s: Wrong size for input argument #%d: Must be less than %d characters.\n"),fname,2,PATH_MAX);
69
 
                }
70
 
                
71
 
                result = getrelativefilename(param1[0],param2[0]);
72
 
                freeArrayOfString(param1,m1*n1);
73
 
                freeArrayOfString(param2,m2*n2);
74
 
                
75
 
                CreateVarFromPtr(Rhs+3,STRING_DATATYPE,(m1=(int)strlen(result), &m1),&n1,&result);
76
 
                LhsVar(1)=Rhs+3;
77
 
                if (result) {FREE(result);result=NULL;}
78
 
                PutLhsVar();
79
 
        }
80
 
        else
81
 
        {
82
 
                if(GetType(1) != sci_strings)
83
 
                {
84
 
                        Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1);
85
 
                }
86
 
                else
87
 
                {
88
 
                        Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,2);
89
 
                }
90
 
        }
91
 
        
92
 
        return 0;
 
30
    static int n1 = 0, m1 = 0, n2 = 0, m2 = 0;
 
31
 
 
32
    CheckRhs(2, 2);
 
33
    CheckLhs(1, 1);
 
34
 
 
35
    if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) )
 
36
    {
 
37
        char **param1 = NULL;
 
38
        char **param2 = NULL;
 
39
        char *result = (char*)MALLOC(PATH_MAX * sizeof(char));
 
40
 
 
41
        GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, &param1);
 
42
 
 
43
        if ( (n1 * m1) != 1 )
 
44
        {
 
45
            freeArrayOfString(param1, m1 * n1);
 
46
            Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
 
47
            return 0;
 
48
        }
 
49
 
 
50
        GetRhsVar(2, MATRIX_OF_STRING_DATATYPE, &m2, &n2, &param2);
 
51
        if ( (n2 * m2) != 1 )
 
52
        {
 
53
            freeArrayOfString(param1, m1 * n1);
 
54
            freeArrayOfString(param2, m2 * n2);
 
55
            Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
 
56
            return 0;
 
57
        }
 
58
 
 
59
        // make sure the names are not too long
 
60
 
 
61
        if ( strlen(param1[0]) > PATH_MAX )
 
62
        {
 
63
            Scierror(999, _("%s: Wrong size for input argument #%d: Must be less than %d characters.\n"), fname, 1, PATH_MAX);
 
64
        }
 
65
 
 
66
        if ( strlen(param2[0]) > PATH_MAX )
 
67
        {
 
68
            Scierror(999, _("%s: Wrong size for input argument #%d: Must be less than %d characters.\n"), fname, 2, PATH_MAX);
 
69
        }
 
70
 
 
71
        result = getrelativefilename(param1[0], param2[0]);
 
72
        freeArrayOfString(param1, m1 * n1);
 
73
        freeArrayOfString(param2, m2 * n2);
 
74
 
 
75
        m1 = (int)strlen(result);
 
76
        CreateVarFromPtr(Rhs + 3, STRING_DATATYPE, &m1, &n1, &result);
 
77
        LhsVar(1) = Rhs + 3;
 
78
        if (result)
 
79
        {
 
80
            FREE(result);
 
81
            result = NULL;
 
82
        }
 
83
        PutLhsVar();
 
84
    }
 
85
    else
 
86
    {
 
87
        if (GetType(1) != sci_strings)
 
88
        {
 
89
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
 
90
        }
 
91
        else
 
92
        {
 
93
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
 
94
        }
 
95
    }
 
96
 
 
97
    return 0;
93
98
}