-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapiexec.cpp
More file actions
77 lines (71 loc) · 2.1 KB
/
apiexec.cpp
File metadata and controls
77 lines (71 loc) · 2.1 KB
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
// This file is part of SmallBASIC
//
// SmallBASIC module api functions
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2023 Chris Warren-Smith
#include <cstring>
#include <cstdio>
#include "param.h"
extern FUNC_SIG lib_func[];
extern FUNC_SIG lib_proc[];
SBLIB_API int sblib_proc_getname(int index, char *proc_name) {
int result;
if (index < sblib_proc_count()) {
strcpy(proc_name, lib_proc[index]._name);
result = 1;
} else {
result = 0;
}
return result;
}
SBLIB_API int sblib_func_getname(int index, char *proc_name) {
int result;
if (index < sblib_func_count()) {
strcpy(proc_name, lib_func[index]._name);
result = 1;
} else {
result = 0;
}
return result;
}
SBLIB_API int sblib_proc_exec(int index, int argc, slib_par_t *params, var_t *retval) {
int result;
if (index >= 0 && index < sblib_proc_count()) {
if (argc < lib_proc[index]._min || argc > lib_proc[index]._max) {
if (lib_proc[index]._min == lib_proc[index]._max) {
error(retval, lib_proc[index]._name, lib_proc[index]._min);
} else {
error(retval, lib_proc[index]._name, lib_proc[index]._min, lib_proc[index]._max);
}
result = 0;
} else {
result = lib_proc[index]._command(argc, params, retval);
}
} else {
fprintf(stderr, "PROC index error [%d]\n", index);
result = 0;
}
return result;
}
SBLIB_API int sblib_func_exec(int index, int argc, slib_par_t *params, var_t *retval) {
int result;
if (index >= 0 && index < sblib_func_count()) {
if (argc < lib_func[index]._min || argc > lib_func[index]._max) {
if (lib_func[index]._min == lib_func[index]._max) {
error(retval, lib_func[index]._name, lib_func[index]._min);
} else {
error(retval, lib_func[index]._name, lib_func[index]._min, lib_func[index]._max);
}
result = 0;
} else {
result = lib_func[index]._command(argc, params, retval);
}
} else {
fprintf(stderr, "FUNC index error [%d]\n", index);
result = 0;
}
return result;
}