File: hanoi.sh.in

package info (click to toggle)
bashdb 4.0.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,820 kB
  • ctags: 942
  • sloc: sh: 10,581; lisp: 885; makefile: 449; ansic: 325
file content (47 lines) | stat: -rwxr-xr-x 998 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!@SH_PROG@
# $Id: hanoi.sh.in,v 1.6 2008/10/02 09:48:50 rockyb Exp $
# Towers of Hanoi
# We've added calls to set line tracing if the 1st argument is "trace"

init() {
  # We want to test _Dbg_set_trace inside a call
  if (( $tracing )) ; then
    _Dbg_linetrace_on
  fi
}

hanoi() { 
  typeset -i n=$1
  # Mul
  # _Dbg_set_trace
  typeset -r a=$2
  typeset -r b=$3
  typeset -r c=$4
  if (( n > 0 )) ; then
    (( n-- ))
    hanoi $n $a $c $b
    ((disc_num=max-n))
    echo "Move disk $n on $a to $b"
    if (( n > 0 )) ; then
       hanoi $n $c $b $a
    fi
  fi
}

typeset -i max=3
typeset -i tracing=0
if [[ "$1" = 'trace' ]] ; then
  if [[ -n $2 ]] ; then
      abs_top_builddir=$2
  elif [[ -z $builddir ]] ; then
      abs_top_builddir=@abs_top_builddir@
  fi
  tracing=1
  source ${abs_top_builddir}/bashdb-trace -B -q -L ${abs_top_builddir} -x ${abs_top_srcdir}/test/data/settrace.cmd
fi
init
hanoi $max "a" "b" "c"
if (( $tracing )) ; then
  _Dbg_linetrace_off
  _Dbg_QUIT_ON_QUIT=1
fi