84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#!/bin/sh
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# CDDL HEADER START
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# The contents of this file are subject to the terms of the
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# Common Development and Distribution License, Version 1.0 only
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# (the "License"). You may not use this file except in compliance
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# with the License.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# or http://www.opensolaris.org/os/licensing.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# See the License for the specific language governing permissions
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# and limitations under the License.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# When distributing Covered Code, include this CDDL HEADER in each
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# If applicable, add the following below this CDDL HEADER, with the
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# fields enclosed by brackets "[]" replaced with your own identifying
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# information: Portions Copyright [yyyy] [name of copyright owner]
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# CDDL HEADER END
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
4e901881a1e657e1cbf12d7ef9b476ec373e7939Dale Ghent# Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# Use is subject to license terms.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# The SMBIOS interfaces defined in <sys/smbios.h> include a set of integer-to-
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# string conversion routines for the various constants defined in the SMBIOS
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# spec. These functions are used by smbios(1M) and prtdiag(1M) and can be
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# leveraged by other clients as well. To simplify maintenance of the source
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# base, this shell script automatically generates the source code for all of
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# these functions from the <sys/smbios.h> header file and its comments. Each
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# set of constants should be given a unique #define prefix, listed in the
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# tables below. The smbios_*_name() functions return the identifier of the
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# cpp define, and the smbios_*_desc() functions return the text of the comment.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsname_funcs='
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BBFL_ smbios_bboard_flag_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BIOSFL_ smbios_bios_flag_name uint64_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BIOSXB1_ smbios_bios_xb1_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BIOSXB2_ smbios_bios_xb2_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAT_ smbios_cache_ctype_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAF_ smbios_cache_flag_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_EVFL_ smbios_evlog_flag_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_IPMI_F_ smbios_ipmi_flag_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_MDF_ smbios_memdevice_flag_name uint_t
4e901881a1e657e1cbf12d7ef9b476ec373e7939Dale GhentSMB_PRC_ smbios_processor_core_flag_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_TYPE_ smbios_type_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLCH1_ smbios_slot_ch1_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLCH2_ smbios_slot_ch2_name uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws'
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsdesc_funcs='
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BBFL_ smbios_bboard_flag_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BBT_ smbios_bboard_type_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BIOSFL_ smbios_bios_flag_desc uint64_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BIOSXB1_ smbios_bios_xb1_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BIOSXB2_ smbios_bios_xb2_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_BOOT_ smbios_boot_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAA_ smbios_cache_assoc_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAT_ smbios_cache_ctype_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAE_ smbios_cache_ecc_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAF_ smbios_cache_flag_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAL_ smbios_cache_loc_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAG_ smbios_cache_logical_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CAM_ smbios_cache_mode_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CHST_ smbios_chassis_state_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_CHT_ smbios_chassis_type_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_EVFL_ smbios_evlog_flag_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_EVHF_ smbios_evlog_format_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_EVM_ smbios_evlog_method_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_HWSEC_PS_ smbios_hwsec_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_IPMI_F_ smbios_ipmi_flag_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_IPMI_T_ smbios_ipmi_type_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_MAL_ smbios_memarray_loc_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_MAU_ smbios_memarray_use_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_MAE_ smbios_memarray_ecc_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_MDF_ smbios_memdevice_flag_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_MDFF_ smbios_memdevice_form_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_MDT_ smbios_memdevice_type_desc uint_t
4e901881a1e657e1cbf12d7ef9b476ec373e7939Dale GhentSMB_MDR_ smbios_memdevice_rank_desc uint_t
6734c4b0468cc77a7871a5dd5c23a5562557d64cRobert MustacchiSMB_OBT_ smbios_onboard_type_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_POC_ smbios_port_conn_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_POT_ smbios_port_type_desc uint_t
4e901881a1e657e1cbf12d7ef9b476ec373e7939Dale GhentSMB_PRC_ smbios_processor_core_flag_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_PRF_ smbios_processor_family_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_PRS_ smbios_processor_status_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_PRT_ smbios_processor_type_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_PRU_ smbios_processor_upgrade_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLCH1_ smbios_slot_ch1_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLCH2_ smbios_slot_ch2_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLL_ smbios_slot_length_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLT_ smbios_slot_type_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLU_ smbios_slot_usage_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_SLW_ smbios_slot_width_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_TYPE_ smbios_type_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsSMB_WAKEUP_ smbios_system_wakeup_desc uint_t
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws'
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsif [ $# -ne 1 ]; then
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws echo "Usage: $0 file.h > file.c" >&2
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws exit 2
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsfi
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsecho "\
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws/*\n\
4e901881a1e657e1cbf12d7ef9b476ec373e7939Dale Ghent * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.\n\
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws * Copyright 2005 Sun Microsystems, Inc. All rights reserved.\n\
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws * Use is subject to license terms.\n\
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws */\n\
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws\n\
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#include <smbios.h>"
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsecho "$name_funcs" | while read p name type; do
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws [ -z "$p" ] && continue
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*[A-Z0-9]*.*$"
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws replace=' case \1: return ("\1");'
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws sed -n "s@$pattern@$replace@p" < $1 || exit 1
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws echo "\t}\n\treturn (NULL);\n}"
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsdone
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# Generate the description functions based on the comment next to a #define.
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# The transformations for descriptive comments are slightly more complicated
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# than those used for the identifier->name functions above:
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# (1) strip any [RO] suffix from the comment (a header file convention)
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# (2) replace any " with \" so it is escaped for the final output string
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws# (3) replace return (...); with return ("..."); to finish the code
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws#
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsecho "$desc_funcs" | while read p name type; do
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws [ -z "$p" ] && continue
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*.*/\\* \(.*\) \\*/$"
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws replace=' case \1: return (\2);'
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws sed -n "s@$pattern@$replace@p" < $1 | sed 's/ ([RO]))/)/' | \
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws sed 's/"/\\"/g' | sed 's/(/("/;s/);$/");/' || exit 1
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws echo "\t}\n\treturn (NULL);\n}"
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsdone
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mws
84ab085a13f931bc78e7415e7ce921dbaa14fcb3mwsexit 0