1#!/bin/sh 2# 3# USAGE: get-version.sh path/to/expat.h 4# 5# This script will print Expat's version number on stdout. For example: 6# 7# $ ./conftools/get-version.sh ./lib/expat.h 8# 1.95.3 9# $ 10# 11 12if test $# = 0; then 13 echo "ERROR: pathname for expat.h was not provided." 14 echo "" 15 echo "USAGE: $0 path/to/expat.h" 16 exit 1 17fi 18if test $# != 1; then 19 echo "ERROR: too many arguments were provided." 20 echo "" 21 echo "USAGE: $0 path/to/expat.h" 22 exit 1 23fi 24 25hdr="$1" 26if test ! -r "$hdr"; then 27 echo "ERROR: '$hdr' does not exist, or is not readable." 28 exit 1 29fi 30 31MAJOR_VERSION="`sed -n -e '/MAJOR_VERSION/s/[^0-9]*//gp' $hdr`" 32MINOR_VERSION="`sed -n -e '/MINOR_VERSION/s/[^0-9]*//gp' $hdr`" 33MICRO_VERSION="`sed -n -e '/MICRO_VERSION/s/[^0-9]*//gp' $hdr`" 34 35# Determine how to tell echo not to print the trailing \n. This is 36# similar to Autoconf's @ECHO_C@ and @ECHO_N@; however, we don't 37# generate this file via autoconf (in fact, get-version.sh is used 38# to *create* ./configure), so we just do something similar inline. 39case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in 40 *c*,-n*) ECHO_N= ECHO_C=' 41' ;; 42 *c*,* ) ECHO_N=-n ECHO_C= ;; 43 *) ECHO_N= ECHO_C='\c' ;; 44esac 45 46echo $ECHO_N "$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$ECHO_C" 47