summaryrefslogtreecommitdiff
path: root/usr/src/lib/libtnf/util.c
blob: f81b8aa19c53c52376dae1d6bfc9716f0636a7d5 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 *	Copyright (c) 1994, by Sun Microsytems, Inc.
 */

#pragma	ident	"%Z%%M%	%I%	%E% SMI"

#include "libtnf.h"

/*
 *
 */

static struct ntop {
	char		*name;
	tag_props_t	prop;
} ntop[] = {
{ TNF_N_INLINE,		TAG_PROP_INLINE },
{ TNF_N_TAGGED,		TAG_PROP_TAGGED },
{ TNF_N_SCALAR,		TAG_PROP_SCALAR },
{ TNF_N_DERIVED,	TAG_PROP_DERIVED },
{ TNF_N_ARRAY,		TAG_PROP_ARRAY },
{ TNF_N_STRING,		TAG_PROP_STRING },
{ TNF_N_STRUCT,		TAG_PROP_STRUCT },
{ TNF_N_TYPE,		TAG_PROP_TYPE },
{ NULL,			0}
};

static struct ntok {
	char		*name;
	tnf_kind_t	kind;
} scalar_ntok[] = {
{ TNF_N_CHAR, 		TNF_K_CHAR },
{ TNF_N_INT8,		TNF_K_INT8 },
{ TNF_N_INT16,		TNF_K_INT16 },
{ TNF_N_INT32,		TNF_K_INT32 },
{ TNF_N_UINT8,		TNF_K_UINT8 },
{ TNF_N_UINT16,		TNF_K_UINT16 },
{ TNF_N_UINT32,		TNF_K_UINT32 },
{ TNF_N_INT64,		TNF_K_INT64 },
{ TNF_N_UINT64,		TNF_K_UINT64 },
{ TNF_N_FLOAT32,	TNF_K_FLOAT32 },
{ TNF_N_FLOAT64,	TNF_K_FLOAT64 },
{ NULL,			0 }
};

/*
 * Compute tag props
 */

tag_props_t
_tnf_get_props(TNF *tnf, tnf_ref32_t *tag)
{
	tag_props_t	props;
	struct ntop  	*p;

	props = 0;

	p = ntop;
	/* No need to get base tag for inherited properties */
	while (p->name) {
		if (HAS_PROPERTY(tnf, tag, p->name))
			props |= p->prop;
		p++;
	}

	return (props);
}

/*
 * Data kind depends on implementation properties of base tag
 */

tnf_kind_t
_tnf_get_kind(TNF *tnf, tnf_ref32_t *tag)
{
	tnf_ref32_t	*base_tag;
	char		*base_name;

	base_tag 	= _tnf_get_base_tag(tnf, tag);
	base_name 	= _tnf_get_name(tnf, base_tag);

	if (HAS_PROPERTY(tnf, base_tag, TNF_N_SCALAR)) {
		struct ntok 	*p;

		p = scalar_ntok;
		while (p->name) {
			if (strcmp(p->name, base_name) == 0)
				return (p->kind);
			p++;
		}
		return (TNF_K_SCALAR);

	} else if (HAS_PROPERTY(tnf, base_tag, TNF_N_ARRAY)) {
		if (strcmp(base_name, TNF_N_STRING) == 0)
			return (TNF_K_STRING);
		else
			return (TNF_K_ARRAY);

	} else if (HAS_PROPERTY(tnf, base_tag, TNF_N_TYPE)) {
		return (TNF_K_TYPE);

	} else if (HAS_PROPERTY(tnf, base_tag, TNF_N_STRUCT)) {
		return (TNF_K_STRUCT);

	} else {		/* abstract */
		return (TNF_K_UNKNOWN);
	}
}