Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site wgivax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!mcnc!unccvax!wgivax!mo From: mo@wgivax.UUCP Newsgroups: net.unix,net.unix-wizards,net.wanted.sources Subject: Re: cross reference generator (long) Message-ID: <134@wgivax.UUCP> Date: Sat, 25-Jan-86 08:13:21 EST Article-I.D.: wgivax.134 Posted: Sat Jan 25 08:13:21 1986 Date-Received: Sun, 26-Jan-86 17:11:13 EST References: <109@humming.UUCP> Lines: 112 Keywords: does such exist? Xref: watmath net.unix:6938 net.unix-wizards:16543 net.wanted.sources:1787 I have written two shell scripts which work with c source code. The first merely uses sed to list the calls made in a .c file. It should only be used with one file at a time, or embedded in a loop which precedes it with the name of the file being listed. Many improvements could be made to it, but here it is: ======================== list_calls ================================== sed ' /\/\*.*\*\// s/\/\*.*\*\///g /\/\*/,/\*\// d /(/ !d /(.*/ s/[a-zA-Z0-9_.]*[ ]*[(]/\ &\ /g /[ ]/ s/[ ]//g ' $1 | sed ' /^if(/ d /^for(/ d /^while(/ d /^switch(/ d /^(/ d /!(/ d /(/ !d /(/ s/(//g /^$/ d ' | sort -u ====================================================================== the second formats the output of "cflow" (sys V) into two output files. the file "whereis" lists each routine, the name of the source file it is in, and the line it begins at. the file "call_tree" lists the calls each routine makes in a hierarchically indented form. it does deal with recursive routines. ========================= flowchart ================================== cflow $* > /tmp/cflow.$$ fgrep : /tmp/cflow.$$ > /tmp/calls.$$ fgrep = /tmp/cflow.$$ | awk '{printf("%-10s = %-10s %-15s %5s\n",$1,$3,$4,$5)}' > whereis tree /tmp/calls.$$ > call_tree rm -f /tmp/cflow.$$ /tmp/calls.$$ ========================= tree ======================================= #include FILE *file,*fopen(); main(argc,argv) int argc; char **argv; { if((file = fopen(argv[1],"r")) == NULL) { perror(argv[1]); exit(-1); } trace("main",NULL); } static int buffer = 0; static int first = 1; trace(name,called_by) char *name,*called_by; { int i,level; char line[80],caller[40],callee[40]; char format[50]; long offset; fseek(file,0,0); while(fgets(line,80,file) != NULL) { offset = ftell(file); sscanf(line,"%s : %s",caller,callee); if(!strcmp(caller,name)) { level = buffer; if(first) { printf("main : %s\n",callee); first = 0; } else { buffer += strlen(caller); sprintf(format,"%%%ds : %%s\n",buffer); printf(format," ",callee); } /* avoid recursive trap */ if(strcmp(callee,name) && strcmp(called_by,callee)) { trace(callee,caller); } buffer = level; fseek(file,offset,0); } } } ============================================================================ Mike O'Shea decvax!mcnc!unccvax!wgivax!mo