xref: /illumos-gate/usr/src/cmd/fm/fmd/common/mkerror.sh (revision 2a8bcb4e)
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
287c478bd9Sstevel@tonic-gateinput="`cat`"
297c478bd9Sstevel@tonic-gate[ -z "$input" ] && exit 1
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gateecho "\
327c478bd9Sstevel@tonic-gate/*\n\
33*d9638e54Smws * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.\n\
347c478bd9Sstevel@tonic-gate * Use is subject to license terms.\n\
357c478bd9Sstevel@tonic-gate */\n\
367c478bd9Sstevel@tonic-gate\n\
377c478bd9Sstevel@tonic-gate#include <strings.h>
387c478bd9Sstevel@tonic-gate#include <fmd_error.h>
397c478bd9Sstevel@tonic-gate\n\
407c478bd9Sstevel@tonic-gatestatic const char *const _fmd_ereports[] = {"
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gatepattern='^[ ]*EFMD_\([A-Z0-9_]*\).*,*'
43*d9638e54Smwsreplace='	"ereport.fm.fmd.\1",'
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gateecho "$input" | sed -n "s/$pattern/$replace/p" | tr '[A-Z]' '[a-z]' || exit 1
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gateecho "\
487c478bd9Sstevel@tonic-gate};\n\
497c478bd9Sstevel@tonic-gate\n\
507c478bd9Sstevel@tonic-gatestatic const char *const _fmd_errstrs[] = {"
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gatepattern='^[ ]*EFMD_[A-Z0-9_]*.*\* \(.*\) \*.*'
537c478bd9Sstevel@tonic-gatereplace='	"\1",'
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gateecho "$input" | sed -n "s/$pattern/$replace/p" || exit 1
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gateecho "\
587c478bd9Sstevel@tonic-gate};\n\
597c478bd9Sstevel@tonic-gate\n\
607c478bd9Sstevel@tonic-gatestatic const int _fmd_nereports =\n\
617c478bd9Sstevel@tonic-gate    sizeof (_fmd_ereports) / sizeof (_fmd_ereports[0]);\n\
627c478bd9Sstevel@tonic-gate\n\
637c478bd9Sstevel@tonic-gatestatic const int _fmd_nerrstrs =\n\
647c478bd9Sstevel@tonic-gate    sizeof (_fmd_errstrs) / sizeof (_fmd_errstrs[0]);\n\
657c478bd9Sstevel@tonic-gate\n\
667c478bd9Sstevel@tonic-gateconst char *
677c478bd9Sstevel@tonic-gatefmd_errclass(int err)
687c478bd9Sstevel@tonic-gate{
697c478bd9Sstevel@tonic-gate	const char *c;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate	if (err >= EFMD_UNKNOWN && (err - EFMD_UNKNOWN) < _fmd_nereports)
727c478bd9Sstevel@tonic-gate		c = _fmd_ereports[err - EFMD_UNKNOWN];
737c478bd9Sstevel@tonic-gate	else
747c478bd9Sstevel@tonic-gate		c = _fmd_ereports[0];
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate	return (c);
777c478bd9Sstevel@tonic-gate}
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gateconst char *
807c478bd9Sstevel@tonic-gatefmd_strerror(int err)
817c478bd9Sstevel@tonic-gate{
827c478bd9Sstevel@tonic-gate	const char *s;
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate	if (err >= EFMD_UNKNOWN && (err - EFMD_UNKNOWN) < _fmd_nerrstrs)
857c478bd9Sstevel@tonic-gate		s = _fmd_errstrs[err - EFMD_UNKNOWN];
867c478bd9Sstevel@tonic-gate	else if (err < 0 || (s = strerror(err)) == NULL)
877c478bd9Sstevel@tonic-gate		s = _fmd_errstrs[0];
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate	return (s);
907c478bd9Sstevel@tonic-gate}
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gateint
937c478bd9Sstevel@tonic-gatefmd_set_errno(int err)
947c478bd9Sstevel@tonic-gate{
957c478bd9Sstevel@tonic-gate	errno = err;
967c478bd9Sstevel@tonic-gate	return (-1);
977c478bd9Sstevel@tonic-gate}"
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gateexit 0
100