SRL Archive - Test corner

Procedure/Function Counter


Garrett

2008-02-14 00:40:59

Counter made for SCAR Scripts

This could be used to help you make decisions for SRL Members.

What does it do?
Just counts the words in the script, like radialwalk, for example.
Then, it spits out the amount of times it is used.

Features:
Use your own words to search
Removes all the comments

Link:
http://garrett92.freehostia.com/Counter

R0b0t1

2008-02-14 13:25:32

This seems like it will take a long time… search through a 3000 line file for something like 20 words…?

Garrett

2008-02-14 14:12:06

eh… does it really fast for me.. It can give the results in less than a second, I tested it on a srcipt with 2657 lines.

ShowerThoughts

2008-02-14 14:20:27

nice, good job looks intresting

Garrett

2008-02-14 15:06:42

I made a new function for it… it doesn't count custom procedures :D …
Oh, and now it is slower, that new function makes it take about extra 5 sec :p
I'm still working on it though, because it isn't counting it all correctly anymore.

EDIT
Uploaded the new source
I think I fixed it… correct me if I'm wrong

The only problem now: it counts the things in comments

Something I will do is add some textboxes so you can search some procedures that might not be on there… like custom procedures or something.

EDIT
Fixed the comment problem, it deletes all the {} and everything inside of them.
All it does now is count the stuff in // comments, which I think it should be fine.
Also, I added in the stuff for custom procedures.
I updated the source

munk

2008-02-14 18:08:14

why dont you just use the same idea with the brackets, and make it not count anything in // to the next \n

Garrett

2008-02-14 18:12:17

Ah.. thats a good idea, lol
I didn't think of that, thanks

Btw.. just updated my script again,
I made it so it can use unlimited custom searches… just remember: the more you have, the longer it is going to take to process it.

Edit
I just tried to do what you said… but it didn't work

munk

2008-02-14 18:33:11

From: Garrett92
Ah.. thats a good idea, lol
I didn't think of that, thanks

Btw.. just updated my script again,
I made it so it can use unlimited custom searches… just remember: the more you have, the longer it is going to take to process it.

Edit
I just tried to do what you said… but it didn't work


:/ im sure theres a way to do it. Is there html entity for a new line? &space;? Im in school and bored so Im gonna look some stuff up. Ill edit.


EDIT: Nah, not html entity for line break. Can I also ask why you didnt use regular expressions?

Garrett

2008-02-14 18:48:57

From: munk
:/ im sure theres a way to do it. Is there html entity for a new line? &space;? Im in school and bored so Im gonna look some stuff up. Ill edit.


EDIT: Nah, not html entity for line break. Can I also ask why you didnt use regular expressions?


what do you mean by regular expressions?

munk

2008-02-14 18:56:01

From: Garrett92
what do you mean by regular expressions?


do you do PHP alot? preg_replace?!

regex(as its more commonly known) = regular expressions

Its actually a Perl thing, but its just basically manipulating strings.

Garrett

2008-02-14 19:33:05

I used to do quite a bit php, not as much anymore though… but I've really only gotten into the basics, mainly php + mysql for website logins and ect. not much else. Though, looking at some of those commands make it look like I could have made this easier.

Edit:
I added the ability to download results, but it doesn't include the custom stuff in it yet… It is just a text file.

munk

2008-02-14 23:13:17

[php]
$str = preg_replace("/(\/\/)(.*?)(\n)/si", "",$str);
[/php]

:D that should take care of all // comments, turn them into "" (nothing)

also your whole substr_count function could be

[php]
Function substr_count($str, $text)
{
preg_match_all("/\S".$text."\S/",$str,$match);
$lines = count($match[0]);
return $lines;
}
[/php]
the \S checks for whitespace(  or \n) but it can easily be made to do whatever you wanna do.

http://www.enginsite.com/Library-Perl-Regular-Expressions-Tutorial.htm

:D
hit me up on msn if you want some help

Garrett

2008-02-15 09:05:14

Thanks… the one for removing comments helped. I think it all works perfectly now. I'm just going to leave my counter the same though, just because it works fine.