xref: /titanic_50/usr/src/lib/scsi/libsmp/common/mkerrno.sh (revision cd3e933325e68e23516a196a8fea7f49b1e497c3)
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#
24# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25#
26
27echo "\
28/*
29 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
30 */
31
32#pragma ident\t\"@(#)mkerrno.sh\t1.2\t08/07/31\tSMI\"
33
34#include <strings.h>
35#include <scsi/libsmp.h>
36
37static const struct {
38\tchar *name;\t\t/* error name */
39\tchar *msg;\t\t/* error message */
40} _smp_errstr[] = {"
41
42pattern='^	\(ESMP_[A-Z0-9_]*\),*'
43replace='	{ "\1",'
44open='	\/\* '
45openrepl='"'
46close=' \*\/$'
47closerepl='" },'
48
49( sed -n "s/$pattern/$replace/p" | sed -n "s/$open/$openrepl/p" |
50    sed -n "s/$close/$closerepl/p" ) || exit 1
51
52echo "\
53};\n\
54\n\
55static int _smp_nerrno = sizeof (_smp_errstr) /\n\
56    sizeof (_smp_errstr[0]);\n\
57\n\
58const char *
59smp_strerror(smp_errno_t err)
60{
61	return (err < 0 || err >= _smp_nerrno ? \"unknown error\" :
62	     _smp_errstr[err].msg);
63}
64
65const char *
66smp_errname(smp_errno_t err)
67{
68	return (err < 0 || err >= _smp_nerrno ? NULL :
69	     _smp_errstr[err].name);
70}
71
72smp_errno_t
73smp_errcode(const char *name)
74{
75	smp_errno_t err;
76
77	for (err = 0; err < _smp_nerrno; err++) {
78		if (strcmp(name, _smp_errstr[err].name) == 0)
79			return (err);
80	}
81
82	return (ESMP_UNKNOWN);
83}"
84
85exit 0
86