184ab085aSmws#!/bin/sh 284ab085aSmws# 384ab085aSmws# CDDL HEADER START 484ab085aSmws# 584ab085aSmws# The contents of this file are subject to the terms of the 684ab085aSmws# Common Development and Distribution License, Version 1.0 only 784ab085aSmws# (the "License"). You may not use this file except in compliance 884ab085aSmws# with the License. 984ab085aSmws# 1084ab085aSmws# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 1184ab085aSmws# or http://www.opensolaris.org/os/licensing. 1284ab085aSmws# See the License for the specific language governing permissions 1384ab085aSmws# and limitations under the License. 1484ab085aSmws# 1584ab085aSmws# When distributing Covered Code, include this CDDL HEADER in each 1684ab085aSmws# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1784ab085aSmws# If applicable, add the following below this CDDL HEADER, with the 1884ab085aSmws# fields enclosed by brackets "[]" replaced with your own identifying 1984ab085aSmws# information: Portions Copyright [yyyy] [name of copyright owner] 2084ab085aSmws# 2184ab085aSmws# CDDL HEADER END 2284ab085aSmws# 2384ab085aSmws# 24*4e901881SDale Ghent# Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. 2584ab085aSmws# Copyright 2005 Sun Microsystems, Inc. All rights reserved. 2684ab085aSmws# Use is subject to license terms. 2784ab085aSmws# 2884ab085aSmws 2984ab085aSmws# 3084ab085aSmws# The SMBIOS interfaces defined in <sys/smbios.h> include a set of integer-to- 3184ab085aSmws# string conversion routines for the various constants defined in the SMBIOS 3284ab085aSmws# spec. These functions are used by smbios(1M) and prtdiag(1M) and can be 3384ab085aSmws# leveraged by other clients as well. To simplify maintenance of the source 3484ab085aSmws# base, this shell script automatically generates the source code for all of 3584ab085aSmws# these functions from the <sys/smbios.h> header file and its comments. Each 3684ab085aSmws# set of constants should be given a unique #define prefix, listed in the 3784ab085aSmws# tables below. The smbios_*_name() functions return the identifier of the 3884ab085aSmws# cpp define, and the smbios_*_desc() functions return the text of the comment. 3984ab085aSmws# 4084ab085aSmws 4184ab085aSmwsname_funcs=' 4284ab085aSmwsSMB_BBFL_ smbios_bboard_flag_name uint_t 4384ab085aSmwsSMB_BIOSFL_ smbios_bios_flag_name uint64_t 4484ab085aSmwsSMB_BIOSXB1_ smbios_bios_xb1_name uint_t 4584ab085aSmwsSMB_BIOSXB2_ smbios_bios_xb2_name uint_t 4684ab085aSmwsSMB_CAT_ smbios_cache_ctype_name uint_t 4784ab085aSmwsSMB_CAF_ smbios_cache_flag_name uint_t 4884ab085aSmwsSMB_EVFL_ smbios_evlog_flag_name uint_t 4984ab085aSmwsSMB_IPMI_F_ smbios_ipmi_flag_name uint_t 5084ab085aSmwsSMB_MDF_ smbios_memdevice_flag_name uint_t 51*4e901881SDale GhentSMB_PRC_ smbios_processor_core_flag_name uint_t 5284ab085aSmwsSMB_TYPE_ smbios_type_name uint_t 5384ab085aSmwsSMB_SLCH1_ smbios_slot_ch1_name uint_t 5484ab085aSmwsSMB_SLCH2_ smbios_slot_ch2_name uint_t 5584ab085aSmws' 5684ab085aSmws 5784ab085aSmwsdesc_funcs=' 5884ab085aSmwsSMB_BBFL_ smbios_bboard_flag_desc uint_t 5984ab085aSmwsSMB_BBT_ smbios_bboard_type_desc uint_t 6084ab085aSmwsSMB_BIOSFL_ smbios_bios_flag_desc uint64_t 6184ab085aSmwsSMB_BIOSXB1_ smbios_bios_xb1_desc uint_t 6284ab085aSmwsSMB_BIOSXB2_ smbios_bios_xb2_desc uint_t 6384ab085aSmwsSMB_BOOT_ smbios_boot_desc uint_t 6484ab085aSmwsSMB_CAA_ smbios_cache_assoc_desc uint_t 6584ab085aSmwsSMB_CAT_ smbios_cache_ctype_desc uint_t 6684ab085aSmwsSMB_CAE_ smbios_cache_ecc_desc uint_t 6784ab085aSmwsSMB_CAF_ smbios_cache_flag_desc uint_t 6884ab085aSmwsSMB_CAL_ smbios_cache_loc_desc uint_t 6984ab085aSmwsSMB_CAG_ smbios_cache_logical_desc uint_t 7084ab085aSmwsSMB_CAM_ smbios_cache_mode_desc uint_t 7184ab085aSmwsSMB_CHST_ smbios_chassis_state_desc uint_t 7284ab085aSmwsSMB_CHT_ smbios_chassis_type_desc uint_t 7384ab085aSmwsSMB_EVFL_ smbios_evlog_flag_desc uint_t 7484ab085aSmwsSMB_EVHF_ smbios_evlog_format_desc uint_t 7584ab085aSmwsSMB_EVM_ smbios_evlog_method_desc uint_t 7684ab085aSmwsSMB_HWSEC_PS_ smbios_hwsec_desc uint_t 7784ab085aSmwsSMB_IPMI_F_ smbios_ipmi_flag_desc uint_t 7884ab085aSmwsSMB_IPMI_T_ smbios_ipmi_type_desc uint_t 7984ab085aSmwsSMB_MAL_ smbios_memarray_loc_desc uint_t 8084ab085aSmwsSMB_MAU_ smbios_memarray_use_desc uint_t 8184ab085aSmwsSMB_MAE_ smbios_memarray_ecc_desc uint_t 8284ab085aSmwsSMB_MDF_ smbios_memdevice_flag_desc uint_t 8384ab085aSmwsSMB_MDFF_ smbios_memdevice_form_desc uint_t 8484ab085aSmwsSMB_MDT_ smbios_memdevice_type_desc uint_t 85*4e901881SDale GhentSMB_MDR_ smbios_memdevice_rank_desc uint_t 8684ab085aSmwsSMB_POC_ smbios_port_conn_desc uint_t 8784ab085aSmwsSMB_POT_ smbios_port_type_desc uint_t 88*4e901881SDale GhentSMB_PRC_ smbios_processor_core_flag_desc uint_t 8984ab085aSmwsSMB_PRF_ smbios_processor_family_desc uint_t 9084ab085aSmwsSMB_PRS_ smbios_processor_status_desc uint_t 9184ab085aSmwsSMB_PRT_ smbios_processor_type_desc uint_t 9284ab085aSmwsSMB_PRU_ smbios_processor_upgrade_desc uint_t 9384ab085aSmwsSMB_SLCH1_ smbios_slot_ch1_desc uint_t 9484ab085aSmwsSMB_SLCH2_ smbios_slot_ch2_desc uint_t 9584ab085aSmwsSMB_SLL_ smbios_slot_length_desc uint_t 9684ab085aSmwsSMB_SLT_ smbios_slot_type_desc uint_t 9784ab085aSmwsSMB_SLU_ smbios_slot_usage_desc uint_t 9884ab085aSmwsSMB_SLW_ smbios_slot_width_desc uint_t 9984ab085aSmwsSMB_TYPE_ smbios_type_desc uint_t 10084ab085aSmwsSMB_WAKEUP_ smbios_system_wakeup_desc uint_t 10184ab085aSmws' 10284ab085aSmws 10384ab085aSmwsif [ $# -ne 1 ]; then 10484ab085aSmws echo "Usage: $0 file.h > file.c" >&2 10584ab085aSmws exit 2 10684ab085aSmwsfi 10784ab085aSmws 10884ab085aSmwsecho "\ 10984ab085aSmws/*\n\ 110*4e901881SDale Ghent * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.\n\ 11184ab085aSmws * Copyright 2005 Sun Microsystems, Inc. All rights reserved.\n\ 11284ab085aSmws * Use is subject to license terms.\n\ 11384ab085aSmws */\n\ 11484ab085aSmws\n\ 11584ab085aSmws#include <smbios.h>" 11684ab085aSmws 11784ab085aSmwsecho "$name_funcs" | while read p name type; do 11884ab085aSmws [ -z "$p" ] && continue 11984ab085aSmws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*[A-Z0-9]*.*$" 12084ab085aSmws replace=' case \1: return ("\1");' 12184ab085aSmws 12284ab085aSmws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {" 12384ab085aSmws sed -n "s@$pattern@$replace@p" < $1 || exit 1 12484ab085aSmws echo "\t}\n\treturn (NULL);\n}" 12584ab085aSmwsdone 12684ab085aSmws 12784ab085aSmws# 12884ab085aSmws# Generate the description functions based on the comment next to a #define. 12984ab085aSmws# The transformations for descriptive comments are slightly more complicated 13084ab085aSmws# than those used for the identifier->name functions above: 13184ab085aSmws# 13284ab085aSmws# (1) strip any [RO] suffix from the comment (a header file convention) 13384ab085aSmws# (2) replace any " with \" so it is escaped for the final output string 13484ab085aSmws# (3) replace return (...); with return ("..."); to finish the code 13584ab085aSmws# 13684ab085aSmwsecho "$desc_funcs" | while read p name type; do 13784ab085aSmws [ -z "$p" ] && continue 13884ab085aSmws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*.*/\\* \(.*\) \\*/$" 13984ab085aSmws replace=' case \1: return (\2);' 14084ab085aSmws 14184ab085aSmws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {" 14284ab085aSmws sed -n "s@$pattern@$replace@p" < $1 | sed 's/ ([RO]))/)/' | \ 14384ab085aSmws sed 's/"/\\"/g' | sed 's/(/("/;s/);$/");/' || exit 1 14484ab085aSmws echo "\t}\n\treturn (NULL);\n}" 14584ab085aSmwsdone 14684ab085aSmws 14784ab085aSmwsexit 0 148