| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <string.h> |
|---|
| 4 | #include <dirent.h> |
|---|
| 5 | #include "sym.h" |
|---|
| 6 | |
|---|
| 7 | #define DBDIR "tools/code_dbase" |
|---|
| 8 | |
|---|
| 9 | #define COMPARE(A,B) ( ! strncmp ( A , B , strlen( B ) ) ) |
|---|
| 10 | #define COMPARE2(A,B) ( ! strcmp ( A , B ) ) |
|---|
| 11 | #define INLINELEN (4*8192) |
|---|
| 12 | #define VARLEN 256 |
|---|
| 13 | #define MAXRECORDS 8192 |
|---|
| 14 | |
|---|
| 15 | int recno = 1 ; |
|---|
| 16 | char outbuf[MAXRECORDS][VARLEN] ; |
|---|
| 17 | |
|---|
| 18 | main( int argc , char * argv[] ) |
|---|
| 19 | { |
|---|
| 20 | DIR *dir ; |
|---|
| 21 | char root[VARLEN] ; |
|---|
| 22 | int cut = 99 ; |
|---|
| 23 | int nentries ; |
|---|
| 24 | int i ; |
|---|
| 25 | |
|---|
| 26 | if (( dir = opendir ( DBDIR )) == NULL ) { |
|---|
| 27 | fprintf(stderr, "Must be in top level WRF directory\n") ; exit(2) ; |
|---|
| 28 | } closedir( dir ) ; |
|---|
| 29 | if ( argc < 2 ) { |
|---|
| 30 | fprintf(stderr,"usage: callgraph root\n") ; |
|---|
| 31 | } |
|---|
| 32 | sym_init() ; |
|---|
| 33 | strcpy( root, argv[1] ) ; |
|---|
| 34 | if ( argv[2] ) { |
|---|
| 35 | cut = atoi( argv[2] ) ; |
|---|
| 36 | } |
|---|
| 37 | upper_case_str( root ) ; |
|---|
| 38 | lower_case_str( root ) ; |
|---|
| 39 | callgraph( root , 0 , cut ) ; |
|---|
| 40 | sprintf(outbuf[0],"var db = new makeArray(%d)\n",recno-1 ) ; |
|---|
| 41 | for ( i = 0 ; i <= recno ; i++ ) |
|---|
| 42 | printf("%s",outbuf[i]) ; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | callgraph ( char * root , int indent , int cut ) |
|---|
| 46 | { |
|---|
| 47 | FILE * CALLEES ; |
|---|
| 48 | char fname[VARLEN] ; |
|---|
| 49 | char * p, * q, *q1, prev ; |
|---|
| 50 | char inln[INLINELEN] ; |
|---|
| 51 | char t[12][VARLEN] ; |
|---|
| 52 | int i ; |
|---|
| 53 | char * doescall ; |
|---|
| 54 | char tempbuf[VARLEN] ; |
|---|
| 55 | int thisrec ; |
|---|
| 56 | |
|---|
| 57 | sprintf(fname,"%s/calls", DBDIR ) ; |
|---|
| 58 | /* skip some routines */ |
|---|
| 59 | if ( |
|---|
| 60 | COMPARE( root , "add_msg" ) || COMPARE( root , "reset_msgs" ) || |
|---|
| 61 | COMPARE( t[2] , "get_" ) || COMPARE( t[2] , "set_" ) || |
|---|
| 62 | COMPARE( t[2] , "mpi_" ) || COMPARE( t[2] , "ext_" ) || |
|---|
| 63 | COMPARE( root , "stencil" ) || COMPARE( root , "wrf_debug" ) || |
|---|
| 64 | COMPARE( root , "wrf_message" ) || COMPARE( root , "wrf_error" ) |
|---|
| 65 | ) return ; |
|---|
| 66 | thisrec = recno++ ; |
|---|
| 67 | #if 0 |
|---|
| 68 | sprintf(tempbuf,"db[%4d] = new dbRecord( %%s, \"%s\", \"../../WRFV2/tools/code_dbase/%s.html\", %d )\n", |
|---|
| 69 | thisrec, root, root, indent ) ; |
|---|
| 70 | #else |
|---|
| 71 | sprintf(tempbuf,"db[%4d] = new dbRecord( %%s, \"%s\", \"%s.html\", %d )\n", |
|---|
| 72 | thisrec, root, root, indent ) ; |
|---|
| 73 | #endif |
|---|
| 74 | |
|---|
| 75 | if (( CALLEES = fopen( fname , "r" )) == NULL ) return ; |
|---|
| 76 | |
|---|
| 77 | doescall = "false" ; |
|---|
| 78 | while ( fgets( inln, INLINELEN, CALLEES ) != NULL ) { |
|---|
| 79 | remove_nl ( inln ) ; |
|---|
| 80 | /* find first non space */ |
|---|
| 81 | for ( p = inln ; *p ; p++ ) { if ( *p != ' ' ) break ; } |
|---|
| 82 | /* change multiple spaces to single space */ |
|---|
| 83 | for ( q = p, q1 = q , prev = *p ; *q ; q++ ) |
|---|
| 84 | { if ( prev == ' ' && *q == ' ' ) { continue ; } else { prev = *q ; *q1++ = *q ; } } |
|---|
| 85 | strcpy( inln, p ) ; |
|---|
| 86 | for ( i = 0 ; i < 11 ; i++ ) { |
|---|
| 87 | strcpy( t[i] , "" ) ; |
|---|
| 88 | get_token_n( inln, " ", i , t[i] ) ; remove_nl(t[i]) ; lower_case_str( t[i] ) ; |
|---|
| 89 | } |
|---|
| 90 | if ( COMPARE2( t[0] , root ) && COMPARE2( t[1] , "calls" ) && ! COMPARE2( t[0] , t[2] ) && |
|---|
| 91 | ! ( |
|---|
| 92 | COMPARE( root , "add_msg" ) || COMPARE( root , "reset_msgs" ) || |
|---|
| 93 | COMPARE( t[2] , "get_" ) || COMPARE( t[2] , "set_" ) || |
|---|
| 94 | COMPARE( t[2] , "mpi_" ) || COMPARE( t[2] , "ext_" ) || |
|---|
| 95 | COMPARE( root , "stencil" ) || COMPARE( root , "wrf_debug" ) || |
|---|
| 96 | COMPARE( root , "wrf_message" ) || COMPARE( root , "wrf_error" ) |
|---|
| 97 | )) { |
|---|
| 98 | if ( indent <= cut && ( ! sym_get ( t[2] ) ) ) { |
|---|
| 99 | sym_add( t[2] ) ; |
|---|
| 100 | doescall = "true" ; |
|---|
| 101 | callgraph ( t[2] , indent + 1, cut ) ; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | sprintf(outbuf[thisrec],tempbuf,doescall) ; |
|---|
| 106 | fclose( CALLEES ) ; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | #if 0 |
|---|
| 110 | /*******************************************************************/ |
|---|
| 111 | |
|---|
| 112 | /* open the file of calls and count them */ |
|---|
| 113 | count_entries ( char * root , int * nentries ) |
|---|
| 114 | { |
|---|
| 115 | FILE * CALLEES ; |
|---|
| 116 | char fname[VARLEN] ; |
|---|
| 117 | char inln[INLINELEN] ; |
|---|
| 118 | char * p, *q, *q1, prev ; |
|---|
| 119 | char t[12][VARLEN] ; |
|---|
| 120 | int i ; |
|---|
| 121 | |
|---|
| 122 | sprintf(fname,"%s/calls", DBDIR ) ; |
|---|
| 123 | if (( CALLEES = fopen( fname , "r" )) == NULL ) return ; |
|---|
| 124 | *nentries = 0 ; |
|---|
| 125 | while ( fgets( inln, INLINELEN, CALLEES ) != NULL ) { |
|---|
| 126 | remove_nl ( inln ) ; |
|---|
| 127 | /* find first non space */ |
|---|
| 128 | for ( p = inln ; *p ; p++ ) { if ( *p != ' ' ) break ; } |
|---|
| 129 | /* change multiple spaces to single space */ |
|---|
| 130 | for ( q = p, q1 = q , prev = *p ; *q ; q++ ) |
|---|
| 131 | { if ( prev == ' ' && *q == ' ' ) { continue ; } else { prev = *q ; *q1++ = *q ; } } |
|---|
| 132 | strcpy( inln, p ) ; |
|---|
| 133 | for ( i = 0 ; i < 11 ; i++ ) { |
|---|
| 134 | strcpy( t[i] , "" ) ; |
|---|
| 135 | get_token_n( inln, " ", i , t[i] ) ; remove_nl(t[i]) ; lower_case_str( t[i] ) ; |
|---|
| 136 | } |
|---|
| 137 | if ( COMPARE2( t[0] , root ) && COMPARE2( t[1] , "calls" ) && ! COMPARE2( t[0] , t[2] ) && |
|---|
| 138 | ! ( |
|---|
| 139 | COMPARE( root , "add_msg" ) || COMPARE( root , "reset_msgs" ) || |
|---|
| 140 | COMPARE( t[2] , "get_" ) || COMPARE( t[2] , "set_" ) || |
|---|
| 141 | COMPARE( t[2] , "mpi_" ) || COMPARE( t[2] , "ext_" ) || |
|---|
| 142 | COMPARE( root , "stencil" ) || COMPARE( root , "wrf_debug" ) || |
|---|
| 143 | COMPARE( root , "wrf_message" ) || COMPARE( root , "wrf_error" ) |
|---|
| 144 | )) { |
|---|
| 145 | sym_add( t[2] ) ; |
|---|
| 146 | (*nentries)++ ; |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | fclose( CALLEES ) ; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | /* old version before adding javascript calltree */ |
|---|
| 155 | main( int argc , char * argv[] ) |
|---|
| 156 | { |
|---|
| 157 | DIR *dir ; |
|---|
| 158 | char root[VARLEN] ; |
|---|
| 159 | int cut = 99 ; |
|---|
| 160 | |
|---|
| 161 | if (( dir = opendir ( DBDIR )) == NULL ) { |
|---|
| 162 | fprintf(stderr, "Must be in top level WRF directory\n") ; exit(2) ; |
|---|
| 163 | } closedir( dir ) ; |
|---|
| 164 | if ( argc < 2 ) { |
|---|
| 165 | fprintf(stderr,"usage: callgraph root\n") ; |
|---|
| 166 | } |
|---|
| 167 | sym_init() ; |
|---|
| 168 | strcpy( root, argv[1] ) ; |
|---|
| 169 | if ( argv[2] ) { |
|---|
| 170 | cut = atoi( argv[2] ) ; |
|---|
| 171 | } |
|---|
| 172 | upper_case_str( root ) ; |
|---|
| 173 | printf("<html>\n" ) ; |
|---|
| 174 | printf("<title> %s Call Tree </title>\n", root ) ; |
|---|
| 175 | printf("<body>\n" ) ; |
|---|
| 176 | printf("<h1> %s Call Tree </h1>\n", root ) ; |
|---|
| 177 | printf("<p><a href=index.html>[1] </a> " ) ; |
|---|
| 178 | printf("<a href=ct2.html>[2] </a> " ) ; |
|---|
| 179 | printf("<a href=ct3.html>[3] </a> " ) ; |
|---|
| 180 | printf("<a href=ct4.html>[4] </a> " ) ; |
|---|
| 181 | printf("<a href=ct5.html>[5] </a> " ) ; |
|---|
| 182 | printf("<a href=ctall.html>[all] </a><p>\n" ) ; |
|---|
| 183 | lower_case_str( root ) ; |
|---|
| 184 | callgraph( root , 0 , cut ) ; |
|---|
| 185 | printf("</body>\n" ) ; |
|---|
| 186 | printf("</html>\n" ) ; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | callgraph ( char * root , int indent , int cut ) |
|---|
| 190 | { |
|---|
| 191 | FILE * CALLEES ; |
|---|
| 192 | char fname[VARLEN] ; |
|---|
| 193 | char * p, * q, *q1, prev ; |
|---|
| 194 | char inln[INLINELEN] ; |
|---|
| 195 | char t[12][VARLEN] ; |
|---|
| 196 | int i ; |
|---|
| 197 | int recno = 1 ; |
|---|
| 198 | |
|---|
| 199 | sprintf(fname,"%s/calls", DBDIR ) ; |
|---|
| 200 | if (( CALLEES = fopen( fname , "r" )) == NULL ) return ; |
|---|
| 201 | if ( |
|---|
| 202 | COMPARE( root , "add_msg" ) || COMPARE( root , "reset_msgs" ) || |
|---|
| 203 | COMPARE( t[2] , "get_" ) || COMPARE( t[2] , "set_" ) || |
|---|
| 204 | COMPARE( t[2] , "mpi_" ) || COMPARE( t[2] , "ext_" ) || |
|---|
| 205 | COMPARE( root , "stencil" ) || COMPARE( root , "wrf_debug" ) || |
|---|
| 206 | COMPARE( root , "wrf_message" ) || COMPARE( root , "wrf_error" ) |
|---|
| 207 | ) return ; |
|---|
| 208 | for ( i = 0 ; i < indent ; i++ ) printf(" !       ") ; |
|---|
| 209 | printf(" <a href=\"%s.html\"> %s </a><br>\n", root, root ) ; |
|---|
| 210 | |
|---|
| 211 | while ( fgets( inln, INLINELEN, CALLEES ) != NULL ) { |
|---|
| 212 | remove_nl ( inln ) ; |
|---|
| 213 | /* find first non space */ |
|---|
| 214 | for ( p = inln ; *p ; p++ ) { if ( *p != ' ' ) break ; } |
|---|
| 215 | /* change multiple spaces to single space */ |
|---|
| 216 | for ( q = p, q1 = q , prev = *p ; *q ; q++ ) |
|---|
| 217 | { if ( prev == ' ' && *q == ' ' ) { continue ; } else { prev = *q ; *q1++ = *q ; } } |
|---|
| 218 | strcpy( inln, p ) ; |
|---|
| 219 | for ( i = 0 ; i < 11 ; i++ ) { |
|---|
| 220 | strcpy( t[i] , "" ) ; |
|---|
| 221 | get_token_n( inln, " ", i , t[i] ) ; remove_nl(t[i]) ; lower_case_str( t[i] ) ; |
|---|
| 222 | } |
|---|
| 223 | if ( COMPARE2( t[0] , root ) && COMPARE2( t[1] , "calls" ) && ! COMPARE2( t[0] , t[2] ) && |
|---|
| 224 | ! ( |
|---|
| 225 | COMPARE( root , "add_msg" ) || COMPARE( root , "reset_msgs" ) || |
|---|
| 226 | COMPARE( t[2] , "get_" ) || COMPARE( t[2] , "set_" ) || |
|---|
| 227 | COMPARE( t[2] , "mpi_" ) || COMPARE( t[2] , "ext_" ) || |
|---|
| 228 | COMPARE( root , "stencil" ) || COMPARE( root , "wrf_debug" ) || |
|---|
| 229 | COMPARE( root , "wrf_message" ) || COMPARE( root , "wrf_error" ) |
|---|
| 230 | )) { |
|---|
| 231 | if ( indent <= cut && ( ! sym_get ( t[2] ) ) ) { |
|---|
| 232 | sym_add( t[2] ) ; |
|---|
| 233 | callgraph ( t[2] , indent + 1, cut ) ; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | } |
|---|
| 237 | } |
|---|
| 238 | fclose( CALLEES ) ; |
|---|
| 239 | } |
|---|
| 240 | ##################### |
|---|
| 241 | # original old PERL code kept just for reference |
|---|
| 242 | |
|---|
| 243 | $dbdir = "tools/code_dbase" ; |
|---|
| 244 | |
|---|
| 245 | if ( ! opendir( TOOLDIR, "tools") ) { |
|---|
| 246 | print "\nMust be in top level WRF directory\n" ; |
|---|
| 247 | exit ; |
|---|
| 248 | } |
|---|
| 249 | closedir TOOLDIR ; |
|---|
| 250 | |
|---|
| 251 | if ( ( scalar @ARGV < 1 ) ) { |
|---|
| 252 | print "usage: callgraph root\n" ; |
|---|
| 253 | exit ; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | $rout1 = lc $ARGV[0] ; |
|---|
| 257 | $rout = $rout1 ; |
|---|
| 258 | |
|---|
| 259 | $routfile = $dbdir."/".$rout ; |
|---|
| 260 | |
|---|
| 261 | if ( $indent == 0 ) { |
|---|
| 262 | print "<html>\n" ; |
|---|
| 263 | print "<title> ",uc $rout," Call Tree </title>\n" ; |
|---|
| 264 | print "<body>\n" ; |
|---|
| 265 | print "<h1> ",uc $rout," Call Tree </h1>\n" ; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | $indent = 0 ; |
|---|
| 269 | |
|---|
| 270 | $first = 1 ; |
|---|
| 271 | |
|---|
| 272 | open CALLEES, "< $dbdir/calls" or die " cannot open $dbdir/calls " ; |
|---|
| 273 | while ( <CALLEES> ) { |
|---|
| 274 | @t = split ' ' ; |
|---|
| 275 | if ( $t[0] eq lc $rout && $t[1] eq "calls" && ! ( $t[2] eq $t[0] ) && ! ($t[2] =~ add_msg) && !($t[2] =~ reset_msgs ) && ! ($t[2] =~ stencil) && !($t[2] =~ wrf_debug) ) { |
|---|
| 276 | if ( $first == 1 ) { |
|---|
| 277 | for ( $i = 0 ; $i < $indent ; $i++ ) { print "|   " ; } |
|---|
| 278 | print "<a href=\"$rout\.html\"> $rout </a><br>\n" ; |
|---|
| 279 | $first = 0 ; |
|---|
| 280 | } |
|---|
| 281 | $i2 = $indent + 1 ; |
|---|
| 282 | if ( $i2 < 7 && (! $prune{$t[2]} ) ) { |
|---|
| 283 | $prune{$t[2]} = "y" ; |
|---|
| 284 | $opstr = "tools/callgraph $t[2] $i2 |" ; |
|---|
| 285 | ####### RECURSE ########## |
|---|
| 286 | open D, $opstr ; |
|---|
| 287 | while ( <D> ) { print ; } |
|---|
| 288 | close D ; |
|---|
| 289 | } |
|---|
| 290 | } |
|---|
| 291 | } |
|---|
| 292 | if ( $indent == 0 ) { |
|---|
| 293 | print "</body>\n" ; |
|---|
| 294 | print "</html>\n" ; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | exit |
|---|
| 298 | #endif |
|---|
| 299 | |
|---|