1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 *	Copyright (c) 1994, by Sun Microsytems, Inc.
24 */
25
26#pragma	ident	"%Z%%M%	%I%	%E% SMI"
27
28#include "libtnf.h"
29
30/*
31 *
32 */
33
34static struct ntop {
35	char		*name;
36	tag_props_t	prop;
37} ntop[] = {
38{ TNF_N_INLINE,		TAG_PROP_INLINE },
39{ TNF_N_TAGGED,		TAG_PROP_TAGGED },
40{ TNF_N_SCALAR,		TAG_PROP_SCALAR },
41{ TNF_N_DERIVED,	TAG_PROP_DERIVED },
42{ TNF_N_ARRAY,		TAG_PROP_ARRAY },
43{ TNF_N_STRING,		TAG_PROP_STRING },
44{ TNF_N_STRUCT,		TAG_PROP_STRUCT },
45{ TNF_N_TYPE,		TAG_PROP_TYPE },
46{ NULL,			0}
47};
48
49static struct ntok {
50	char		*name;
51	tnf_kind_t	kind;
52} scalar_ntok[] = {
53{ TNF_N_CHAR, 		TNF_K_CHAR },
54{ TNF_N_INT8,		TNF_K_INT8 },
55{ TNF_N_INT16,		TNF_K_INT16 },
56{ TNF_N_INT32,		TNF_K_INT32 },
57{ TNF_N_UINT8,		TNF_K_UINT8 },
58{ TNF_N_UINT16,		TNF_K_UINT16 },
59{ TNF_N_UINT32,		TNF_K_UINT32 },
60{ TNF_N_INT64,		TNF_K_INT64 },
61{ TNF_N_UINT64,		TNF_K_UINT64 },
62{ TNF_N_FLOAT32,	TNF_K_FLOAT32 },
63{ TNF_N_FLOAT64,	TNF_K_FLOAT64 },
64{ NULL,			0 }
65};
66
67/*
68 * Compute tag props
69 */
70
71tag_props_t
72_tnf_get_props(TNF *tnf, tnf_ref32_t *tag)
73{
74	tag_props_t	props;
75	struct ntop  	*p;
76
77	props = 0;
78
79	p = ntop;
80	/* No need to get base tag for inherited properties */
81	while (p->name) {
82		if (HAS_PROPERTY(tnf, tag, p->name))
83			props |= p->prop;
84		p++;
85	}
86
87	return (props);
88}
89
90/*
91 * Data kind depends on implementation properties of base tag
92 */
93
94tnf_kind_t
95_tnf_get_kind(TNF *tnf, tnf_ref32_t *tag)
96{
97	tnf_ref32_t	*base_tag;
98	char		*base_name;
99
100	base_tag 	= _tnf_get_base_tag(tnf, tag);
101	base_name 	= _tnf_get_name(tnf, base_tag);
102
103	if (HAS_PROPERTY(tnf, base_tag, TNF_N_SCALAR)) {
104		struct ntok 	*p;
105
106		p = scalar_ntok;
107		while (p->name) {
108			if (strcmp(p->name, base_name) == 0)
109				return (p->kind);
110			p++;
111		}
112		return (TNF_K_SCALAR);
113
114	} else if (HAS_PROPERTY(tnf, base_tag, TNF_N_ARRAY)) {
115		if (strcmp(base_name, TNF_N_STRING) == 0)
116			return (TNF_K_STRING);
117		else
118			return (TNF_K_ARRAY);
119
120	} else if (HAS_PROPERTY(tnf, base_tag, TNF_N_TYPE)) {
121		return (TNF_K_TYPE);
122
123	} else if (HAS_PROPERTY(tnf, base_tag, TNF_N_STRUCT)) {
124		return (TNF_K_STRUCT);
125
126	} else {		/* abstract */
127		return (TNF_K_UNKNOWN);
128	}
129}
130