makeset.sh 594 B

123456789101112131415161718192021222324
  1. #! /bin/sh
  2. echo "/* Generated by $0 */"
  3. needcomma=0
  4. printedtype=0
  5. while read -r line; do
  6. [ -z "${line%%#*}" ] && continue # skip comments
  7. # :type/:end
  8. if [ -n "${line}" -a -z "${line%%:*}" ]; then
  9. # Close out the last type.
  10. [ ${printedtype} -eq 1 ] && printf "%c\n\n" '"'
  11. type="${line#:}"
  12. [ "${type}" = "end" ] && break
  13. printf "#define DEFAULT_%s \"%c\n" $(echo "${type}" | tr '[:lower:]' '[:upper:]') '\'
  14. needcomma=0
  15. printedtype=1
  16. else
  17. # entry
  18. # Comma-separate the last entry.
  19. [ ${needcomma} -eq 1 ] && printf ",%c\n" '\'
  20. printf "%s" "${line}"
  21. needcomma=1
  22. fi
  23. done