mIRC Home    About    Download    Register    News    Help

Print Thread
Parseing for the last color code #73967 06/03/04 01:30 AM
Joined: Jan 2004
Posts: 10
R
rennir Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Jan 2004
Posts: 10
I'm working on a script that cuts up a long string of text into multiple posts so that no text is lost due to irc string restrictions. Now, the people i'm writing this for tend to use a lot of color codes, so I want my script to properly identify the last color code used before a specific point in this string and prepend it to the next string so it looks like a logical extention of the text instead of being all broken up.

Here's my current script so you can see what it does.

Code:
 on *:input:*: { 
  if ( ( $left($1,1) != / ) || ( $1 == /me ) ) {
    var %next     = <-next->
    var %continue = <-cont->
    var %done     = <-end->
    var %more     = <-more->
    var %textlen = $len($1-)
    if (%textlen > 400) {    
      var %pos = 1
      var %text = $mid($1-, %pos, 400)
      var %firsttime = 1
      while ( %text != $null ) {
        if ( $len($deltok(%text, -1, 32)) < 370 ) {
          %text = $left(%text, 370)
          inc %pos 370
        }
        else {
          %text = $deltok(%text,-1,32)
          inc %pos $len(%text)
          inc %pos
        }
        var %outtext = %text
        %text = $mid($1-, %pos, 400)
        if (%firsttime == 1) {
          if ($gettok(%outtext, 1, 32) == /me) {
            %outtext %next
          }
          else {
            say %outtext %next
          }
          %firsttime = 0;
        }
        else {
          if (%text != $null) {
            say %continue %outtext %next
          }
          else {
            if (%textlen <= 945) {
              say %continue %outtext %done
            }
            else {
              say %continue %outtext %more
            }
          }
        }
      }
      halt
    }
  }
} 


So now the question is, How do determine what was the last color code used, at the end of %outtext so I can prepend it to the next string being sent. Any ideas?

Rennir

Re: Parseing for the last color code #73968 06/03/04 01:51 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
To be honest I'm too tired/lazy to look through your code right now (coming up on 2am here). However here's a little alias to return the state of various control codes at the end of some text, hopefully it'll be of some use to use to you.

Code:
get_end_cc {
  if ($prop == bold) return $iif($calc($count($$1,) % 2),$true,$null)
  if ($prop == underline) return $iif($calc($count($$1,) % 2),$true,$null)
  if ($prop == reverse) return $iif($calc($count($$1,) % 2),$true,$null)
  var %re = /(\d{1,2}(?:,\d{1,2})*)(?:[^]*)$/
  !.echo -q $regex(get_last,$$1,%re)
  return $iif($regml(get_last,1),$ifmatch,$null)
}


ie.
var %text = h4ello 12,15there how are you?
$get_end_cc(%text).bold returns $true
$get_end_cc(%text).underline returns $null
$get_end_cc(%text).reverse returns $null
$get_end_cc(%text) returns 12,15

Edit: Removed some unnecessary code


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Parseing for the last color code #73969 06/03/04 02:11 AM
Joined: Jan 2004
Posts: 10
R
rennir Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Jan 2004
Posts: 10
Silly me, I searched and found your old post that talked about this and did this exact thing, Now I'm trying to just get it to work.. Hmmm Let me try your new thing. I'm still not sure WHERE I'm supposed to put this function.. in the alias section? I'm kind of still new on scripting.

Rennir

Re: Parseing for the last color code #73970 06/03/04 02:14 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Yeah it goes in the alias section.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Parseing for the last color code #73971 06/03/04 02:20 AM
Joined: Jan 2004
Posts: 10
R
rennir Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Jan 2004
Posts: 10
I feel like I need to be spoon feed how to do this stuff. Ugh, Okay I got it to work, now how do I use it so when I send the output the new color code. Here's 2 cents of code.

Code:
%nextcolor = $get_end_cc(%oldtext)
say  %nextcolor  %nexttext
 


This doesn't seem to work for me. How do I use this value now to send a color code for the next string?

Rennir

Re: Parseing for the last color code #73972 06/03/04 03:30 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
say $+(, %nextcolor, %nexttext)


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Parseing for the last color code #73973 06/03/04 08:58 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
get_end_cc { etc etc


/me cuts that bit of code out and steals it for himself.

mahahaha you well never get it back now!


Thanks thats gonna help in something I have, i been removing colors etc from a chunk of text in the middle of a line, i just been reseting at the end of the chunk, now i can add this and set it to what it should be at that moment.

Edit add:
just thought i might add a little to your code
I replaced $$1 with $gettok($$1,-1,15) as 15 is gonna reset anything, so you only wanna check from then on. I wouldnt have thought of it, except i was using that to rest the colors myself.

Last edited by DaveC; 06/03/04 09:14 AM.
Re: Parseing for the last color code #73974 06/03/04 12:09 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Well for the colours the regex checks for no following ^O char anyway, and from some benchmarks I found the slightly simpler regex in combination with $gettok() works out slightly slower than the current method. However I should've used $gettok() when checking for for the other control codes. Whoops blush.

Better put the 'good' version up here just for clarity.
Code:
get_end_cc {
  if ($prop == bold) return $iif($calc($count($gettok($$1, -1, 15), ) % 2), $true, $null)
  if ($prop == underline) return $iif($calc($count($gettok($$1, -1, 15), ) % 2), $true, $null)
  if ($prop == reverse) return $iif($calc($count($gettok($$1, -1, 15), ) % 2), $true, $null)
  var %re = /(\d{1,2}(?:,\d{1,2})*)(?:[^]*)$/
  !.echo -q $regex(get_last, $$1, %re)
  return $iif($regml(get_last,1), $ifmatch, $null)
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Parseing for the last color code #73975 07/03/04 01:08 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
yeah i saw those two on the end of the regex ctrl-k and ctrl-o and managed with my limited experence with regex to pickup that they were limiting the search to ones that DONT have an occurance of them after it? (is that what they do)


Actually i had a few of suggestions for that alias,
(1) (i have done this in mine)
Move the color reply to a if ($prop == color) and have the default no $prop output output the actual string thats needed to restore the color and burk settings.

(2) (which i couldnt manage to do since i no good with regex, i tried for 2 hours frown )
Pull from the string for the last valid dd,dd (dd being one or 2 digits) and then sweep for the last valid dd (which may end up the same one) then create a new forgrond,background combo from them as the current system well find "11" in a line like this "aaa9,10bbb11ccc" when it really needs to find "9,10" and "11" and make a "11,10"

I tried and failed.
/me sobs and creis into his blanket.


Re: Parseing for the last color code #73976 07/03/04 01:16 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
yeah i saw those two on the end of the regex ctrl-k and ctrl-o and managed with my limited experence with regex to pickup that they were limiting the search to ones that DONT have an occurance of them after it? (is that what they do)

Yeah, the [[color:blue]^][/color] means that it's a character set, which is negated so it will only match text that doesn't contain the specified characters.


Good points about the alias, try it now:
Code:
get_end_cc {
  if ($prop == bold) return $iif($calc($count($gettok($$1, -1, 15), ) % 2), $true, $null)
  if ($prop == underline) return $iif($calc($count($gettok($$1, -1, 15), ) % 2), $true, $null)
  if ($prop == reverse) return $iif($calc($count($gettok($$1, -1, 15), ) % 2), $true, $null)
  if (colo*r iswm $prop) {
    var %re = /(?:\d{1,2},(\d{1,2})(?!.*(?:|\D|\d{1,2},\d{1,2}).*$).*)*(\d{1,2}(?:,\d{1,2})*)(?:[^]*)$/
    if (!$regex(get_last, $$1, %re)) return $null
    var %r = $iif($regml(get_last, 2) != $null, $+($ifmatch,$chr(44),$regml(get_last,1)), $regml(get_last, 1)), %n = $numtok(%r, 44)
    return $puttok(%r, $right($+(0,$gettok(%r, %n, 44)), 2), %n, 44)
  }
  else {
    var %end_txt = $gettok($$1, -1, 15)
    var %r = $+($iif($calc($count(%end_txt,) % 2),), $iif($calc($count(%end_txt,) % 2),), $iif($calc($count(%end_txt,) % 2),))
    var %re = /(?:\d{1,2},(\d{1,2})(?!.*(?:\D|\d{1,2},\d{1,2}).*$).*)*(\d{1,2}(?:,\d{1,2})*)(?:[^]*)$/
    if (!$regex(get_last, %end_txt, %re)) return %r
    var %x = $iif($regml(get_last, 2) != $null, $+($ifmatch,$chr(44),$regml(get_last,1)), $regml(get_last, 1)), %n = $numtok(%x, 44)
    return $+(%r, , $puttok(%x, $right($+(0,$gettok(%x, %n, 44)), 2), %n, 44))
  }
}


Edit: Added auto-colour-double-digitting

Last edited by starbucks_mafia; 07/03/04 02:25 PM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Parseing for the last color code #73977 07/03/04 07:16 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Excellent, ill take that and put it through my rigurus testing procedure, (actualy ill just put it to work and hope for the best, much like how Microsoft work)

Thanks.