X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=build-aux%2Fpmccabe2html;h=3d266d42d35f9f1f66456b2815f467637656f635;hb=c27b11980b8b4c2fa4686a291b1b773073b07289;hp=03e697b3d961046ad15288b78534a5b6ce4763d4;hpb=7301ffa106d3b478030607ca1d83b74531468506;p=gnulib.git diff --git a/build-aux/pmccabe2html b/build-aux/pmccabe2html old mode 100755 new mode 100644 index 03e697b3d..3d266d42d --- a/build-aux/pmccabe2html +++ b/build-aux/pmccabe2html @@ -1,7 +1,6 @@ -#!/usr/bin/awk -f -# pmccabe2html - pmccabe to html converter +# pmccabe2html - AWK script to convert pmccabe output to html -*- awk -*- -# Copyright (C) 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,18 +17,21 @@ # Written by Jose E. Marchesi . # Adapted for gnulib by Simon Josefsson . +# Added support for C++ by Giuseppe Scrivano . # Typical Invocation is from a Makefile.am: # -# libidn-cyclo.html: -# $(PMCCABE) ${top_srcdir}/lib/*.[ch] \ -# | sort -nr \ -# | $(AWK) -f ${top_srcdir}/build-aux/pmccabe2html \ -# -v lang=html -v name="$(PACKAGE_NAME)" \ -# -v vcurl="http://git.savannah.gnu.org/gitweb/?p=libidn.git;a=blob;f=%FILENAME%;hb=HEAD" \ -# -v url="http://www.gnu.org/software/libidn/" \ -# > tmp -# mv tmp libidn-cyclo.html +# cyclo-$(PACKAGE).html: +# $(PMCCABE) ${top_srcdir}/lib/*.[ch] \ +# | sort -nr \ +# | $(AWK) -f ${top_srcdir}/build-aux/pmccabe2html \ +# -v lang=html -v name="$(PACKAGE_NAME)" \ +# -v vcurl="http://git.savannah.gnu.org/gitweb/?p=$(PACKAGE).git;a=blob;f=%FILENAME%;hb=HEAD" \ +# -v url="http://www.gnu.org/software/$(PACKAGE)/" \ +# -v css=${top_srcdir}/build-aux/pmccabe.css \ +# -v cut_dir=${top_srcdir}/ \ +# > $@-tmp +# mv $@-tmp $@ # # The variables available are: # lang output language, either 'html' or 'wiki' @@ -38,6 +40,8 @@ # vcurl URL to version controlled source code browser, # a %FILENAME% in the string is replaced with the relative # source filename +# css CSS stylesheet filename, included verbatim in HTML output +# css_url link to CSS stylesheet, an URL # Prologue & configuration BEGIN { @@ -52,7 +56,6 @@ BEGIN { cyclo_simple_max = 10 cyclo_moderate_max = 20 cyclo_high_max = 50 - cut_dir = "/../" source_file_link_tmpl = vcurl # HTML options @@ -61,8 +64,7 @@ BEGIN { html_prolog = "Back to " package_name " Homepage

" } html_epilog = "
\ -Copyright (c) 2007, 2008 Free Software Foundation Inc." - css_url = "pmccabe.css" +Copyright (c) 2007, 2008 Free Software Foundation, Inc." html_doctype = "" html_comment = "" @@ -115,7 +117,7 @@ function html_fnc_table_complete (caption) function html_fnc_table_abbrev (caption) { - html_fnc_table(caption, 1, 0, 0, 0, 0, 0, 0) + html_fnc_table(caption, 1, 0, 1, 0, 1, 0, 0) } @@ -133,23 +135,22 @@ function html_fnc_table (caption, { print "" caption "" } - html_fnc_header(fname_p, - mcyclo_p, - cyclo_p, - num_statements_p, - num_lines_p, - first_line_p, + html_fnc_header(fname_p, + mcyclo_p, + cyclo_p, + num_statements_p, + num_lines_p, + first_line_p, file_p) for (nfnc = 1; nfnc < nfuncs; nfnc++) { - fnc = fnames[nfnc] - html_fnc(fnc, - fname_p, - mcyclo_p, - cyclo_p, - num_statements_p, - num_lines_p, - first_line_p, + html_fnc(nfnc, + fname_p, + mcyclo_p, + cyclo_p, + num_statements_p, + num_lines_p, + first_line_p, file_p) } print "" @@ -199,6 +200,18 @@ function html_header () { print "" } + if (css != "") + { + print "" + close(css) + } print "" print "" @@ -278,7 +291,7 @@ function html_fnc_header (fname_p, print "" } -function html_fnc (fname, +function html_fnc (nfun, fname_p, mcyclo_p, cyclo_p, @@ -287,17 +300,19 @@ function html_fnc (fname, first_line_p, file_p) { + fname = fnames[nfun] + # Function name trclass = "function_entry_simple" - if (mcyclo[fname] > cyclo_high_max) + if (mcyclo[nfun] > cyclo_high_max) { trclass="function_entry_untestable" - } - else if (mcyclo[fname] > cyclo_moderate_max) + } + else if (mcyclo[nfun] > cyclo_moderate_max) { trclass="function_entry_high" } - else if (mcyclo[fname] > cyclo_simple_max) + else if (mcyclo[nfun] > cyclo_simple_max) { trclass="function_entry_moderate" } @@ -306,7 +321,7 @@ function html_fnc (fname, if (fname_p) { print "" - if (mcyclo[fname] > cyclo_simple_max) + if (file_p && mcyclo[nfun] > cyclo_simple_max) { print "\ " @@ -325,35 +340,35 @@ function html_fnc (fname, { # Modified cyclo print "" - print mcyclo[fname] + print mcyclo[nfun] print "" } if (cyclo_p) { # Cyclo print "" - print cyclo[fname] + print cyclo[nfun] print "" } if (num_statements_p) { # Number of statements print "" - print num_statements[fname] + print num_statements[nfun] print "" } if (num_lines_p) { # Number of lines print "" - print num_lines[fname] + print num_lines[nfun] print "" } if (first_line_p) { # First line print "" - print first_line[fname] + print first_line[nfun] print "" } if (file_p) @@ -363,26 +378,26 @@ function html_fnc (fname, { # Get href target href = source_file_link_tmpl - sub(/%FILENAME%/, file[fname], href) + sub(/%FILENAME%/, file[nfun], href) } # Source file print "" if (href != "") { - print "" file[fname] "" + print "" file[nfun] "" } else { - print file[fname] + print file[nfun] } - + print "" print "" - if (mcyclo[fname] > cyclo_simple_max) + if (mcyclo[nfun] > cyclo_simple_max) { print "" @@ -394,20 +409,21 @@ function html_fnc (fname, if (num_lines_p) { num_columns++ } if (first_line_p) { num_columns++ } if (file_p) { num_columns++ } - + print "" print "
" print "
"
-            while ((getline codeline < (fname "_fn.txt")) > 0)
+
+            while ((getline codeline < (fname nfun "_fn.txt")) > 0)
             {
                 sub(/\\/, ">", codeline)
                 sub(/&/, "&", codeline)
-                
+
                 print codeline
             }
-            close(fname "_fn.txt")
-            system("rm " fname "_fn.txt")
+            close(fname nfun "_fn.txt")
+            system("rm " fname nfun "_fn.txt")
             print "
" print "
" print "" @@ -501,7 +517,7 @@ function html_function_cyclo () print "Simple module, without much risk" print "" print "" - # Moderate + # Moderate print "" print "" print " " @@ -573,7 +589,7 @@ function wiki_function_cyclo () print "==Details for all functions==" print "Used ranges:" - + print "{| class =\"cyclo_ranges_table\"" print "|-" print "| class=\"cyclo_ranges_header_entry\" | " @@ -630,23 +646,22 @@ function wiki_fnc_table (caption, { print "|+" caption } - wiki_fnc_header(fname_p, - mcyclo_p, - cyclo_p, - num_statements_p, - num_lines_p, - first_line_p, + wiki_fnc_header(fname_p, + mcyclo_p, + cyclo_p, + num_statements_p, + num_lines_p, + first_line_p, file_p) for (nfnc = 1; nfnc < nfuncs; nfnc++) { - fnc = fnames[nfnc] - wiki_fnc(fnc, - fname_p, - mcyclo_p, - cyclo_p, - num_statements_p, - num_lines_p, - first_line_p, + wiki_fnc(nfnc, + fname_p, + mcyclo_p, + cyclo_p, + num_statements_p, + num_lines_p, + first_line_p, file_p) } print "|}" @@ -693,7 +708,7 @@ function wiki_fnc_header (fname_p, } } -function wiki_fnc (fname, +function wiki_fnc (nfnc, fname_p, mcyclo_p, cyclo_p, @@ -702,17 +717,19 @@ function wiki_fnc (fname, first_line_p, file_p) { + fname = fnames[nfnc] + # Function name trclass = "cyclo_function_entry_simple" - if (mcyclo[fname] > cyclo_high_max) + if (mcyclo[nfnc] > cyclo_high_max) { trclass="cyclo_function_entry_untestable" - } - else if (mcyclo[fname] > cyclo_moderate_max) + } + else if (mcyclo[nfnc] > cyclo_moderate_max) { trclass="cyclo_function_entry_high" } - else if (mcyclo[fname] > cyclo_simple_max) + else if (mcyclo[nfnc] > cyclo_simple_max) { trclass="cyclo_function_entry_moderate" } @@ -725,27 +742,27 @@ function wiki_fnc (fname, if (mcyclo_p) { # Modified cyclo - print "| class=\"cyclo_function_entry_cyclo\" |" mcyclo[fname] + print "| class=\"cyclo_function_entry_cyclo\" |" mcyclo[nfnc] } if (cyclo_p) { # Cyclo - print "| class=\"cyclo_function_entry_cyclo\" |" cyclo[fname] + print "| class=\"cyclo_function_entry_cyclo\" |" cyclo[nfnc] } if (num_statements_p) { # Number of statements - print "| class=\"cyclo_function_entry_number\" |" num_statements[fname] + print "| class=\"cyclo_function_entry_number\" |" num_statements[nfnc] } if (num_lines_p) { # Number of lines - print "| class=\"cyclo_function_entry_number\" |" num_lines[fname] + print "| class=\"cyclo_function_entry_number\" |" num_lines[nfnc] } if (first_line_p) { # First line - print "| class=\"cyclo_function_entry_number\" |" first_line[fname] + print "| class=\"cyclo_function_entry_number\" |" first_line[nfnc] } if (file_p) { @@ -754,12 +771,12 @@ function wiki_fnc (fname, { # Get href target href = source_file_link_tmpl - sub(/%FILENAME%/, file[fname], href) + sub(/%FILENAME%/, file[nfnc], href) } - + # Source file print "| class=\"cyclo_function_entry_filename\" |" \ - ((href != "") ? "[" href " " file[fname] "]" : "[" file[fname] "]") + ((href != "") ? "[" href " " file[nfnc] "]" : "[" file[nfnc] "]") } } @@ -769,34 +786,36 @@ function wiki_fnc (fname, nfuncs++; fnames[nfuncs] = function_name - mcyclo[function_name] = $1 - cyclo[function_name] = $2 - num_statements[function_name] = $3 - first_line[function_name] = $4 - num_lines[function_name] = $5 + mcyclo[nfuncs] = $1 + cyclo[nfuncs] = $2 + num_statements[nfuncs] = $3 + first_line[nfuncs] = $4 + num_lines[nfuncs] = $5 # Build the filename from the file_spec ($6) begin_util_path = index($6, cut_dir) tmpfilename = substr($6, begin_util_path + length(cut_dir)) sub(/\([0-9]+\):/, "", tmpfilename) - file[function_name] = tmpfilename + file[nfuncs] = tmpfilename - if (mcyclo[function_name] > cyclo_simple_max) + if (mcyclo[nfuncs] > cyclo_simple_max) { # Extract function contents to a fn_txt file filepath = $6 + sub(/\([0-9]+\):/, "", filepath) num_line = 0 + while ((getline codeline < filepath) > 0) { num_line++; - if ((num_line >= first_line[function_name]) && - (num_line < first_line[function_name] + num_lines[function_name])) + if ((num_line >= first_line[nfuncs]) && + (num_line < first_line[nfuncs] + num_lines[nfuncs])) { - print codeline > (function_name "_fn.txt") + print codeline > (function_name nfuncs "_fn.txt") } } - close (function_name "_fn.txt") + close (function_name nfuncs "_fn.txt") close(filepath) } @@ -819,7 +838,7 @@ END { } # Print prolog - if ((output_lang == "html") && + if ((output_lang == "html") && (html_prolog != "")) { print html_prolog @@ -865,9 +884,9 @@ END { wiki_function_cyclo() } } - + # Print epilog - if ((output_lang == "html") && + if ((output_lang == "html") && (html_epilog != "")) { print html_epilog