usage_compressed 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. target="$1"
  3. loc="$2"
  4. test "$target" || exit 1
  5. test "$loc" || loc=.
  6. test -x "$loc/usage" || exit 1
  7. test "$SED" || SED=sed
  8. test "$DD" || DD=dd
  9. # Some people were bitten by their system lacking a (proper) od
  10. od -v -b </dev/null >/dev/null
  11. if test $? != 0; then
  12. echo 'od tool is not installed or cannot accept "-v -b" options'
  13. exit 1
  14. fi
  15. exec >"$target.$$"
  16. echo '#define UNPACKED_USAGE "" \'
  17. "$loc/usage" | od -v -b \
  18. | grep -v '^ ' \
  19. | $SED -e 's/^[^ ]*//' \
  20. -e 's/ //g' \
  21. -e '/^$/d' \
  22. -e 's/\(...\)/\\\1/g' \
  23. -e 's/^/"/' \
  24. -e 's/$/" \\/'
  25. echo ''
  26. # "grep -v '^ '" is for toybox's od bug: od -b prints some extra lines:
  27. #0000000 010 000 010 000 133 055 144 146 135 040 133 055 143 040 103 117
  28. # 000010 000010 026533 063144 020135 026533 020143 047503
  29. #0000020 116 106 104 111 122 135 040 133 055 154 040 114 117 107 106 111
  30. # 043116 044504 056522 055440 066055 046040 043517 044506
  31. #0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111
  32. # 042514 020135 026533 020141 041501 044524 047117 044506
  33. echo "#define UNPACKED_USAGE_LENGTH `$loc/usage | wc -c`"
  34. echo
  35. echo '#define PACKED_USAGE \'
  36. ## Breaks on big-endian systems!
  37. ## # Extra effort to avoid using "od -t x1": -t is not available
  38. ## # in non-CONFIG_DESKTOPed busybox od
  39. ##
  40. ## "$loc/usage" | bzip2 -1 | od -v -x \
  41. ## | $SED -e 's/^[^ ]*//' \
  42. ## -e 's/ //g' \
  43. ## -e '/^$/d' \
  44. ## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
  45. ## -e 's/$/ \\/'
  46. "$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
  47. | grep -v '^ ' \
  48. | $SED -e 's/^[^ ]*//' \
  49. -e 's/ //g' \
  50. -e '/^$/d' \
  51. -e 's/\(...\)/0\1,/g' \
  52. -e 's/$/ \\/'
  53. echo ''
  54. mv -- "$target.$$" "$target"