Index: trunk/devel/run
===================================================================
--- trunk/devel/run	(revision 1120)
+++ trunk/devel/run	(revision 1122)
@@ -1,5 +1,6 @@
 #!/bin/bash
 # this script is for developers only
-stopfpm() {
+
+stopfpm() { # {{{1
 	if [[ -f $pidfile ]]; then
 		pid=`cat $pidfile 2>/dev/null || true`
@@ -12,24 +13,26 @@
 }
 
-set -e
-MAKE=/usr/bin/make
-
-. devel/run.cfg
-if [[ $# -gt 0 ]]; then
-	action=$1
-	shift
-	if [[ $# -gt 0 ]]; then
-		args=("$@")
-	elif [[ $action = "make" ]]; then
-		args=()
-	fi
-fi
-
-case "$action" in
-prep*)
-	exec $MAKE -f devel/prepare.mak "${args[@]}"
-	;;
-po2php)
-	./run mergepo "${args[0]}"
+xtest() { # {{{1
+	$MAKE -f devel/test.mak
+}
+
+prep() { # {{{1
+	$MAKE -f devel/prepare.mak "$@"
+}
+
+mergepo() { # {{{1
+	prep
+	local i
+	find htdocs -iname '*.po' | while read -r i; do
+		if [[ -f $i-merged ]]; then
+			mv $i-merged $i
+		fi
+	done
+}
+
+po2php() { # {{{1
+	mergepo
+
+	local phpfile
 	find htdocs -iname '*.po' | while read -r i; do
 		phpfile=${i/.po/.php}
@@ -37,20 +40,7 @@
 		mv $phpfile.tmp $phpfile
 	done
-	exit
-	;;
-mergepo)
-	./run prep "${args[0]}"
-	find htdocs -iname '*.po' | while read -r i; do
-		if [[ -f $i-merged ]]; then
-			mv $i-merged $i
-		fi
-	done
-	exit
-	;;
-tags)
-	rm -f tags
-	exec $MAKE -f devel/prepare.mak tags "${args[@]}"
-	;;
-dep*)
+}
+
+updatedeps() { # {{{1
 	pwd=$(readlink -f "$(pwd)")
 	builddir=$(readlink -f ../trunk-php5-debug-zts)
@@ -97,23 +87,38 @@
 		echo
 	done > Makefile.frag.deps
-	exit
-	;;
-xtest)
-	exec $MAKE -f devel/test.mak
-	;;
-esac
-
-case "${args[0]}" in
-fpm)
-	pidfile=devel.pid
-	stopfpm
-	;;
-stopfpm)
-	pidfile=devel.pid
-	stopfpm
-	exit
-	;;
-esac
-
+}
+# }}}1
+
+set -e
+MAKE=/usr/bin/make
+
+. devel/run.cfg
+PHPSDIR=${PHPSDIR:-$HOME/test}
+
+if [[ $# -eq 0 ]]; then
+	set -- "$action" "${args[@]}"
+fi
+
+if [[ $# -gt 0 ]]; then
+	action=$1
+	shift
+fi
+
+# devel actions
+case "$action" in
+prep*) prep "$@"; exit;;
+tags) rm -f tags; prep tags "$@"; exit;;
+po2php) po2php; exit;;
+mergepo) mergepo; exit;;
+dep*) updatedeps; exit;;
+xtest) xtest; exit;;
+esac
+
+case "$1" in
+fpm) pidfile=devel.pid; stopfpm;;
+stopfpm) pidfile=devel.pid; stopfpm; exit;;
+esac
+
+# process each $dirs
 basename=$(basename $(pwd))
 if echo $basename | grep -- - >/dev/null; then :; else
@@ -127,5 +132,5 @@
 
 		pwd
-		$0 "$action" "${args[@]}"
+		$0 "$action" "$@"
 	done
 	exit
@@ -136,34 +141,10 @@
 xcachesrcdir=../$xcachebasename
 pidfile=../$xcachebasename/devel.pid
-
-case "$action" in
-phpize)
-	if [[ -r Makefile ]]; then
-		$MAKE xcachesvnclean || true
-	fi
-	;;
-esac
-
-rm -f php-src
-find -L . -action l | xargs rm -fv
-lndir "$xcachesrcdir" >/dev/null || true
-find . -iname .\*.swp | xargs rm -f
-ln -sf ~/src/php/$phpbasename php-src
-for i in ~/src/php/$phpbasename/sapi/cgi/php{,-cgi}; do
-	if [[ -r $i ]]; then
-		ln -sf "$i" php-cgi
-	fi
-done
-ln -sf ~/src/php/$phpbasename/sapi/cli/php php-cli
-ln -sf ~/src/php/$phpbasename/sapi/fpm/php-fpm php-fpm
-
-case "$action" in
-phpize)
-	PHPDIRS=${PHPDIRS:-$HOME/test}
-	if [[ ! -x $PHPDIRS/$phpbasename/bin/phpize ]]; then
-		echo $PHPDIRS/$phpbasename/bin/phpize not found
+phpize() { # {{{1
+	if [[ ! -x $PHPSDIR/$phpbasename/bin/phpize ]]; then
+		echo $PHPSDIR/$phpbasename/bin/phpize not found
 		exit
 	fi
-	export PATH=$PHPDIRS/$phpbasename/bin:$PATH
+	export PATH=$PHPSDIR/$phpbasename/bin:$PATH
 	phpize --clean \
 	&& phpize \
@@ -177,29 +158,83 @@
 		--enable-xcache-test \
 		--enable-xcache-constant
-	exit
-	;;
-make)
-	MAKEARGS=("$@")
-	;;
-esac
-
-LANG=C $MAKE $MAKEOPTS "${MAKEARGS[@]}" 2>&1 \
-| sed -ur \
-	-e 's#Werror=implicit-function-declaration#We/rror=i/mplicit-function-declaration#' \
-	-e 's#-pedantic-errors#-pedantic-e/rrors#' \
-	-e 's#\./xc_processor\.h#'$PWD'/xc_processor.h#' \
-	-e 's#\./xc_processor\.c\.h#'$PWD'/xc_processor.c.h#' \
-| hi error implicit warn FAIL
-ret=${PIPESTATUS[0]}
-if [[ $ret -ne 0 || $action = make ]]; then
-	exit $ret
-fi
-
-if [[ -z ${args[0]} ]]; then
-	args=(devel.php)
+}
+make() { # {{{1
+	LANG=C $MAKE $MAKEOPTS "$@" 2>&1 \
+	| sed -ur \
+		-e 's#Werror=implicit-function-declaration#We/rror=i/mplicit-function-declaration#' \
+		-e 's#-pedantic-errors#-pedantic-e/rrors#' \
+		-e 's#\./xc_processor\.h#'$PWD'/xc_processor.h#' \
+		-e 's#\./xc_processor\.c\.h#'$PWD'/xc_processor.c.h#' \
+	| hi error implicit warn FAIL
+	ret=${PIPESTATUS[0]}
+	if [[ $ret -ne 0 ]]; then
+		exit $ret
+	fi
+}
+# }}}
+
+# prepare {{{1
+case "$action" in
+phpize)
+	if [[ -r Makefile ]]; then
+		$MAKE xcachesvnclean || true
+	fi
+	;;
+esac
+
+rm -f php-src
+find -L . -type l | xargs rm -fv
+lndir "$xcachesrcdir" >/dev/null || true
+find . -iname .\*.swp | xargs rm -f
+ln -sf ~/src/php/$phpbasename php-src
+for i in ~/src/php/$phpbasename/sapi/cgi/php{,-cgi}; do
+	if [[ -r $i ]]; then
+		ln -sf "$i" php-cgi
+	fi
+done
+ln -sf ~/src/php/$phpbasename/sapi/cli/php php-cli
+ln -sf ~/src/php/$phpbasename/sapi/fpm/php-fpm php-fpm
+
+case "$action" in
+phpize) phpize; exit;;
+make) make "$@"; exit;;
+*) make;;
+esac
+# }}}1
+
+if [[ -z $1 ]]; then
+	set -- devel.php
 fi
 
 cmd=()
 tracer=()
+
+# run utils {{{1
+case "$action" in
+dc)
+	exec ./php-cli -c devel.ini ./bin/phpdc.phpr $@ | tee decompiled.php
+	;;
+dop)
+	exec ./php-cli -c devel.ini ./bin/phpdop.phpr $@
+	;;
+retest)
+	exec $MAKE xcachetest "$@" TESTS="`grep '^/.*\.phpt$' php_test_results_*.txt | uniq | xargs`"
+	;;
+test)
+	case "$1" in
+	*.phpt)
+		exec $MAKE xcachetest TEST_ARGS=-v TESTS="$*"
+		;;
+	*/)
+		exec $MAKE xcachetest TESTS="$*"
+		;;
+	*)
+		exec $MAKE xcachetest
+		;;
+	esac
+	;;
+esac
+# }}}
+# pick sapi {{{1
 case "$basename" in
 *-apache1*)
@@ -210,13 +245,13 @@
 	;;
 *)
-	case "${args[0]}" in
+	case "$1" in
 	fcgi)
 		cmd=(./php-cgi -q -c devel.ini)
-		args=(-b 1026)
+		set -- -b 1026
 		;;
 	fpm)
 		echo Starting fpm ...
 		cmd=(./php-fpm -c devel.ini -y devel.fpm -g $(readlink -f $pidfile))
-		args=()
+		set --
 		;;
 	*)
@@ -227,5 +262,6 @@
 	"${cmd[@]}" -v || true
 esac
-
+# }}}
+# pick action {{{1
 case "$action" in
 ltr*)
@@ -244,30 +280,9 @@
 	tracer=(valgrind --gen-suppressions=all)
 	;;
-dc)
-	exec ./php-cli -c devel.ini ./bin/phpdc.phpr "${args[@]}" | tee decompiled.php
-	;;
-dop)
-	exec ./php-cli -c devel.ini ./bin/phpdop.phpr "${args[@]}"
-	;;
-retest)
-	exec $MAKE xcachetest "$@" TESTS="`grep '^/.*\.phpt$' php_test_results_*.txt | uniq | xargs`"
-	;;
-test)
-	case "${args[0]}" in
-	*.phpt)
-		exec $MAKE xcachetest TEST_ARGS=-v TESTS="${args[*]}"
-		;;
-	*/)
-		exec $MAKE xcachetest TESTS="${args[@]}"
-		;;
-	*)
-		exec $MAKE xcachetest
-		;;
-	esac
-	;;
-esac
-
+esac
+
+# run {{{1
 export XCACHE_SKIP_FCGI_WARNING=1
-commandLine=("${tracer[@]}" "${cmd[@]}" "${args[@]}")
+commandLine=("${tracer[@]}" "${cmd[@]}" "$@")
 
 case "${cmd[0]}" in
@@ -276,6 +291,7 @@
 	"${commandLine[@]}"
 	echo -n "Ctrl-C to stop"
-	trap stopfpm SIGINT SIGTERM
+	trap stopfpm SIGINT SIGTERM exit
 	cat > /dev/null || true
+	stopfpm
 	;;
 *)
@@ -283,2 +299,3 @@
 	;;
 esac
+# }}}
