#!/bin/sh # # Code generator for trace events # # Copyright IBM, Corp. 2010 # # This work is licensed under the terms of the GNU GPL, version 2. See # the COPYING file in the top-level directory. # Disable pathname expansion, makes processing text with '*' characters simpler set -f usage() { cat >&2 < return 0 if property is present, or 1 otherwise has_property() { local props prop props=${1%%\(*} props=${props% *} for prop in $props; do if [ "$prop" = "$2" ]; then return 0 fi done return 1 } # Get the argument list of a trace event, including types and names get_args() { local args args=${1#*\(} args=${args%%\)*} echo "$args" } # Get the argument name list of a trace event get_argnames() { local nfields field name sep nfields=0 sep="$2" for field in $(get_args "$1"); do nfields=$((nfields + 1)) # Drop pointer star field=${field#\*} # Only argument names have commas at the end name=${field%,} test "$field" = "$name" && continue printf "%s%s " $name $sep done # Last argument name if [ "$nfields" -gt 1 ] then printf "%s" "$name" fi } # Get the number of arguments to a trace event get_argc() { local name argc argc=0 for name in $(get_argnames "$1", ","); do argc=$((argc + 1)) done echo $argc } # Get the format string including double quotes for a trace event get_fmt() { puts "${1#*)}" } linetoh_begin_nop() { return } linetoh_nop() { local name args name=$(get_name "$1") args=$(get_args "$1") # Define an empty function for the trace event cat < #include "trace/stderr.h" extern TraceEvent trace_list[]; EOF stderr_event_num=0 } linetoh_stderr() { local name args argnames argc fmt name=$(get_name "$1") args=$(get_args "$1") argnames=$(get_argnames "$1" ",") argc=$(get_argc "$1") fmt=$(get_fmt "$1") if [ "$argc" -gt 0 ]; then argnames=", $argnames" fi cat <" ust_clean_namespace } linetoh_ust() { local name args argnames name=$(get_name "$1") args=$(get_args "$1") argnames=$(get_argnames "$1", ",") cat < $(ust_clean_namespace) #include "trace.h" EOF } linetoc_ust() { local name args argnames fmt name=$(get_name "$1") args=$(get_args "$1") argnames=$(get_argnames "$1", ",") [ -z "$argnames" ] || argnames=", $argnames" fmt=$(get_fmt "$1") cat <