summaryrefslogtreecommitdiff
path: root/modules/m2sci/macros/kernel/translateorder.sci
blob: 89acd5d8b0da212545a35c6334a3048b5f1aa8ed (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
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ???? - INRIA - Scilab
//
// 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  [transorder]=translateorder(transorder,funtxt,overfunname)
    //  TRANSLATEORDER Recursive function
    //  Determinates a translate order of the M-files found in Paths (used by "translatepaths" function)
    //  Output-Input
    //  -transorder : a vector containing the M-files names which are arranged in order to respect an priority order of translation
    //  Input
    //  -funtxt : a vector which contains the name of a M-file found in the Paths (its first component: funtxt(1)), and the called functions by this file (the others components : funtxt(2:$))
    //  -overfunname : a vector which contains the files names being passed like argument of     "translateorder" function

    // the file is already in the list
    if or(transorder==funtxt(1)) then
        return
    end

    if size(funtxt,"*")>1 then
        for i=2:size(funtxt,1)
            // the called function is already in the list
            if find(funtxt(i)==transorder)<>[] then
                continue
                // the called function is already passed in argument of "translateorder" function (a loop)
            elseif find(funtxt(i)==overfunname)<>[] then
                disp([overfunname;funtxt(i)],"loop: ")
                //return
                continue
                // order the under level, also we call translateorder (recursive)
            else
                overfunname($+1)=funtxt(1)
                execstr("[transorder]=translateorder(transorder,"+funtxt(i)+"vect,overfunname)")
            end
        end
        transorder($+1)=funtxt(1)
    else
        // no called function by the M-file, also we put the M-file name in the transorder vector
        transorder($+1)=funtxt(1)
    end

endfunction