#!/bin/bash

SPACES="                                                                                     "
function fmt_echo {
    local STRING="$1"
    STRING="${STRING//\\n/ }"
    STRING="${STRING//  / }"
    echo -n "\"$STRING\" "
    if test ${#STRING} -lt $2 ; then
	echo -n "${SPACES:0:$2-${#STRING}}"
    fi
}

fmt_key_w=14
fmt_knm_w=6
#fmt_xfc_w=6
fmt_edc_w=6
#fmt_xfn_w=32
fmt_edn_w=32

fmt_echo "Linux key" $fmt_key_w
fmt_echo "linux#" $fmt_knm_w
#fmt_echo "XF86IC" $fmt_xfc_w
fmt_echo "EVDVIC" $fmt_edc_w
#fmt_echo "X MS Multimedia Symbol" $fmt_xfn_w
fmt_echo "X evdev Symbol" $fmt_edn_w
echo


exec <input_linux.txt

while read DEFINE KEY CODE ; do
    if test "$DEFINE" != "#define" ; then
	echo "$DEFINE $KEY $CODE"
	continue
    fi
    let EVDEVCODE=CODE+8
#    XF86CODE=$(grep '<.*>.*=' ~/PACKAGES/xkeyboard-config-stable-noarch/BUILD/xkeyboard-config-0.9/keycodes/xfree86 | grep -w $CODE | sed 's@//.*@@;s/^.*<//;s/>.*//')
    XEVDEVCODE=$(grep '<.*>.*=' ~/PACKAGES/xkeyboard-config-stable-noarch/BUILD/xkeyboard-config-0.9/keycodes/evdev | grep -w $EVDEVCODE | sed 's@//.*@@;s/^.*<//;s/>.*//')

#    XF86NAME=$(grep "<$XF86CODE>" input_inet_msmulti.txt | sed 's/^.*{//;s/}.*//')
    XEVDEVNAME=$(grep "<$XEVDEVCODE>" input_inet_evdev.txt | sed 's/^.*{//;s/}.*//')

    fmt_echo "$KEY" $fmt_key_w
    fmt_echo "$CODE" $fmt_knm_w
#    fmt_echo "$XF86CODE" $fmt_xfc_w
    fmt_echo "$XEVDEVCODE" $fmt_edc_w
#    fmt_echo "$XF86NAME" $fmt_edn_w
    fmt_echo "$XEVDEVNAME" $fmt_edn_w
    echo

done
