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

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.373 Revision 1.375
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 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/eutils.eclass,v 1.373 2011/12/16 23:38:41 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.375 2011/12/17 04:55:41 vapier Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
172# eshopts_pop 172# eshopts_pop
173# @CODE 173# @CODE
174eshopts_push() { 174eshopts_push() {
175 # have to assume __ESHOPTS_SAVE__ isn't screwed with 175 # have to assume __ESHOPTS_SAVE__ isn't screwed with
176 # as a `declare -a` here will reset its value 176 # as a `declare -a` here will reset its value
177 local i=${#__ESHOPTS_SAVE__[@]}
177 if [[ $1 == -[su] ]] ; then 178 if [[ $1 == -[su] ]] ; then
178 estack_push eshopts "$(shopt -p)" 179 __ESHOPTS_SAVE__[$i]=$(shopt -p)
179 [[ $# -eq 0 ]] && return 0 180 [[ $# -eq 0 ]] && return 0
180 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*" 181 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
181 else 182 else
182 estack_push eshopts $- 183 __ESHOPTS_SAVE__[$i]=$-
183 [[ $# -eq 0 ]] && return 0 184 [[ $# -eq 0 ]] && return 0
184 set "$@" || die "${FUNCNAME}: bad options to set: $*" 185 set "$@" || die "${FUNCNAME}: bad options to set: $*"
185 fi 186 fi
186} 187}
187 188
189# @USAGE: 190# @USAGE:
190# @DESCRIPTION: 191# @DESCRIPTION:
191# Restore the shell options to the state saved with the corresponding 192# Restore the shell options to the state saved with the corresponding
192# eshopts_push call. See that function for more details. 193# eshopts_push call. See that function for more details.
193eshopts_pop() { 194eshopts_pop() {
194 local s 195 [[ $# -ne 0 ]] && die "${FUNCNAME} takes no arguments"
195 estack_pop eshopts s || die "${FUNCNAME}: unbalanced push" 196 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 ))
197 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
198 local s=${__ESHOPTS_SAVE__[$i]}
199 unset __ESHOPTS_SAVE__[$i]
196 if [[ ${s} == "shopt -"* ]] ; then 200 if [[ ${s} == "shopt -"* ]] ; then
197 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}" 201 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
198 else 202 else
199 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-" 203 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-"
200 set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}" 204 set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}"

Legend:
Removed from v.1.373  
changed lines
  Added in v.1.375

  ViewVC Help
Powered by ViewVC 1.1.20