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

« back to all changes in this revision

Viewing changes to modules/windows_tools/sci_gateway/c/sci_findfileassociation.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) INRIA - Allan CORNET
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
*/
14
14
#include <windows.h>
15
15
#include <string.h>
16
16
#include "gw_windows_tools.h"
17
 
#include "MALLOC.h" 
 
17
#include "MALLOC.h"
18
18
#include "Scierror.h"
19
19
#include "FindFileAssociation.h"
20
20
#include "PATH_MAX.h"
21
21
#include "stack-c.h"
22
22
#include "localization.h"
23
23
/*--------------------------------------------------------------------------*/
24
 
int sci_findfileassociation(char *fname,unsigned long l)
25
 
{       
26
 
        static int l1,n1,m1;
27
 
        char *Output=NULL;
28
 
        char ExtraParam[PATH_MAX];
29
 
        char AssocParam[PATH_MAX];
30
 
 
31
 
        Rhs=Max(Rhs,0);
32
 
        CheckRhs(1,2);
33
 
        CheckLhs(0,1);
34
 
 
35
 
        if (Rhs == 1)
36
 
        {
37
 
                if (GetType(1) != sci_strings)
38
 
                {
39
 
                        Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n") ,fname,1);
40
 
                        return 0;
41
 
                }
42
 
                else
43
 
                {
44
 
                        char *param=NULL;
45
 
 
46
 
                        GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
47
 
                        param=cstk(l1);
48
 
                        strcpy(AssocParam,param);
49
 
 
50
 
                        strcpy(ExtraParam,"open");
51
 
                }
52
 
        }
53
 
        else
54
 
        {
55
 
                if ( (GetType(1) != sci_strings) && (GetType(2) != sci_strings) )
56
 
                {
57
 
                        Scierror(999,_("%s: Wrong type for input arguments: Strings expected.\n"),fname);
58
 
                        return 0;
59
 
                }
60
 
                else
61
 
                {
62
 
                        char *param=NULL;
63
 
 
64
 
                        GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
65
 
                        param=cstk(l1);
66
 
 
67
 
                        strcpy(AssocParam,param);
68
 
 
69
 
                        GetRhsVar(2,STRING_DATATYPE,&m1,&n1,&l1);
70
 
                        param=cstk(l1);
71
 
 
72
 
                        strcpy(ExtraParam,param);
73
 
                }
74
 
        }
75
 
 
76
 
        Output=FindFileAssociation(AssocParam,ExtraParam) ;
77
 
 
78
 
        if (Output)
79
 
        {
80
 
                n1=1;
81
 
                CreateVarFromPtr(Rhs+ 1,STRING_DATATYPE,(m1=(int)strlen(Output), &m1),&n1,&Output);
82
 
        }
83
 
        else
84
 
        {
85
 
                n1=0;
86
 
                m1=0;
87
 
                l1=0;
88
 
                CreateVarFromPtr(Rhs+ 1,MATRIX_OF_DOUBLE_DATATYPE,&n1,&m1,&l1);
89
 
        }
90
 
                
91
 
        if (Output) {FREE(Output);Output=NULL;}
92
 
    LhsVar(1) = Rhs+1;
93
 
    PutLhsVar();        
94
 
 
95
 
        return 0;
 
24
int sci_findfileassociation(char *fname, unsigned long l)
 
25
{
 
26
    static int l1, n1, m1;
 
27
    char *Output = NULL;
 
28
    char ExtraParam[PATH_MAX];
 
29
    char AssocParam[PATH_MAX];
 
30
 
 
31
    Rhs = Max(Rhs, 0);
 
32
    CheckRhs(1, 2);
 
33
    CheckLhs(0, 1);
 
34
 
 
35
    if (Rhs == 1)
 
36
    {
 
37
        if (GetType(1) != sci_strings)
 
38
        {
 
39
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n") , fname, 1);
 
40
            return 0;
 
41
        }
 
42
        else
 
43
        {
 
44
            char *param = NULL;
 
45
 
 
46
            GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1);
 
47
            param = cstk(l1);
 
48
            strcpy(AssocParam, param);
 
49
 
 
50
            strcpy(ExtraParam, "open");
 
51
        }
 
52
    }
 
53
    else
 
54
    {
 
55
        if ( (GetType(1) != sci_strings) && (GetType(2) != sci_strings) )
 
56
        {
 
57
            Scierror(999, _("%s: Wrong type for input arguments: Strings expected.\n"), fname);
 
58
            return 0;
 
59
        }
 
60
        else
 
61
        {
 
62
            char *param = NULL;
 
63
 
 
64
            GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1);
 
65
            param = cstk(l1);
 
66
 
 
67
            strcpy(AssocParam, param);
 
68
 
 
69
            GetRhsVar(2, STRING_DATATYPE, &m1, &n1, &l1);
 
70
            param = cstk(l1);
 
71
 
 
72
            strcpy(ExtraParam, param);
 
73
        }
 
74
    }
 
75
 
 
76
    Output = FindFileAssociation(AssocParam, ExtraParam) ;
 
77
 
 
78
    if (Output)
 
79
    {
 
80
        n1 = 1;
 
81
        m1 = (int)strlen(Output);
 
82
        CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, &m1, &n1, &Output);
 
83
    }
 
84
    else
 
85
    {
 
86
        n1 = 0;
 
87
        m1 = 0;
 
88
        l1 = 0;
 
89
        CreateVarFromPtr(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &n1, &m1, &l1);
 
90
    }
 
91
 
 
92
    if (Output)
 
93
    {
 
94
        FREE(Output);
 
95
        Output = NULL;
 
96
    }
 
97
    LhsVar(1) = Rhs + 1;
 
98
    PutLhsVar();
 
99
 
 
100
    return 0;
96
101
}
97
102
/*--------------------------------------------------------------------------*/