mIRC Home    About    Download    Register    News    Help

Topic Options
#141070 - 04/02/06 09:05 AM $replace with a large string
snabbi Offline
Ameglian cow

Registered: 03/09/03
Posts: 38
I am not able to reproduce my errors, because i can not see exactly when the error occurs.

I have made a rss newstracker which downloads newsitems and displays them to the channel when new newsitems are posted. I need to replace some characters to human readable characters and on this line I have had several crashes.Well actually it isn't a crash but mirc uses 100% cpu time for quite a long time, ctrl break still works! I will try to get a reproductive example a.s.a.p. but for know you will have to do with my code:

;Mirc crashes on the return statement. I do stress out that it does not crash most of the times, that is why I think it is caused by a large string/line from the rss feed

alias web.parser {
if ( < isin $1- ) {
var %i = $pos($1-,<,0) | var %ii = 1
while ( %ii <= %i ) {
set %fok.1. [ $+ [ %ii ] ] $calc($pos($1-,&lt;, %ii ) - 1)
set %fok.2. [ $+ [ %ii ] ] $calc($pos($1-,&gt;, %ii ) + 4)
if ( %ii = 1 ) { var %totaal = $ $+ left($ $+ 1-, $+ %fok.1.1 $+ ) }
if ( %ii != 1 ) { var %ff = %fok.2. [ $+ [ $calc(%ii - 1) ] ]
var %totaal = %totaal $ $+ mid($ $+ 1-, $+ %ff $+ , $+ $calc(%fok.1. [ $+ [ %ii ] ] - %ff +1 ) $+ )
}
if ( %ii == %i ) { var %totaal = %totaal $ $+ right($ $+ 1-,- $+ $calc(%fok.2. [ $+ [ %ii ] ] - 1) $+ ) }
inc %ii
}
.unset %fok.1.*
.unset %fok.2.*
tokenize 32 $replace($replace($eval(%totaal,3),$chr(32),$chr(0160)),$chr(0160) $+ $chr(0160),$chr(0160))
}
;the next line is the line which causes my problems
return $replace($1-,&rsquo;,',á,,ï,,é,,ö,,ë,,$chr(38) $+ $chr(35) $+ 039 $+ $chr(59),$chr(39),$chr(38) $+ quot $+ $chr(59),$chr(34),$chr(38) $+ amp $+ $chr(59),$chr(38),&#8221;,$chr(34),&#8217;,',&#8220;,$chr(34))
}

Top
#141071 - 04/02/06 10:39 AM Re: $replace with a large string
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
Code:
alias web.parser {
  var -s %r = $1-
  while ( &amp;lt; isin %r ) {
    var -s %r = $left(%r,$calc($pos(%r,&amp;lt;,1) - 1))) $mid(%r,$calc($pos(%r,&amp;gt;,1)))
  }
  var -s %r = $replace(%r,$chr(32),$chr(0160),$chr(0160) $+ $chr(0160),$chr(0160))
  var -s %r = $replace(%r,&amp;rsquo;,',á,,ï,,é,,ö,,ë,,$chr(38) $+ $chr(35) $+ 039 $+ $chr(59),$chr(39),$chr(38) $+ quot $+ $chr(59),$chr(34),$chr(38) $+ amp $+ $chr(59),$chr
(38),&amp;#8221;,$chr(34),&amp;#8217;,',&amp;#8220;,$chr(34))
  return %r
}


Try that...
I saw that you were creating a string of a $left, $mid(s) and a $right of the $1- that removed all &lt;<unknown>&gt; occurances, I didnt really see why you would build such a string of identifiers rather than just make the new string, if there was some reason then likely mine wont work either. Butr if it does thats all im doing also, then i do your replaces and return.

I cant see why it would freeze up on the return it looks like a simple replace, your always going from a bigger to a smaller string so it should never "string length to long" on you either.

* i left in -s on the VAR command so you can watch the progress of it in the status window, if it works but still freezes up this might give you some clues. If it works without problem now, just remove all the -s from the var commands.

Top
#141072 - 04/02/06 05:06 PM Re: $replace with a large string
snabbi Offline
Ameglian cow

Registered: 03/09/03
Posts: 38
Thank you for tiding up my code. This topic can be closed. I found my problem. I am using a while construction to find the </description> tag, but the rss feed is faulty and does not close the <description> tag. This is why I can never find the end and mirc keeps looking.

It must be a pure coincidence that it stops at that line each time.

Thank you for your time

Top