xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/mkerror.sh (revision 51396a8ee7fb52fe0ab33bfe7b4f495ad431904a)
1#!/bin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance 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 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#ident	"@(#)mkerror.sh	1.1	06/02/11 SMI"
27
28#pragma ident	"%Z%%M%	%I%	%E% SMI"
29
30
31input="`cat`"
32[ -z "$input" ] && exit 1
33
34if [ $1 = "liberrors" ] ; then
35echo "\
36/*\n\
37 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.\n\
38 * Use is subject to license terms.\n\
39 */\n\
40\n\
41#pragma ident\t\"@(#)mkerror.sh\t1.2\t05/06/08 SMI\"\n\
42\n\
43#include <strings.h>
44#include <topo_error.h>
45#include <topo_mod.h>
46
47\n\
48static const char *const _topo_errstrs[] = {"
49
50pattern='^[ ]*ETOPO_[A-Z0-9_]*.*\* \(.*\) \*.*'
51replace='	"\1",'
52
53echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
54
55echo "\
56};\n\
57\n\
58static const int _topo_nerrstrs =\n\
59    sizeof (_topo_errstrs) / sizeof (_topo_errstrs[0]);\n\
60\n\
61
62int
63topo_hdl_errno(topo_hdl_t *thp)
64{
65	return (thp->th_errno);
66}
67
68int
69topo_hdl_seterrno(topo_hdl_t *thp, int err)
70{
71	thp->th_errno = err;
72	return (-1);
73}
74
75const char *
76topo_hdl_errmsg(topo_hdl_t *thp)
77{
78	return (topo_strerror(thp->th_errno));
79}"
80
81elif [ $1 = "properrors" ] ; then
82
83echo "\
84\n\
85static const char *const _topo_properrstrs[] = {"
86
87pattern='^[ ]*ETOPO_PROP_[A-Z0-9_]*.*\* \(.*\) \*.*'
88replace='	"\1",'
89
90echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
91
92echo "\
93};\n\
94\n\
95static const int _topo_nproperrstrs =\n\
96    sizeof (_topo_properrstrs) / sizeof (_topo_properrstrs[0]);"
97
98elif [ $1 = "methoderrors" ] ; then
99
100echo "\
101\n\
102static const char *const _topo_methoderrstrs[] = {"
103
104pattern='^[ ]*ETOPO_METHOD_[A-Z0-9_]*.*\* \(.*\) \*.*'
105replace='	"\1",'
106
107echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
108
109echo "\
110};\n\
111\n\
112static const int _topo_nmethoderrstrs =\n\
113    sizeof (_topo_methoderrstrs) / sizeof (_topo_methoderrstrs[0]);"
114
115elif [ $1 = "fmrierrors" ] ; then
116
117echo "\
118\n\
119static const char *const _topo_fmrierrstrs[] = {"
120
121pattern='^[ ]*ETOPO_FMRI_[A-Z0-9_]*.*\* \(.*\) \*.*'
122replace='	"\1",'
123
124echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
125
126echo "\
127};\n\
128\n\
129static const int _topo_nfmrierrstrs =\n\
130    sizeof (_topo_fmrierrstrs) / sizeof (_topo_fmrierrstrs[0]);"
131
132elif [ $1 = "hdlerrors" ] ; then
133
134echo "\
135\n\
136static const char *const _topo_hdlerrstrs[] = {"
137
138pattern='^[ ]*ETOPO_HDL_[A-Z0-9_]*.*\* \(.*\) \*.*'
139replace='	"\1",'
140
141echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
142
143echo "\
144};\n\
145\n\
146static const int _topo_nhdlerrstrs =\n\
147    sizeof (_topo_hdlerrstrs) / sizeof (_topo_hdlerrstrs[0]);"
148
149else
150
151echo "\
152\n\
153static const char *const _topo_moderrstrs[] = {"
154
155pattern='^[ ]*EMOD_[A-Z0-9_]*.*\* \(.*\) \*.*'
156replace='	"\1",'
157
158echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
159
160echo "\
161};\n\
162static const int _topo_nmoderrstrs =\n\
163    sizeof (_topo_moderrstrs) / sizeof (_topo_moderrstrs[0]);\n\
164\n\
165
166int
167topo_mod_errno(topo_mod_t *mp)
168{
169	return (mp->tm_errno);
170}
171
172int
173topo_mod_seterrno(topo_mod_t *mp, int err)
174{
175	mp->tm_errno = err;
176	return (-1);
177}
178
179const char *
180topo_mod_errmsg(topo_mod_t *mp)
181{
182	return (topo_strerror(mp->tm_errno));
183}
184
185const char *
186topo_strerror(int err)
187{
188	const char *s;
189
190	if (err >= ETOPO_UNKNOWN && (err - ETOPO_UNKNOWN) < _topo_nerrstrs)
191		s = _topo_errstrs[err - ETOPO_UNKNOWN];
192	else if (err >= EMOD_UNKNOWN && (err - EMOD_UNKNOWN) <
193	    _topo_nmoderrstrs)
194		s = _topo_moderrstrs[err - EMOD_UNKNOWN];
195	else if (err >= ETOPO_PROP_UNKNOWN && (err - ETOPO_PROP_UNKNOWN) <
196	    _topo_nproperrstrs)
197		s = _topo_properrstrs[err - ETOPO_PROP_UNKNOWN];
198	else if (err >= ETOPO_METHOD_UNKNOWN && (err - ETOPO_METHOD_UNKNOWN) <
199	    _topo_nmethoderrstrs)
200		s = _topo_methoderrstrs[err - ETOPO_METHOD_UNKNOWN];
201	else if (err >= ETOPO_HDL_UNKNOWN && (err - ETOPO_HDL_UNKNOWN) <
202	    _topo_nhdlerrstrs)
203		s = _topo_hdlerrstrs[err - ETOPO_HDL_UNKNOWN];
204	else if (err >= ETOPO_FMRI_UNKNOWN && (err - ETOPO_FMRI_UNKNOWN) <
205	    _topo_nfmrierrstrs)
206		s = _topo_fmrierrstrs[err - ETOPO_FMRI_UNKNOWN];
207	else
208		s = _topo_errstrs[0];
209
210	return (s);
211}"
212
213fi
214
215exit 0
216