makehelp.sh 835 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! /bin/sh
  2. echo "/* Generated by $0 */"
  3. echo "#include \"cmds.h\""
  4. echo "help_t help[] = {"
  5. needcomma=0
  6. IFS="
  7. "
  8. sed -e 's,["],\\&,g' | while read -r line; do
  9. if [ -n "${line}" -a -z "${line%%:*}" ]; then
  10. if [ ${needcomma} -eq 1 ]; then
  11. printf "\""
  12. [ ${garble} -eq 1 ] && printf ")"
  13. printf "},\n"
  14. fi
  15. line="${line#:}"
  16. garble=0
  17. if [ "${line%:}" != "${line}" ]; then
  18. garble=1
  19. line="${line%:}"
  20. fi
  21. type="${line%:*}"
  22. cmd="${line#*:}"
  23. [ "${cmd}" = "end" ] && break
  24. case ${type} in
  25. hub) type_flag="HUB" ;;
  26. leaf) type_flag="LEAF" ;;
  27. *) type_flag="0" ;;
  28. esac
  29. if [ ${garble} -eq 0 ]; then
  30. printf " {%s, \"%s\", 0, \"" ${type_flag} "${cmd}"
  31. else
  32. printf " {%s, \"%s\", STR(\"" ${type_flag} "${cmd}"
  33. fi
  34. needcomma=0
  35. else
  36. printf "%s\\\n" "${line}"
  37. needcomma=1
  38. fi
  39. done
  40. echo "};"