]> git.saurik.com Git - wxWidgets.git/blob - src/regex/splice.sh
check that the version of __sync_sub_and_fetch that returns a value is supported...
[wxWidgets.git] / src / regex / splice.sh
1 #!/bin/sh
2 #############################################################################
3 # Name: splice
4 # Purpose: Splice a marked section of regcustom.h into regex.h
5 # Author: Mike Wetherell
6 # RCS-ID: $Id$
7 # Copyright: (c) 2004 Mike Wetherell
8 # Licence: wxWindows licence
9 #############################################################################
10
11 #
12 # Works by greping for the marks then passing their line numbers to sed. Which
13 # is slighly the long way round, but allows some error checking.
14 #
15
16 SRC=regcustom.h
17 DST=regex.h
18 MARK1='^/\* --- begin --- \*/$'
19 MARK2='^/\* --- end --- \*/$'
20 PROG=`basename $0`
21 TMP=$DST.tmp
22
23 # findline(pattern, file)
24 # Prints the line number of the 1st line matching the pattern in the file
25 #
26 findline() {
27 if ! LINE=`grep -n -- "$1" "$2"`; then
28 echo "$PROG: marker '$1' not found in '$2'" >&2
29 return 1
30 fi
31 echo $LINE | sed -n '1s/[^0-9].*//p' # take just the line number
32 }
33
34 # findmarkers([out] line1, [out] line2, pattern1, pattern2, file)
35 # Returns (via the variables named in the 1st two parameters) the line
36 # numbers of the lines matching the patterns in file. Checks pattern1 comes
37 # before pattern2.
38 #
39 findmarkers() {
40 if ! LINE1=`findline "$3" "$5"` || ! LINE2=`findline "$4" "$5"`; then
41 return 1
42 fi
43 if [ $LINE1 -ge $LINE2 ]; then
44 echo "$PROG: marker '$3' not before '$4' in '$5'" >&2
45 return 1
46 fi
47 eval $1=$LINE1
48 eval $2=$LINE2
49 }
50
51 # find markers
52 #
53 if findmarkers SRCLINE1 SRCLINE2 "$MARK1" "$MARK2" $SRC &&
54 findmarkers DSTLINE1 DSTLINE2 "$MARK1" "$MARK2" $DST
55 then
56 # do splice
57 #
58 if (sed $DSTLINE1,\$d $DST &&
59 sed -n $SRCLINE1,${SRCLINE2}p $SRC &&
60 sed 1,${DSTLINE2}d $DST) > $TMP
61 then
62 mv $TMP $DST
63 exit 0
64 else
65 rm $TMP
66 fi
67 fi
68
69 exit 1