1
0

get-version.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # USAGE: get-version.sh path/to/expat.h
  3. #
  4. # This script will print Expat's version number on stdout. For example:
  5. #
  6. # $ ./conftools/get-version.sh ./lib/expat.h
  7. # 1.95.3
  8. # __ __ _
  9. # ___\ \/ /_ __ __ _| |_
  10. # / _ \\ /| '_ \ / _` | __|
  11. # | __// \| |_) | (_| | |_
  12. # \___/_/\_\ .__/ \__,_|\__|
  13. # |_| XML parser
  14. #
  15. # Copyright (c) 2002 Greg Stein <[email protected]>
  16. # Copyright (c) 2017 Kerin Millar <[email protected]>
  17. # Licensed under the MIT license:
  18. #
  19. # Permission is hereby granted, free of charge, to any person obtaining
  20. # a copy of this software and associated documentation files (the
  21. # "Software"), to deal in the Software without restriction, including
  22. # without limitation the rights to use, copy, modify, merge, publish,
  23. # distribute, sublicense, and/or sell copies of the Software, and to permit
  24. # persons to whom the Software is furnished to do so, subject to the
  25. # following conditions:
  26. #
  27. # The above copyright notice and this permission notice shall be included
  28. # in all copies or substantial portions of the Software.
  29. #
  30. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  31. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  33. # NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  34. # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  35. # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  36. # USE OR OTHER DEALINGS IN THE SOFTWARE.
  37. if test $# = 0; then
  38. echo "ERROR: pathname for expat.h was not provided."
  39. echo ""
  40. echo "USAGE: $0 path/to/expat.h"
  41. exit 1
  42. fi
  43. if test $# != 1; then
  44. echo "ERROR: too many arguments were provided."
  45. echo ""
  46. echo "USAGE: $0 path/to/expat.h"
  47. exit 1
  48. fi
  49. hdr="$1"
  50. if test ! -r "$hdr"; then
  51. echo "ERROR: '$hdr' does not exist, or is not readable."
  52. exit 1
  53. fi
  54. MAJOR_VERSION=$(sed -n -e '/MAJOR_VERSION/s/[^0-9]*//gp' "$hdr")
  55. MINOR_VERSION=$(sed -n -e '/MINOR_VERSION/s/[^0-9]*//gp' "$hdr")
  56. MICRO_VERSION=$(sed -n -e '/MICRO_VERSION/s/[^0-9]*//gp' "$hdr")
  57. printf '%s.%s.%s' "$MAJOR_VERSION" "$MINOR_VERSION" "$MICRO_VERSION"