Home | History | Annotate | Download | only in common
      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 
     31 input="`cat`"
     32 [ -z "$input" ] && exit 1
     33 
     34 if [ $1 = "liberrors" ] ; then
     35 echo "\
     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\
     48 static const char *const _topo_errstrs[] = {"
     49 
     50 pattern='^[ ]*ETOPO_[A-Z0-9_]*.*\* \(.*\) \*.*'
     51 replace='	"\1",'
     52 
     53 echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
     54 
     55 echo "\
     56 };\n\
     57 \n\
     58 static const int _topo_nerrstrs =\n\
     59     sizeof (_topo_errstrs) / sizeof (_topo_errstrs[0]);\n\
     60 \n\
     61 
     62 int
     63 topo_hdl_errno(topo_hdl_t *thp)
     64 {
     65 	return (thp->th_errno);
     66 }
     67 
     68 int
     69 topo_hdl_seterrno(topo_hdl_t *thp, int err)
     70 {
     71 	thp->th_errno = err;
     72 	return (-1);
     73 }
     74 
     75 const char *
     76 topo_hdl_errmsg(topo_hdl_t *thp)
     77 {
     78 	return (topo_strerror(thp->th_errno));
     79 }"
     80 
     81 elif [ $1 = "properrors" ] ; then
     82 
     83 echo "\
     84 \n\
     85 static const char *const _topo_properrstrs[] = {"
     86 
     87 pattern='^[ ]*ETOPO_PROP_[A-Z0-9_]*.*\* \(.*\) \*.*'
     88 replace='	"\1",'
     89 
     90 echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
     91 
     92 echo "\
     93 };\n\
     94 \n\
     95 static const int _topo_nproperrstrs =\n\
     96     sizeof (_topo_properrstrs) / sizeof (_topo_properrstrs[0]);"
     97 
     98 elif [ $1 = "methoderrors" ] ; then
     99 
    100 echo "\
    101 \n\
    102 static const char *const _topo_methoderrstrs[] = {"
    103 
    104 pattern='^[ ]*ETOPO_METHOD_[A-Z0-9_]*.*\* \(.*\) \*.*'
    105 replace='	"\1",'
    106 
    107 echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
    108 
    109 echo "\
    110 };\n\
    111 \n\
    112 static const int _topo_nmethoderrstrs =\n\
    113     sizeof (_topo_methoderrstrs) / sizeof (_topo_methoderrstrs[0]);"
    114 
    115 elif [ $1 = "fmrierrors" ] ; then
    116 
    117 echo "\
    118 \n\
    119 static const char *const _topo_fmrierrstrs[] = {"
    120 
    121 pattern='^[ ]*ETOPO_FMRI_[A-Z0-9_]*.*\* \(.*\) \*.*'
    122 replace='	"\1",'
    123 
    124 echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
    125 
    126 echo "\
    127 };\n\
    128 \n\
    129 static const int _topo_nfmrierrstrs =\n\
    130     sizeof (_topo_fmrierrstrs) / sizeof (_topo_fmrierrstrs[0]);"
    131 
    132 elif [ $1 = "hdlerrors" ] ; then
    133 
    134 echo "\
    135 \n\
    136 static const char *const _topo_hdlerrstrs[] = {"
    137 
    138 pattern='^[ ]*ETOPO_HDL_[A-Z0-9_]*.*\* \(.*\) \*.*'
    139 replace='	"\1",'
    140 
    141 echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
    142 
    143 echo "\
    144 };\n\
    145 \n\
    146 static const int _topo_nhdlerrstrs =\n\
    147     sizeof (_topo_hdlerrstrs) / sizeof (_topo_hdlerrstrs[0]);"
    148 
    149 else
    150 
    151 echo "\
    152 \n\
    153 static const char *const _topo_moderrstrs[] = {"
    154 
    155 pattern='^[ ]*EMOD_[A-Z0-9_]*.*\* \(.*\) \*.*'
    156 replace='	"\1",'
    157 
    158 echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
    159 
    160 echo "\
    161 };\n\
    162 static const int _topo_nmoderrstrs =\n\
    163     sizeof (_topo_moderrstrs) / sizeof (_topo_moderrstrs[0]);\n\
    164 \n\
    165 
    166 int
    167 topo_mod_errno(topo_mod_t *mp)
    168 {
    169 	return (mp->tm_errno);
    170 }
    171 
    172 int
    173 topo_mod_seterrno(topo_mod_t *mp, int err)
    174 {
    175 	mp->tm_errno = err;
    176 	return (-1);
    177 }
    178 
    179 const char *
    180 topo_mod_errmsg(topo_mod_t *mp)
    181 {
    182 	return (topo_strerror(mp->tm_errno));
    183 }
    184 
    185 const char *
    186 topo_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 
    213 fi
    214 
    215 exit 0
    216