1# pmccabe2html - AWK script to convert pmccabe output to html -*- awk -*- 2 3# Copyright (C) 2007-2018 Free Software Foundation, Inc. 4 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18# Written by Jose E. Marchesi <jemarch@gnu.org>. 19# Adapted for gnulib by Simon Josefsson <simon@josefsson.org>. 20# Added support for C++ by Giuseppe Scrivano <gscrivano@gnu.org>. 21 22# Typical Invocation is from a Makefile.am: 23# 24# CYCLO_SOURCES = ${top_srcdir}/src/*.[ch] 25# 26# cyclo-$(PACKAGE).html: $(CYCLO_SOURCES) 27# $(PMCCABE) $(CYCLO_SOURCES) \ 28# | sort -nr \ 29# | $(AWK) -f ${top_srcdir}/build-aux/pmccabe2html \ 30# -v lang=html -v name="$(PACKAGE_NAME)" \ 31# -v vcurl="https://git.savannah.gnu.org/gitweb/?p=$(PACKAGE).git;a=blob;f=%FILENAME%;hb=HEAD" \ 32# -v url="https://www.gnu.org/software/$(PACKAGE)/" \ 33# -v css=${top_srcdir}/build-aux/pmccabe.css \ 34# -v cut_dir=${top_srcdir}/ \ 35# > $@-tmp 36# mv $@-tmp $@ 37# 38# The variables available are: 39# lang output language, either 'html' or 'wiki' 40# name project name 41# url link to project's home page 42# vcurl URL to version controlled source code browser, 43# a %FILENAME% in the string is replaced with the relative 44# source filename 45# css CSS stylesheet filename, included verbatim in HTML output 46# css_url link to CSS stylesheet, an URL 47 48# Prologue & configuration 49BEGIN { 50 # Portable lookup of present time. 51 "date +%s" | getline epoch_time 52 "date" | getline chronos_time 53 54 section_global_stats_p = 1 55 section_function_cyclo_p = 1 56 57 # "html" or "wiki" 58 package_name = name 59 output_lang = lang 60 61 # General Options 62 cyclo_simple_max = 10 63 cyclo_moderate_max = 20 64 cyclo_high_max = 50 65 source_file_link_tmpl = vcurl 66 67 # HTML options 68 if (url != "") 69 { 70 html_prolog = "<a href=\"" url "\">Back to " package_name " Homepage</a><br/><br/>" 71 } 72 html_epilog = "<hr color=\"black\" size=\"2\"/> \ 73Copyright (c) 2007, 2008 Free Software Foundation, Inc." 74 html_doctype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \ 75\"http://www.w3.org/TR/html401/loose.dtd\">" 76 html_comment = "<!-- Generated by gnulib's pmccabe2html at " epoch_time " -->" 77 html_title = "Cyclomatic Complexity report for " package_name 78 79 # Wiki options 80 wiki_prolog = "{{Note|This page has been automatically generated}}" 81 wiki_epilog = "" 82 83 # Internal variables 84 nfuncs = 0; 85} 86 87# Functions 88 89function build_stats() 90{ 91 # Maximum modified cyclo 92 for (fcn in mcyclo) 93 { 94 num_of_functions++ 95 if (mcyclo[fcn] > max_mcyclo) 96 { 97 max_mcyclo = mcyclo[fcn] 98 } 99 100 if (mcyclo[fcn] > cyclo_high_max) 101 { 102 num_of_untestable_functions++ 103 } 104 else if (mcyclo[fcn] > cyclo_moderate_max) 105 { 106 num_of_high_functions++ 107 } 108 else if (mcyclo[fcn] > cyclo_simple_max) 109 { 110 num_of_moderate_functions++ 111 } 112 else 113 { 114 num_of_simple_functions++ 115 } 116 } 117} 118 119function html_fnc_table_complete (caption) 120{ 121 html_fnc_table(caption, 1, 1, 0, 1, 1, 0, 1) 122} 123 124function html_fnc_table_abbrev (caption) 125{ 126 html_fnc_table(caption, 1, 1, 0, 0, 1, 0, 0) 127} 128 129 130function html_fnc_table (caption, 131 fname_p, 132 mcyclo_p, 133 cyclo_p, 134 num_statements_p, 135 num_lines_p, 136 first_line_p, 137 file_p) 138{ 139 print "<table width=\"90%\" class=\"function_table\" cellpadding=\"0\" cellspacing=\"0\">" 140 if (caption != "") 141 { 142 print "<caption class=\"function_table_caption\">" caption "</caption>" 143 } 144 html_fnc_header(fname_p, 145 mcyclo_p, 146 cyclo_p, 147 num_statements_p, 148 num_lines_p, 149 first_line_p, 150 file_p) 151 for (nfnc = 1; nfnc <= nfuncs; nfnc++) 152 { 153 html_fnc(nfnc, 154 fname_p, 155 mcyclo_p, 156 cyclo_p, 157 num_statements_p, 158 num_lines_p, 159 first_line_p, 160 file_p) 161 } 162 print "</table>" 163} 164 165function html_header () 166{ 167 print html_doctype 168 print "<html>" 169 print html_comment 170 print "<head>" 171 print "<title>" html_title "</title>" 172 print "" 173 print "<meta name=\"description\" content=\"" html_title "\">" 174 print "<meta name=\"keywords\" content=\"" html_title "\">" 175 print "<meta name=\"resource-type\" content=\"document\">" 176 print "<meta name=\"distribution\" content=\"global\">" 177 print "<meta name=\"Generator\" content=\"pmccabe2html\">" 178 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" 179 print "<script language=\"javascript\" type=\"text/javascript\">" 180 print "function show_hide(idCapa, idButton, fuerzaVisibilidad)\ 181{\ 182 var button = document.getElementById(idButton);\ 183 var capa = document.getElementById(idCapa);\ 184 if (capa)\ 185 {\ 186 if (fuerzaVisibilidad && fuerzaVisibilidad!=\"\") {\ 187 if (fuerzaVisibilidad==\"visible\") capa.style.display=\"\";\ 188 else capa.style.display=\"none\";\ 189 }\ 190 else\ 191 {\ 192 if (capa.style.display == \"none\") {\ 193 capa.style.display = \"\";\ 194 button.innerHTML = \"↑\";\ 195 } else {\ 196 capa.style.display = \"none\";\ 197 button.innerHTML = \"↓\"; \ 198 }\ 199 }\ 200 }\ 201}" 202 print "</script>" 203 204 205 if (css_url != "") 206 { 207 print "<link rel=\"stylesheet\" href=\"" css_url "\" type =\"text/css\" media=\"screen\"/>" 208 } 209 if (css != "") 210 { 211 print "<style type =\"text/css\" media=\"screen\">" 212 print "<!--" 213 while ((getline cssline < css) > 0) 214 { 215 print cssline 216 } 217 print "-->" 218 print "</style>" 219 close(css) 220 } 221 print "</head>" 222 print "<body lang=\"en\" bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000FF\" \ 223vlink=\"#800080\" alink=\"#FF0000\">" 224} 225 226function html_footer () 227{ 228 print "</body>" 229 print "</html>" 230} 231 232function html_fnc_header (fname_p, 233 mcyclo_p, 234 cyclo_p, 235 num_statements_p, 236 num_lines_p, 237 first_line_p, 238 file_p) 239{ 240 print "<tr class=\"function_table_header\">" 241 if (fname_p) 242 { 243 # Function name 244 print "<td class=\"function_table_header_entry\">" 245 print "" 246 print "</td>" 247 248 print "<td class=\"function_table_header_entry\">" 249 print "Function Name" 250 print "</td>" 251 } 252 if (mcyclo_p) 253 { 254 # Modified cyclo 255 print "<td class=\"function_table_header_entry\">" 256 print "Modified Cyclo" 257 print "</td>" 258 } 259 if (cyclo_p) 260 { 261 # Cyclo 262 print "<td class=\"function_table_header_entry\">" 263 print "Cyclomatic" 264 print "<br/>" 265 print "Complexity" 266 print "</td>" 267 } 268 if (num_statements_p) 269 { 270 print "<td class=\"function_table_header_entry\">" 271 print "Number of" 272 print "<br/>" 273 print "Statements" 274 print "</td>" 275 } 276 if (num_lines_p) 277 { 278 print "<td class=\"function_table_header_entry\">" 279 print "Number of" 280 print "<br/>" 281 print "Lines" 282 print "</td>" 283 } 284 if (first_line_p) 285 { 286 print "<td class=\"function_table_header_entry\">" 287 print "First Line" 288 print "</td>" 289 } 290 if (file_p) 291 { 292 print "<td class=\"function_table_header_entry\">" 293 print "Source File" 294 print "</td>" 295 296 } 297 print "</tr>" 298} 299 300function html_fnc (nfun, 301 fname_p, 302 mcyclo_p, 303 cyclo_p, 304 num_statements_p, 305 num_lines_p, 306 first_line_p, 307 file_p) 308{ 309 fname = fnames[nfun] 310 311 # Function name 312 trclass = "function_entry_simple" 313 if (mcyclo[nfun] > cyclo_high_max) 314 { 315 trclass="function_entry_untestable" 316 } 317 else if (mcyclo[nfun] > cyclo_moderate_max) 318 { 319 trclass="function_entry_high" 320 } 321 else if (mcyclo[nfun] > cyclo_simple_max) 322 { 323 trclass="function_entry_moderate" 324 } 325 326 print "<tr class=\"" trclass "\">" 327 if (fname_p) 328 { 329 print "<td class=\"function_entry_filename\">" 330 if (file_p && mcyclo[nfun] > cyclo_simple_max) 331 { 332 print "<a href=\"javascript:void(0);\" title=\"show/hide function source\" onClick=\"javascript:show_hide('" fname "_src', '" fname "_button')\">\ 333<span id=\"" fname "_button\">↓</span></a>" 334 } 335 else 336 { 337 print " " 338 } 339 print "</td>" 340 341 print "<td class=\"function_entry_name\">" 342 print fname 343 print "</td>" 344 } 345 if (mcyclo_p) 346 { 347 # Modified cyclo 348 print "<td class=\"function_entry_cyclo\">" 349 print mcyclo[nfun] 350 print "</td>" 351 } 352 if (cyclo_p) 353 { 354 # Cyclo 355 print "<td class=\"function_entry_cyclo\">" 356 print cyclo[nfun] 357 print "</td>" 358 } 359 if (num_statements_p) 360 { 361 # Number of statements 362 print "<td class=\"function_entry_number\">" 363 print num_statements[nfun] 364 print "</td>" 365 } 366 if (num_lines_p) 367 { 368 # Number of lines 369 print "<td class=\"function_entry_number\">" 370 print num_lines[nfun] 371 print "</td>" 372 } 373 if (first_line_p) 374 { 375 # First line 376 print "<td class=\"function_entry_number\">" 377 print first_line[nfun] 378 print "</td>" 379 } 380 if (file_p) 381 { 382 href = "" 383 if (source_file_link_tmpl != "") 384 { 385 # Get href target 386 href = source_file_link_tmpl 387 sub(/%FILENAME%/, file[nfun], href) 388 } 389 390 # Source file 391 print "<td class=\"function_entry_filename\">" 392 if (href != "") 393 { 394 print "<a href=\"" href "\">" file[nfun] "</a>" 395 } 396 else 397 { 398 print file[nfun] 399 } 400 401 print "</td>" 402 403 404 print "</tr>" 405 406 if (mcyclo[nfun] > cyclo_simple_max) 407 { 408 print "<tr>" 409 410 num_columns = 1; 411 if (fname_p) { num_columns++ } 412 if (mcyclo_p) { num_columns++ } 413 if (cyclo_p) { num_columns++ } 414 if (num_statements_p) { num_columns++ } 415 if (num_lines_p) { num_columns++ } 416 if (first_line_p) { num_columns++ } 417 if (file_p) { num_columns++ } 418 419 print "<td colspan=\"" num_columns "\" height=\"0\">" 420 print "<div id=\"" fname "_src\" class=\"function_src\" style=\"position: relative; display: none;\">" 421 print "<pre class=\"function_src\">" 422 423 while ((getline codeline < (fname nfun "_fn.txt")) > 0) 424 { 425 gsub(/&/, "\\&", codeline) # Must come first. 426 gsub(/</, "\\<", codeline) 427 gsub(/>/, "\\>", codeline) 428 429 print codeline 430 } 431 close(fname nfun "_fn.txt") 432 system("rm " "'" fname "'" nfun "_fn.txt") 433 print "</pre>" 434 print "</div>" 435 print "</td>" 436 print "</tr>" 437 } 438 439 } 440} 441 442function html_global_stats () 443{ 444 print "<div class=\"section_title\">Summary</div>" 445 446 print "<table class=\"summary_table\">" 447 # Total number of functions 448 print "<tr>" 449 print "<td class=\"summary_header_entry\">" 450 print "Total number of functions" 451 print "</td>" 452 print "<td class=\"summary_number_entry\">" 453 print num_of_functions 454 print "</td>" 455 print "</tr>" 456 # Number of simple functions 457 print "<tr>" 458 print "<td class=\"summary_header_entry\">" 459 print "Number of low risk functions" 460 print "</td>" 461 print "<td class=\"summary_number_entry\">" 462 print num_of_simple_functions 463 print "</td>" 464 print "</tr>" 465 # Number of moderate functions 466 print "<tr>" 467 print "<td class=\"summary_header_entry\">" 468 print "Number of moderate risk functions" 469 print "</td>" 470 print "<td class=\"summary_number_entry\">" 471 print num_of_moderate_functions 472 print "</td>" 473 print "</tr>" 474 # Number of high functions 475 print "<tr>" 476 print "<td class=\"summary_header_entry\">" 477 print "Number of high risk functions" 478 print "</td>" 479 print "<td class=\"summary_number_entry\">" 480 print num_of_high_functions 481 print "</td>" 482 print "</tr>" 483 # Number of untestable functions 484 print "<tr>" 485 print "<td class=\"summary_header_entry\">" 486 print "Number of untestable functions" 487 print "</td>" 488 print "<td class=\"summary_number_entry\">" 489 print num_of_untestable_functions 490 print "</td>" 491 print "</tr>" 492 print "</table>" 493 print "<br/>" 494} 495 496function html_function_cyclo () 497{ 498 print "<div class=\"section_title\">Details for all functions</div>" 499 500 print "<table class=\"ranges_table\">" 501 print "<tr>" 502 print "<td class=\"ranges_header_entry\">" 503 print " " 504 print "</td>" 505 print "<td class=\"ranges_header_entry\">" 506 print "Cyclomatic Complexity" 507 print "</td>" 508 print "<td class=\"ranges_header_entry\">" 509 print "Risk Evaluation" 510 print "</td>" 511 print "</tr>" 512 # Simple 513 print "<tr>" 514 print "<td class=\"ranges_entry_simple\">" 515 print " " 516 print "</td>" 517 print "<td class=\"ranges_entry\">" 518 print "0 - " cyclo_simple_max 519 print "</td>" 520 print "<td class=\"ranges_entry\">" 521 print "Simple module, without much risk" 522 print "</td>" 523 print "</tr>" 524 # Moderate 525 print "<tr>" 526 print "<td class=\"ranges_entry_moderate\">" 527 print " " 528 print "</td>" 529 print "<td class=\"ranges_entry\">" 530 print cyclo_simple_max + 1 " - " cyclo_moderate_max 531 print "</td>" 532 print "<td class=\"ranges_entry\">" 533 print "More complex module, moderate risk" 534 print "</td>" 535 print "</tr>" 536 # High 537 print "<tr>" 538 print "<td class=\"ranges_entry_high\">" 539 print " " 540 print "</td>" 541 print "<td class=\"ranges_entry\">" 542 print cyclo_moderate_max + 1 " - " cyclo_high_max 543 print "</td>" 544 print "<td class=\"ranges_entry\">" 545 print "Complex module, high risk" 546 print "</td>" 547 print "</tr>" 548 # Untestable 549 print "<tr>" 550 print "<td class=\"ranges_entry_untestable\">" 551 print " " 552 print "</td>" 553 print "<td class=\"ranges_entry\">" 554 print "greater than " cyclo_high_max 555 print "</td>" 556 print "<td class=\"ranges_entry\">" 557 print "Untestable module, very high risk" 558 print "</td>" 559 print "</tr>" 560 print "</table>" 561 print "<br/>" 562 html_fnc_table_complete("") 563} 564 565function wiki_global_stats () 566{ 567 print "{| class=\"cyclo_summary_table\"" 568 # Total number of functions 569 print "|-" 570 print "| class=\"cyclo_summary_header_entry\" | Total number of functions" 571 print "| class=\"cyclo_summary_number_entry\" |" num_of_functions 572 # Number of simple functions 573 print "|-" 574 print "| class=\"cyclo_summary_header_entry\" | Number of low risk functions" 575 print "| class=\"cyclo_summary_number_entry\" |" num_of_simple_functions 576 # Number of moderate functions 577 print "|-" 578 print "| class=\"cyclo_summary_header_entry\" | Number of moderate risk functions" 579 print "| class=\"cyclo_summary_number_entry\" |" num_of_moderate_functions 580 # Number of high functions 581 print "|-" 582 print "| class=\"cyclo_summary_header_entry\" | Number of high risk functions" 583 print "| class=\"cyclo_summary_number_entry\" |" num_of_high_functions 584 # Number of untestable functions 585 print "|-" 586 print "| class=\"cyclo_summary_header_entry\" | Number of untestable functions" 587 print "| class=\"cyclo_summary_number_entry\" |" num_of_untestable_functions 588 print "|}" 589} 590 591function wiki_function_cyclo () 592{ 593 print "==Details for all functions==" 594 595 print "Used ranges:" 596 597 print "{| class =\"cyclo_ranges_table\"" 598 print "|-" 599 print "| class=\"cyclo_ranges_header_entry\" | " 600 print "| class=\"cyclo_ranges_header_entry\" | Cyclomatic Complexity" 601 print "| class=\"cyclo_ranges_header_entry\" | Risk Evaluation" 602 # Simple 603 print "|-" 604 print "| class=\"cyclo_ranges_entry_simple\" | " 605 print "| class=\"cyclo_ranges_entry\" | 0 - " cyclo_simple_max 606 print "| class=\"cyclo_ranges_entry\" | Simple module, without much risk" 607 # Moderate 608 print "|-" 609 print "| class=\"cyclo_ranges_entry_moderate\" | " 610 print "| class=\"cyclo_ranges_entry\" |" cyclo_simple_max + 1 " - " cyclo_moderate_max 611 print "| class=\"cyclo_ranges_entry\" | More complex module, moderate risk" 612 # High 613 print "|-" 614 print "| class=\"cyclo_ranges_entry_high\" | " 615 print "| class=\"cyclo_ranges_entry\" |" cyclo_moderate_max + 1 " - " cyclo_high_max 616 print "| class=\"cyclo_ranges_entry\" | Complex module, high risk" 617 # Untestable 618 print "|-" 619 print "| class=\"cyclo_ranges_entry_untestable\" | " 620 print "| class=\"cyclo_ranges_entry\" | greater than " cyclo_high_max 621 print "| class=\"cyclo_ranges_entry\" | Untestable module, very high risk" 622 print "|}" 623 624 print "" 625 print "" 626 wiki_fnc_table_complete("") 627} 628 629function wiki_fnc_table_complete (caption) 630{ 631 wiki_fnc_table(caption, 1, 1, 0, 1, 1, 0, 1) 632} 633 634function wiki_fnc_table_abbrev (caption) 635{ 636 wiki_fnc_table(caption, 1, 0, 0, 0, 0, 0, 0) 637} 638 639function wiki_fnc_table (caption, 640 fname_p, 641 mcyclo_p, 642 cyclo_p, 643 num_statements_p, 644 num_lines_p, 645 first_line_p, 646 file_p) 647{ 648 print "{| width=\"90%\" class=\"cyclo_function_table\" cellpadding=\"0\" cellspacing=\"0\">" 649 if (caption != "") 650 { 651 print "|+" caption 652 } 653 wiki_fnc_header(fname_p, 654 mcyclo_p, 655 cyclo_p, 656 num_statements_p, 657 num_lines_p, 658 first_line_p, 659 file_p) 660 for (nfnc = 1; nfnc <= nfuncs; nfnc++) 661 { 662 wiki_fnc(nfnc, 663 fname_p, 664 mcyclo_p, 665 cyclo_p, 666 num_statements_p, 667 num_lines_p, 668 first_line_p, 669 file_p) 670 } 671 print "|}" 672} 673 674function wiki_fnc_header (fname_p, 675 mcyclo_p, 676 cyclo_p, 677 num_statements_p, 678 num_lines_p, 679 first_line_p, 680 file_p) 681{ 682 if (fname_p) 683 { 684 # Function name 685 print "! class=\"cyclo_function_table_header_entry\" | Function Name" 686 } 687 if (mcyclo_p) 688 { 689 # Modified cyclo 690 print "! class=\"cyclo_function_table_header_entry\" | Modified Cyclo" 691 } 692 if (cyclo_p) 693 { 694 # Cyclo 695 print "! class=\"cyclo_function_table_header_entry\" | Cyclomatic Complexity" 696 } 697 if (num_statements_p) 698 { 699 print "! class=\"cyclo_function_table_header_entry\" | Number of Statements" 700 } 701 if (num_lines_p) 702 { 703 print "! class=\"cyclo_function_table_header_entry\" | Number of Lines" 704 } 705 if (first_line_p) 706 { 707 print "! class=\"cyclo_function_table_header_entry\" | First Line" 708 } 709 if (file_p) 710 { 711 print "! class=\"cyclo_function_table_header_entry\" | Source File" 712 } 713} 714 715function wiki_fnc (nfnc, 716 fname_p, 717 mcyclo_p, 718 cyclo_p, 719 num_statements_p, 720 num_lines_p, 721 first_line_p, 722 file_p) 723{ 724 fname = fnames[nfnc] 725 726 # Function name 727 trclass = "cyclo_function_entry_simple" 728 if (mcyclo[nfnc] > cyclo_high_max) 729 { 730 trclass="cyclo_function_entry_untestable" 731 } 732 else if (mcyclo[nfnc] > cyclo_moderate_max) 733 { 734 trclass="cyclo_function_entry_high" 735 } 736 else if (mcyclo[nfnc] > cyclo_simple_max) 737 { 738 trclass="cyclo_function_entry_moderate" 739 } 740 741 print "|- class=\"" trclass "\"" 742 if (fname_p) 743 { 744 print "| class=\"cyclo_function_entry_name\" |" fname 745 } 746 if (mcyclo_p) 747 { 748 # Modified cyclo 749 print "| class=\"cyclo_function_entry_cyclo\" |" mcyclo[nfnc] 750 } 751 if (cyclo_p) 752 { 753 # Cyclo 754 print "| class=\"cyclo_function_entry_cyclo\" |" cyclo[nfnc] 755 } 756 if (num_statements_p) 757 { 758 # Number of statements 759 print "| class=\"cyclo_function_entry_number\" |" num_statements[nfnc] 760 } 761 if (num_lines_p) 762 { 763 # Number of lines 764 print "| class=\"cyclo_function_entry_number\" |" num_lines[nfnc] 765 } 766 if (first_line_p) 767 { 768 # First line 769 print "| class=\"cyclo_function_entry_number\" |" first_line[nfnc] 770 } 771 if (file_p) 772 { 773 href = "" 774 if (source_file_link_tmpl != "") 775 { 776 # Get href target 777 href = source_file_link_tmpl 778 sub(/%FILENAME%/, file[nfnc], href) 779 } 780 781 # Source file 782 print "| class=\"cyclo_function_entry_filename\" |" \ 783 ((href != "") ? "[" href " " file[nfnc] "]" : "[" file[nfnc] "]") 784 } 785} 786 787# Scan data from a line 788{ 789 function_name = $7 790 791 nfuncs++; 792 fnames[nfuncs] = function_name 793 mcyclo[nfuncs] = $1 794 cyclo[nfuncs] = $2 795 num_statements[nfuncs] = $3 796 first_line[nfuncs] = $4 797 num_lines[nfuncs] = $5 798 799 # Build the filename from the file_spec ($6) 800 begin_util_path = index($6, cut_dir) 801 tmpfilename = substr($6, begin_util_path + length(cut_dir)) 802 sub(/\([0-9]+\):/, "", tmpfilename) 803 file[nfuncs] = tmpfilename 804 805 if (mcyclo[nfuncs] > cyclo_simple_max) 806 { 807 # Extract function contents to a fn_txt file 808 filepath = $6 809 810 sub(/\([0-9]+\):/, "", filepath) 811 num_line = 0 812 813 while ((getline codeline < filepath) > 0) 814 { 815 num_line++; 816 if ((num_line >= first_line[nfuncs]) && 817 (num_line < first_line[nfuncs] + num_lines[nfuncs])) 818 { 819 print codeline > (function_name nfuncs "_fn.txt") 820 } 821 } 822 close (function_name nfuncs "_fn.txt") 823 close(filepath) 824 } 825 826 # Initial values for statistics variables 827 num_of_functions = 0 828 max_mcyclo = 0 829 max_function_length = 0 830 num_of_simple_functions = 0 831 num_of_moderate_functions = 0 832 num_of_high_functions = 0 833 num_of_untestable_functions = 0 834} 835 836# Epilogue 837END { 838 # Print header (only for html) 839 if (output_lang == "html") 840 { 841 html_header() 842 } 843 844 # Print prolog 845 if ((output_lang == "html") && 846 (html_prolog != "")) 847 { 848 print html_prolog 849 } 850 if ((output_lang == "wiki") && 851 (wiki_prolog != "")) 852 { 853 print wiki_prolog 854 } 855 856 if (output_lang == "html") 857 { 858 print "<div class=\"page_title\">" package_name " Cyclomatic Complexity Report</div>" 859 print "<p>Report generated at: <span class=\"report_timestamp\">" chronos_time "</span></p>" 860 } 861 if (output_lang == "wiki") 862 { 863 print "==" package_name " Cyclomatic Complexity Report==" 864 print "Report generated at: '''" chronos_time "'''" 865 } 866 867 if (section_global_stats_p) 868 { 869 build_stats() 870 871 if (output_lang == "html") 872 { 873 html_global_stats() 874 } 875 if (output_lang == "wiki") 876 { 877 wiki_global_stats() 878 } 879 } 880 if (section_function_cyclo_p) 881 { 882 if (output_lang == "html") 883 { 884 html_function_cyclo() 885 } 886 if (output_lang == "wiki") 887 { 888 wiki_function_cyclo() 889 } 890 } 891 892 # Print epilog 893 if ((output_lang == "html") && 894 (html_epilog != "")) 895 { 896 print html_epilog 897 } 898 if ((output_lang == "wiki") && 899 (wiki_epilog != "")) 900 { 901 print wiki_epilog 902 } 903 904 # Print footer (html only) 905 if (output_lang == "html") 906 { 907 html_footer() 908 } 909} 910 911# End of pmccabe2html 912