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