mIRC Homepage
Posted By: hixxy Miscallaneous identifiers - 09/02/06 01:23 AM
$rangetok(N,N,asc) - returns a range from N to N separated by asc.
$rangetok(1,5,44) -> 1,2,3,4,5
$rangetok(5,3,46) -> 5.4.3

$reverse(<string>) - returns <string> backwards.
$reverse(hello) -> olleh
$reverse(olleh) -> hello

$blendian(<string>) - converts a string from big to little endian (same as $reverse but swaps every two bytes instead of every byte. Maybe we could specify the number of bytes to swap in $reverse.)
$blendian(1234) -> 3412
$blendian(12345678) -> 78563412

$clsid2progid(<clsid>) - converts a clsid to a progid for use in $com().
$clsid2progid({72C24DD5-D70A-438B-8A42-98424B88AFB8}) -> WScript.Shell
$clsid2progid({0D43FE01-F093-11CF-8940-00A0C9054228}) -> Scripting.FileSystemObject

Not interested in workarounds.. I can make them if need be.
Posted By: PhantasyX Re: Miscallaneous identifiers - 09/02/06 01:59 AM
I concur with the idea of them all.
Posted By: Jigsy Re: Miscallaneous identifiers - 09/02/06 01:08 PM
$reverse isn't that hard to script but I still like the ideas smile

Code:
alias reverse {
  if ($1-) {
    var %x = 0
    while (%x &lt; $len($1-)) {
      inc %x 1
      var %string = $mid($1-,%x,1) $+ %string
    }
    return %string
  }
}
Posted By: FiberOPtics Re: Miscallaneous identifiers - 09/02/06 01:18 PM
$reverse(0) gives no output in your alias.

if (<value>) is $false if <value> is 0, $null or $false

You don't need that if check anyway, because it is already achieved through the while loop. A /while is basically an /if check which repeats the body of the while loop until the expression evaluates to $false.

Btw identifiers delimit tokens by commas, not by spaces, so inside your alias, the entire string is stored in $1, using $1- is not necessary. And it's nasty to put that $len in your while condition, with every iteration it must calculate the length of the string.

Additionally, you are only declaring the local variable %string inside the while loop, meaning if no input was given, and you had a global variable %string, it would give the value of that instead of $null. Even if you would give an input, with the very first iteration in the while loop, it would still mess things up because %string would evaluate to the value of the global %string and be appended to the local variable %string.

But anyway, I guess you didn't read hixxy's post very carefully because it states at the end:

"Not interested in workarounds.. I can make them if need be."
Posted By: Jigsy Re: Miscallaneous identifiers - 09/02/06 02:52 PM
Yeah I have a problem with reading ...


Anyway ... I'd like to see a $shortscriptdir identifier so I don't have to use $shortfn($scriptdir) all the time ...
Posted By: starbucks_mafia Re: Miscallaneous identifiers - 09/02/06 08:09 PM
$rangetok(): Could be useful.

$reverse(): Personally I don't think of this as something which is particularly useful in a general scripting sense. Sure, a lot of people have 'reverse text' aliases/responders but I'd say it's someting to be left up to scripting. I think half the fun of a reverse-string function in any language is trying to find the best way to do it. I remember there was a big thread about making the fastest reverse identifier in the Scripting forum once before that I always found very interesting.

$blendian(): Seems like a bit of a niche use for a built-in identifier to me.

$clsid2prog(): I rarely use COM so I've got no opinion on this whatsoever.

As always, insert 'personal opinion' disclaimer here etc. etc.
Posted By: hixxy Re: Miscallaneous identifiers - 09/02/06 09:00 PM
Quote:
$blendian(): Seems like a bit of a niche use for a built-in identifier to me.


You're right, that's why I suggested the addition to $reverse in brackets. The $blendian thing was something I had to script for use in a specific algorithm for a protocol.
Posted By: DaveC Re: Miscallaneous identifiers - 09/02/06 09:41 PM
Im a bit confused on this...
$blendian(1234) -> 3412
$blendian(12345678) -> 78563412

I awlays thought bigendian values were the highest byte first, be it word or dword or what ever is bigger than dword (ddword?)

As in if the hex value of a number was 0x12345678 the dword value would be stored/transmitted as four bytes as follows 0x12 0x34 0x56 0x78
Unlike say x86 values which are LSB (least significant byte first) 0x78 0x56 0x34 0x12

Now in your example ignoring that the value might have been decimal, ill assume its a hex representation, doesnt that mean the out put was actually LSB ? (low endian <- i dont know if thats a real name)
Posted By: hixxy Re: Miscallaneous identifiers - 09/02/06 09:54 PM
I didn't really do that much research into this, I just know that I read documentation on an algorithm and the authors said you swap bytes around.

Quote:
These hexadecimal numbers should be written in Little Endian order, this means that you should swap the bytes around in a number of languages (for example PHP and C#, but not Perl and Visual Basic) in order to have access to the values of these integers. You should also take in account the default Endian Order of the system you are working on (for example, Intel machines are LE, while Apple machines are typically using BE).


Their examples also suggest this is correct.

Quote:
0x5b301715 = 0x1517305b = 353841243
0x9e3947f8 = 0xf847399e = 2017933726
0xff981604 = 0x041698ff = 68589823
Posted By: DaveC Re: Miscallaneous identifiers - 10/02/06 06:52 AM
ok i see where you have come from, taking the last example (LE) 0xff981604 = (BE) 0x041698ff = (DEC) 68589823 68,589,823 is in hex 0x041698FF which is a close representation to a big endian ordered value anyway, so the only real meaning full values that you might load in $bigendian( ) is a string representing a Low Endian value in which case it would swap it around as per your specs, actually it might as well be called $endian( ) and the function would work in both directions, as 12345678 becomes 78563412 and 78563412 becomes 12345678.

Still would it be that usefull, not exactly a large number of people would ever need to convert a hex value to LE order or viseversa?

Still no reason not to have something is it smile

/me runs off yealling BigEdian BigEndian BigEndian

PS: i did think $reverse was a little silly tho!
Posted By: hixxy Re: Miscallaneous identifiers - 10/02/06 07:19 AM
** from now on when I talk about reverse I'm talking about the addition suggested in the brackets to $blendian **

Quote:
Still would it be that usefull, not exactly a large number of people would ever need to convert a hex value to LE order or viseversa?


Nope. That's why I suggested the addition to $reverse in brackets as an alternative.

As for reverse being silly we already have at least one practical use for it, which is what we just talked about; endian swapping, even if this isn't a pressing task.
Posted By: Sat Re: Miscallaneous identifiers - 10/02/06 02:32 PM
Just a thought - I think a byteswapping function would be much more practically applicable if it were to take and produce decimal numbers instead of hexadecimal. This would make it compatible with $longip without having to use $base all the time. At least for me, the combination of $longip and a byteswapping function would be rather useful; however, that means it would not be natural to group it under a new $reverse identifier, as that function would work on a character level. It would also need an extra option/property to distinguish between shorts and longs.

Personally, I would have no use for a byteswapping function that takes hexadecimal values, as the workarounds for most practical uses of it would then be shorter/simpler.
Posted By: Talon Re: Miscallaneous identifiers - 13/02/06 06:48 AM
USELESS! $gettok(this is a test,1-2,32) = this is. why do you need a new identifier for this?
Posted By: hixxy Re: Miscallaneous identifiers - 13/02/06 06:50 AM
What?! None of my suggestions are anything like that.
Posted By: Talon Re: Miscallaneous identifiers - 13/02/06 08:05 AM
sorry, i didnt read closely what it did, i thought you wanted to get a range of tokens, which mIRC already does.. I didnt realize you meant construct a range..
Posted By: DaveC Re: Miscallaneous identifiers - 13/02/06 10:11 AM
i would include in $rangetok

$rangetok(N1,N2,asc) - returns a range from N1 to N2 separated by asc, N1 and N2 being numbers or any non number which means a tokenized list of asc values from N1 to N2, not including the token eperator, so $rangtok(D,G,32) -> D E F G
Posted By: RusselB Re: Miscallaneous identifiers - 13/02/06 10:45 AM
Sounds good to me, and one thing that I would like to see (if I haven't missed it..if I have, someone point it out to me), is soemthing similar to $didtok but uses the items selected in a dialog box. $did(<name>,<id>,0).sel will return the number of items selected, but if I want a list of just those items, I have to loop through them. Not bad if you don't have too many items, but if the list is lengthy, it can take a bit of time.
Posted By: qwerty Re: Miscallaneous identifiers - 18/02/06 04:49 PM
Here's an even faster version than the binvar one (more than twice as fast), using $regsubex():
Code:
alias rev var %a = $1 | return $regsubex(%a,/./g,$mid(%a,-\n,1))

The variable is there because of a $regsubex() bug, when it's fixed it could be as short/simple as
Code:
return $regsubex($1,/./g,$mid($1,-\n,1))


$regsubex() has a lot of potential, with a little imagination you can even do things unrelated to pattern matching smile

Edit: FiberOPtics pointed out that the alias kills spaces... as you know $mid() does retain them, it's whatever's being done internally in $regsubex() that kills them frown I want to believe that those $regsubex() problems will be ironed out eventually though.
© mIRC Discussion Forums