ReactOS  0.4.12-dev-918-g6c6e7b8
stats.c File Reference
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
Include dependency graph for stats.c:

Go to the source code of this file.

Classes

struct  _EXTENSION_INFO
 
union  _FILE_INFO
 

Macros

#define MAX_OPTIONS   2
 

Typedefs

typedef struct _EXTENSION_INFO EXTENSION_INFO
 
typedef struct _EXTENSION_INFOPEXTENSION_INFO
 
typedef struct _FILE_INFO FILE_INFO
 
typedef struct _FILE_INFOPFILE_INFO
 

Functions

VOID Initialize (VOID)
 
VOID Cleanup (VOID)
 
PEXTENSION_INFO AddExtension (LPTSTR ExtName, LPTSTR Description)
 
PFILE_INFO AddFile (LPTSTR FileName, PEXTENSION_INFO ExtInfo)
 
VOID CleanupAfterFile (VOID)
 
BOOL LoadFile (LPTSTR FileName)
 
VOID ReadLines (PFILE_INFO StatInfo)
 
VOID PrintStatistics (VOID)
 
BOOL ProcessFiles (LPTSTR Path)
 
BOOL ProcessDirectories (LPTSTR Path)
 
VOID Execute (LPTSTR Path)
 
BOOLEAN IsOptionSet (TCHAR *Option)
 
int _tmain (int argc, _TCHAR *argv[])
 

Variables

HANDLE FileHandle
 
PEXTENSION_INFO ExtInfoList
 
PFILE_INFO StatInfoList
 
BOOLEAN SkipEmptyLines
 
BOOLEAN BeSilent
 
TCHAROptions [MAX_OPTIONS]
 

Macro Definition Documentation

◆ MAX_OPTIONS

#define MAX_OPTIONS   2

Definition at line 43 of file stats.c.

Typedef Documentation

◆ EXTENSION_INFO

◆ FILE_INFO

◆ PEXTENSION_INFO

◆ PFILE_INFO

Function Documentation

◆ _tmain()

int _tmain ( int  argc,
_TCHAR argv[] 
)

Definition at line 446 of file stats.c.

447 {
448  int a;
449 
450  _tprintf (_T("ReactOS Project Statistics\n"));
451  _tprintf (_T("==========================\n\n"));
452 
453  if (argc < 2 || argc > 2 + MAX_OPTIONS)
454  {
455  _tprintf(_T("Usage: stats [-e] [-s] directory\n"));
456  _tprintf(_T(" -e: don't count empty lines\n"));
457  _tprintf(_T(" -s: be silent, don't print directories while processing\n"));
458  return 1;
459  }
460 
461  Initialize();
462  AddExtension (_T("c\0\0"), _T("Ansi C Source files"));
463  AddExtension (_T("cpp\0cxx\0\0"), _T("C++ Source files"));
464  AddExtension (_T("h\0\0"), _T("Header files"));
465 
466  for(a = 1; a < argc - 1; a++)
467  {
468  Options[a - 1] = argv[a];
469  }
470 
471  SkipEmptyLines = IsOptionSet(_T("-e"));
472  BeSilent = IsOptionSet(_T("-s"));
473 
474  Execute (argv[argc - 1]);
475  Cleanup();
476 
477  return 0;
478 }
static int argc
Definition: ServiceArgs.c:12
#define _tprintf
Definition: tchar.h:506
TCHAR * Options[MAX_OPTIONS]
Definition: stats.c:44
VOID Cleanup(VOID)
Definition: stats.c:56
VOID Execute(LPTSTR Path)
Definition: stats.c:407
PEXTENSION_INFO AddExtension(LPTSTR ExtName, LPTSTR Description)
Definition: stats.c:72
#define MAX_OPTIONS
Definition: stats.c:43
BOOLEAN SkipEmptyLines
Definition: stats.c:41
#define argv
Definition: mplay32.c:18
#define a
Definition: ke_i.h:78
BOOLEAN BeSilent
Definition: stats.c:41
#define _T(x)
Definition: vfdio.h:22
BOOLEAN IsOptionSet(TCHAR *Option)
Definition: stats.c:431
VOID Initialize(VOID)
Definition: stats.c:48
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ AddExtension()

PEXTENSION_INFO AddExtension ( LPTSTR  ExtName,
LPTSTR  Description 
)

Definition at line 72 of file stats.c.

74 {
75  PEXTENSION_INFO ExtInfo;
77  TCHAR *t;
78  DWORD ln;
79 
80  ExtInfo = (PEXTENSION_INFO) HeapAlloc (GetProcessHeap(), 0, sizeof (EXTENSION_INFO));
81  if (!ExtInfo)
82  return NULL;
83 
84  for(t = ExtName; *t != _T('\0'); t += _tcslen(t) + 1);
85  ln = (DWORD_PTR)t - (DWORD_PTR)ExtName;
86 
87  ZeroMemory (ExtInfo, sizeof (EXTENSION_INFO));
88  memcpy (ExtInfo->ExtName, ExtName, ln);
89  _tcscpy (ExtInfo->Description, Description);
90 
91  for(t = ExtInfo->ExtName; *t != _T('\0'); t += _tcslen(t) + 1)
92  {
93  if(ExtInfo->nExtensions++ != 0)
94  _tcscat (ExtInfo->ExpandedExtName, _T(";"));
95  _tcscat (ExtInfo->ExpandedExtName, _T("*."));
96  _tcscat (ExtInfo->ExpandedExtName, t);
97  }
98 
99  if (ExtInfoList)
100  {
101  Info = ExtInfoList;
102  while (Info->Next != NULL)
103  {
104  Info = Info->Next;
105  }
106  Info->Next = ExtInfo;
107  }
108  else
109  {
110  ExtInfoList = ExtInfo;
111  }
112 
113  return ExtInfo;
114 }
#define DWORD_PTR
Definition: treelist.c:76
GLdouble GLdouble t
Definition: gl.h:2047
PEXTENSION_INFO ExtInfoList
Definition: stats.c:39
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1635
static const WCHAR Description[]
Definition: oid.c:1266
struct TraceInfo Info
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
struct _EXTENSION_INFO EXTENSION_INFO
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint32_t DWORD_PTR
Definition: typedefs.h:63
TCHAR ExpandedExtName[128]
Definition: stats.c:19
TCHAR ExtName[16]
Definition: stats.c:18
TCHAR Description[256]
Definition: stats.c:21
struct _EXTENSION_INFO * PEXTENSION_INFO
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
DWORD nExtensions
Definition: stats.c:20

Referenced by _tmain().

◆ AddFile()

PFILE_INFO AddFile ( LPTSTR  FileName,
PEXTENSION_INFO  ExtInfo 
)

Definition at line 118 of file stats.c.

120 {
121  PFILE_INFO StatInfo;
123 
124  StatInfo = (PFILE_INFO) HeapAlloc (GetProcessHeap(), 0, sizeof (FILE_INFO));
125  if (!StatInfo)
126  return NULL;
127  ZeroMemory (StatInfo, sizeof (FILE_INFO));
128  _tcscpy (StatInfo->FileName, FileName);
129  StatInfo->ExtInfo = ExtInfo;
130 
131  if (ExtInfo->StatInfoList)
132  {
133  Info = ExtInfo->StatInfoList;
134  while (Info->StatInfoListNext != NULL)
135  {
136  Info = Info->StatInfoListNext;
137  }
138  Info->StatInfoListNext = StatInfo;
139  }
140  else
141  {
142  ExtInfo->StatInfoList = StatInfo;
143  }
144 
145  if (StatInfoList)
146  {
147  Info = StatInfoList;
148  while (Info->Next != NULL)
149  {
150  Info = Info->Next;
151  }
152  Info->Next = StatInfo;
153  }
154  else
155  {
156  StatInfoList = StatInfo;
157  }
158 
159  return StatInfo;
160 }
struct _FILE_INFO FILE_INFO
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1635
struct TraceInfo Info
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
struct _FILE_INFO * PFILE_INFO
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
TCHAR FileName[MAX_PATH]
Definition: stats.c:32
PFILE_INFO StatInfoList
Definition: stats.c:40
PEXTENSION_INFO ExtInfo
Definition: stats.c:31
struct _FILE_INFO * StatInfoList
Definition: stats.c:17

Referenced by ProcessFiles().

◆ Cleanup()

VOID Cleanup ( VOID  )

Definition at line 56 of file stats.c.

57 {
58  PEXTENSION_INFO ExtInfo;
59  PEXTENSION_INFO NextExtInfo;
60 
61  ExtInfo = ExtInfoList;
62  while (ExtInfo != NULL)
63  {
64  NextExtInfo = ExtInfo->Next;
65  HeapFree (GetProcessHeap(), 0, ExtInfo);
66  ExtInfo = NextExtInfo;
67  }
68 }
PEXTENSION_INFO ExtInfoList
Definition: stats.c:39
struct _EXTENSION_INFO * Next
Definition: stats.c:16
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by _tmain().

◆ CleanupAfterFile()

VOID CleanupAfterFile ( VOID  )

Definition at line 164 of file stats.c.

165 {
168 }
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
HANDLE FileHandle
Definition: stats.c:38

Referenced by ProcessFiles().

◆ Execute()

VOID Execute ( LPTSTR  Path)

Definition at line 407 of file stats.c.

408 {
409  if (!ExtInfoList)
410  {
411  _tprintf (_T("No extensions specified.\n"));
412  return;
413  }
414 
415  if (!ProcessDirectories (Path))
416  {
417  _tprintf (_T("Failed to process directories.\n"));
418  return;
419  }
420 
421  if (!ProcessFiles (Path))
422  {
423  _tprintf (_T("Failed to process files.\n"));
424  return;
425  }
426 
427  PrintStatistics();
428 }
#define _tprintf
Definition: tchar.h:506
PEXTENSION_INFO ExtInfoList
Definition: stats.c:39
BOOL ProcessDirectories(LPTSTR Path)
Definition: stats.c:358
#define _T(x)
Definition: vfdio.h:22
BOOL ProcessFiles(LPTSTR Path)
Definition: stats.c:292
VOID PrintStatistics(VOID)
Definition: stats.c:236
PRTL_UNICODE_STRING_BUFFER Path

Referenced by _tmain(), DECLARE_INTERFACE_(), and MiIsAccessAllowed().

◆ Initialize()

VOID Initialize ( VOID  )

Definition at line 48 of file stats.c.

49 {
50  ExtInfoList = NULL;
52 }
PEXTENSION_INFO ExtInfoList
Definition: stats.c:39
smooth NULL
Definition: ftsmooth.c:416
PFILE_INFO StatInfoList
Definition: stats.c:40

Referenced by _tmain().

◆ IsOptionSet()

BOOLEAN IsOptionSet ( TCHAR Option)

Definition at line 431 of file stats.c.

432 {
433  int i;
434  for(i = 0; i < MAX_OPTIONS; i++)
435  {
436  if(!Options[i])
437  continue;
438 
439  if(!_tcscmp(Options[i], Option))
440  return TRUE;
441  }
442  return FALSE;
443 }
#define TRUE
Definition: types.h:120
TCHAR * Options[MAX_OPTIONS]
Definition: stats.c:44
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define MAX_OPTIONS
Definition: stats.c:43
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by _tmain().

◆ LoadFile()

BOOL LoadFile ( LPTSTR  FileName)

Definition at line 172 of file stats.c.

173 {
174  LONG FileSize;
175 
176  FileHandle = CreateFile (FileName, // Create this file
177  GENERIC_READ, // Open for reading
178  0, // No sharing
179  NULL, // No security
180  OPEN_EXISTING, // Open the file
181  FILE_ATTRIBUTE_NORMAL, // Normal file
182  NULL); // No attribute template
184  return FALSE;
185 
187  if (FileSize <= 0)
188  {
190  return FALSE;
191  }
192 
193  return TRUE;
194 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
HANDLE FileHandle
Definition: stats.c:38
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define GENERIC_READ
Definition: compat.h:124
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904

Referenced by ProcessFiles().

◆ PrintStatistics()

VOID PrintStatistics ( VOID  )

Definition at line 236 of file stats.c.

237 {
239  DWORD TotalFileCount;
240  DWORD TotalLineCount;
241  DWORD TotalAvgLF;
242  DWORD TotalEmptyLines;
243 
244  TotalFileCount = 0;
245  TotalLineCount = 0;
246  TotalEmptyLines = 0;
247  Info = ExtInfoList;
248 
249  for (Info = ExtInfoList; Info != NULL; Info = Info->Next)
250  {
251  TotalFileCount += Info->FileCount;
252  TotalLineCount += Info->LineCount;
253  TotalEmptyLines += Info->EmptyLines;
254  }
255 
256  TotalAvgLF = (TotalFileCount ? TotalLineCount / TotalFileCount : 0);
257 
258  for (Info = ExtInfoList; Info != NULL; Info = Info->Next)
259  {
260  DWORD AvgLF;
261 
262  if (Info->FileCount != 0)
263  {
264  AvgLF = (Info->FileCount ? Info->LineCount / Info->FileCount : 0);
265  }
266  else
267  {
268  AvgLF = 0;
269  }
270 
271  _tprintf (_T("\n"));
272  _tprintf (_T("File extension%c : %s\n"), ((Info->nExtensions > 1) ? _T('s') : _T(' ')), Info->ExpandedExtName);
273  _tprintf (_T("File ext. description : %s\n"), Info->Description);
274  _tprintf (_T("Number of files : %lu\n"), Info->FileCount);
275  _tprintf (_T("Number of lines : %lu\n"), Info->LineCount);
276  if(SkipEmptyLines)
277  _tprintf (_T("Number of empty lines : %lu\n"), Info->EmptyLines);
278  _tprintf (_T("Proportion of lines : %.2f %%\n"), (float)(TotalLineCount ? (((float)Info->LineCount * 100) / (float)TotalLineCount) : 0));
279  _tprintf (_T("Average no. lines/file : %lu\n"), AvgLF);
280  }
281 
282  _tprintf (_T("\n"));
283  _tprintf (_T("Total number of files : %lu\n"), TotalFileCount);
284  _tprintf (_T("Total number of lines : %lu\n"), TotalLineCount);
285  if(SkipEmptyLines)
286  _tprintf (_T("Total number of empty lines : %lu\n"), TotalEmptyLines);
287  _tprintf (_T("Average no. lines/file : %lu\n"), TotalAvgLF);
288 }
#define _tprintf
Definition: tchar.h:506
PEXTENSION_INFO ExtInfoList
Definition: stats.c:39
BOOLEAN SkipEmptyLines
Definition: stats.c:41
struct TraceInfo Info
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)

Referenced by Execute().

◆ ProcessDirectories()

BOOL ProcessDirectories ( LPTSTR  Path)

Definition at line 358 of file stats.c.

359 {
362  HANDLE SearchHandle;
363  BOOL More;
364 
365  if(!BeSilent)
366  {
367  _tprintf (_T("Processing %s ...\n"), Path);
368  }
369 
371  _tcscat (SearchPath, _T("\\*.*"));
372 
373  SearchHandle = FindFirstFileEx (SearchPath,
375  &FindFile,
377  NULL,
378  0);
379  if (SearchHandle != INVALID_HANDLE_VALUE)
380  {
381  More = TRUE;
382  while (More)
383  {
384  if ((FindFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
385  && (_tcscmp (FindFile.cFileName, _T(".")) != 0)
386  && (_tcscmp (FindFile.cFileName, _T("..")) != 0)
387  && (_tcscmp (FindFile.cFileName, _T("CVS")) != 0)
388  && (_tcscmp (FindFile.cFileName, _T(".svn")) != 0))
389  {
391  _tcscat (SearchPath, _T("\\"));
392  _tcscat (SearchPath, FindFile.cFileName);
394  return FALSE;
395  if (!ProcessFiles (SearchPath))
396  return FALSE;
397  }
398  More = FindNextFile (SearchHandle, &FindFile);
399  }
400  FindClose (SearchHandle);
401  }
402  return TRUE;
403 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define SearchPath
Definition: winbase.h:3714
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL ProcessDirectories(LPTSTR Path)
Definition: stats.c:358
BOOLEAN BeSilent
Definition: stats.c:41
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define FindNextFile
Definition: winbase.h:3602
#define MAX_PATH
Definition: compat.h:26
BOOL ProcessFiles(LPTSTR Path)
Definition: stats.c:292
PRTL_UNICODE_STRING_BUFFER Path
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
#define FindFirstFileEx
Definition: winbase.h:3597
Definition: find.c:28
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by Execute().

◆ ProcessFiles()

BOOL ProcessFiles ( LPTSTR  Path)

Definition at line 292 of file stats.c.

293 {
296  TCHAR SearchPath[256];
297  TCHAR FileName[256];
298  TCHAR *Ext;
299  HANDLE SearchHandle;
300  BOOL More;
301 
302  Info = ExtInfoList;
303  while (Info != NULL)
304  {
305  Ext = Info->ExtName;
306  do
307  {
308  ZeroMemory (&FindFile, sizeof (FindFile));
310  _tcscat (SearchPath, _T("\\*."));
312  _tcscpy (FindFile.cFileName, SearchPath);
313  SearchHandle = FindFirstFile (SearchPath, &FindFile);
314  if (SearchHandle != INVALID_HANDLE_VALUE)
315  {
316  More = TRUE;
317  while (More)
318  {
319  if (!(FindFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
320  {
321  _tcscpy (FileName, Path);
322  _tcscat (FileName, _T("\\"));
323  _tcscat (FileName, FindFile.cFileName);
324 
325  if (LoadFile (FileName))
326  {
327  PFILE_INFO StatInfo;
328 
329  StatInfo = AddFile (FindFile.cFileName, Info);
330  if (!StatInfo)
331  {
332  _tprintf (_T("Not enough free memory.\n"));
333  return FALSE;
334  }
335 
336  ReadLines (StatInfo);
337 
338  Info->FileCount++;
339  Info->LineCount += StatInfo->LineCount;
340  Info->EmptyLines += StatInfo->EmptyLines;
341 
343  }
344  }
345  More = FindNextFile (SearchHandle, &FindFile);
346  }
347  FindClose (SearchHandle);
348  }
349  Ext += _tcslen(Ext) + 1;
350  } while(*Ext != _T('\0'));
351  Info = Info->Next;
352  }
353  return TRUE;
354 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
PEXTENSION_INFO ExtInfoList
Definition: stats.c:39
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1635
PFILE_INFO AddFile(LPTSTR FileName, PEXTENSION_INFO ExtInfo)
Definition: stats.c:118
struct TraceInfo Info
#define SearchPath
Definition: winbase.h:3714
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL LoadFile(LPTSTR FileName)
Definition: stats.c:172
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
#define FindFirstFile
Definition: winbase.h:3596
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
DWORD EmptyLines
Definition: stats.c:34
#define FindNextFile
Definition: winbase.h:3602
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
static struct proto Ext[]
Definition: mkg3states.c:89
VOID CleanupAfterFile(VOID)
Definition: stats.c:164
PRTL_UNICODE_STRING_BUFFER Path
VOID ReadLines(PFILE_INFO StatInfo)
Definition: stats.c:198
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
DWORD LineCount
Definition: stats.c:33
Definition: find.c:28
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by Execute(), and ProcessDirectories().

◆ ReadLines()

VOID ReadLines ( PFILE_INFO  StatInfo)

Definition at line 198 of file stats.c.

199 {
200  DWORD ReadBytes, LineLen;
201  static char FileBuffer[1024];
202  char LastChar = '\0';
203  char *Current;
204 
205  LineLen = 0;
206  while(ReadFile (FileHandle, FileBuffer, sizeof(FileBuffer), &ReadBytes, NULL) && ReadBytes >= sizeof(char))
207  {
208  for(Current = FileBuffer; ReadBytes > 0; ReadBytes -= sizeof(char), Current++)
209  {
210  if(*Current == '\n' && LastChar == '\r')
211  {
212  LastChar = '\0';
213  if(!SkipEmptyLines || (LineLen > 0))
214  StatInfo->LineCount++;
215  if(LineLen == 0)
216  StatInfo->EmptyLines++;
217  LineLen = 0;
218  continue;
219  }
220  LastChar = *Current;
221  if(SkipEmptyLines && (*Current == ' ' || *Current == '\t'))
222  {
223  continue;
224  }
225  if(*Current != '\r')
226  LineLen++;
227  }
228  }
229 
230  StatInfo->LineCount += (LineLen > 0);
231  StatInfo->EmptyLines += ((LastChar != '\0') && (LineLen == 0));
232 }
BOOLEAN SkipEmptyLines
Definition: stats.c:41
HANDLE FileHandle
Definition: stats.c:38
smooth NULL
Definition: ftsmooth.c:416
unsigned char
Definition: typeof.h:29
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
DWORD EmptyLines
Definition: stats.c:34
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
DWORD LineCount
Definition: stats.c:33

Referenced by ProcessFiles().

Variable Documentation

◆ BeSilent

BOOLEAN BeSilent

Definition at line 41 of file stats.c.

Referenced by _tmain(), and ProcessDirectories().

◆ ExtInfoList

PEXTENSION_INFO ExtInfoList

Definition at line 39 of file stats.c.

Referenced by AddExtension(), Cleanup(), Execute(), Initialize(), PrintStatistics(), and ProcessFiles().

◆ FileHandle

Definition at line 38 of file stats.c.

Referenced by _IRQL_requires_max_(), AddDiskToList(), ApphelpCheckRunAppEx(), BaseCheckRunApp(), BaseMarkFileForDelete(), BasepCheckBadapp(), BasepCheckWebBladeHashes(), BasepOpenFileForMove(), BasicBehaviorChecks(), BindIoCompletionCallback(), BlImgLoadImageWithProgress2(), BmFwInitializeBootDirectoryPath(), call_ApphelpCheckRunApp(), CallApphelpWithImage(), CheckForValidPEAndVendor(), CleanupAfterFile(), CmpInitHiveFromFile(), CmSaveKey(), CmSaveMergedKeys(), CompareFileContents(), CreateFileA(), CreateFileW(), CreateIoCompletionPort(), CreatePartitionList(), CreateProcessInternalW(), CreateRegistryFile(), CSR_API(), DbgUiConvertStateChangeStructure(), DeleteFileW(), DoesPathExist(), DosCreateFile(), DosCreateFileEx(), DosDeviceIoControl(), DosFlushFileBuffers(), DosInt21h(), DosLoadDriver(), DosLoadExecutable(), DosOpenFile(), DosPrintCharacter(), DosReadCharacter(), DosReadFile(), DosReadLineBuffered(), DosSeekFile(), DosWriteFile(), Ext2Close(), Ext2GetFileInformation(), Ext2Open(), Ext2OpenDevice(), Ext2OpenFile(), Ext2Read(), Ext2Seek(), Fat12Format(), Fat12WriteBootSector(), Fat12WriteFAT(), Fat12WriteRootDirectory(), Fat16Format(), Fat16WriteBootSector(), Fat16WriteFAT(), Fat16WriteRootDirectory(), Fat32Format(), Fat32WriteBootSector(), Fat32WriteFAT(), Fat32WriteFsInfo(), Fat32WriteRootDirectory(), FatClose(), FatGetFileInformation(), FatOpen(), FatRead(), FatSeek(), FatWipeSectors(), Fatx16WriteFAT(), Fatx32WriteFAT(), FatxFormat(), FatxWriteBootSector(), FatxWriteRootDirectory(), FileClose(), FileLoadByHandle(), FilterConnectCommunicationPort(), FindBootStore(), FindFirstStreamW(), FsCloseFile(), FsGetFileInformation(), FsGetFileSize(), FsReadFile(), FsRecRegisterFs(), FsSetFilePointer(), GetFileSecurityW(), GetFileSystem(), ImageAddCertificate(), ImageGetDigestStream(), ImageRemoveCertificate(), InfOpenFile(), InfWriteFile(), IniCacheLoad(), IniCacheLoadByHandle(), IniCacheSave(), IniCacheSaveByHandle(), InstallBtrfsBootCodeToDisk(), InstallFat12BootCodeToFloppy(), InstallFat16BootCode(), InstallFat16BootCodeToFile(), InstallFat32BootCode(), InstallFat32BootCodeToFile(), InstallMbrBootCodeToDiskHelper(), InstallSetupInfFile(), IntGdiAddFontResource(), IntGetCodePageEntry(), IoCreateFile(), IoCreateFileSpecifyDeviceObjectHint(), IoCreateStreamFileObjectEx(), IopCreateFile(), IopCreateLogFile(), IopGetDeviceObjectPointer(), IopMarkBootPartition(), IopWriteLogFile(), IsoClose(), IsoGetFileInformation(), IsoOpen(), IsoRead(), IsoSeek(), IsThereAValidBootSector(), kbd_c(), kbd_def(), kbd_h(), kbd_rc(), KdbpSymLoadModuleSymbols(), LdrpCheckForLoadedDll(), LdrpCreateDllSection(), LdrVerifyImageMatchesChecksum(), LoadFile(), LogMessage(), main(), MapDebugInformation(), MapFile(), MiShutdownSystem(), MmCreateArm3Section(), MmCreateSection(), MmLoadSystemImage(), DriveVolume::MoveFileDumb(), MyDeleteFile(), NdisCloseFile(), NdisMapFile(), NdisOpenFile(), NdisUnmapFile(), NtCancelIoFile(), NtCreateFile(), NtCreateMailslotFile(), NtCreateNamedPipeFile(), NtCreatePagingFile(), NtCreateSection(), NtFlushBuffersFile(), NtfsClose(), NtfsGetFileInformation(), NtfsOpen(), NtfsRead(), NtfsSeek(), NtLockFile(), NtNotifyChangeDirectoryFile(), NtOpenFile(), NtQueryDirectoryFile(), NtQueryInformationFile(), NtQueryVolumeInformationFile(), NtReadFile(), NtSaveKey(), NtSaveKeyEx(), NtSaveMergedKeys(), NtSetInformationFile(), NtSetVolumeInformationFile(), NtUnlockFile(), NtWriteFile(), OpenAndMapFile(), OpenFile(), PopAddRemoveSysCapsCallback(), PrintNameTable(), ProtectBootIni(), PsLocateSystemDll(), QueryFileInfo(), ReadBlock(), ReadLines(), RegRestoreKeyW(), RegSaveKeyW(), RtlCreateBootStatusDataFile(), RtlGetSetBootStatusData(), RtlLockBootStatusData(), RtlSetIoCompletionCallback(), RtlUnlockBootStatusData(), SaveBootSector(), SetFileAttributesW(), SetFileSecurityW(), SetLastWriteTime(), SetupDeleteFile(), SmpDeletePagingFile(), SmpGetPagingFileSize(), SmpInitializeKnownDllsInternal(), SmpProcessFileRenames(), START_TEST(), Test_ApphelpCheckRunApp(), Test_ImageSection(), Test_ImageSection2(), TestAllInformation(), TestProviderInfo(), TestRead(), TestRelativeNames(), TestSharedCacheMap(), TestWrite(), TouchFileTimes(), UnprotectBootIni(), VfatFormat(), VfatxFormat(), WaitNamedPipeW(), WritePartitions(), xHalIoAssignDriveLetters(), and xOpenFile().

◆ Options

TCHAR* Options[MAX_OPTIONS]

Definition at line 44 of file stats.c.

Referenced by _tmain(), and IsOptionSet().

◆ SkipEmptyLines

BOOLEAN SkipEmptyLines

Definition at line 41 of file stats.c.

Referenced by _tmain(), PrintStatistics(), and ReadLines().

◆ StatInfoList

PFILE_INFO StatInfoList

Definition at line 40 of file stats.c.

Referenced by AddFile(), and Initialize().