-
Notifications
You must be signed in to change notification settings - Fork 153
/
value.c
75 lines (61 loc) · 1.58 KB
/
value.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
/*
* value.c -- Generic type (holds all types)
*
* Copyright (c) GoAhead Software Inc., 1995-2010. All Rights Reserved.
*
*/
/******************************** Description *********************************/
/*
* This module provides a generic type that can hold all possible types.
* It is designed to provide maximum effeciency.
*/
/********************************* Includes ***********************************/
#include "uemf.h"
/*********************************** Locals ***********************************/
/*********************************** Code *************************************/
/*
* Initialize a integer value.
*/
value_t valueInteger(long value)
{
value_t v;
memset(&v, 0x0, sizeof(v));
v.valid = 1;
v.type = integer;
v.value.integer = value;
return v;
}
/******************************************************************************/
/*
* Initialize a string value.
*/
value_t valueString(char_t* value, int flags)
{
value_t v;
memset(&v, 0x0, sizeof(v));
v.valid = 1;
v.type = string;
if (flags & VALUE_ALLOCATE) {
v.allocated = 1;
v.value.string = gstrdup(B_L, value);
} else {
v.allocated = 0;
v.value.string = value;
}
return v;
}
/******************************************************************************/
/*
* Free any storage allocated for a value.
*/
void valueFree(value_t* v)
{
if (v->valid && v->allocated && v->type == string &&
v->value.string != NULL) {
bfree(B_L, v->value.string);
}
v->type = undefined;
v->valid = 0;
v->allocated = 0;
}
/******************************************************************************/