pmccabe2html 24 KB

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