#!/bin/sh #---------------------------------------------------------------------------- # /usr/local/bin/techo - table echo # # Copyright (c) 2004 Frank Meyer # # Creation: 20.08.20004 max # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # usage #---------------------------------------------------------------------------- # # techo [-tty|-html|-file] [-std|-info|-warn|-error] begin width width ... # techo [-tty|-html|-file] [-std|-info|-warn|-error] row [-std|-info|-warn|-error] message ... # techo [-tty|-html|-file] [-std|-info|-warn|-error] end # # options: # -tty use console colors # -html use html tags for colors # -file don't use any color tags # # message-options: # -std print standard message (default) # -info print info message # -warn print warning message # -error print error message # # example: # techo begin 4 20 10 20 # techo row "" foo foo foo # techo row "->" -info "bar foo" foo -warn "foo bar" # techo row "" foofoo -error foobar foo # techo -info row "" foo -error foobar foobar # techo end # #---------------------------------------------------------------------------- #============================================================================ # helper #============================================================================ # fixed spaces string - 80 character long (fast method) _techo_spacestr=" " _techo_printcol () { _techo_str="$1" _techo_width=$2 _techo_str="$_techo_str""$_techo_spacestr" echo -n "${_techo_str: 0: $_techo_width}" } #============================================================================ # main #============================================================================ techo () { _techo_opt='STD' _techo_mode="$_EISLIB_PRINTMODE" _techo_call='' _techo_colors='' while [ 1 ] do case "$1" in -std) _techo_opt='STD'; shift;; -info) _techo_opt='INFO'; shift;; -warn) _techo_opt='WARN'; shift;; -error) _techo_opt='ERROR'; shift;; -tty) _techo_mode=tty; shift;; -html) _techo_mode=html; shift;; -file) _techo_mode=file; shift;; *) break;; esac done case "$1" in begin|row|end) _techo_call=$1; shift;; *) _techo_call='row';; esac if [ "$_techo_mode" = "tty" ] then case "$_techo_call" in begin) _techo_xpos=0 _techo_column=1 while [ $# -gt 0 ] do eval _EISLIB_TECHO_${_techo_column}="$_techo_xpos" let _techo_xpos=$_techo_xpos+$1 let _techo_column=$_techo_column+1 shift done if [ $_techo_xpos -gt 80 ] then colecho_tty "You cannot use techo with more than 80 colums." $_EISLIB_COLOR_TTY_ERROR exit 255 fi ;; row) _techo_column=1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} while [ $# -gt 0 -a "$_techo_xpos" != "" ] do case $1 in -info) _techo_colors="$_EISLIB_COLOR_TTY_INFO"; shift;; -warn) _techo_colors="$_EISLIB_COLOR_TTY_WARN"; shift;; -error) _techo_colors="$_EISLIB_COLOR_TTY_ERROR"; shift;; -std) _techo_colors="$_EISLIB_COLOR_TTY_STD"; shift;; *) eval _techo_colors='$'_EISLIB_COLOR_TTY_${_techo_opt};; esac if [ $_techo_xpos -ne 0 ] then colecho_tty -n "\r\033[${_techo_xpos}C$1" $_techo_colors else colecho_tty -n "$1" $_techo_colors fi let _techo_column=$_techo_column+1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} shift done echo ;; end) _techo_column=1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} while [ "$_techo_xpos" != "" ] do unset _EISLIB_TECHO_${_techo_column} let _techo_column=$_techo_column+1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} done ;; esac elif [ "$_techo_mode" = "html" ] then case "$_techo_call" in begin) _techo_xpos=0 echo "" echo "" while [ $# -gt 0 ] do _techo_width=`/usr/bin/expr $1 \* 100 / 80` echo "" let _techo_xpos=$_techo_xpos+$1 shift done echo "" if [ $_techo_xpos -gt 80 ] then colecho_html "You cannot use techo with more than 80 colums." $_EISLIB_COLOR_HTML_ERROR exit 255 fi ;; row) _techo_column=1 echo "" while [ $# -gt 0 ] do _techo_flags='' case $1 in -info) _techo_colors="$_EISLIB_COLOR_HTML_INFO"; shift;; -warn) _techo_colors="$_EISLIB_COLOR_HTML_WARN"; shift;; -error) _techo_colors="$_EISLIB_COLOR_HTML_ERROR"; shift;; -std) _techo_colors="$_EISLIB_COLOR_HTML_STD"; shift;; *) eval _techo_colors='$'_EISLIB_COLOR_HTML_${_techo_opt};; esac echo -n "" shift done echo "" ;; end) echo "
" colecho_html "$1" $_techo_colors echo "
" ;; esac else case "$_techo_call" in begin) _techo_xpos=0 _techo_column=1 while [ $# -gt 0 ] do eval _EISLIB_TECHO_${_techo_column}="$1" let _techo_xpos=$_techo_xpos+$1 let _techo_column=$_techo_column+1 shift done if [ $_techo_xpos -gt 80 ] then echo "You cannot use techo with more than 80 colums." exit 255 fi ;; row) _techo_column=1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} while [ $# -gt 0 -a "$_techo_xpos" != "" ] do case $1 in -info|-warn|-error|-std) shift;; *) ;; esac _techo_printcol "$1" $_techo_xpos let _techo_column=$_techo_column+1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} shift done echo ;; end) _techo_column=1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} while [ "$_techo_xpos" != "" ] do unset _EISLIB_TECHO_${_techo_column} let _techo_column=$_techo_column+1 eval _techo_xpos='$'_EISLIB_TECHO_${_techo_column} done ;; esac fi } #============================================================================ # end #============================================================================