#!/bin/bash # # extract and order seq from test floor # # $Author: alfredo $ $Revision: 1.21 $ USAGE=" This script convert test language program into text and csv format it takes the c-like *.tl file and generates a csv/txt output $0 -f -s -C -q f: .tl file s: seq function C: output csv q: keep test function name example: tl_to_csv -f sample.tl -q -c > sample.csv " seqlog="" csv="" fn="" if [ "$#" -lt "2" ] then echo "missing file" echo "$USAGE" exit fi while getopts "f:sCq" idx do case $idx in f) infile="$OPTARG";; s) seqlog="yes";; C) csv="yes";; q) fn="yes";; \?) echo "$USAGE";exit;; esac done echo "# process `date` by : $0 $* : user: $USER" echo "# author : $Author: alfredo $ Rev $Revision: 1.21 $" # # use cpp to takes out comments send stderr to /dev/null to eliminate # warning and error due to #include # sed ' /\/\*/!b :a /\*\//!{ N ba } s:/\*.*\*/:: /^ *$/d ' $infile | gawk -v seqlog="$seqlog" -v csv="$csv" -v fn="$fn" ' BEGIN{ countseq=0 countzero=0 tnum=1 str0="" oval[0]="unit" oval[1]="min" oval[2]="max" oval[3]="FRmin" oval[4]="FRmax" oval[5]="QRmin" oval[6]="QRmax" oval[7]="QTmin" oval[8]="QTmax" if( csv == "yes" ) { # printf("%-40s,","\"Test name\"") printf("%s,","\"Test name\"") printf("%s,","tnum") if( fn == "yes" ) { printf("%s,","seqfunc") printf("%s,","binfunc") } } else { printf("%-32s","\"Test name\"") printf("%-9s","tnum") if( fn == "yes" ) { printf("%-48s,","seqfunc") printf("%-40s,","binfunc") } } for(i=0;i<=8;i++) { if( csv == "yes" ) { # printf("%-8s,",oval[i]) printf("%s,",oval[i]) } else { printf("%-8s",oval[i]) } } printf("\n") } # # # START FUNCTIONS DEFINITION # # function get_units(instr) { len=length(instr) for(k=1;k<=len;k++) { if(substr(instr,k,1) ~ /[a-zA-Z]/) { temp=substr(instr,k,len-k+1) return temp } } } function get_number(nstr) { len=length(nstr) for(k=1;k<=len;k++) { if(substr(nstr,k,1) ~ /[a-zA-Z]/) { temp=substr(nstr,1,k-1) return temp } } temp=substr(nstr,1,k-1) return temp } function gen_lim(str) { # oval[0] oval[1] oval[2] oval[3] oval[4] oval[5] oval[6] oval[7] oval[8] #< unit >< min >< max>< FR min > # d=split(str,fl," *") # printf("%d\n",d) i=1 loop=0 delete oval while(i <= d ) { if(fl[i] == "==") { oval[1]=fl[i+1] i=i+2 } for(k=1;k<=2;k++) { if(fl[i] == ">") { oval[1]=fl[i+1] i=i+2 } if(fl[i] == "<") { oval[2]=fl[i+1] i=i+2 } } if(fl[i] == "FR:") { i=i+1 for(k=1;k<=2;k++) { if(fl[i] == ">") { oval[3]=fl[i+1] i=i+2 } if(fl[i] == "<") { oval[4]=fl[i+1] i=i+2 } } } if(fl[i] == "QR:") { i=i+1 for(k=1;k<=2;k++) { if(fl[i] == ">") { oval[5]=fl[i+1] i=i+2 } if(fl[i] == "<") { oval[6]=fl[i+1] i=i+2 } } } if(fl[i] == "QT:") { i=i+1 for(k=1;k<=2;k++) { if(fl[i] == ">") { oval[7]=fl[i+1] i=i+2 } if(fl[i] == "<") { oval[8]=fl[i+1] i=i+2 } } } loop ++ if(loop > 100 ) { printf("\n\nLooping forever, giving up on : %s\n\n",str) exit(2) } } # # check unit # for(i=1;i<=8;i++) { if(length(oval[i]) > 0 ) { oval[0]=get_units(oval[i]) } } if( csv == "yes") { # printf("%-8s,",oval[0]) printf("%s,",oval[0]) } else { printf("%-8s",oval[0]) } for(i=1;i<=8;i++) { if( csv == "yes") { # printf("%-8s,",get_number(oval[i])) printf("%s,",get_number(oval[i])) } else { printf("%-8s",get_number(oval[i])) } } printf("\n") } function filter_upto_colon(fname) { # 1 remove start test number if any left gsub(/\$[0-9][0-9]*/,"",str0) # 2 remove tab gsub(/\t/," ",str0) # 3 remove extra spaces gsub(/ */," ",str0) # 4 remove inline comments sub(/\/\*.*\*\//,"",str0) # 5 add a space between < or > and the number gsub(/[<>]/," & ",str0) # 6 add a space between == and the number gsub(/==/,"& ",str0) # 7 remove space at the beginning of the line sub(/^ */,"",str0) # 8 remove double space potentially generated by rule 6 sub(/ */," ",str0) # 9 remove text log functions len=split(str0,ar," ") binfunc=ar[len] sub(/f\(.*$/,"",str0) # # find the string # len=split(str0,ar,"\"") # printf("# %s %d\n",str0,len) if( len > 3 ) { printf("more than 2 \" in test name !! ") exit(1) } # dealing with the test name itself ar[2] if( len == 0 ) return if(length(ar[2]) > 1 ) { ostr="\""ar[2]"\"" if( csv == "yes" ) { # printf("%-40s,",ostr) printf("%s,",ostr) # printing test number printf("%d,",tnum) tnum++ if( fn == "yes" ) { gsub(/,/,"@",fname) printf("%s,","\""fname"\"") gsub(/,/,"@",binfunc) printf("%s,","\""binfunc"\"") } } else { printf("%-32s",ostr) # printing test number printf("%-9d",tnum) tnum++ if( fn == "yes" ) { printf("%-48s",fname) printf("%-40s",binfunc) } } } # !!! missing test !!! mean no limit so skip everything if( str0 ~ /missing limits/) { printf("\n") return } # working on the limits is they are before the test name ar[1] if(length(ar[1]) > 1 ) { sub(/^ */,"",ar[1]) sub(/ *$/,"",ar[1]) # printf("|%s|",ar[1]) gen_lim(ar[1]) return } # working on the limits is they are after the test name ar[2] if(length(ar[3]) > 1 ) { sub(/^ */,"",ar[3]) sub(/ *$/,"",ar[3]) # printf("|%s|",ar[3]) gen_lim(ar[3]) return } printf("\n") } /SEQUENCER/{ countseq++ if( (fn == "yes") || (seqlog == "yes") ) { if(countseq > 1) { printf("## }\n") } printf("## %s {\n",$0) } } # # try to get rid of if(0) # /if\( *0 *\)/{ countzero++ getline while( $0 !~ /}/) { # print "------- ",$0 getline } } /seq /{ # printf("\n") fname="" if( fn == "yes" ) { gsub(/ *, */,",") split($0,tname) fname=tname[2] # sub(/\(.*/,"",fname) # fname=" <> "fname } str0=$0 while( $0 !~ /{/ ) { gsub(/\n/," ") getline if( $0 ~ /}/) { printf("} before { !!\n") exit } str0=str0 $0 count=1 } if(seqlog == "yes") { # printf("\033[38m") print "## "str0 # printf("\033[0m") printf("\n") } do { str0="" do { getline if($1 ~ /\$[0-9][0-9]*/) { sub(/\$/,"",$1) tnum=$1 $1="" } if( $0 ~ /}/) count-- if( count == 0 ) { break } if( $0 ~ /{/) count++ # remove \n gsub(/\n/," ") str0=str0 $0 } while( $0 !~ /;/ ) filter_upto_colon(fname) } while( count > 0 ) if(seqlog == "yes") { # printf("\033[38m") print "##",$0 # printf("\033[0m") } } END{ # close the last SEQUENCER printf("## }\n") printf("# found:\n") printf("# %-3d if(0)\n",countzero) printf("# %-3d SEQUENCER\n",countseq) } '