#!/bin/bash # # extract and order seq from test floor # # $Author: alfredo $ $Revision: 1.8 $ USAGE=" This script converts csv into Test Language, the input must be compatible with the output format of tl_to_csv $0 -f f: .csv limits file " if [ "$#" -lt "2" ] then echo "missing file" echo "$USAGE" exit fi while getopts "f:" idx do case $idx in f) infile="$OPTARG";; \?) echo "$USAGE";exit;; esac done dt=`date` gawk -v dt="$dt" ' BEGIN{ FS="," oldfunc="" oldtnum=-1 fbegin=1 fSEQ=1 unit="unit" tname="tname" tnum="tnum" frmin="frmin" frmax="frmax" qrmax="qrmax" qrmin="qrmin" qtmax="qtmax" qtmin="qtmin" min="min" # generic min max="max" # generic max seqfunc="seqfunc" binfunc="binfunc" testq[unit]=100 testq[tname]=100 testq[tnum]=100 testq[frmin]=100 testq[frmax]=100 testq[qrmin]=100 testq[qrmax]=100 testq[qtmin]=100 testq[qtmax]=100 testq[min]=100 testq[max]=100 testq[seqfunc]=100 testq[binfunc]=100 max_nf=0 tnameflag=0 binfunction="f(temp_bin)" } $1 ~ /## *SEQUENCER/{ if( fSEQ == 0 ) { printf("}\n") } sub(/## */,"") gsub(/\"/,"") printf("\n %s\n",$1) fSEQ=0 fbegin=1 next } $1 ~ /##/{ sub(/##/,"") gsub(/\"/,"") printf("\n %s\n",$1) next } /^ *$/{next} $1 ~ / *# */{ next } /[tT][eE][sS][tT][ _]*[nN][aA][mM][eE]/{ if(tnameflag == 0) { tnameflag=1 } else { printf("\n\ncsv file with multiple \"Test name\" not allowed\n\n") exit } max_nf=NF for(i=1;i<=max_nf;i++) { if( $i ~ /[uU][nN][iI][tT]/ ) { testq[unit]=i } if( $i ~ /[tT][eE][sS][tT][ _]*[nN][aA][mM][eE]/ ) { testq[tname]=i } if( $i ~ /[tT][nN][uU][mM]/ ) { testq[tnum]=i } if( $i ~ /FR[ _]*[mM][iI][nN]/ ) { testq[frmin]=i } if( $i ~ /FR[ _]*[mM][aA][xX]/ ) { testq[frmax]=i } if( $i ~ /QR[ _]*[mM][iI][nN]/ ) { testq[qrmin]=i } if( $i ~ /QR[ _]*[mM][aA][xX]/ ) { testq[qrmax]=i } if( $i ~ /QT[ _]*[mM][iI][nN]/ ) { testq[qtmin]=i } if( $i ~ /QT[ _]*[mM][aA][xX]/ ) { testq[qtmax]=i } if( $i ~ /^["]*[mM][aA][xX]/ ) { testq[max]=i } if( $i ~ /^["]*[mM][iI][nN]/ ) { testq[min]=i } if( $i ~ /seqfunc/ ) { testq[seqfunc]=i } if( $i ~ /binfunc/ ) { testq[binfunc]=i } } printf("/* prostprocess %s by csv_to_tl $Revision: 1.8 $ $Author: alfredo $ */\n",dt) printf("/* input file %s */\n\n",FILENAME) next } { # generating seq function if( $testq[seqfunc] != "" ) { gsub(/\"/,"",$testq[seqfunc]) gsub(/@/,",",$testq[seqfunc]) if( $testq[seqfunc] != oldfunc) { if(fbegin == 0) { printf("}\n") } oldfunc=$testq[seqfunc] print "\nseq ", $testq[seqfunc], "\n{" fbegin=0 } } # generating test numbers if( $testq[tnum] != "" ) { if( $testq[tnum] != oldtnum+1) { print "$"$testq[tnum],"\n" } oldtnum=$testq[tnum] } } { # test name may comes with or without <> function, the test name should be without # function. Another possibility is to have test name with or without "". this # section take care of these problems, the output should have one single double # quote sub(/ *<>[^"]*/,"",$testq[tname]) sub(/^/,"\"",$testq[tname]) sub(/$/,"\"",$testq[tname]) gsub(/""/,"\"",$testq[tname]) # remove space in the string becasue some csv application add "" everywhere (xcel) # other (gnumeric) do not for(idx in testq) { if( idx != tname ) { gsub(/ */,"",$testq[idx]) gsub(/"/,"",$testq[idx]) } } printf("%-32s ", $testq[tname]) ostr="" if($testq[min] !~ /^ *$/ ) { # need this check single value limits if($testq[max] == "" ) { ostr=sprintf("%-11s ","== "$testq[min]$testq[unit]) } else { ostr=sprintf("%-11s ","> "$testq[min]$testq[unit]) } } if($testq[max] !~ /^ *$/ ) ostr=ostr""sprintf("%-11s ","< "$testq[max]$testq[unit]) if($testq[frmin] !~ /^ *$/ ) ostr=ostr""sprintf("%-16s ","FR: > "$testq[frmin]$testq[unit]) if($testq[frmax] !~ /^ *$/ ) ostr=ostr""sprintf("%-11s ","< "$testq[frmax]$testq[unit]) if($testq[qrmin] !~ /^ *$/ ) ostr=ostr""sprintf("%-16s ","QR: > "$testq[qrmin]$testq[unit]) if($testq[qrmax] !~ /^ *$/ ) ostr=ostr""sprintf("%-11s ","< "$testq[qrmax]$testq[unit]) if($testq[qtmin] !~ /^ *$/ ) ostr=ostr""sprintf("%-16s ","QT: > "$testq[qtmin]$testq[unit]) if($testq[qtmax] !~ /^ *$/ ) ostr=ostr""sprintf("%-11s ","< "$testq[qtmax]$testq[unit]) if( length(ostr) == 0 ) { printf("!!! missing limits !!! ") } gsub(/@/,",",$testq[binfunc]) ostr=ostr""$testq[binfunc] printf("%s",ostr) printf("\n") } END{ if( fbegin == 0) printf("}\n") printf("/* END of sequence \n") for(var in testq) { printf("test/limit %-30s location %d\n", var,testq[var]) } printf("*/\n") } ' "$infile"