summaryrefslogtreecommitdiff
path: root/modules/m2sci/macros/kernel/isdefinedvar.sci
blob: e0bdca09c6e8dd116859d173179ed56fa02d3825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

function [boolval,index]=isdefinedvar(var)
    // Verify if variable is defined in varslist
    // Input:
    // - var: a M2SCI tlist (funcall, operation...) or a character string (name) for special variables
    // Special variables i, j, pi, eps, nargin, nargout
    // Output:
    // - boolval:
    //   %T if input tlist is a defined 'variable' (already found while converting M-file)
    //   %F if input is not a 'variable' or an uknown 'variable'

    // Global variable for M2SCI
    global("varslist")

    // level is declared in m2sci.sci and modified in clause2sci.sci
    level;

    boolval=%F
    index=[]

    // If input is a string
    if type(var)==10 then
        if and(var<>["i","j","pi","eps","%nargin","%nargout"]) then
            warning(msprintf(gettext("Bad use of isdefinedvar() with input: %s."),var))
            return
        end
        varname=var
    else
        // If input is not a 'variable', it can be a defined variable...
        if typeof(var)=="variable" then
            varname=var.name
        elseif typeof(var)=="m2scivar" then
            varname=var.matname
        else
            return
        end
    end

    // Compare with all existing variables varslist
    levelsize=size(level,1)
    i=0
    while i<levelsize & boolval==%F
        for k=1:size(varslist)
            // Search a variable which has the same name
            if varslist(k).matname==varname then
                // Search a variable which is in the same level or in an inferior level
                if varslist(k).level==level(1:levelsize-i) then
                    boolval=%T
                    index=k
                    return
                end
            end
        end
        i=i+1
    end

endfunction