#!/usr/local/bin/gawk -E # -E required for getopt so doesn't conflict with Gawk command line options @include "init.awk" #@include "getopt.awk" @include "library.awk" BEGIN { # print "tcount -- Run test cases. -h for help" Optind = Opterr = 1 while ((c = getopt(ARGC, ARGV, "gzh:n:l:p:")) != -1) { if(C == "p") # -p Use project name. Defaults to what's in project.cfg -> default.id pid = verifypid(Optarg) if(c == "n") { # -n Process only a single name Loadfrom["type"] = "name" Loadfrom["name"] = verifyval(Optarg) } if(c == "l") { # -l Process entire project directory Loadfrom["type"] = "project" Loadfrom["name"] = "" } if(c == "z") { # -z Show "z" entries (ie. known mis-matches) ZFlag = 1 } if(c == "g") { # -g Show entries with a negative final score GFlag = 1 } if(c == "h") { # -h Help usage() exit } } setProject(pid) # library.awk .. load Project[] paths via project.cfg # if -p not given, use default noted in project.cfg if(Loadfrom["type"] ~ /name/) { if(! processsingle(Loadfrom["name"], Project["tccfg"]) ) { print "Unable to find " Loadfrom["name"] " in " Project["tccfg"] exit } } else if(Loadfrom["type"] ~ /project/) { checkexists(Project["tccfg"], "tcount.awk", "exit") checkexists(Project["tcin"], "tcount.awk", "exit") processproject(Project["tccfg"]) } else { print "Option -l or -n required" > "/dev/stderr" exit } } function processsingle(name, filen, str) { re = "^" regesc(name) "$" while ((getline str < filen ) > 0) { split(str,a,"|") if(a[1] ~ re) { process(strip(a[1]),strip(a[2]),strip(a[3])) close(filen) return 1 } } close(filen) return 0 } function processproject(filen, str) { while ((getline str < filen ) > 0) { split(str,a,"|") process(strip(a[1]),strip(a[2]),strip(a[3])) } close(filen) } function process(name, type, ztype, out,a,c,i,b,e,ftype,command) { command = Exe["talgo"] " -d1 -p " Project["id"] " -f \"" name "\"" out = sys2var(command) c = split(out,a,"\n") # Check for missing "Final:" while(i++ < c) { if( a[i] ~ /^Final[:]/ ) e++ } if(! e) { Z++ print Z ". " name " missing Final score. | ./" gensub("-d 1","-d 2","g", gensub(Home,"","g",command) ) return } delete Result # Load "Original list" i=0 while(i++ < c) { if(a[i] ~ /Original list/) { orflag = 1 i = i + 2 } if(orflag == 1) { Result[a[i]] = a[i] orflag = 2 continue } if(orflag == 2) { if(a[i] !~ /@/) { orflag = 0 continue } else { Result[a[i]] = a[i] } } } i=0 while(i++ < c) { if( a[i] ~ /^Final[:]/ ) { e++ split(a[i],b," ") ftype = strip(b[2]) if(type ~ /falsepos/ ) { Z++ print Z ". " b[2] " is a false positive | ./" gensub("-d 1","-d 2","g", gensub(Home,"","g",command) ) break } if(GFlag) { for(o in Result) { split(o,g," = ") if( strip(b[2]) == strip(g[1]) ) { split(g[2],h,"|") if(int(strip(h[1])) < 1) { Z++ print Z ". " name " negative Final score. | ./" gensub("-d 1","-d 2","g", gensub(Home,"","g",command) ) } } } } else { if( type != ftype) { if( entity(type, "type") == "z" && ZFlag) { Z++ print Z ". " b[2] " not equal to " ztype " | ./" gensub("-d 1","-d 2","g", gensub(Home,"","g",command) ) } else if( entity(type, "type") != "z") { Z++ print Z ". " b[2] " not equal to " type " | ./" gensub("-d 1","-d 2","g", gensub(Home,"","g",command) ) } } } } } } # # Return the requested entity from an id string # eg. id = tmpO@Gustave_Jéquier@w@3 # entity = "name" (second field) or "type" (third field) # function entity(id, type, a,c) { c = split(id, a, "@") if(type !~ /^name$|^type$/ || c != 4) { print "tcount.awk: error in function entity(): wrong id or type" exit } if(type ~ /^name$/) return a[2] if(type ~ /^type$/) return a[3] } function usage() { print "Options are:" print " -p Project name. Defaults to what's in project.cfg -> default.id" print " -l Process entire project" print " -n Process only 1 name in project" print " -z Show z entries ie. known mismatches" print "" print "Examples: " print " tcount -n \"Charles Dickens\"" print " tcount -l " print " tcount -p births1870.0001-1000 -l " print "" }