mIRC Home    About    Download    Register    News    Help

Topic Options
#57334 - 25/10/03 06:37 AM Ansi 2 mIRC
phrozenfire Offline
Babel fish

Registered: 30/12/02
Posts: 68
I have text like this:

Code:
You see exits leading northeast, south, and northwest.


I need to detect all the ANSI codes (they all look like  or similar), and then return the whole phrase in mIRC codes (using the identifier $ansi2mirc). Where there is a different ANSI code, it needs to find the new color for when it changes, so there could be several different ANSI codes in a sentence, meaning that there would be several different colors. It has to find all of them. Thanks.

Note: Putting the whole thing, if there is more than once ANSI code, into $ansi2mirc returns an error, so that's not a possibility.


Top
#57335 - 25/10/03 09:30 AM Re: Ansi 2 mIRC
LocutusofBorg Offline
Hoopy frood

Registered: 23/03/03
Posts: 1271
Loc: Sunnydale, CA
ok, I'm not the world's best with regular expressions, but set your whole line in a variable called %txt and apply the following line to count how many times they format [N;NNm makes an appearance.
Code:
$regex(%txt,/(\[[0-9];[0-9]{2}m)/g)

The problem is $ansi2mirc([1;34m) returns [1;34m for mem, so I'm probably doing something wrong in detecting the ansi code.

You can use this as a basis for a $regsub, to replace the ansi code with $ansi2mirc(ansicode)
_________________________
DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius

Top
#57336 - 25/10/03 03:58 PM Re: Ansi 2 mIRC
phrozenfire Offline
Babel fish

Registered: 30/12/02
Posts: 68
You need a $chr(27) before the [#;##m. You might need to change your code, I'm not sure.

Top
#57337 - 25/10/03 04:09 PM Re: Ansi 2 mIRC
LocutusofBorg Offline
Hoopy frood

Registered: 23/03/03
Posts: 1271
Loc: Sunnydale, CA
Ok, this is not the most beautiful, and a $regsub will probably be faster, but this works:

set your line into a variable called %txt
Code:
alias tst {
  var %i = $regex(%txt,/(\[[0-9];[0-9]{2}m)/g)
  while (%i >= 1) {
    %txt = $replace(%txt,$regml(1),$ansi2mirc($regml(1)))
    %i = $regex(%txt,/(\[[0-9];[0-9]{2}m)/g)
  }
  echo -a %txt
}
_________________________
DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius

Top
#57338 - 25/10/03 04:14 PM Re: Ansi 2 mIRC
phrozenfire Offline
Babel fish

Registered: 30/12/02
Posts: 68
I totally forgot to point this out, sometimes the ";" is not there. Example:

Code:
The bright sun shines down, blanketing you with its life-giving warmth. A runic


If somebody could fix the code above, that would be awesome. Thanks.

Top
#57339 - 25/10/03 04:39 PM Re: Ansi 2 mIRC
LocutusofBorg Offline
Hoopy frood

Registered: 23/03/03
Posts: 1271
Loc: Sunnydale, CA
replace the regex with
Code:
$regex(%txt,/(\[[0-9]?;?[0-9]{2}m)/g)

or so I'm told
_________________________
DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius

Top
#57340 - 25/10/03 05:23 PM Re: Ansi 2 mIRC
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
Quote:
Note: Putting the whole thing, if there is more than once ANSI code, into $ansi2mirc returns an error, so that's not a possibility.

I'll take a guess here but try this:
Code:
//var %a = You see exits leading northeast, south, and northwest. | echo -a $ansi2mirc(%a)
The reason that it errors could be the commas in the string. Commas are used for separating parameters in identifiers: if put directly in $ansi2mirc() mirc thinks you're passing more than one parameters to it, so it errors.
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#57341 - 25/10/03 09:54 PM Re: Ansi 2 mIRC
LocutusofBorg Offline
Hoopy frood

Registered: 23/03/03
Posts: 1271
Loc: Sunnydale, CA
Which is why I suggested he put the string in a variable and use the variable in the #regex...
_________________________
DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius

Top
#57342 - 26/10/03 01:19 AM Re: Ansi 2 mIRC
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
If you agree that the commas was the cause of the error, why did you post the regex solution? What I'm saying is that it's possible that $ansi2mirc only returned an error because of the commas in the string, not because it doesn't support more than one codes in the input. $ansi2mirc does support multiple codes (compare the outputs of $ansi2mirc(%txt) and /tst, you'll see they're the same), which means that the regex isn't needed.
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#57343 - 26/10/03 07:34 AM Re: Ansi 2 mIRC
LocutusofBorg Offline
Hoopy frood

Registered: 23/03/03
Posts: 1271
Loc: Sunnydale, CA
I said the regex coukldn't deal with comma's in the string =which is true=. I did not say that $ansi2mirc(string) wouldn't work, the original poster did (see original post, bottom line). I never said commas were the problem in $ansi2mirc (but they will be - mirc identifiers cannot deal with comma's in text strings since comma's are used to separate arguments), when I said comma's would give a problem, I was referring to the regex.
_________________________
DALnet #Helpdesk
I hear and I forget. I see and I remember. I do and I understand. -Confucius

Top