|
|
hi,
i have been given a project titled "source code parser and code counter in PERL". i have to come up with a system that actually counts lines of codes involved in a folder. as im new here, i have no idea at all and im not exposed to PERL before. is there anyone that can guide me step by step on how to do that..?
its very urgent....
geetha
|
|
|
|
|
|
void CLineCounterDlg::OnFileCount()
{
...
// Handle non asolute paths a little better
char dev = 0;
if (*(dir+1) == ':')
dev = *dir;
while (item)
{
filename = new char[dir_size + strlen(item->filename) + 1];
if (*item->filename == '\\' && dev)
sprintf(filename, "%c:%s", dev, item->filename);
else if (*(item->filename+1) == ':')
strcpy(filename, item->filename);
else
sprintf(filename, "%s%s", dir, item->filename);
ProcessFile(filename, item);
**********************************************
_counter_data count(const char* _filedata_, unsigned int _datalen_)
{
...
// put all the count logic into 'isgoodline' bool _recall_ = false,
_ignore_cmnt_ = false;
do
{
_this_line = NULL;
_this_line = findline(_file_data + _last_, _size_);
if (_this_line)
{
char *_token_line = new char[_size_ + 1];
unsigned long _token_size = tokenize(_file_data + _last_, _size_, _token_line);
_last_+=_size_ + 2; // "\r\n"
if (!_token_line || _token_size <= 0)
{
data._blank_++;
delete [] _token_line;
continue;
}
isgoodline(data, _token_line, _token_size, _recall_, _ignore_cmnt_);
delete [] _token_line;
}
} while(_this_line);
*************************************************
void isgoodline(_counter_data &data, char *_token_line, unsigned long _token_size, bool &_recall_, bool &_ignore_cmnt_)
{
bool _save_recall_ = _recall_;
bool ret = false;
int _line_sz = _token_size;
char *_start_ = NULL;
char *_end_ = NULL;
char *_eol = _token_line + _token_size,
_eol_char;
if (!_token_line)
return;
// null terminate the line
_eol_char = *_eol;
*_eol = 0;
if (!_recall_)
{
_ignore_cmnt_ = false;
_start_ = strstr(_token_line, "//");
if (_start_)
{
if (strncmp(_token_line, "//", 2))
{
// comment not at beginning of line
if (strlen(_start_) == 2)
{
// empty comment
data._lines_++;
}
else
{
data._lines_++; // code before the comment
data._comnt_++;
}
}
else
{
// comment at beginning of line
if (strlen(_start_) == 2)
{
// empty comment
data._blank_++;
}
else
data._comnt_++;
}
}
else
{
_start_ = strstr(_token_line, "/*");
if (_start_)
{
_end_ = (char*) strstr(_start_+2, "*/");
if (_end_)
{
if (strncmp(_token_line, "/*", 2))
{
// comment not at beginning of line
data._lines_++; // code before the comment
if (strlen(_start_) != 4)
data._comnt_++; // not empty comment
}
else if (strlen(_start_) != 4)
data._comnt_++; // not empty comment
else
data._blank_++; // empty comment
}
else
{
_recall_ = true; // start of multiline comment
if (strlen(_start_) == 2)
data._blank_++;
else
data._comnt_++; // not empty comment
}
}
else
data._lines_++;
}
}
else
{
// look for CVS tag inside multiline comment
// and ignore all the comments after it (in this block)
if (!_ignore_cmnt_ && strstr(_token_line, "$Log$"))
_ignore_cmnt_ = true;
_end_ = (char*) strstr(_token_line, "*/");
if (_end_)
{
_recall_ = false;
if (strncmp(_token_line, "*/", 2))
{
// comment not at beginning of line
if (!_ignore_cmnt_)
data._comnt_++;
else
data._blank_++;
}
else
data._blank_++;
}
else if (!_ignore_cmnt_)
data._comnt_++;
else
data._blank_++;
}
*_eol = _eol_char;
}
**********************************************
Also the way the percentage of comments to total lines is kind of irrelevant. Its more useful to
measure % comments to # of source lines.
But this was real useful to me to get a quick handle on a project I work on and create a spreadsheet from the results.
Thanks
Ray
|
|
|
|
|
it will be convenient to merge all the source file into one file for printing or what ever. MS never provide a way so that I can print whole project in one "pushing"
good job! so 5 pt from here
|
|
|
|
|
Actually Visual Studio 6 does at least provide a way for you to print all open documents. It is one of the sample Macros. I am sure that with a little tweaking you can edit the macro such that it does not require the documents to be open in order to print (i.e. it will open them to print, then close them.
|
|
|
|
|
Ok so I just wrote a simple FTP server and I wanted to know how much lines I used.
Anyway, it seems that your program doesn't count lines for all C++ styles. A file with 664 lines returned 0 lines in every fields. thats not normal.
The files that were counted incorrectly were not written by me, but they do compile.
Oh and I don't like your user interface. The menu's are simply not useful and there shouldnt be any Count item. simply count the lines on file open. Its just a waste of time for the poor user.
oh well.
heres a sample of my stack.cpp (which returns 0 lines, I can guarantee that its wrong):
<br />
#include "stack.h"<br />
<br />
int StackNotEmpty(stk_stack * theStack) {<br />
return( theStack ? (int) theStack->top : 0);<br />
}<br />
<br />
stk_stack * StackJoin(stk_stack * stack1, stk_stack * stack2) {<br />
if (!stack1->tail) {<br />
free(stack1);<br />
return(stack2);<br />
} else {<br />
stack1->tail->next=stack2->top;<br />
stack1->tail=stack2->tail;<br />
free(stack2);<br />
return(stack1);<br />
}<br />
}<br />
|
|
|
|
|
why don't you count lines in *.rc* files?
|
|
|
|
|
Well, I find the project interesting, and since i've never put a contribution of mine on the web site, i should not be allowed to write what follows, but : the code itself is really .... ugly . Maybe that's why this article is not in the programming sample. However, this works, and that's the point, i think
~RaGE();
|
|
|
|
|
please write software that has real use. See my article:
Here
|
|
|
|
|
Actually, for people tasked with estimating software project costs, this is pretty useful. SLOC (Source Lines of Code) is a common measure for the size of a program. When estimating Project Costs, it is useful to run this utility on similar past projects to get a good estimate on future projects.
The most difficult question to answer is : "How long will it take?"
Doug Kimzey
COO
PC Engineering, Inc.
|
|
|
|
|
Interesting, since my experience is that its the figuring out what code to type, rather than the amount typed that has an impact on the project's budget.
But then, what do I know....Im just a programmer....
|
|
|
|
|
kokie wrote: please write software that has real use. See my article:
Here
If you don't need it, ignore it. What did your comment add to the discussion, other than a blatant pointer to something you contributed that has nothing to do with the topic at hand?
|
|
|
|
|
kokie wrote:
please write software that has real use. See my article:
Here
Apparently his code is more useful than yours, seeing as yours has a 2.81 out of 5 rating and this article has a 4.55 out of 5 rating.
Nelno
|
|
|
|
|
I think that this program is a good measurement tool to see how much of the code is commented.
A usefull program is a live program. Always changes, new tasks are added and often old code is reviewed. A well written and well commented code is easier to change and debugged.
What if you write a program, don't write a single line of comment, go to a different project, and three years after you have changed project, that old customer comes back because he found finally some forgotten bugs and by the way asks for some changes. Will you be able to do these modifications in the least possible time?
Well maybe you are, but a typical developer won't. Besides code commenting is a sign of a disciplined developer who knows that giving 1 hour today to write some comments will save him 1 day tomorrow.
I don't have bugs in my code. I just have a few features.
|
|
|
|
|
I rate it as 5 pts
|
|
|
|
|
What about starting from a WorkSpace: .dsw file.
Best regards,
|
|
|
|
|
Good work. I have a suggestion. U should have put a number for each line at the time of viewing the file.
|
|
|
|
|
What about those constructions:
int n; //counter
or
/*
This is a very useful
help about the function
*/
|
|
|
|
|
I must not use Java, .Net is the way...
I must not use Java, .Net is the way...
I must not use Java, .Net is the way...
I must not use Java, .Net is the way...
I must not use Java, .Net is the way...
I must not use Java, .Net is the way...
Damn these blackboards....
Stephen Kellett
--
C++/Java/Win NT/Unix variants
Memory leaks/corruptions/performance/system problems. UK based.
Problems with RSI/WRULD? Contact me for advice.
|
|
|
|
|
|
Java is the way to platform independence, .Net is what MS wanted to do with Java - extend, "improve" - thus making it incompatiable with anything else.
Java is the way to go. I program in .Net at work and it's alright - but if you have a choice go Java. Java is more mature and the J2EE is proven.
Once you go .Net you are hopelessly locked into the MS way. For instance do you know that Windows 2000 support is going to end in 2005? Forced upgrades, closed source core products... think about it...
/**********************************
Paul Evans, Dorset, UK.
Personal Homepage "EnjoySoftware" @
http://www.enjoysoftware.co.uk/
**********************************/
|
|
|
|
|
Hm... There is a nice line counting free utility:
http://www.wndtabs.com/plc/
|
|
|
|
|
I had no idea about that program (wndtabs.com/plc/).
This program was written in a saturday night when my fried and me were trying to relax.
_declspec
|
|
|
|
|
Also wndtabs looks better, it uses worspaceWiz (shareware ?). I vote
for this project because it is self-contained.
Brian
|
|
|
|