/[gentoo-x86]/eclass/fixheadtails.eclass
Gentoo

Contents of /eclass/fixheadtails.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Mon Aug 22 04:46:31 2011 UTC (3 years ago) by vapier
Branch: MAIN
Changes since 1.11: +4 -4 lines
fix random bugs in eclass documentation, and convert to new @AUTHOR tag

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

  ViewVC Help
Powered by ViewVC 1.1.20