Click here to Skip to main content
Click here to Skip to main content
Go to top

Code Statistic Assistant

, 2 Mar 2006
Rate this:
Please Sign up or sign in to vote.
A C/C++, Datastrcture and Win32 API Project

Introduce

This project for my deeper understand in C/C++ and Win32 API. I know this implementation is not nice enough, but it runs well. In this file, the program trait will be explain. And give some descriptions about the structure and example. I use the C Version to describte this project, but as you see, you can down a Cpp Version.

Trait


1) Run in command line/with parameters
2) easy to use.
3) statistic file which type include .txt, .C, .C++, .h, .java.
4) it can deal with specific files, or specific directory(include sub-directory).
5) Set valid file for statistic.

Data Structure


The purpose of this secssion is to describe structures. Including
struct LIB , ITEM and CMDMSG. CMDMSG, which i define as command
message, is a message which take parameters and command type use in
CommandExplain.
/*
*The definition of struct ITEM, which use to record the statistic info.
*/
typedef struct ITEM{
char filename[ FILE_NAME_MAX_LEN + 1 ];
char path[ PATH_MAX_LEN + 1 ];
FILE_T type;
long totalLine;
long commentLine;
long bankLine;
long codeLine;
}ITEM, *PITEM;
/*
*The definition of struct LIB, which use to record the LIB info.
*/
typedef struct LIB{
long totalCode; //total line
long comment; //comment line
long bank; //bank line
long code; //code line
long sizTab; //size of table
long HeaderNUM; //header file counter
long CNUM; //C source file counter
long CppNUM; //C++ source file counter
long TxtNUM; //txt file counter
long JavaNUM; //java source file counter
double result; //result = ( comment + bank ) div totalCode
BOOL fStat; //statistic flag
BOOL fModify; //modification flag
TABLE table;
char szLibName[ FILE_NAME_MAX_LEN + PATH_MAX_LEN + 1 ];
}LIB, *PLIB;
/*
*The definition of command message(CMDMSG) & its handle(HCMDMSG).
*Note: firARG is a pointer to first argument, it may be a filename / NULL
* secARG is variable signed state/FILE_T
* pFindArg is a pointer to find argument struct
*/
typedef struct CMDMSG{
CMD_T command;
char *firARG;
int secARG;
PFINDARG pFindArg;
} CMDMSG, *HCMDMSG;

A simple API example


The function StatUnderDirHelp uses Win32 API, FindFirstFile, FindNextFile and FindClose.


static BOOL StatUnderDirHelp(PLIB pLib, char *szDir, char *szType)
{
char szFileName[256];
char szTmpFileName[256];
BOOL flag;
PITEM pItm;
HANDLE hFind;
WIN32_FIND_DATA FindData;

strcpy( szFileName, szDir );
strcat( szFileName, "\\" );
strcat( szFileName, szType );

hFind = FindFirstFile( szFileName, &FindData );
while ( hFind != INVALID_HANDLE_VALUE )
{
strcpy( szTmpFileName, szDir );
strcat( szTmpFileName, "\\" );
strcat( szTmpFileName, FindData.cFileName );
pItm = MakeItem();
strcpy( pItm->filename, FindData.cFileName );
strcpy( pItm->path, szDir );
if ( ( flag = StatFile( pItm, szTmpFileName ) ) == FILE_OPEN_ERR )
{
FindClose( hFind );
FreeItem( pItm );
return FILE_OPEN_ERR;
}
if ( flag != INVAILD_FILE )
{
if ( AddItem( pLib, pItm ) == MEM_EMPTY )
{
FindClose( hFind );
return MEM_EMPTY;
}
}
if ( !FindNextFile( hFind, &FindData ) )
{
break;
}
}
FindClose( hFind );
return SUCCESS;
}

Postscript

Contact me if you have some comments or found bugs.(sense_8@163.com).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

sense_8
Web Developer
China China
No Biography provided

Comments and Discussions

 
GeneralAbout your article... PinmemberGeert van Horrik25-Feb-06 23:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 3 Mar 2006
Article Copyright 2006 by sense_8
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid