-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmod_utils.c
75 lines (63 loc) · 1.44 KB
/
mod_utils.c
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
// This file is part of SmallBASIC
//
// Module Support Routines
//
// Also provides access to var_t routines for platforms that do
// not support backlinking (such as windows).
//
// 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) 2000 Nicholas Christopoulos
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "mod_utils.h"
var_int_t v_igetval(var_t *v) {
var_int_t result;
switch (v ? v->type : -1) {
case V_INT:
result = v->v.i;
case V_NUM:
result = v->v.n;
default:
result = 0;
}
return result;
}
int mod_parint(int n, slib_par_t *params, int param_count, int *val) {
if (n < 0 || n >= param_count) {
return 0;
}
*val = v_igetval(params[n].var_p);
return 1;
}
int mod_parstr_ptr(int n, slib_par_t *params, int param_count, char **ptr) {
if (n < 0 || n >= param_count) {
return 0;
}
var_t *param = params[n].var_p;
if (param->type == V_STR) {
*ptr = param->v.p.ptr;
} else {
*ptr = '\0';
}
return 1;
}
int mod_opt_parstr_ptr(int n, slib_par_t *params, int param_count, char **ptr, const char *def_val) {
if (n < 0) {
return 0;
}
if (n < param_count) {
var_t *param = params[n].var_p;
if (param->type == V_STR) {
*ptr = param->v.p.ptr;
} else {
*ptr = '\0';
}
} else {
*ptr = (char *)def_val;
}
return 1;
}