summaryrefslogtreecommitdiff
path: root/modules/functions/src/c/isScilabFunction.c
blob: 3804db067f89665a1ec8a5cda2183fb379a1e349 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2011 - DIGITEO - Allan CORNET
*
* 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
*
*/
/*--------------------------------------------------------------------------*/
#include <string.h>
#include "isScilabFunction.h"
#include "searchmacroinlibraries.h"
#include "api_scilab.h"
#include "stack-c.h"
#include "sci_types.h"
#include "stack-def.h"
#include "Funtab.h"
#include "freeArrayOfString.h"
/*--------------------------------------------------------------------------*/
BOOL isScilabFunction(const char * functionName)
{
    return (isScilabBuiltIn(functionName) ||
            isScilabMacroVariable(functionName) ||
            isScilabMacro(functionName));
}
/*--------------------------------------------------------------------------*/
BOOL isScilabMacro(const char * functionName)
{
    if (functionName)
    {
        char **librariesResult = NULL;
        int librariesResultSize = 0;

        librariesResult = searchmacroinlibraries((char*)functionName, &librariesResultSize);
        freeArrayOfString(librariesResult, librariesResultSize);
        if (librariesResultSize > 0)
        {
            return TRUE;
        }
    }
    return FALSE;
}
/*--------------------------------------------------------------------------*/
BOOL isScilabMacroVariable(const char * functionName)
{
    if (functionName)
    {
        int *piAddr = NULL;
        SciErr sciErr = getVarAddressFromName(pvApiCtx, functionName, &piAddr);
        if (sciErr.iErr == 0)
        {
            int typeVariable = 0;
            sciErr = getVarType(pvApiCtx, piAddr, &typeVariable);
            if (sciErr.iErr == 0)
            {
                return (BOOL)(typeVariable == sci_c_function);
            }
        }
    }
    return FALSE;
}
/*--------------------------------------------------------------------------*/
BOOL isScilabBuiltIn(const char * functionName)
{
    if (functionName)
    {
        int id[nsiz];
        int funptr = 0;
        int zero = 0;
        int one = 1;
        int job = one; /* Find function & returns fptr value */
        C2F(cvname)(id, (char*)functionName, &zero, (unsigned long)strlen(functionName));
        C2F(funtab)(id, &funptr, &job, "NULL_NAME", zero);
        return (BOOL)(funptr != zero);
    }
    return FALSE;
}
/*--------------------------------------------------------------------------*/