x11-drivers/xf86-input-wacom: arm stable wrt bug #704592
[gentoo.git] / eclass / fixheadtails.eclass
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: fixheadtails.eclass
5 # @MAINTAINER:
6 # base-system@gentoo.org
7 # @AUTHOR:
8 # Original author John Mylchreest <johnm@gentoo.org>
9 # @BLURB: functions to replace obsolete head/tail with POSIX compliant ones
10
11 DEPEND=">=sys-apps/sed-4"
12
13 _do_sed_fix() {
14         einfo " - fixed $1"
15         sed -i \
16                 -e 's/head \+-\([0-9]\)/head -n \1/g' \
17                 -e 's/tail \+\([-+][0-9]\+\)c/tail -c \1/g' \
18                 -e 's/tail \+\([-+][0-9]\)/tail -n \1/g' ${1} || \
19                         die "sed ${1} failed"
20 }
21
22 # @FUNCTION: ht_fix_file
23 # @USAGE: <files>
24 # @DESCRIPTION:
25 # Fix all the specified files.
26 ht_fix_file() {
27         local i
28         einfo "Replacing obsolete head/tail with POSIX compliant ones"
29         for i in "$@" ; do
30                 _do_sed_fix "$i"
31         done
32 }
33
34 # @FUNCTION: ht_fix_all
35 # @DESCRIPTION:
36 # Find and fix all files in the current directory as needed.
37 ht_fix_all() {
38         local MATCHES
39         MATCHES=$(grep -l -s -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u)
40         [[ -n ${MATCHES} ]] \
41                 && ht_fix_file ${MATCHES} \
42                 || einfo "No need for ht_fix_all anymore !"
43 }