8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libtnf / util.c
blobf81b8aa19c53c52376dae1d6bfc9716f0636a7d5
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include "libtnf.h"
34 static 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}
49 static 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 }
68 * Compute tag props
71 tag_props_t
72 _tnf_get_props(TNF *tnf, tnf_ref32_t *tag)
74 tag_props_t props;
75 struct ntop *p;
77 props = 0;
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++;
87 return (props);
91 * Data kind depends on implementation properties of base tag
94 tnf_kind_t
95 _tnf_get_kind(TNF *tnf, tnf_ref32_t *tag)
97 tnf_ref32_t *base_tag;
98 char *base_name;
100 base_tag = _tnf_get_base_tag(tnf, tag);
101 base_name = _tnf_get_name(tnf, base_tag);
103 if (HAS_PROPERTY(tnf, base_tag, TNF_N_SCALAR)) {
104 struct ntok *p;
106 p = scalar_ntok;
107 while (p->name) {
108 if (strcmp(p->name, base_name) == 0)
109 return (p->kind);
110 p++;
112 return (TNF_K_SCALAR);
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);
120 } else if (HAS_PROPERTY(tnf, base_tag, TNF_N_TYPE)) {
121 return (TNF_K_TYPE);
123 } else if (HAS_PROPERTY(tnf, base_tag, TNF_N_STRUCT)) {
124 return (TNF_K_STRUCT);
126 } else { /* abstract */
127 return (TNF_K_UNKNOWN);