2
0
mirror of https://codeberg.org/kiss-community/repo synced 2024-11-14 18:50:10 -07:00
repo/wayland/xkeyboard-config/files/xml2lst
2022-05-10 18:05:28 -05:00

50 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# converts the <rules>.xml file to the old format <rules>.lst file
# Usage: xml2lst < filename.xml > filename.lst
[ "$1" ] && exec 0< "$1"
var=0 com=0 nam=''
printf '! model\n'
while read -r l || [ "$l" ]; do case $l in
*'<name>'*) n=${l#*>} n=${n%<*};;
*'<description>'*) l=${l#*>}; printf ' %-15s %s\n' "$n" "${l%<*}" ;;
*'</modelList>'*) break
esac; done
printf '\n! layout\n'
while read -r l || [ "$l" ]; do case $l in
*'<variantList>'*) var=1;;
*'</variantList>'*) var=0;;
*'</layoutList>'*) break;;
*'<name>'*)
l="${l#*>}"
[ "$var" -eq 0 ] && ln=${l%<*} || n=${l%<*}
;;
*'<description>'*)
l=${l#*>}
case $var in
0) printf ' %-15s %s\n' "${ln}" "${l%<*}" ;;
*) nam="${nam%x} $(printf '%-15s %s: %s\nx' "$n" "$ln" "${l%<*}")"
esac
;;
esac; done
printf '\n! variant\n%s\n! option\n' "${nam%x}"
while read -r l || [ "$l" ]; do case $l in
*'-->'*) com=0;;
*'<!--'*) com=1;;
*'</optionList>'*) break;;
*'<name>'*) n=${l#*>} n=${n%<*} ;;
*'<description>'*)
l=${l#*>}
[ "$com" -ne 0 ] || printf ' %-20s %s\n' "$n" "${l%<*}"
;;
esac; done