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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28
29#pragma ident	"%Z%%M%	%I%	%E% SMI"
30
31
32input="`cat`"
33[ -z "$input" ] && exit 1
34
35if [ $1 = "internal" ] ; then
36echo "\
37/*\n\
38 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.\n\
39 * Use is subject to license terms.\n\
40 */\n\
41\n\
42#pragma ident\t\"@(#)mkerror.sh\t1.2\t05/06/08 SMI\"\n\
43\n\
44#include <strings.h>
45#include <topo_error.h>
46#include <topo_mod.h>
47
48\n\
49static const char *const _topo_errstrs[] = {"
50
51pattern='^[ ]*ETOPO_[A-Z0-9_]*.*\* \(.*\) \*.*'
52replace='	"\1",'
53
54echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
55
56echo "\
57};\n\
58\n\
59static const int _topo_nerrstrs =\n\
60    sizeof (_topo_errstrs) / sizeof (_topo_errstrs[0]);\n\
61\n\
62
63int
64topo_hdl_errno(topo_hdl_t *thp)
65{
66	return (thp->th_errno);
67}
68
69int
70topo_hdl_seterrno(topo_hdl_t *thp, int err)
71{
72	thp->th_errno = err;
73	return (-1);
74}
75
76const char *
77topo_hdl_errmsg(topo_hdl_t *thp)
78{
79	return (topo_strerror(thp->th_errno));
80}"
81
82else
83
84echo "\
85static const char *const _topo_moderrstrs[] = {"
86
87pattern='^[ ]*EMOD_[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_nmoderrstrs =\n\
96    sizeof (_topo_moderrstrs) / sizeof (_topo_moderrstrs[0]);\n\
97\n\
98
99int
100topo_mod_errno(topo_mod_t *mp)
101{
102	return (mp->tm_errno);
103}
104
105int
106topo_mod_seterrno(topo_mod_t *mp, int err)
107{
108	mp->tm_errno = err;
109	return (-1);
110}
111
112const char *
113topo_mod_errmsg(topo_mod_t *mp)
114{
115	return (topo_strerror(mp->tm_errno));
116}
117
118const char *
119topo_strerror(int err)
120{
121	const char *s;
122
123	if (err >= ETOPO_UNKNOWN && (err - ETOPO_UNKNOWN) < _topo_nerrstrs)
124		s = _topo_errstrs[err - ETOPO_UNKNOWN];
125	else if (err >= EMOD_UNKNOWN && (err - EMOD_UNKNOWN) <  _topo_nmoderrstrs)
126		s = _topo_moderrstrs[err - EMOD_UNKNOWN];
127	else
128		s = _topo_errstrs[0];
129
130	return (s);
131}"
132
133fi
134
135exit 0
136