bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / support / jk_exec.m4
1 dnl
2 dnl Licensed to the Apache Software Foundation (ASF) under one or more
3 dnl contributor license agreements.  See the NOTICE file distributed with
4 dnl this work for additional information regarding copyright ownership.
5 dnl The ASF licenses this file to You under the Apache License, Version 2.0
6 dnl (the "License"); you may not use this file except in compliance with
7 dnl the License.  You may obtain a copy of the License at
8 dnl
9 dnl     http://www.apache.org/licenses/LICENSE-2.0
10 dnl
11 dnl Unless required by applicable law or agreed to in writing, software
12 dnl distributed under the License is distributed on an "AS IS" BASIS,
13 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 dnl See the License for the specific language governing permissions and
15 dnl limitations under the License.
16 dnl
17
18 dnl --------------------------------------------------------------------------
19 dnl
20 dnl Inspired by Pier works on webapp m4 macros :)
21 dnl
22 dnl Version $Id: jk_exec.m4 802231 2009-08-07 21:43:52Z markt $
23 dnl --------------------------------------------------------------------------
24
25 dnl --------------------------------------------------------------------------
26 dnl JK_EXEC
27 dnl   Execute a program filtering its output (pretty printing).
28 dnl
29 dnl   Parameters:
30 dnl     $1 => name of the variable containing the return value (error code).
31 dnl     $2 => name of the binary/script to invoke
32 dnl     $3 => message used for pretty printing output
33 dnl     $4 => the directory where the command must be executed
34 dnl --------------------------------------------------------------------------
35 AC_DEFUN(
36   [JK_EXEC],
37   [
38     jk_exec_curdir="`pwd`"
39     if test -d "$4" ; then
40       cd "$4"
41     else
42       AC_MSG_ERROR([can't switch to directory $4])
43     fi
44
45     echo "  invoking \"$2\""
46     echo "  in directory \"$4\""
47     echo "-1" > retvalue.tmp
48
49     set $2
50     jk_exec_file=[$]1
51     if test ! -x "${jk_exec_file}" ; then
52       cd "${jk_exec_curdir}"
53       AC_MSG_ERROR([cannot find or execute \"${jk_exec_file}\" in \"$4\"])
54       exit 1
55     fi
56     unset jk_exec_file
57
58     {
59       $2
60       echo
61       echo "jk_exec_retvalue $?"
62     } | {
63       jk_exec_ret=0
64       while true ; do
65         read jk_exec_first jk_exec_line
66         if test ! "$?" -eq "0" ; then
67           break
68         else
69           if test "${jk_exec_first}" = "jk_exec_retvalue" ; then
70             jk_exec_ret="${jk_exec_line}"
71           else
72             if test -n "${jk_exec_line}" ; then
73              echo "    $3: ${jk_exec_first} ${jk_exec_line}"
74             fi
75           fi
76         fi
77       done
78       echo "${jk_exec_ret}" > retvalue.tmp
79       unset jk_exec_first
80       unset jk_exec_line
81       unset jk_exec_ret
82     }
83
84     $1="`cat retvalue.tmp`"
85     rm -f retvalue.tmp
86     echo "  execution of \"$2\""
87     echo "  returned with value \"${$1}\""
88
89     cd "${jk_exec_curdir}"
90     unset jk_exec_curdir
91   ])