xref: /titanic_50/usr/src/cmd/fm/fmd/common/mkerror.sh (revision d9638e547d8811f2c689977f8dd2a353938b61fd)
17c478bd9Sstevel@tonic-gate#!/bin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate# with the License.
97c478bd9Sstevel@tonic-gate#
107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate# and limitations under the License.
147c478bd9Sstevel@tonic-gate#
157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate# CDDL HEADER END
227c478bd9Sstevel@tonic-gate#
237c478bd9Sstevel@tonic-gate#
24*d9638e54Smws# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gateinput="`cat`"
327c478bd9Sstevel@tonic-gate[ -z "$input" ] && exit 1
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gateecho "\
357c478bd9Sstevel@tonic-gate/*\n\
36*d9638e54Smws * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.\n\
377c478bd9Sstevel@tonic-gate * Use is subject to license terms.\n\
387c478bd9Sstevel@tonic-gate */\n\
397c478bd9Sstevel@tonic-gate\n\
407c478bd9Sstevel@tonic-gate#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n\
417c478bd9Sstevel@tonic-gate\n\
427c478bd9Sstevel@tonic-gate#include <strings.h>
437c478bd9Sstevel@tonic-gate#include <fmd_error.h>
447c478bd9Sstevel@tonic-gate\n\
457c478bd9Sstevel@tonic-gatestatic const char *const _fmd_ereports[] = {"
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gatepattern='^[ ]*EFMD_\([A-Z0-9_]*\).*,*'
48*d9638e54Smwsreplace='	"ereport.fm.fmd.\1",'
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gateecho "$input" | sed -n "s/$pattern/$replace/p" | tr '[A-Z]' '[a-z]' || exit 1
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gateecho "\
537c478bd9Sstevel@tonic-gate};\n\
547c478bd9Sstevel@tonic-gate\n\
557c478bd9Sstevel@tonic-gatestatic const char *const _fmd_errstrs[] = {"
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gatepattern='^[ ]*EFMD_[A-Z0-9_]*.*\* \(.*\) \*.*'
587c478bd9Sstevel@tonic-gatereplace='	"\1",'
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gateecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gateecho "\
637c478bd9Sstevel@tonic-gate};\n\
647c478bd9Sstevel@tonic-gate\n\
657c478bd9Sstevel@tonic-gatestatic const int _fmd_nereports =\n\
667c478bd9Sstevel@tonic-gate    sizeof (_fmd_ereports) / sizeof (_fmd_ereports[0]);\n\
677c478bd9Sstevel@tonic-gate\n\
687c478bd9Sstevel@tonic-gatestatic const int _fmd_nerrstrs =\n\
697c478bd9Sstevel@tonic-gate    sizeof (_fmd_errstrs) / sizeof (_fmd_errstrs[0]);\n\
707c478bd9Sstevel@tonic-gate\n\
717c478bd9Sstevel@tonic-gateconst char *
727c478bd9Sstevel@tonic-gatefmd_errclass(int err)
737c478bd9Sstevel@tonic-gate{
747c478bd9Sstevel@tonic-gate	const char *c;
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate	if (err >= EFMD_UNKNOWN && (err - EFMD_UNKNOWN) < _fmd_nereports)
777c478bd9Sstevel@tonic-gate		c = _fmd_ereports[err - EFMD_UNKNOWN];
787c478bd9Sstevel@tonic-gate	else
797c478bd9Sstevel@tonic-gate		c = _fmd_ereports[0];
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate	return (c);
827c478bd9Sstevel@tonic-gate}
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gateconst char *
857c478bd9Sstevel@tonic-gatefmd_strerror(int err)
867c478bd9Sstevel@tonic-gate{
877c478bd9Sstevel@tonic-gate	const char *s;
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate	if (err >= EFMD_UNKNOWN && (err - EFMD_UNKNOWN) < _fmd_nerrstrs)
907c478bd9Sstevel@tonic-gate		s = _fmd_errstrs[err - EFMD_UNKNOWN];
917c478bd9Sstevel@tonic-gate	else if (err < 0 || (s = strerror(err)) == NULL)
927c478bd9Sstevel@tonic-gate		s = _fmd_errstrs[0];
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate	return (s);
957c478bd9Sstevel@tonic-gate}
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gateint
987c478bd9Sstevel@tonic-gatefmd_set_errno(int err)
997c478bd9Sstevel@tonic-gate{
1007c478bd9Sstevel@tonic-gate	errno = err;
1017c478bd9Sstevel@tonic-gate	return (-1);
1027c478bd9Sstevel@tonic-gate}"
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gateexit 0
105