| 1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/fixheadtails.eclass,v 1.1 2003/09/17 21:15:18 johnm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/fixheadtails.eclass,v 1.2 2003/11/26 22:13:35 mr_bones_ Exp $ |
| 4 | # |
4 | # |
| 5 | # Author John Mylchreest <johnm@gentoo.org> |
5 | # Author John Mylchreest <johnm@gentoo.org> |
| 6 | |
6 | |
| 7 | ECLASS=fixheadtails |
7 | ECLASS=fixheadtails |
| 8 | INHERITED="$INHERITED $ECLASS" |
8 | INHERITED="$INHERITED $ECLASS" |
|
|
9 | DEPEND="${DEPEND} >=sys-apps/sed-4" |
| 9 | |
10 | |
| 10 | # ht_fix_all |
11 | # ht_fix_all |
| 11 | # This fixes all files within the current directory. |
12 | # This fixes all files within the current directory. |
| 12 | # Do be used in src_unpack ; cd ${S}; ht_fix_all |
13 | # Do be used in src_unpack ; cd ${S}; ht_fix_all |
| 13 | |
14 | |
| 14 | # ht_fix_file <param> [<param>] [<param>].. |
15 | # ht_fix_file <param> [<param>] [<param>].. |
| 15 | # This fixes the files passed by PARAM |
16 | # This fixes the files passed by PARAM |
| 16 | # to be used for specific files. ie: ht_fix_file "${FILESDIR}/mypatch.patch" |
17 | # to be used for specific files. ie: ht_fix_file "${FILESDIR}/mypatch.patch" |
| 17 | |
18 | |
| 18 | ht_fix_all() { |
19 | do_sed_fix() { |
| 19 | local MATCHES |
20 | sed -i \ |
| 20 | |
21 | -e 's/head -\(.*\)/head -n \1/' \ |
| 21 | einfo "Replacing obsolete head/tail with posix compliant ones" |
22 | -e 's/tail \([-+]\)\(.*\)/tail -n \1\2/' ${1} || \ |
| 22 | for MATCHES in $(grep -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | cut -f1 -d: | sort -u) ; do |
23 | die "sed ${1} failed" |
| 23 | cp -f ${MATCHES} ${MATCHES}.orig |
|
|
| 24 | sed -e 's/head -\(.*\)/head -n \1/' -e 's/tail \([-+]\)\(.*\)/tail -n \1\2/' \ |
|
|
| 25 | < ${MATCHES}.orig \ |
|
|
| 26 | > ${MATCHES} |
|
|
| 27 | rm ${MATCHES}.orig |
|
|
| 28 | done |
|
|
| 29 | } |
24 | } |
| 30 | |
25 | |
| 31 | ht_fix_file() { |
26 | ht_fix_file() { |
| 32 | local i |
27 | local i |
| 33 | |
28 | |
| 34 | einfo "Replacing obsolete head/tail with posix compliant ones" |
29 | einfo "Replacing obsolete head/tail with POSIX compliant ones" |
| 35 | for i in "${@}" |
30 | for i in "${@}" |
| 36 | do |
31 | do |
| 37 | if [ -n "$(grep -i -e "head -[ 0-9]" -e "tail [+-][ 0-9]" ${i})" ] ; then |
32 | do_sed_fix ${i} |
| 38 | cp -f ${i} ${i}.orig |
|
|
| 39 | sed -e 's/head -\(.*\)/head -n \1/' -e 's/tail \([-+]\)\(.*\)/tail -n \1\2/' \ |
|
|
| 40 | < ${i}.orig \ |
|
|
| 41 | > ${i} |
|
|
| 42 | rm ${i}.orig |
|
|
| 43 | fi |
|
|
| 44 | done |
33 | done |
| 45 | eend |
|
|
| 46 | } |
34 | } |
|
|
35 | |
|
|
36 | ht_fix_all() { |
|
|
37 | local MATCHES |
|
|
38 | MATCHES="$(grep -l -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u)" |
|
|
39 | ht_fix_file ${MATCHES} |
|
|
40 | } |