-- Lines (thousands) select sum(nline) / 1000 from FILES -- Comments (thousands) select (sum(nlcomment) + sum(nbcomment)) / 1000 from FILES -- Statements (thousands) select sum(nstatement) / 1000 from FILES -- Source files select count(*) from FILES -- Linked modules select count(*) from PROJECTS -- C functions select count(*) from FUNCTIONS where defined and not ismacro -- Macro definitions select count(*) from IDS where macro -- Header files per C source file select (select count(*) from FILES where name like '%.c') / (select count(*) from FILES where name like '%.h') -- Average structure complexity in files select avg(pow(fanout.c * fanin.c, 2)) from (select basefileid fid, count(definerid) c from ( select distinct BASEFILEID, DEFINERID, FOFFSET from INCTRIGGERS) i2 group by basefileid) fanout inner join (select definerid fid, count(basefileid) c from ( select distinct BASEFILEID, DEFINERID, FOFFSET from INCTRIGGERS) i2 group by definerid) fanin on fanout.fid = fanin.fid -- % global functions select 100 - 100.0 * (select count(*) from FUNCTIONS where defined and filescoped and not ismacro) / (select count(*) from FUNCTIONS where defined and not ismacro) -- % strictly structured functions select 100 - (select count(*) from FUNCTIONMETRICS where nreturn > 1 or ngoto > 0) / (select count(*) from FUNCTIONMETRICS) * 100 -- % labeled statements select 100.0 * sum(nlabel) / sum(nstmt) from FUNCTIONMETRICS -- Average number of parameters to functions select avg(nparam) from FUNCTIONMETRICS -- Average depth of maximum nesting select avg(maxnest) from FUNCTIONMETRICS -- Tokens per statement select 1.0 * sum(npptoken) / sum(nstmt) from FUNCTIONMETRICS -- Average structure complexity in functions select avg(cstruc) from FUNCTIONMETRICS -- % style conforming typedef identifiers select 100 * (select count(*) from IDS where typedef and name like '%_t') / (select count(*) from IDS where typedef) ; select 100 * (select count(*) from IDS where typedef and name like '%_t') / (select count(*) from IDS where typedef) ; select 100 * (select count(*) from IDS where typedef and name like '%_t') / (select count(*) from IDS where typedef) ; select 100 * (select count(*) from IDS where typedef and name regexp '^[A-Z0-9_]*$') / (select count(*) from IDS where typedef) -- % style conforming aggregate tags select 0 ; select 0 ; select 100 * (select count(*) from IDS where suetag and name like '%_s') / (select count(*) from IDS where suetag) ; select 100 * (select count(*) from IDS where suetag and name regexp '^_[A-Z0-9_]*$') / (select count(*) from IDS where suetag) -- Characters per line select 1.0 * sum(nchar) / sum(nline) from FILES -- % of numeric constants in operands select 100.0 * sum(nnconst) / (sum(nnconst) + sum(nid)) from FUNCTIONMETRICS -- % unsafe function-like macros select 100.0 * (select count(*) from FUNCTIONMETRICS left join FUNCTIONS on functionid = id where defined and ismacro and ndo = 0 and nstmt > 1) / (select count(*) from FUNCTIONS where defined and ismacro) -- % of preprocessor directives in header files select 100.0 * sum(nppdirective) / sum(nline) from FILES where name like '%.h' -- % of non-\#include directives in C files select 100.0 * (sum(nppdirective) - sum(nincfile)) / sum(nline) from FILES where name like '%.c' -- % of preprocessor directives in functions select 100.0 * sum(nppdirective) / sum(nline) from FUNCTIONMETRICS -- % of preprocessor conditionals in functions select 100.0 * sum(nppcond) / sum(nline) from FUNCTIONMETRICS -- % of function-like macros in defined functions select (100.0 * (select count(*) from FUNCTIONS where defined and ismacro) / (select count(*) from FUNCTIONS where defined )) -- % of macros in unique identifiers select (100.0 * (select count(*) from IDS where macro) / (select count(*) from IDS)) -- % of macros in identifiers select (100.0 * (select count(*) from TOKENS left join IDS on TOKENS.eid = IDS.eid where macro) / (select count(*) from TOKENS)) -- % of variable declarations with global scope select (100.0 * (select count(*) from IDS where lscope and ordinary and not fun) / (select count(*) from IDS)) -- % of variable operands with global scope select (100.0 * (select count(*) from TOKENS left join IDS on TOKENS.eid = IDS.eid where lscope and ordinary and not fun) / (select count(*) from TOKENS)) -- % of identifiers with wrongly global scope select 100.0 * (select count(*) from (select TOKENS.eid from TOKENS left join IDS on TOKENS.eid = IDS.eid where ordinary and lscope group by eid having min(fid) = max(fid) ) static) / (select count(*) from IDS) -- % of variable declarations with file scope select (100.0 * (select count(*) from IDS where cscope and ordinary and not fun) / (select count(*) from IDS)) -- % of variable operands with file scope select (100.0 * (select count(*) from TOKENS left join IDS on TOKENS.eid = IDS.eid where cscope and ordinary and not fun) / (select count(*) from TOKENS)) -- Variables per typedef or aggregate select ((select count(*) from IDS where ordinary and not fun) / (select count(*) from IDS where suetag or typedef)) -- Data elements per aggregate or enumeration select ((select count(*) from IDS where sumember or enum) / (select count(*) from IDS where suetag)) -- File length (in lines) of C files and headers. select nline from FILES where name like '%.c' select nline from FILES where name like '%.h' -- Defined global functions and structures. select npfunction from FILES where name like '%.c' select naggregate from FILES where name like '%.h' -- Extended cyclomatic complexity and number of statements per function. select ccycl2 from FUNCTIONMETRICS select nstmt from FUNCTIONMETRICS -- Halstead complexity. select chal from FUNCTIONMETRICS -- Common coupling at file and global scope. select nufid / nuid * 100 from FUNCTIONMETRICS where nuid > 0 select nupid / nuid * 100 from FUNCTIONMETRICS where nuid > 0 -- Length of global and aggregate identifiers. select length(name) from IDS where lscope select length(name) from IDS where suetag -- Comment density in C and header files. select nccomment / nstatement from FILES where name like '%.c' and nstatement > 0 select (nlcomment + nbcomment) / (naggregate + namember + nppfmacro + nppomacro + nenum + npfunction + nffunction + npvar + nfvar) from FILES where name like '%.h' and naggregate + namember + nppfmacro + nppomacro > 0 and nuline / nline < .2 -- Preprocessing expansion in functions and files. select nctoken / npptoken from FUNCTIONS inner join FUNCTIONMETRICS on id = functionid where defined and not ismacro and npptoken > 0 select (0.0 + sum(FILES.nctoken) / count(FILES.nctoken) - sum(FUNCTIONMETRICS.nctoken)) / (sum(FILES.npptoken) / count(FILES.npptoken) - sum(FUNCTIONMETRICS.npptoken)) from FUNCTIONS inner join FUNCTIONMETRICS on id = functionid left join FILES on FUNCTIONS.fid = FILES.fid where defined and not ismacro and FILES.npptoken > 0 group by FILES.fid -- Average level of namespace pollution in C files. select avg(NGNSOC) from FUNCTIONMETRICS left join FUNCTIONS on id = functionid left join FILES on FUNCTIONS.FID = FILES.fid where FILES.name like '%.c' group by FILES.fid