Update of /cvsroot/leaf/devel/ccarr/devel/leaf-tools
In directory sc8-pr-cvs1:/tmp/cvs-serv10610

Modified Files:
        hier.help tmpl 
Log Message:
tmpl can now unroll foreach loops and do simple conditionals; documentation to follow.


Index: hier.help
===================================================================
RCS file: /cvsroot/leaf/devel/ccarr/devel/leaf-tools/hier.help,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hier.help   17 Feb 2003 07:30:28 -0000      1.2
--- hier.help   19 Feb 2003 05:56:58 -0000      1.3
***************
*** 1,3 ****
! Bering config-db hierarchy
  
  network/
--- 1,3 ----
! Proposed bering config-db hierarchy
  
  network/

Index: tmpl
===================================================================
RCS file: /cvsroot/leaf/devel/ccarr/devel/leaf-tools/tmpl,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** tmpl        12 Feb 2003 05:31:10 -0000      1.1.1.1
--- tmpl        19 Feb 2003 05:56:58 -0000      1.2
***************
*** 13,17 ****
        then
                mkdir -p `dirname "$1"` # create path
!               exec >&"$1"
        fi
  }
--- 13,17 ----
        then
                mkdir -p `dirname "$1"` # create path
!               exec > "$1"
        fi
  }
***************
*** 47,62 ****
  proc_tmpl ()
  {
!       # change input field separator to ...
!       oldifs="$IFS"
        IFS=$'\n'
  
!       # read and process template line by line ...
!       for line in `cat $itmpl`
        do
!               eval "echo \"$line\""
        done
  
!       # and back again before we're done
!       IFS="$oldifs"
  }
  
--- 47,164 ----
  proc_tmpl ()
  {
!       # reopen stdin from itmpl
!       exec < $itmpl
! 
!       # change input field separator to bare newline
!       oIFS="$IFS"
        IFS=$'\n'
  
!       # read and process template line by line
!       while read line
        do
!               if is_directive $line
!               then
!                       op $line
!               else
!                       eval "echo \"$line\""
!               fi
        done
  
!       # restore IFS
!       IFS="$oIFS"
! }
! 
! ################################################################################
! #
! # returns true if line is a directive
! #
! is_directive ()
! {
!       echo $1 | grep -q '^@' && return 0 || return 1
! }
! 
! ################################################################################
! #
! # returns true if line is an end directive
! #
! is_end ()
! {
!       echo $1 | grep -q '^@END' && return 0 || return 1
! }
! 
! ################################################################################
! #
! # implements a foreach loop -> @FOREACH <alias> <array>
! #
! FOREACH ()
! {
!       alias="$1"
!       array=`set | sed -n "s/^\($2_[0-9]\).*/\1/p" | uniq | sort -n`
!       shift 2
! 
!       # a helper variable so templates can count iterations
!       loop_index=0
! 
!       # unroll loop, aliasing each element to user-provided alias name
!       for elem in $array
!       do
!               # process block lines in $@
!               for arg
!               do
!                       # one pass to get the alias interpolated
!                       preproc=`echo "$arg" | sed "s/\\$$alias/\\$$elem/g"`
! 
!                       # another to get the _value_ of the interpolated var 
!                       eval "echo \"$preproc\""
!               done
! 
!               loop_index=$((loop_index + 1))
!       done
! }
! 
! ################################################################################
! #
! # a simple if construct - can we get an else here, people!?
! #
! IF ()
! {
!       if test $1
!       then
!               shift
!               eval "echo \"$@\""
!       fi
! }
! 
! ################################################################################
! #
! # recursively read lines to @END and call opcode, passing through args and lines
! #
! op ()
! {
!       local op=${1#@} # remove @ prefix
! 
!       # localize and initialize input and output
!       local input=''
!       local output=''
! 
!       while read line
!       do
!               if is_directive "$line"
!               then
!                       if is_end "$line"
!                       then
!                               # close out this loop; arg separation is a side
!                               # effect of single quoting below: be careful!
!                               eval "$op $input"
!                               return
!                       else
!                               # new op: recurse and append output from op
!                               input="$input '`op $line`'"
!                       fi
!               else
!                       # regular line; append
!                       input="$input '$line'"
!               fi
!       done
  }
  
***************
*** 65,71 ****
  # process args
  #
! if test $# -ge 2
  then
!       while test $# -gt 0
        do
                case "$1" in
--- 167,173 ----
  # process args
  #
! if test "$#" -ge 2
  then
!       while test "$#" -gt 0
        do
                case "$1" in
***************
*** 99,100 ****
--- 201,203 ----
  fi
  
+ exit 0




-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
Leaf-cvs-commits mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-cvs-commits

Reply via email to