From: Keith M. <kei...@us...> - 2006-04-21 19:26:15
|
Update of /cvsroot/mingw/portmaker/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31502/lib Modified Files: mingwPORT.functions Log Message: * lib/mingwPORT.functions: Add comments to document function usage. (win32path, pref, perform, require, action, step, die): New functions. (ask): Add optional `QueryMark' argument; force expansion of possible shell variables specified in reply. * src/portmaker.sh (ask): Use `QueryMark' feature. * template/mingwPORT.help, template/mingwPORT.messages: New files. * template/mingwPORT.getopts: New file. (CLEAN_UP_ON_EXIT): Defined. * template/Makefile (template_SOURCES): Add above three new files. * template/mingwPORT.sh (mingwPORT.functions): Use new functions. (mingwPORT): New shell variable; define and use it. (mingwPORT.help, mingwPORT.messages, mingwPORT.getopts): Source them. (mingwPORT.site): New site customisation hook; source preferentially. (CLEANUP_ON_EXIT): Eval it. Index: mingwPORT.functions =================================================================== RCS file: /cvsroot/mingw/portmaker/lib/mingwPORT.functions,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mingwPORT.functions 12 Sep 2005 19:49:00 -0000 1.2 --- mingwPORT.functions 21 Apr 2006 19:26:06 -0000 1.3 *************** *** 2,15 **** # Required. Shell functions used by mingwPORT. ! # ask "User prompt" "Default response" VariableToStoreResponse ! function ask() { ! echo -n "$1 " ! [ -n "$2" ] && echo -n "($2) " ! read $3 ! [ -z "$(eval echo \${$3\})" ] && eval $3=\"$2\" } ! # isyes $variable ! function isyes() { case $1 in [Yy] | [Yy][Ee] | [Yy][Ee][Ss]) true ;; --- 2,26 ---- # Required. Shell functions used by mingwPORT. ! ask() ! # usage: ask "User prompt" "Default response" ResponseVar [QueryMark] ! # ! # Display "User prompt", then wait for user's response, assigning it ! # to `ResponseVar'; if user enters nothing, then substitute the default ! # assignment `ResponseVar="Default response"'. ! # ! # If "Default response" is non-null, it is appended to "User prompt", ! # generating a prompt of the form `User prompt (Default response)'; ! # if `QueryMark' is specified, it is appended to the displayed prompt. ! { ! echo -n "$1"; [ -n "$2" ] && echo -n " ($2)"; echo -n "$4 "; read $3 ! eval '[ -z "$'$3'" ] && '$3'=$2 || '$3'=`eval echo "$'$3'"`' } ! isyes() ! # usage: isyes $variable ! # ! # Test the value stored in $variable for a case insensitive match to ! # the string "yes", or any abbreviated form thereof. ! { case $1 in [Yy] | [Yy][Ee] | [Yy][Ee][Ss]) true ;; *************** *** 17,18 **** --- 28,125 ---- esac } + + win32path() + # usage: Win32PathName=`win32path "/MSYS/PathName"` + # + # Determine the native Win32 path name equivalent for the POSIX style + # "/MSYS/PathName"; (CAVEAT: the specified "/MSYS/PathName" *must* + # reference an existing *directory* on the MSYS or POSIX host). + { + 2>/dev/null cd $1; pwd -W + } + + pref() + # usage: pref "OptionallySourcedCommandFile" [OptionalArguments [...]] + # + # Source a `preferential' configuration overlay script, *if* the named + # "OptionallySourcedCommandFile" has been provided. If the named script + # is not present, then this function silently does nothing. + # + # If any "OptionalArguments" are specified, then they will be available + # as command line arguments, within the scope of execution of the named + # "OptionallySourcedCommandFile". + { + [ -f "$1" ] && . "$@" + } + + perform() + # usage: perform Action OptionalStep + # + # If a file "mingwPORT.OptionalStep" exists, then source it according + # to the designated strategy for the specified Action. The supported + # Action keywords, and their effects are: + # + # step simply source the "mingwPORT.OptionalStep" file. + # + # action if the additional file "mingwPORT.beforeOptionalStep" exists, + # then source it first; then source "mingwPORT.OptionalStep"; + # finally, if "mingwPORT.afterOptionalStep" exists, source it. + # + # If any "OptionalArguments" are specified, then they will be available + # as command line arguments, within the scope of execution of all files + # sourced by this function call. + { + [ -f "$mingwPORT.$2" ] && "$@" + } + + require() + # usage: require Action RequiredStep + # + # If the file "mingwPORT.RequiredStep" exists, and is readable, then + # this function sources it, exactly analogously to the `perform' function, + # in accordance with identical strategies specified by the Action keyword; + # otherwise, this function causes the mingwPORT to issue an appropriate + # diagnostic message, and abort. + { + [ -f "$mingwPORT.$2" ] || die $2 "$MSG_ENOENT" + [ -r "$mingwPORT.$2" ] || die $2 "$MSG_EACCESS" + "$@" + } + + step() + # usage: step ModuleName + # + # Source the file "mingwPORT.ModuleName"; this is the function dispatcher + # invoked when either `perform' or `require' is called with Action = step. + { + . "$mingwPORT.$@" + } + + action() + # usage: action StepWithOptionalWrapperActions + # + # If file "mingwPORT.beforeStepWithOptionalWrapperActions" exists, then + # source it; then source "mingwPORT.StepWithOptionalWrapperActions"; and + # finally, if file "mingwPORT.afterStepWithOptionalWrapperActions" exists, + # source it; this is the function dispatcher invoked when either `perform' + # or `require' is called with Action = action. + { + pref "$mingwPORT.before$@" + . "$mingwPORT.$@" + pref "$mingwPORT.after$@" + } + + die() + # usage: die ModuleName "Message Saying Why" + # + # Display a diagnostic message, and cause the mingwPORT to abort; this + # is the function dispatcher invoked by `require', when the specified + # "mingwPORT.ModuleName" file cannot be sourced; it may also be invoked + # directly from any sourced "mingwPORT.ModuleName" file, to diagnose + # any fatal condition. + { + echo >&2 "$CMD:mingwPORT.$1: $2" + exit 1 + } + + # $RCSfile$: end of file: vim: ft=sh |