#!/bin/bash # IOSLIB version 1.0.4 (Hua-hua). # Copyright (C) 2006 Matous Jan Fialka. # Released under the terms of GNU/GPL. IOS_StdOut() { builtin echo -e "$@" return 0 } IOS_StdErr() { IOS_StdOut "$@" 1>&2 return 1 } IOS_GetFun() { return 0 } IOS_RegFun() { local Fun="$@ $(IOS_GetFun)" eval " IOS_GetFun() { IOS_StdOut \"$Fun\" } " } IOS_HasFun() { local Fun= for Fun in $(IOS_GetFun) do if [[ $Fun = $1 ]] then return 0 fi done return 1 } IOS_GetSect() { IOS_StdOut ROOT } IOS_GetSectName() { local CSect=$(IOS_GetSect) IOS_StdOut ${CSect##*_} } IOS_GetPSect() { local PSect=$(IOS_GetSect) IOS_StdOut ${PSect%_*} } IOS_GetPSectName() { local PSect=$(IOS_GetPSect) IOS_StdOut ${PSect##*_} } IOS_LeaveSect() { local PSect=$(IOS_GetPSect) eval " IOS_GetSect() { IOS_StdOut '$PSect' } " } IOS_EnterSect() { local CSect=$(IOS_GetSect)_$1 eval " IOS_GetSect() { IOS_StdOut '$CSect' } " } IOS_InSameSect() { return $([[ $(IOS_GetPSect)_$1 = $(IOS_GetSect) ]]) } IOS_EqSectName() { until [[ $1 = '' ]] do if [[ $(IOS_GetSectName) = $1 ]] then return 0 fi shift done return 1 } IOS_EqPSectName() { until [[ $1 = '' ]] do if [[ $(IOS_GetPSectName) = $1 ]] then return 0 fi shift done return 1 } IOS_IsNeg() { return 1 } IOS_SetVar() { eval "IOS_$(IOS_GetSect)_$1=\"$2\"" } IOS_GetVar() { eval "IOS_StdOut \"\$IOS_$(IOS_GetSect)_$1\"" } IOS_GetMatches() { local Ret=1 local Query=$1 local Word= local Sub= shift for Word in $@ do if [[ $Word = '@'* ]] then if Sub=$(${Word#'@'} $Query) then IOS_StdOut $Word Ret=0 fi else if [[ $Word = $Query* ]] then IOS_StdOut $Word Ret=0 fi fi done return $Ret } IOS_NegCall() { IOS_IsNeg() { return 0 } if IOS_HasFun ${@// *} then $@ fi IOS_IsNeg() { return 1 } } IOS_Source() { local Line while builtin read Line do Line=${Line//!*} if IOS_HasFun ${Line// *} then $Line fi done } print() { if ! IOS_IsNeg then case $1 in stdout) shift IOS_StdOut "$@" ;; stderr) shift IOS_StdErr "$@" ;; esac fi } end() { IOS_LeaveSect } undo() { IOS_NegCall "$@" } IOS_RegFun print IOS_RegFun end IOS_RegFun undo