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