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