| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2008 Gentoo Foundation |
| 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.10 2005/12/20 01:31:53 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/fixheadtails.eclass,v 1.11 2008/02/19 05:27:25 vapier Exp $ |
| 4 | # |
4 | # |
| 5 | # Author John Mylchreest <johnm@gentoo.org> |
5 | # Original author John Mylchreest <johnm@gentoo.org> |
|
|
6 | |
|
|
7 | # @ECLASS: fixheadtails.eclass |
|
|
8 | # @MAINTAINER: |
|
|
9 | # base-system@gentoo.org |
|
|
10 | # @BLURB: functions to replace obsolete head/tail with POSIX compliant ones |
| 6 | |
11 | |
| 7 | DEPEND=">=sys-apps/sed-4" |
12 | DEPEND=">=sys-apps/sed-4" |
| 8 | |
13 | |
| 9 | # ht_fix_all |
|
|
| 10 | # This fixes all files within the current directory. |
|
|
| 11 | # Do be used in src_unpack ; cd ${S}; ht_fix_all |
|
|
| 12 | |
|
|
| 13 | # ht_fix_file <param> [<param>] [<param>].. |
|
|
| 14 | # This fixes the files passed by PARAM |
|
|
| 15 | # to be used for specific files. ie: ht_fix_file "${FILESDIR}/mypatch.patch" |
|
|
| 16 | |
|
|
| 17 | do_sed_fix() { |
14 | __do_sed_fix() { |
| 18 | einfo " - fixed $1" |
15 | einfo " - fixed $1" |
| 19 | sed -i \ |
16 | sed -i \ |
| 20 | -e 's/head \+-\([0-9]\)/head -n \1/g' \ |
17 | -e 's/head \+-\([0-9]\)/head -n \1/g' \ |
| 21 | -e 's/tail \+\([-+][0-9]\+\)c/tail -c \1/g' \ |
18 | -e 's/tail \+\([-+][0-9]\+\)c/tail -c \1/g' \ |
| 22 | -e 's/tail \+\([-+][0-9]\)/tail -n \1/g' ${1} || \ |
19 | -e 's/tail \+\([-+][0-9]\)/tail -n \1/g' ${1} || \ |
| 23 | die "sed ${1} failed" |
20 | die "sed ${1} failed" |
| 24 | } |
21 | } |
| 25 | |
22 | |
|
|
23 | # @FUNCTION: ht_fix_file |
|
|
24 | # @USAGE: <files> |
|
|
25 | # @DESCRIPTION: |
|
|
26 | # Fix all the specified files. |
| 26 | ht_fix_file() { |
27 | ht_fix_file() { |
| 27 | local i |
28 | local i |
| 28 | |
|
|
| 29 | einfo "Replacing obsolete head/tail with POSIX compliant ones" |
29 | einfo "Replacing obsolete head/tail with POSIX compliant ones" |
| 30 | for i in "${@}" |
30 | for i in "$@" ; do |
| 31 | do |
|
|
| 32 | do_sed_fix ${i} |
31 | __do_sed_fix "$i" |
| 33 | done |
32 | done |
| 34 | } |
33 | } |
| 35 | |
34 | |
|
|
35 | # @FUNCTION: ht_fix_all |
|
|
36 | # @DESCRIPTION: |
|
|
37 | # Find and fix all files in the current directory as needed. |
| 36 | ht_fix_all() { |
38 | ht_fix_all() { |
| 37 | local MATCHES |
39 | local MATCHES |
| 38 | MATCHES=$(grep -l -s -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u) |
40 | MATCHES=$(grep -l -s -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u) |
| 39 | [[ -n ${MATCHES} ]] \ |
41 | [[ -n ${MATCHES} ]] \ |
| 40 | && ht_fix_file ${MATCHES} \ |
42 | && ht_fix_file ${MATCHES} \ |