cat /home/pe1dnn/.xastir/logs/tnc.log.old \
    /home/pe1dnn/.xastir/logs/tnc.log \
| egrep "^P[ABEDI][0-9][A-Z]+[-]*[0-9]*>" | gawk '
BEGIN {
    dump = 0
    idx = 0
    mic = 0
    time = 0
    okay = 0

    calls[0]=""
    call_num = 0
    whois[0]=""
}

{
    i = index($0, ">")
    call = substr($0, 1, i-1) "          "
    call = substr(call, 1, 9)

    i = index($0, ":")
    line = substr($0, i+1)

    if(match(substr(line,1,1), "[=!]") != 0)
    {
        dump = 1
        time = 0
        mic = 0
    }
    else if(match(substr(line,1,1), "[@\/]") != 0)
    {
        dump = 1
        time = 1
        mic = 0
    }
    else if(match(substr(line,1,1), "[\x1c\x1d\x60\x27\`]") != 0)
    {
        dump = 1;
        mic = 1
    }

    if(dump == 1)
    {
        okay = 0

        if(mic == 0)
        {
            if(time == 0)
            {
                c = substr(line, 2, 1)
                if((c < "0") || (c > "9"))
                {
                    line = substr(line, 15)
                    comp = 1
                }
                else
                {
                    line = substr(line, 21)
                    comp = 0
                }

                if(substr(line, 1, 3) == "PHG")
                {
                    line = substr(line, 9)
                }

                while(substr(line, 1, 1) == " ")
                {
                    line = substr(line, 2)
                }
            }
            else
            {
                c = substr(line, 9, 1)
                if((c < "0") || (c > "9"))
                {
                    line = substr(line, 22)
                    comp = 1
                }
                else
                {
                    line = substr(line, 28)
                    comp = 0
                }

                if(substr(line, 1, 3) == "PHG")
                {
                    line = substr(line, 9)
                }

                while(substr(line, 1, 1) == " ")
                {
                    line = substr(line, 2)
                }
            }
            
            if(line != "")
            {
                okay = 1
            }

            if(comp == 0)
                line = "(NORMAL) :" line
            else
                line = "(COMPRES):" line
        }
        else
        {
            line = substr(line,10)

            type  = substr(line, 1, 1)
            if(type == ">")
            {
                type = "(TH-D7)  :"
                line = substr(line, 2)
            }
            else if(type == "]")
            {
                type = "(TM-D700):"
                line = substr(line, 2)
            }
            else
            {
                type = "(MIC-E)  :" 
            }

            if(substr(line, 4, 1) == "}")
            {
                line = substr(line, 5)
            }

            if(line != "")
            {
                okay = 1
            }

            line = type line
        }

        if(okay == 1)
        {
            line = call line

            if(substr(line, 23, 1) != "/")
            {
                call_pos = -1;
                for(i = 0; (i < call_num) && (call_pos == -1); i++)
                {
                    if(calls[i] == call)
                    {
                        call_pos = i;
                    }
                }

                if(call_pos == -1)
                {
                    call_pos = call_num;
                    calls[call_pos] = call;
                    # print "new call " call " position  " call_pos
                    call_num++;
                }

                whois[call] = line
            }
        }
    }
    dump = 0;
}

END {
    for(i = 0; i < call_num; i++)
    {
        print whois[calls[i]]
    }
}
' | sort
