#! /local/bin/bash

TMPDIR=/bioweb/htdocs/seqanal/tmp
PISELOG=/bioweb/logs/bioweb.log

# log Web
#logw() {
    c=""
    l=""
    p=""
    if [ "x$1" = "x" ]; then
	c="d"; \
    else \
	c=$1;
    fi
    if [ "x$2" = "x" ]; then
	l=20; \
    else \
	l=$2;
    fi
    if [ $c != "d" -a $c != "c" -a $c != "a" -a $c != "r" -a $c != "h" ]; then
	if [ $c = "-" ]; then 
	    l=$c;
	    if [ "x$2" != "x" ]; then
		p=$2
	    fi
	elif expr 1 + $c > /dev/null 2>&1 ; then
	    l=$c;
	    if [ "x$2" != "x" ]; then
		p=$2
	    fi
   	else
	    p=$c;
	    l=20;
	fi
	c="d";
    fi
    if [ $c = "a" ]; then
	if [ "x$2" = "x" ]; then
	    l=10;
	elif ! expr 1 + $2 > /dev/null 2>&1 ; then
	    p=$2
	    l=10
	fi
	if [ $2 = "-" ]; then
		l=999999999999999;
	else
		let l=$l*4;
	fi
    fi
    if [ $l = "-" ]; then
	l=999999999999999;
    fi
    if [ "x$l" = "x" ]; then
	l=20;
    fi
    if [ "x$3" != "x" ]; then
	p=$3
    elif [ "x$p" = "x" ]; then
	p="."
    fi
    if ! expr 1 + $l > /dev/null 2>&1 ; then
	p=$l;
	l=20;
    fi
    if [ $p != "." ]; then
	p="$p||"
    fi
    #echo "debug> c=$c l=$l p=$p"
    if [ $c = "c" ]; then
	for d in `cat $PISELOG | grep "^$p" | awk -F'||' '{print $5}' | tail -$l` ; do
	    cat $PISELOG | grep $d | awk -F'||' '{print $1,"--",$4,"-",$3}'
	    if [ -f $d/params ]; then
		echo "$d/params:"
		cat $d/params
	    fi
	done
    elif [ $c = "r" ]; then
	cat $PISELOG | grep "^$p" | \
	    awk -F'||' '{print $1,"--",$4,"-",$5}' | \
	    tail -$l;
    elif [ $c = "h" ]; then
	cat $PISELOG | grep "^$p" | \
	    awk -F'||' '{print $1,"--",$4,"-",$7}' | \
	    tail -$l;
    elif [ $c = "d" ]; then
	cat $PISELOG | grep "^$p" | \
	    awk -F'||' '{print $1,"--",$4,"-",$6}' | \
	    tail -$l;
    elif [ $c = "a" ]; then
	cat $PISELOG | grep "^$p" | \
	    awk -F'||' '{print $1,"--",$4,"-",$2, "\n\t",$6, "\n\t",$3, 
			    "\n\t", $5, "\n\t", $7}' | \
	    tail -$l;
    fi
#}
