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

Contents of /eclass/fixheadtails.eclass

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20