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