Forward port to latest release.

For further history and justifiation of this patch, see http://cygwin.com/ml/cygwin/2007-01/msg00113.html and follow the embedded links and threads.

--
Chuck

2007-02-05  Charles Wilson  <...>

        * bin/cygport.in (custom_dummy_core): new function, used to test
        custom-command framework
        (custom_dummy): ditto
        (main): add implentation for custom-show) and customN-*)


Index: bin/cygport.in
===================================================================
RCS file: /cvsroot/cygwin-ports/cygport/bin/cygport.in,v
retrieving revision 1.53
diff -u -r1.53 cygport.in
--- bin/cygport.in      5 Feb 2007 03:28:43 -0000       1.53
+++ bin/cygport.in      5 Feb 2007 21:36:30 -0000
@@ -1650,11 +1650,38 @@
 
 
################################################################################
 #
+# test target for custom command hooks
+#
+################################################################################
+custom_dummy_core() {
+       local -i my_c=0
+       local -i my_argc=$#
+
+       while (( my_c < my_argc ))
+       do
+               my_c+=1
+               echo "${my_c}: $1"
+               shift
+       done
+}
+custom_dummy() {
+       inform "custom_dummy called with $# args"
+       custom_dummy_core "$@"
+}
+export -f custom_dummy_core custom_dummy
+readonly -f custom_dummy_core custom_dummy
+
+################################################################################
+#
 # End of functions
 #
 
################################################################################
 
 declare -i arg_n=2
+declare -i custom_arg_n
+declare -i custom_argc
+declare -a custom_args
+declare -x custom_cmd
 
 while (( arg_n < argc ))
 do
@@ -1731,6 +1758,46 @@
                        finish;
                        _status=$?;
                        ;;
+               custom-show)
+                       for fnc in $(set | sed -n '/()/s/()//p')
+                       do
+                               if test "$(type -t ${fnc})" == "function"
+                               then
+                                       echo " ${fnc}"
+                               fi
+                       done
+                       ;;
+               custom0-* | custom1-* | custom2-* | custom3-* | custom4-* | \
+               custom5-* | custom6-* | custom7-* | custom8-* | custom9-* )
+                       custom_argc=${argv[${arg_n}]:6:1}
+                       custom_cmd=${argv[${arg_n}]:8}
+                       if [ -z "${custom_cmd}" ]
+                       then
+                               error "${argv[${arg_n}]}* command has no target 
following the 'custom${custom_argc}-'"
+                       fi
+
+                       # consume arguments
+                       custom_arg_n=0
+                       while (( custom_arg_n < custom_argc )) && (( arg_n+1 < 
argc ))
+                       do
+                               arg_n+=1
+                               custom_args[${custom_arg_n}]="${argv[${arg_n}]}"
+                               custom_arg_n+=1
+                       done
+                       if (( custom_arg_n < custom_argc ))
+                       then
+                               error "custom${custom_argc} command 
${custom_cmd}: not enough arguments"
+                       fi
+                       
+                       if test "$(type -t ${custom_cmd})" == "function"
+                       then
+                               __stage ${custom_cmd} && eval "${custom_cmd} 
[EMAIL PROTECTED]"
+                               _status=$?;
+                       else
+                               error "${custom_cmd} is not a shell function"
+                       fi
+                       unset custom_args
+                       ;;
                help)
                        __show_help;
                        exit 0;

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply via email to