# sqrtree - Version 1.1 (12 January 1998) # Print the call-tree structure of an SQR program # Copyright 1997 by Wayne Ivory - wivory@wsl.com.au # This shell script may be freely copied and distributed as long as the # copyright notice remains intact. if [ $# -ne 1 ] then echo "Usage: $0 sqrfile" exit 1 fi awk ' function printtree(PNAME,INDENT,f) { print INDENT PNAME " (" PROCLINE[PNAME] ")" for (f=1 ; f<=CALLCOUNT[PNAME] ; f++) {printf("%-6s",CALLLINE[PNAME,f]) ; printtree(CALLEDPROC[PNAME,f],INDENT " ")} } BEGIN{FNAME=FILENAME ; while (i=index(FNAME,"/")) FNAME=substr(FNAME,i+1) ; print FNAME ; print " "} { if ($1 == "begin-procedure" || $1 == "BEGIN-PROCEDURE" || $1 == "Begin-Procedure") { POS=match($2,"[^-_A-Za-z0-9]") if (POS == 0) POS=length($2)+1 PROCEDURE=substr($2,1,POS-1) PROCLINE[PROCEDURE]=NR } i=match($0,"[Dd][Oo] ") if (i > 0 && substr($1,1,1) != "!" && substr($1,1,6) != "#debug") { j=match(substr($0,i+3),"[^ ]") i=i+j+2 POS=match(substr($0,i),"[^-_A-Za-z0-9]") if (POS == 0) POS=length($0)-i+2 CALLCOUNT[PROCEDURE]++ CALLEDPROC[PROCEDURE,CALLCOUNT[PROCEDURE]]=substr($0,i,POS-1) CALLLINE[PROCEDURE,CALLCOUNT[PROCEDURE]]=NR } } END{for (i=1 ; i<=CALLCOUNT[""] ; i++) {printf("%-6s",CALLLINE["",i]) ; printtree(CALLEDPROC["",i],"")}}' $1