Typos Code Comparison

By Typo on Jul 25, 2008

Typos Code Comparison is a little snippet that allows you to easily compare two peices of code. You enter the codes into seperate boxes and simply hit the "Compare" button and it will tell you how many lines and bytes are in each code and what the total difference is.

I have included bracket check buttons for each code entry box that will alert you if there is a bracket mismatch when pressed. It also searches for any brackets that mirc would ignore and warns you if any are found incase they were accidental. This will also trigger on good code too like in $regex($1-,/}/g) so it doesn't always point to an error. These two bracket checks are done at the same time but report differently if a problem is found. It is easy to tell which is the mismatch check and which is the extra bracket check.

I have included an Always On Top button that will set the window to be always on top of other windows and when pressed again will undo the on top setting. The button changes names to make it clear if it will be setting or unsetting the on top setting.

I have also included a button to clear all fields for when you want to start over.

Enjoy.

Image

;begin Typos Code Comparison
menu * {
  -
  <[Typos Code Comparison]>:compare 
  -
}
alias compare dialog $iif($dialog(compare),-ev,-md) Compare Compare
dialog Compare {
  title "Typos Code Comparison"
  size -1 -1 191 256
  option dbu
  button "Paste Code 2", 3, 77 112 40 12
  button "Done", 4, 78 239 37 12, default ok cancel
  button "Paste Code 1", 5, 76 26 40 12
  button "Compare Codes", 6, 75 198 42 12
  edit "", 1, 4 40 183 64, multi return autohs autovs hsbar vsbar
  edit "", 2, 4 126 183 64, multi return autohs autovs hsbar vsbar
  box "", 9, 2 20 187 87
  box "", 10, 2 106 187 87
  box "", 11, 2 192 187 41
  text "Enter the codes to be compared into each box and then press the compare button.  Using the paste button will not erase the text first.", 12, 12 5 166 13, center
  text "Pressing Compare Codes will replace this text with information about the differences in the codes.", 7, 15 214 161 13, center
  box "", 16, 14 209 164 20
  button "{ }", 17, 176 26 10 12
  button "{ }", 18, 176 112 10 12
  button "Stay On Top", 19, 5 243 39 8
  edit "", 39, 4 25 183 154, hide disable read
  text "", 40, 6 66 179 74, hide disable center
  box "", 41, 2 20 187 173, hide disable
  button "OK", 42, 77 179 37 12, hide disable
  box "", 43, 9 0 172 21
  box "", 44, 2 237 46 17
  box "", 45, 75 233 43 21
  box "", 46, 143 237 46 17
  button "Erase all fields.", 47, 146 243 39 8
}
on *:dialog:compare:sclick:3:{
  var %tmpcbnum $cb(0), %tmpnum = 1
  while (%tmpnum <= %tmpcbnum) {
    did -az compare 2 $iif(%tmpnum > 1,$crlf) $+ $cb(%tmpnum)
    inc %tmpnum
  }
}
on *:dialog:compare:sclick:5:{
  var %tmpcbnum $cb(0), %tmpnum = 1
  while (%tmpnum <= %tmpcbnum) {
    did -az compare 1 $iif(%tmpnum > 1,$crlf) $+ $cb(%tmpnum)
    inc %tmpnum
  }
}
on *:dialog:compare:sclick:6:{
  if ($did(compare,1).lines == 1) && (!$did(compare,1,1).text) || ($did(compare,2).lines == 1) && (!$did(compare,2,1).text) {
    noop $input(You must enter a code in both code entry boxes before trying to compare them.,ouwd,Error! Nothing to compare!)
    return
  }
  filter -gifc compare 1 tempcompare.tmp /[^(?:^$)]/
  var %tmplines1 $lines(tempcompare.tmp), %tmpsize1 $calc($file(tempcompare.tmp).size - 2)
  filter -gifc compare 2 tempcompare.tmp /[^(?:^$)]/
  var %tmplines2 $lines(tempcompare.tmp), %tmpsize2 $calc($file(tempcompare.tmp).size - 2)
  var %tmpcompmsg1 $remove($calc(%tmpsize1 - %tmpsize2),-), %tmpcompmsg2 $remove($calc(%tmplines1 - %tmplines2),-)
  did -raz compare 7 Thats %tmpsize1 byte $+ $iif(%tmpsize1 > 1,s) in %tmplines1 line $+ $iif(%tmplines1 > 1,s) versus %tmpsize2 bytes in %tmplines2 lines for a difference of %tmpcompmsg1 byte $+ $iif(%tmpcompmsg1 > 1,s) and %tmpcompmsg2 line $+ $iif(%tmpcompmsg2 > 1,s) $+ .
  .remove tempcompare.tmp
}
on *:dialog:compare:sclick:17:{ $checkbrackets(1) }
on *:dialog:compare:sclick:18:{ $checkbrackets(2) }
on *:dialog:compare:sclick:19:{
  dialog - $+ $iif($did(compare,19) == Stay On Top,o,n) compare
  did -a compare 19 $iif($did(compare,19) == Stay On Top,Undo On Top,Stay On Top)
}
on *:dialog:compare:sclick:42:{
  did -hb compare 39-42
  did -ve compare 1-3,5,9-10,17-18
}
on *:dialog:compare:sclick:47:{ 
  did -r compare 1-2,7
  did -a compare 7 Pressing Compare Codes will replace this text with information about the differences in the codes.
}
alias checkbrackets {
  var %tmpdola1 = $1, %leftbracketcntfull = 0, %leftbracketcnt = 0, %rightbracketcntfull = 0, %rightbracketcnt = 0
  if ($did(compare,%tmpdola1).lines == 1) && (!$did(compare,%tmpdola1,1).text) {
    noop $input(You must enter a code before trying a bracket check.,ouwd,Error! Nothing to check!)
    return
  }
  var %dlines $did(compare,%tmpdola1).lines
  while (%dlines ) {
    if ($regex($did(compare,%tmpdola1,%dlines).text,/((?::|\s|^){(?:\s|$))/g)) { inc -u2 %leftbracketcnt $regml(0) }
    if ($chr(123) isin  $did(compare,%tmpdola1,%dlines).text) { inc -u2 %leftbracketcntfull $count($v2,$chr(123)) } 
    dec %dlines
  }
  var %dlines $did(compare,%tmpdola1).lines            
  while (%dlines) {                       
    if ($chr(125) isin $did(compare,%tmpdola1,%dlines).text) { inc -u2 %rightbracketcntfull $count($v2,$chr(125)) }
    dec %dlines
  }
  var %tmpcnt $did(compare,%tmpdola1).lines, %rightbracketcnt = 0
  while (%tmpcnt) {
    tokenize 32 $did(compare,%tmpdola1,%tmpcnt)
    if ($1-) { var %tmpnumba $iif($2- != $null,$numtok($1-,32),1) }
    while (%tmpnumba) {
      if ($ [ $+ [ %tmpnumba ] ] == $chr(125)) { inc %rightbracketcnt }
      dec %tmpnumba  
    }
    dec %tmpcnt
  }
  if (%leftbracketcnt == %rightbracketcnt) { var %tmpmsg = Your brackets appear to be all matching up. $crlf, %tmpnotright = yes }
  else { var %tmpmsg = %tmpmsg You have a bracket mismatch. $crlf }
  if (%rightbracketcnt != %rightbracketcntfull) || (%leftbracketcnt != %leftbracketcntfull) { var %tmpmsg = %tmpmsg There seems to be $calc((%leftbracketcntfull - %leftbracketcnt) + (%rightbracketcntfull - %rightbracketcnt)) brackets that mirc will not recognize as valid. This doesn't always mean there is an error as sometimes you might use $chr(125) in the code itself like the $chr(125) found in $!regex($1-,/}/). }
  elseif (%tmpnotright == yes) || (%leftbracketcntfull) && (%leftbracketcnt) && (%rightbracketcntfull) && (%rightbracketcnt) { var %tmpmsg = No bracket errors detected. }
  var %tmpmsg = %tmpmsg $crlf $crlf $crlf Press OK to to return to the code entry boxes.
  did -hb compare 1-3,5,17-18,9-10
  did -ev compare 39-42
  did -b compare 39
  did -a compare 40 %tmpmsg
}
;end Typos Code Comparison

Comments

Sign in to comment.
Eugenio   -  Sep 26, 2008

ROFL @ sam
agreed!

 Respond  
Typo   -  Sep 26, 2008

This script was honestly something I almost didnt release, it was done on a whim and in between other projects.

I meant to come back and do an update to show both file sizes as discussed above but honestly completely forgot until now. I'll try to remember to do it the next time I have nothing to code and some free time on my hands.

Thanks for the rating and the comment.

 Respond  
^Neptune   -  Sep 26, 2008

stfu Lindrian :<

This script is kinda nice, although not the most useful thing in the world. I think it would be nicer to place the bytes statements under each of the seperate script boxes.

Anyways, although I don't exactly thing it's highly useful, i'll rate it 8/10. Does what it says on the tin, and that's all that matters.

 Respond  
Lindrian   -  Jul 30, 2008

Yes ,that is entirely up to you how you wish to return the values. But when you actually count the size of a snippet, you use the algorithm i posted.

Trailing and leading spaces are never accounted for :P, thats just the way its always been.

And what $file().size really is counting, is the additional data windows saves, and not the content itself only.

Just to show what I mean:
Image (If you look at the acual size, you see its 1 byte)

But then again, several options on how to count would be nice. Definitely a improvement.

 Respond  
Typo   -  Jul 30, 2008

Look, I understand what your staying and have from the beginning but you don\'t seem to understand what I\'m saying.

I\'m not counting characters. I\'m counting the size of the whole code. Maybe I do it differently than scripting competition comparison scripts but I do so on purpose.

In order to actually use a code it must be saved into a file and doing so makes it so the carriage returns and spaces do count for something.

And your right, the $file().size does count leading and trailing spaces but that\'s because they actually affect the file size. In every test I\'ve tried the $file().size matches exactly with the reported file size from windows.

Like I said before, I\'m probably going to add options to select how the bytes are counted, either literally, like the examples you gave or actual file size like I\'ve been doing.

I\'ll get on that tomorrow as I\'m working on something else at the moment.

 Respond  
Lindrian   -  Jul 30, 2008

If you say so.

(11:01:37) (@Kol) $file().size tends to be innacurate
(11:01:41) (@Kol) Due to extra information stored with the file
(11:02:19) (@Kol) and $file().size counts trailing/leading spaces i believe

Those 2 extra bytes are the information stored in the file, besides what you wanted to save.

 Respond  
Typo   -  Jul 30, 2008

Look, fact is, if I changed the code and made the reported code size start not matching the file size, I would get complaints and in my opinion rightfully so.

It makes NO sense to say \"My code is 100 bytes unless you save it in a file and then its more than that because I used more than one line.\"

I had to decide how I was going to count the bytes for this script first thing when I started and I decided to do it this way because it just makes sense to have the code size match the size it will be in a file. Afterall, we do keep codes in files in the real world and in that real world a carriage return cost 2 bytes. I already made one exception to this by not counting completely blank lines in the code sizes.

We both know I could easily change this but the problem I have is that everybody else seems to like it as it is except for you.

And btw the third website you posted doesnt even exist.

Just because something is done differently doesnt make it wrong.

Perhaps I will add an option to select the way it does its count. MAybe make it so you could chose to count either by the actual character count like you wish or by file size like I have it and I could even add an option to count blank lines or not at that point. I\'ll think on that.

 Respond  
Eugenio   -  Jul 29, 2008

bloody hell
rofl

 Respond  
Lindrian   -  Jul 29, 2008

When dealing with code-byte counting, you\'re way off.

It\'s done like the following sites/scripts show:

http://h1.ripway.com/Chessnut/count.htm
http://forum.swiftirc.net/viewtopic.php?t=11738
http://www.mightscript.com/count.html

And I criticized your coding and tried to help, because I know you have potentional to do so much better.

 Respond  
Eugenio   -  Jul 29, 2008

Typo mate seriously dw, your codes work, and do what they are meant to without 1,000,000,000 lines of regex.

 Respond  
Typo   -  Jul 29, 2008

I will do my best to just ignore the fact that your technically dogging on every script I have released by attacking my style of coding which nobody else seems to have a problem with, tho I do wonder why you single me out with so many better examples of sloppy coding spread throughout hawkee.

Atleast take a minute and explain why you say the byte count is off.
I have asked over and over for you to explain why you say its wrong but you won\'t.

I will give new examples as to why my method is correct because apparently the examples above werent enough. First off. You keep saying the byte count is wrong but windows and mirc seem to agree with me. I used windows and notepad for my examples before so I will try different methods this time.

New example one:
Type the following in any window and it will show you that 2 characters dont always mean 2 bytes. You have to consider the carriage return.

//write -c testbyte.temp a | write -n testbyte.temp b | echo -a The file size is $file(testbyte.temp).size bytes. | .remove testbyte.temp

It writes the letter A to the first line in a new file called tempbytes.temp and then writes the letter B in the second line. After that it echos the size of the file we just made to the active window and then it deletes the file.

In the Write commands the -c parameter clears the file first if it exists and the -n parameter stops it from adding a $crlf to the end of the added line. (Without the -n a new line is started so the file size would be 6 bytes and not 4).

New example two:
Use alt+r in mirc to open the script editor in the remotes tab. After ensuring you are in the remote tab goto File and then select New. This will start a new remote file and the name of it will be visible in the lower left corner and is usually something like script1.mrc. Write two lines of one letter each and then hit ok to save and close it but be sure you remember the file name or write it down. Now just type

//echo -a $file(scriptfile.mrc).size

Where scriptfile.mrc would be replaced with the new script file you made. For me the line was \"//echo -a $file(script4.mrc).size\".
You will see the file is 6 bytes. This is because mirc, like the write command, automatically adds the carriage return at the end of the last line so the next line exists to recieve text so its adding a blank line to the end of the file.

The script also uses the $file().size method to get the size of the code so the repeated statements of innacurate byte count still confuse me.

See, the point of my script is to compare codes which it does very well and if I counted the byte size differently I dont think it would be considered accurate by anybody except Lindrian. Why should I have my reported codes size not match the actual file size it will be when its saved in any program whether it be notepad or in mirc or whatever else? I wouldnt consider those real world results.

BTW: I never said I didnt need a lesson in regex, infact Ive repeatedly said in several posts that Im trying to learn it and before this whole mess I was actually trying to remember who had offered me regex help on some server if I went (it was u I remember now obv) but I couldnt remember who.

 Respond  
Eugenio   -  Jul 28, 2008

ROFL @ showing a pic to someone over the fone.

 Respond  
Lindrian   -  Jul 28, 2008

EL, this would be like trying to show a picture to someone over the phone, it\'s just so much easier showing them it. And if he did not want to communicate over IRC, it is his own loss and not mine. I offered my help, he declined, end of story.

 Respond  
EL   -  Jul 28, 2008

I don\'t dispute your status i know your one of the more capable on hawkee.Maybe just explain in a comment what the error corrections should be jsut enuff for him to gain the grasp of the errors and not have to go into teachin him everything.Some ppl cant devote time to connect to other servers an take a course.Whats easyer for you maybe be easyer for him.And the middle ground is hawkee.So i dunno if you don\'t wanna help im that\'s fine by him i guess as for myself im justa n00b so what do i know.`-.-´

 Respond  
Eugenio   -  Jul 28, 2008

rofl @ unefficient
and hes 19 ?!?
:o
/me faints

 Respond  
Lindrian   -  Jul 28, 2008

EL: I would be more than happy to help, I have not earned my status on several sites because I am not willing to help. But people like Typo do piss me off. I tried inviting him for a mature conversation on a server im active on (not my own), so I could in depth explain everything, since it would be 100x easier.

I, myself, am 19 years old, soon 20.

And I rated this a 3 because:

1) Regex patterns are not correct
2) Coding is unefficient
3) The byte-counting is invalid.

In my opinion, a script like that is \"Not useful\" - 3.

 Respond  
Jonesy44   -  Jul 28, 2008

Hehe, i did pretty dam soon, cos i\'m so lazy.

I suck at regex, so i cant really help there, sorry.

 Respond  
Typo   -  Jul 28, 2008

Thanks jonsey, thats one of the bad habbits I have that I was talking about above, its fixed now. I noticed another == 0 and two more != $nulls that I got rid of too.
I just wish I could have got the regex to work for me for the right bracket check. I ended up using the method in my code because no matter what I did I couldnt get the right bracker search regex I came uo with catch the second } in } } but it caugth it EVERYWHERE else I needed it to. Thats the one part of this code I do personally think could be better. Dont get me wrong, it works just fine, its just if I had nailed the regex the code would be a few lines smaller.

Anyhow, thanks for the comment. I really need to break myself of that habbit and I think I finally will.
edit
On a closer look I found quite a few more if $v1 == $null or != $null or == 0 that I also fixed. Told ya it was a bad habbit. Those must be the horribly messy coding that Lindrian was talking about. Im just a horrible person I know. Lol :P
edit

 Respond  
Jonesy44   -  Jul 28, 2008

Just a tip, with the regex. it can be just \"if ($regex())\" rather than \"if ($regex() > 0)\"

 Respond  
Eugenio   -  Jul 28, 2008

lmao this code aint incomplete foo
does the job
no one here is a \"kid\" as I dont see any baby goats T_T
its the way Typo codes so gtfo, just coz he doesnt use a billion lines of regex like joo doesnt mean the code dont work rofl FAIL
gettin your tampon in a twist over nothing, shut joor mouf

 Respond  
Typo   -  Jul 28, 2008

No kidding, Imagine if I couldnt have fixed the regex on my own or if he had actually been right about the file size issue. If either of those were true I would STILL be waiting for the information I needed to fix it.

Thats his definition of help.

 Respond  
EL   -  Jul 28, 2008

Ok yeah Lindrian thats just childish rating this a 3.And you sit there callin him a kiddie? why are you commenting an when asked to explain your comment you refuse? doesn\'t make much sense man.You posted a comment to help and the coder doesn\'t understand and asks you to explain so he can better understand and learn ETC.Yes you did offer further help on your server but why not throw down the explanation rite here like the rest of us?.You mite as well have said /help $regex.and btw how old are u?.`-.-´

 Respond  
Typo   -  Jul 28, 2008

Im 29 years old jack ass and if you could just once explain how something is wrong people might actually believe you.

I never asked you to argue.

ALL I EVER ASKED FROM YOU IS TO EXPLAIN YOURSELF!

Your the one acting like a child.

 Respond  
Lindrian   -  Jul 28, 2008

I will not argue with stubborn kids, which is why im not going to explain myself. I think your entire code is rubbish; every aspect I look at it, somethng is wrong.You\'re one of those kids who think you\'re right even thought you\'re wrong, and will not accept the fact that you were wrong.

 Respond  
Eugenio   -  Jul 28, 2008

rofl typo leave it
fucking FAIL
good code 9/10 nuff said

 Respond  
Typo   -  Jul 28, 2008

Lol at your newest edit of your last comment, You think you actually tried to help me? You never once did anything but say stuff is wrong. Not once did you explain why its wrong, how its wrong or how to fix it.

Your an ass!

 Respond  
Typo   -  Jul 28, 2008

I love how you still cannot even try and explain yourself.

How is the file size wrong?

How is the file size example wrong because if the file size is than it must be too?

I didnt say I knew anything. All I wanted from you was an explanation of your own comments and you cant even manage to backup your own words.

You made a comment on my regex without even giving me an example of what I should have used and I immediately responded with updated code that fixes it even tho I forgot to update the script with it and even if you didnt know what I was trying to do I made a response to you with the new code that detailed what I was trying to do and your too stupid to even read it. You made the same regex comment today which makes it obvious you didnt read a single thing in my replies to you.

Also, you called my code messy and wont back that up either.

I would have deleted the comment too if I had made it, you looked like an idiot.

To everyone else: By this pooint I have hopefully made it clear that Lindrians comments were made in error. I have given him muliple chances to explain himself and he basically refuses.

The file size is fine, the script is fine. The problems all lye within lindrian and his inability to backup anything he says.
This whole thing started with a comment from him that said

ok, im not sure how ur calculating those bytes, but its definitely wrong.

And your regexes are totally messed up aswell, /[^(?:^$)]/ means \"match the following literals: ^(:?$) (and the ^ is even duplicate - I really doubt this is what you\'re trying to do).
And he was right about the regex, which is fixed, even tho the script was still working fine but what strikes me is the statement \"ok, im not sure how ur calculating those bytes, but its definitely wrong.\". Does it really take that much effort or expertise to look at the code and see I\'m using mircs own $file().size? I would think that someone qualified to call my coding messy would be able to figure out how I was calculating the file size.

I\'m done now.

If anyone cares to see it here is the comment Lindrian deleted after making.

Byte are not counted like that typo. Each character is one byte, trailing and leading spaces are not accounted for.
And that regex would match anything but (, ?, :, ^, $, ) - is that what you\'re trying to do?
I mean not offense at all, but your code (coding style?) feels quite messy, if you want, I can teach you some \'better\' coding (im not trying to brag, really) and how to properly master regex. If you\'re up for it, I\'ll be at: irc.deltaanime.net @ #Lindrian

 Respond  
Lindrian   -  Jul 28, 2008

I deleted my own comment, as you seem to know perfectly well on how to do what you want to do.

By having that said, this is the last time I am going to interfere in your business & and try to help. You can get help from others.

 Respond  
Typo   -  Jul 28, 2008

Updated with the regex line I meant to change a few days ago. Even tho the old regex wasnt right it still worked right for some reason so this doesnt really affect functionality but it is definately a recommened update.

 Respond  
Typo   -  Jul 28, 2008

If bytes are not counted like that then why is it that my following example is valid? And BTW, who the hell was talking about spaces at all? Trailing or leading spaces have nothing to do with anything Ive talked about yet. Its the carriage returns.
Do you even know how to read a response to your own comment?

For instance, weve all been taught that a single character is one byte so the following:

A
B

would look like it should be 2 bytes but we would be forgetting the 2 bytes for the carriage return needed to start the second line.
If you start a new file and save it with the above lines you will see when looking at the file properties that it is 4 bytes and not 2.
Did you even try that?
You can say all day long that file sizes dont work that way but your wrong. Its simple, start a new file, make two lines of one character each and save it, check the file size in windows and by using $file().size as well. It will never equal 2 bytes even tho its two characters.

The script just compares 2 codes anyway, I could theoretically account for the carriage returns and take it out of the file size so it compares actual used characters but then nothing would match actual file sizes and I see no point in that.

Now on to the regex. You know I am learning regex and in the comment I made to you in this thread I mentioned that I realized you were right about the regex and came up with a fix and told you what it was that I was trying to do.

The following lines are from the tutorial @ http://www.hawkee.com/phpBB2/viewtopic.php?t=9764 .
[quote]
To negate a character group (meaning \"anything but\"), use a ^ character.
Also remember that you still have to escape special characters inside a character group. People tend to forget that for some reason.
$regex(abcdefg,/[^a-e]/g) -- Returns 2 because 2 letters (f and g) satisfied the character group of \"anything but a-e\"

Im sure you get what I was trying to do now but Im guessing by your comment that my method is wrong so Ill look into changing it with another method or a better regex right now. Off the top of my head I think just using /(^(?!$))/ should be fine but I need to make positive first .[/quote]
I thought I had upgraded the code to the regex I mentioned in the above quote which was addressed to you but apparently I didnt so I will do so now. The new regex is /(^(?!$))/ and it seems to work great for me. I even did a test using /filter with -x to make it send the non matching lines and it did kick back the blanks.

Had you actually read what I typed in response to you instead of making the rude comment above you could have just mentioned that I needed to do the update I forgot to do so and if the new regex is actually wrong than you definately could have caught that too and since I went into detail to you what I was trying you actually could have helped me without inviting me to your network again.

I mean not offense at all, but your code (coding style?) feels quite messy, if you want, I can teach you some \'better\' coding (im not trying to brag, really) and how to properly master regex. If you\'re up for it, I\'ll be at: irc.deltaanime.net @ #Lindrian
Who the hell would not take offense to that?
I want to know what about my coding style is messy, sure Im learning regex and your better than me at it but what about my coding exactly is it that you find messy?
Sure I use the if $1 == $null instead of if $1 and a couple other things like that that I consider bad habbits but compared to most my code is damn clean and easy to follow.

I decline the invitation to your network but I do reccomend in the future that you keep your posts less opinion and more factual.
Why tell someone somethings wrong and not why or how to fix it. Why say a file size is wrong when you dont even look at the code to see that its $file().size thats getting the size so it has to be right. Why for the second time dong on my regex without reading my response to you and helping me actually fix it. And btw, helping here is much more appropriate than making people come to your network.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.