mirror of
https://github.com/acpica/acpica/
synced 2025-01-13 12:59:18 +03:00
acpisrc: Improve comment counting mechanism.
Count first and last lines of multi-line comments as whitespace, not comment lines. Handle Linux legal header in addition to standard acpica header.
This commit is contained in:
parent
853c286f14
commit
86b0a69e1f
@ -115,8 +115,12 @@
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#define LINES_IN_LEGAL_HEADER 105 /* See above */
|
||||
|
||||
#define LINES_IN_LEGAL_HEADER 105 /* See above */
|
||||
#define LEGAL_HEADER_SIGNATURE " * 2.1. This is your license from Intel Corp. under its intellectual property"
|
||||
#define LINES_IN_LINUX_HEADER 34
|
||||
#define LINUX_HEADER_SIGNATURE " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"
|
||||
#define LINES_IN_ASL_HEADER 29 /* Header as output from disassembler */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
@ -201,6 +205,7 @@ extern UINT32 Gbl_CommentLines;
|
||||
extern UINT32 Gbl_LongLines;
|
||||
extern UINT32 Gbl_TotalLines;
|
||||
extern UINT32 Gbl_HeaderSize;
|
||||
extern UINT32 Gbl_HeaderLines;
|
||||
extern struct stat Gbl_StatBuf;
|
||||
extern char *Gbl_FileBuffer;
|
||||
extern UINT32 Gbl_FileSize;
|
||||
|
@ -1216,14 +1216,27 @@ AsCountSourceLines (
|
||||
|
||||
while (*SubBuffer)
|
||||
{
|
||||
/* Ignore comments */
|
||||
/* Detect comments (// comments are not used, non-ansii) */
|
||||
|
||||
if ((SubBuffer[0] == '/') &&
|
||||
(SubBuffer[1] == '*'))
|
||||
{
|
||||
CommentCount++;
|
||||
SubBuffer += 2;
|
||||
|
||||
/* First line of multi-line comment is often just whitespace */
|
||||
|
||||
if (SubBuffer[0] == '\n')
|
||||
{
|
||||
WhiteCount++;
|
||||
SubBuffer++;
|
||||
}
|
||||
else
|
||||
{
|
||||
CommentCount++;
|
||||
}
|
||||
|
||||
/* Find end of comment */
|
||||
|
||||
while (SubBuffer[0] && SubBuffer[1] &&
|
||||
!(((SubBuffer[0] == '*') &&
|
||||
(SubBuffer[1] == '/'))))
|
||||
@ -1258,7 +1271,11 @@ AsCountSourceLines (
|
||||
|
||||
/* Adjust comment count for legal header */
|
||||
|
||||
CommentCount -= Gbl_HeaderSize;
|
||||
if (Gbl_HeaderSize < CommentCount)
|
||||
{
|
||||
CommentCount -= Gbl_HeaderSize;
|
||||
Gbl_HeaderLines += Gbl_HeaderSize;
|
||||
}
|
||||
|
||||
Gbl_SourceLines += LineCount;
|
||||
Gbl_WhiteLines += WhiteCount;
|
||||
|
@ -317,13 +317,13 @@ AsDetectLoneLineFeeds (
|
||||
{
|
||||
if (!Gbl_IgnoreLoneLineFeeds)
|
||||
{
|
||||
printf ("****File has UNIX format**** (LF only, not CR/LF) %d lines, %s\n",
|
||||
LfCount, Filename);
|
||||
printf ("%s: ****File has UNIX format**** (LF only, not CR/LF) %d lines\n",
|
||||
Filename, LfCount);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%d lone linefeeds in file %s\n", LfCount, Filename);
|
||||
printf ("%s: %d lone linefeeds in file\n", Filename, LfCount);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@ -579,12 +579,6 @@ AsProcessOneFile (
|
||||
char *OutPathname = NULL;
|
||||
|
||||
|
||||
Gbl_HeaderSize = LINES_IN_LEGAL_HEADER; /* Normal C file and H header */
|
||||
if (strstr (Filename, ".asl"))
|
||||
{
|
||||
Gbl_HeaderSize = 29; /* Lines in default ASL header */
|
||||
}
|
||||
|
||||
/* Allocate a file pathname buffer for both source and target */
|
||||
|
||||
Pathname = calloc (MaxPathLength + strlen (Filename) + 2, 1);
|
||||
@ -611,6 +605,20 @@ AsProcessOneFile (
|
||||
return -1;
|
||||
}
|
||||
|
||||
Gbl_HeaderSize = 0;
|
||||
if (strstr (Filename, ".asl"))
|
||||
{
|
||||
Gbl_HeaderSize = LINES_IN_ASL_HEADER; /* Lines in default ASL header */
|
||||
}
|
||||
else if (strstr (Gbl_FileBuffer, LEGAL_HEADER_SIGNATURE))
|
||||
{
|
||||
Gbl_HeaderSize = LINES_IN_LEGAL_HEADER; /* Normal C file and H header */
|
||||
}
|
||||
else if (strstr (Gbl_FileBuffer, LINUX_HEADER_SIGNATURE))
|
||||
{
|
||||
Gbl_HeaderSize = LINES_IN_LINUX_HEADER; /* Linuxized C file and H header */
|
||||
}
|
||||
|
||||
/* Process the file in the buffer */
|
||||
|
||||
Gbl_MadeChanges = FALSE;
|
||||
|
@ -131,6 +131,7 @@ UINT32 Gbl_CommentLines = 0;
|
||||
UINT32 Gbl_SourceLines = 0;
|
||||
UINT32 Gbl_LongLines = 0;
|
||||
UINT32 Gbl_TotalLines = 0;
|
||||
UINT32 Gbl_HeaderLines = 0;
|
||||
UINT32 Gbl_HeaderSize = 0;
|
||||
void *Gbl_StructDefs = NULL;
|
||||
|
||||
@ -254,10 +255,15 @@ AsDisplayStats (void)
|
||||
printf ("%8u Lines of non-comment whitespace\n", Gbl_WhiteLines);
|
||||
printf ("%8u Lines of comments\n", Gbl_CommentLines);
|
||||
printf ("%8u Long lines found\n", Gbl_LongLines);
|
||||
printf ("%6.1f Ratio of code to whitespace\n",
|
||||
printf ("%8.1f Ratio of code to whitespace\n",
|
||||
((float) Gbl_SourceLines / (float) Gbl_WhiteLines));
|
||||
printf ("%6.1f Ratio of code to comments\n",
|
||||
printf ("%8.1f Ratio of code to comments\n",
|
||||
((float) Gbl_SourceLines / (float) (Gbl_CommentLines + Gbl_NonAnsiComments)));
|
||||
printf (" %u%% code, %u%% comments, %u%% whitespace, %u%% headers\n",
|
||||
(Gbl_SourceLines * 100) / Gbl_TotalLines,
|
||||
(Gbl_CommentLines * 100) / Gbl_TotalLines,
|
||||
(Gbl_WhiteLines * 100) / Gbl_TotalLines,
|
||||
(Gbl_HeaderLines * 100) / Gbl_TotalLines);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user