#!/bin/sh #--------------------------------------------------------------------------- # /usr/local/bin/techo - table echo # # Creation: 2004-08-20 max # Last Update: $Id$ # # Copyright (c) 2004-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org # # 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|--link] 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) # --stdbr print standard message (default)(bright) # --info print info message (green) # --warn print warning message (yellow)(bright) # --error print error message (red)(brightinvers) # --link print message '>' (cyan) # # example: # techo --begin '3 3r 15 10 28* 20' # techo --row "" 1 foo foo "This is a somehow longer text, since i need a very long line of text" foo # techo --row "->" 2 --info "bar foo" --warn "foo bar" foo # techo --row "" 12 foofoo foo foo --error foobar # techo --info --row "" 24 foo foobar foo --error foobar # techo --end # # -------------------------------------------------------------------------- # ========================================================================== # main # ========================================================================== techo () { _techo_opt='STD' _techo_mode="$_EISLIB_PRINTMODE" _techo_call='' _techo_colors='' while [ 1 ] do case "$1" in --std|-std) _techo_opt='STD'; shift;; --stdbr) _techo_opt='STDBR'; shift;; --info|-info) _techo_opt='INFO'; shift;; --warn|-warn) _techo_opt='WARN'; shift;; --error|-error) _techo_opt='ERROR'; shift;; --link) _techo_opt='LINK'; shift;; --tty|-tty) _techo_mode=tty; shift;; --html|-html) _techo_mode=html; shift;; --file|-file) _techo_mode=file; shift;; *) break;; esac done _techo_mode2=`echo $_techo_mode | tr 'a-z' 'A-Z'` case "${1}" in --begin|begin) _techo_call='begin'; shift;; --row|row) _techo_call='row'; shift;; --end|end) _techo_call='end'; shift;; *) _techo_call='row';; esac case "${_techo_call}" in begin) _techo_total=0 _techo_total_variable=0 # don't expand '*', do sed for _techo_width in `echo "\"${*}\"" | tr -d 'rl' | sed 's# #" "#g'` do case "${_techo_width}" in *'*'*) # we can not use backticks in backticks, so we use $($( )) _techo_total_variable=$(/usr/bin/expr ${_techo_total_variable} + $(echo "${_techo_width}" | tr -d '*"')) ;; esac _techo_total=$(/usr/bin/expr ${_techo_total} + $(echo "${_techo_width}" | tr -d '*"')) done # check for row length only if != file if [ "${_techo_mode}" != "file" ] then if [ ${_techo_total} -gt 80 ] then mecho --${_techo_mode} --error "You cannot use techo with more than 80 columns." exit 255 fi _techo_width_factor=100 if [ ${_EISLIB_SCREENSIZE_X} -gt 80 -a ${_techo_total_variable} -gt 0 ] then let _techo_width_factor=($_EISLIB_SCREENSIZE_X-80)*100/$_techo_total_variable+100 fi fi ;; esac if [ "$_techo_mode" = "tty" -o "$_techo_mode" = "file" ] then case "${_techo_call}" in begin) eval _techo_pre='$'_EISLIB_COLOR_${_techo_mode2}_PRE eval _techo_post='$'_EISLIB_COLOR_${_techo_mode2}_POST eval _techo_reset='$'_EISLIB_COLOR_${_techo_mode2}_RESET _techo_column=1 for _techo_line in `echo "\"${*}\"" | sed 's# #" "#g'` do case "${_techo_line}" in *r*) _techo_align='';; *) _techo_align='-';; esac _techo_width=`echo "${_techo_line}" | tr -d 'rl*"'` case "${_techo_line}" in *'*'*) let _techo_width=$_techo_width*$_techo_width_factor/100 ;; esac let _techo_width-- # generates pre-formatet string # ...%b...%-7.7s... # UTF-8 fix: ksh specific workaround for printf command: # modified format string to count characters # instead of bytes # eval _EISLIB_TECHO_${_techo_column}='${_techo_pre}%b${_techo_post}%${_techo_align}${_techo_width}.${_techo_width}s${_techo_reset}\ ' eval _EISLIB_TECHO_${_techo_column}='${_techo_pre}%b${_techo_post}%${_techo_align}${_techo_width}.${_techo_width}Ls${_techo_reset}\ ' let _techo_column++ shift done ;; row) _techo_column=1 _techo_mask=$_EISLIB_TECHO_1 while [ $# -gt 0 -a "$_techo_mask" != "" ] do case $1 in --info|-info) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_INFO; shift;; --warn|-warn) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_WARN; shift;; --error|-error) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_ERROR; shift;; --std|-std) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_STD; shift;; --link) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_LINK; shift;; *) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_${_techo_opt};; esac # UTF-8 fix: modified printf command call to # count characters instead of bytes # printf "${_techo_mask}" "$_techo_colors" "$1" ksh -c "printf \"${_techo_mask}\" \"$_techo_colors\" \"$1\"" let _techo_column++ eval _techo_mask='$'_EISLIB_TECHO_${_techo_column} shift done echo ;; end) _techo_column=1 _techo_mask=$_EISLIB_TECHO_1 while [ "$_techo_mask" != "" ] do unset _EISLIB_TECHO_${_techo_column} let _techo_column++ eval _techo_mask='$'_EISLIB_TECHO_${_techo_column} done ;; esac elif [ "$_techo_mode" = "html" ] then case "$_techo_call" in begin) echo "" echo "" for _techo_line in `echo "\"${*}\"" | sed 's# #" "#g'` do case "${_techo_line}" in *r*) _techo_align='right';; *) _techo_align='left';; esac _techo_width=`echo "${_techo_line}" | tr -d 'rl*"'` _techo_width=`/usr/bin/expr $_techo_width \* 100 / 80` echo "" shift done echo "" ;; row) _techo_column=1 echo "" while [ $# -gt 0 ] do _techo_flags='' case $1 in --info|-info) _techo_colors="$_EISLIB_COLOR_HTML_INFO"; shift;; --warn|-warn) _techo_colors="$_EISLIB_COLOR_HTML_WARN"; shift;; --error|-error) _techo_colors="$_EISLIB_COLOR_HTML_ERROR"; shift;; --std|-std) _techo_colors="$_EISLIB_COLOR_HTML_STD"; shift;; --link) _techo_colors="$_EISLIB_COLOR_HTML_LINK"; shift;; *) eval _techo_colors='$'_EISLIB_COLOR_HTML_${_techo_opt};; esac echo -n "" shift done echo "" ;; end) echo "
" printf "${_EISLIB_COLOR_HTML_PRE}%s${_EISLIB_COLOR_HTML_POST}%s${_EISLIB_COLOR_HTML_RESET}" "$_techo_colors" "$1" echo "
" ;; esac fi } # ========================================================================== # end # ==========================================================================