17aec1d6eScindi#!/bin/sh
27aec1d6eScindi#
37aec1d6eScindi# CDDL HEADER START
47aec1d6eScindi#
57aec1d6eScindi# The contents of this file are subject to the terms of the
60eb822a1Scindi# Common Development and Distribution License (the "License").
70eb822a1Scindi# You may not use this file except in compliance with the License.
87aec1d6eScindi#
97aec1d6eScindi# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107aec1d6eScindi# or http://www.opensolaris.org/os/licensing.
117aec1d6eScindi# See the License for the specific language governing permissions
127aec1d6eScindi# and limitations under the License.
137aec1d6eScindi#
147aec1d6eScindi# When distributing Covered Code, include this CDDL HEADER in each
157aec1d6eScindi# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167aec1d6eScindi# If applicable, add the following below this CDDL HEADER, with the
177aec1d6eScindi# fields enclosed by brackets "[]" replaced with your own identifying
187aec1d6eScindi# information: Portions Copyright [yyyy] [name of copyright owner]
197aec1d6eScindi#
207aec1d6eScindi# CDDL HEADER END
217aec1d6eScindi#
227aec1d6eScindi#
23dd566498Svn# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247aec1d6eScindi# Use is subject to license terms.
257aec1d6eScindi#
267aec1d6eScindi
277aec1d6eScindiinput="`cat`"
287aec1d6eScindi[ -z "$input" ] && exit 1
297aec1d6eScindi
300eb822a1Scindiif [ $1 = "liberrors" ] ; then
317aec1d6eScindiecho "\
327aec1d6eScindi/*\n\
33c40d7343Scindi * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.\n\
347aec1d6eScindi * Use is subject to license terms.\n\
357aec1d6eScindi */\n\
367aec1d6eScindi\n\
377aec1d6eScindi#include <strings.h>
387aec1d6eScindi#include <topo_error.h>
397aec1d6eScindi#include <topo_mod.h>
407aec1d6eScindi
417aec1d6eScindi\n\
427aec1d6eScindistatic const char *const _topo_errstrs[] = {"
437aec1d6eScindi
447aec1d6eScindipattern='^[ ]*ETOPO_[A-Z0-9_]*.*\* \(.*\) \*.*'
457aec1d6eScindireplace='	"\1",'
467aec1d6eScindi
477aec1d6eScindiecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
487aec1d6eScindi
497aec1d6eScindiecho "\
507aec1d6eScindi};\n\
517aec1d6eScindi\n\
527aec1d6eScindistatic const int _topo_nerrstrs =\n\
537aec1d6eScindi    sizeof (_topo_errstrs) / sizeof (_topo_errstrs[0]);\n\
547aec1d6eScindi\n\
557aec1d6eScindi
567aec1d6eScindiint
577aec1d6eScinditopo_hdl_errno(topo_hdl_t *thp)
587aec1d6eScindi{
597aec1d6eScindi	return (thp->th_errno);
607aec1d6eScindi}
617aec1d6eScindi
627aec1d6eScindiint
637aec1d6eScinditopo_hdl_seterrno(topo_hdl_t *thp, int err)
647aec1d6eScindi{
657aec1d6eScindi	thp->th_errno = err;
667aec1d6eScindi	return (-1);
677aec1d6eScindi}
687aec1d6eScindi
697aec1d6eScindiconst char *
707aec1d6eScinditopo_hdl_errmsg(topo_hdl_t *thp)
717aec1d6eScindi{
727aec1d6eScindi	return (topo_strerror(thp->th_errno));
737aec1d6eScindi}"
747aec1d6eScindi
750eb822a1Scindielif [ $1 = "properrors" ] ; then
760eb822a1Scindi
770eb822a1Scindiecho "\
780eb822a1Scindi\n\
790eb822a1Scindistatic const char *const _topo_properrstrs[] = {"
800eb822a1Scindi
810eb822a1Scindipattern='^[ ]*ETOPO_PROP_[A-Z0-9_]*.*\* \(.*\) \*.*'
820eb822a1Scindireplace='	"\1",'
830eb822a1Scindi
840eb822a1Scindiecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
850eb822a1Scindi
860eb822a1Scindiecho "\
870eb822a1Scindi};\n\
880eb822a1Scindi\n\
890eb822a1Scindistatic const int _topo_nproperrstrs =\n\
900eb822a1Scindi    sizeof (_topo_properrstrs) / sizeof (_topo_properrstrs[0]);"
910eb822a1Scindi
92dd566498Svnelif [ $1 = "methoderrors" ] ; then
93dd566498Svn
94dd566498Svnecho "\
95dd566498Svn\n\
96dd566498Svnstatic const char *const _topo_methoderrstrs[] = {"
97dd566498Svn
98dd566498Svnpattern='^[ ]*ETOPO_METHOD_[A-Z0-9_]*.*\* \(.*\) \*.*'
99dd566498Svnreplace='	"\1",'
100dd566498Svn
101dd566498Svnecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
102dd566498Svn
103dd566498Svnecho "\
104dd566498Svn};\n\
105dd566498Svn\n\
106dd566498Svnstatic const int _topo_nmethoderrstrs =\n\
107dd566498Svn    sizeof (_topo_methoderrstrs) / sizeof (_topo_methoderrstrs[0]);"
108c40d7343Scindi
109c40d7343Scindielif [ $1 = "fmrierrors" ] ; then
110c40d7343Scindi
111c40d7343Scindiecho "\
112c40d7343Scindi\n\
113c40d7343Scindistatic const char *const _topo_fmrierrstrs[] = {"
114c40d7343Scindi
115c40d7343Scindipattern='^[ ]*ETOPO_FMRI_[A-Z0-9_]*.*\* \(.*\) \*.*'
116c40d7343Scindireplace='	"\1",'
117c40d7343Scindi
118c40d7343Scindiecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
119c40d7343Scindi
120c40d7343Scindiecho "\
121c40d7343Scindi};\n\
122c40d7343Scindi\n\
123c40d7343Scindistatic const int _topo_nfmrierrstrs =\n\
124c40d7343Scindi    sizeof (_topo_fmrierrstrs) / sizeof (_topo_fmrierrstrs[0]);"
125c40d7343Scindi
126c40d7343Scindielif [ $1 = "hdlerrors" ] ; then
127c40d7343Scindi
128c40d7343Scindiecho "\
129c40d7343Scindi\n\
130c40d7343Scindistatic const char *const _topo_hdlerrstrs[] = {"
131c40d7343Scindi
132c40d7343Scindipattern='^[ ]*ETOPO_HDL_[A-Z0-9_]*.*\* \(.*\) \*.*'
133c40d7343Scindireplace='	"\1",'
134c40d7343Scindi
135c40d7343Scindiecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
136c40d7343Scindi
137c40d7343Scindiecho "\
138c40d7343Scindi};\n\
139c40d7343Scindi\n\
140c40d7343Scindistatic const int _topo_nhdlerrstrs =\n\
141c40d7343Scindi    sizeof (_topo_hdlerrstrs) / sizeof (_topo_hdlerrstrs[0]);"
142c40d7343Scindi
1437aec1d6eScindielse
1447aec1d6eScindi
1457aec1d6eScindiecho "\
1460eb822a1Scindi\n\
1477aec1d6eScindistatic const char *const _topo_moderrstrs[] = {"
1487aec1d6eScindi
1497aec1d6eScindipattern='^[ ]*EMOD_[A-Z0-9_]*.*\* \(.*\) \*.*'
1507aec1d6eScindireplace='	"\1",'
1517aec1d6eScindi
1527aec1d6eScindiecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
1537aec1d6eScindi
1547aec1d6eScindiecho "\
1557aec1d6eScindi};\n\
1567aec1d6eScindistatic const int _topo_nmoderrstrs =\n\
1577aec1d6eScindi    sizeof (_topo_moderrstrs) / sizeof (_topo_moderrstrs[0]);\n\
1587aec1d6eScindi\n\
1597aec1d6eScindi
1607aec1d6eScindiint
1617aec1d6eScinditopo_mod_errno(topo_mod_t *mp)
1627aec1d6eScindi{
1637aec1d6eScindi	return (mp->tm_errno);
1647aec1d6eScindi}
1657aec1d6eScindi
1667aec1d6eScindiint
1677aec1d6eScinditopo_mod_seterrno(topo_mod_t *mp, int err)
1687aec1d6eScindi{
1697aec1d6eScindi	mp->tm_errno = err;
1707aec1d6eScindi	return (-1);
1717aec1d6eScindi}
1727aec1d6eScindi
1737aec1d6eScindiconst char *
1747aec1d6eScinditopo_mod_errmsg(topo_mod_t *mp)
1757aec1d6eScindi{
1767aec1d6eScindi	return (topo_strerror(mp->tm_errno));
1777aec1d6eScindi}
1787aec1d6eScindi
1797aec1d6eScindiconst char *
1807aec1d6eScinditopo_strerror(int err)
1817aec1d6eScindi{
1827aec1d6eScindi	const char *s;
1837aec1d6eScindi
1847aec1d6eScindi	if (err >= ETOPO_UNKNOWN && (err - ETOPO_UNKNOWN) < _topo_nerrstrs)
1857aec1d6eScindi		s = _topo_errstrs[err - ETOPO_UNKNOWN];
1860eb822a1Scindi	else if (err >= EMOD_UNKNOWN && (err - EMOD_UNKNOWN) <
1870eb822a1Scindi	    _topo_nmoderrstrs)
1887aec1d6eScindi		s = _topo_moderrstrs[err - EMOD_UNKNOWN];
1890eb822a1Scindi	else if (err >= ETOPO_PROP_UNKNOWN && (err - ETOPO_PROP_UNKNOWN) <
1900eb822a1Scindi	    _topo_nproperrstrs)
1910eb822a1Scindi		s = _topo_properrstrs[err - ETOPO_PROP_UNKNOWN];
192dd566498Svn	else if (err >= ETOPO_METHOD_UNKNOWN && (err - ETOPO_METHOD_UNKNOWN) <
193dd566498Svn	    _topo_nmethoderrstrs)
194*15fa5289Scindi		s = _topo_methoderrstrs[err - ETOPO_METHOD_UNKNOWN];
195c40d7343Scindi	else if (err >= ETOPO_HDL_UNKNOWN && (err - ETOPO_HDL_UNKNOWN) <
196c40d7343Scindi	    _topo_nhdlerrstrs)
197*15fa5289Scindi		s = _topo_hdlerrstrs[err - ETOPO_HDL_UNKNOWN];
198c40d7343Scindi	else if (err >= ETOPO_FMRI_UNKNOWN && (err - ETOPO_FMRI_UNKNOWN) <
199c40d7343Scindi	    _topo_nfmrierrstrs)
200*15fa5289Scindi		s = _topo_fmrierrstrs[err - ETOPO_FMRI_UNKNOWN];
2017aec1d6eScindi	else
2027aec1d6eScindi		s = _topo_errstrs[0];
2037aec1d6eScindi
2047aec1d6eScindi	return (s);
2057aec1d6eScindi}"
2067aec1d6eScindi
2077aec1d6eScindifi
2087aec1d6eScindi
2097aec1d6eScindiexit 0
210