From 6b040fc505e701557f0e29b82e693696a095c938 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 29 Apr 2016 01:02:13 +0000 Subject: [PATCH] xlat/gen.sh: prepare for adding #val_type directive support This is essentially a no-op change that makes the following change easier to read. * xlat/gen.sh (print_xlat, print_xlat_pair): New functions. (cond_xlat, gen_header): Use them. --- xlat/gen.sh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/xlat/gen.sh b/xlat/gen.sh index 4d08f013..ac3d4663 100755 --- a/xlat/gen.sh +++ b/xlat/gen.sh @@ -59,21 +59,39 @@ cond_def() fi } +print_xlat() +{ + local val + val="$1"; shift + + echo " XLAT(${val})," +} + +print_xlat_pair() +{ + local val str + val="$1"; shift + str="$1"; shift + + echo " XLAT_PAIR(${val}, \"${str}\")," +} + cond_xlat() { - local line val m def xlat + local line val m def xlat str line="$1"; shift + str="$1"; shift val="$(printf %s "${line}" | sed -n 's/^\([^[:space:]]\+\).*$/\1/p')" m="${val%%|*}" def="$(printf %s "${line}" | sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')" - if [ "${m}" = "${m#1<<}" ]; then - xlat=" XLAT(${val})," + if [ -z "${str}" ]; then + xlat="$(print_xlat "${val}")" else m="${m#1<<}" - xlat=" XLAT_PAIR(${val}, \"${m}\")," + xlat="$(print_xlat_pair "${val}" "${str}")" fi if [ -z "${def}" ]; then @@ -170,20 +188,20 @@ gen_header() ;; [A-Z_]*) # symbolic constants if [ -n "${unconditional}" ]; then - echo " XLAT(${line})," + print_xlat "${line}" else - cond_xlat "${line}" + cond_xlat "${line}" '' fi ;; '1<<'[A-Z_]*) # symbolic constants with shift if [ -n "${unconditional}" ]; then - echo " XLAT_PAIR(${line}, \"${line#1<<}\")," + print_xlat_pair "${line}" "${line#1<<}" else - cond_xlat "${line}" + cond_xlat "${line}" "${line#1<<}" fi ;; [0-9]*) # numeric constants - echo " XLAT(${line})," + print_xlat "${line}" ;; *) # verbatim lines echo "${line}" -- 2.40.0