mIRC Home    About    Download    Register    News    Help

Print Thread
#85709 06/06/04 06:41 PM
Joined: Jun 2003
Posts: 114
T
Thray Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Jun 2003
Posts: 114
I have made an output alias for a socket bot that hard-wraps the text so that it is never more than a specified length. However, I want to do a soft wrap (wherein it never cuts into the middle of a word unless the word itself is > max length) but I can't quite figure out how to go about it.
Could anyone gimme a suggestion?
Heres the hard wrap:
Code:
alias kuran.output {
  var %kuran.length = 80
  var %kuran.output = $2-

  while ($len(%kuran.output) > 0) {
    sockwrite -n $1 $left(%kuran.output, %kuran.length)
    %kuran.output = $right(%kuran.output, $calc(0 - %kuran.length))
  }
}
  


-------------
I am the self-appointed God of needlessly complex mIRCscript.
#85710 06/06/04 07:20 PM
Joined: May 2004
Posts: 24
K
Ameglian cow
Offline
Ameglian cow
K
Joined: May 2004
Posts: 24
time ago i made a script that maybe can help you :tongue:

alias spezza {
if ($1-) {
var %wrap = $wrap($1-,Tahoma,8,195,0), %x = 1
while (%x <= %wrap) {
write %dd.w $wrap($1-,Tahoma,8,195,%x)
inc %x
}
}
}

#85711 07/06/04 12:31 AM
Joined: Jun 2003
Posts: 114
T
Thray Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Jun 2003
Posts: 114
Code:
alias kuran.output {
  var %length = 80
  var %output = $2-
  var %buffer
  var %looprot

  while ($len(%output) &gt; 0) {
    %buffer = $null
    while ($gettok(%output, 1, 32) &gt; %length) {
      sockwrite -n $1 $left(%output, %length)
      %output = $right(%output, $calc(0 - %length))
      inc %looprot
      if (%looprot &gt; 50) { halt }
    }
    while ($len(%buffer) &lt; %length &amp;&amp; $len(%output) &gt; 0) {
      %buffer = $instok(%buffer, $gettok(%output, 1, 32), $numtok(%buffer, 32), 32)
      %output = $deltok(%output, 1, 32)
      inc %looprot
      if (%looprot &gt; 50) { halt }
    }
    if ($len(%buffer) &gt; %length) {
      %output = $instok(%output, $gettok(%buffer, $numtok(%buffer, 32), 32), 0, 32)
      %buffer = $deltok(%buffer, $numtok(%buffer, 32), 32)
    }
    inc %looprot
    if (%looprot &gt; 50) { halt }
  }
}


This was my sloppy attempt at doing it (note the %looprot to make absolutely sure theres no infinite loops)
However, it doesn't work. Oddly enough, it still hard wraps.


-------------
I am the self-appointed God of needlessly complex mIRCscript.
#85712 07/06/04 12:57 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Try this:
Code:
alias kuran.output {
  !.echo -q $regex($2-,/(.{1,80})(?: |$)|(\S{80})/g)
  var %i = 1
  while $regml(%i) != $null { 
    sockwrite -n $1 $ifmatch
    inc %i 
  }
}

Last edited by qwerty; 07/06/04 01:06 AM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#85713 07/06/04 01:28 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
You might also want the s modifier on there in case the input has newlines itself.
Also '\s|$' might be more useful in place of ' |$'.

Last edited by starbucks_mafia; 07/06/04 01:44 AM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
#85714 07/06/04 01:32 AM
Joined: Jun 2003
Posts: 114
T
Thray Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Jun 2003
Posts: 114
God I hate regexes, I can never understand em.
But thanks, it works perfect.


-------------
I am the self-appointed God of needlessly complex mIRCscript.
#85715 07/06/04 05:18 AM
Joined: Jun 2003
Posts: 114
T
Thray Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Jun 2003
Posts: 114
One last question...
Is there any way to make it indent all after the second part of a line?
So when it wraps around, the part it wraps is indented with $chr(160) ?


-------------
I am the self-appointed God of needlessly complex mIRCscript.
#85716 07/06/04 09:24 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Yep, /gs would cover the extreme cases that the text contains newlines. "\s" might also be preferable to " " if the text is going to be echoed in a custom window (in other types of windows tab doesn't look like whitespace).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#85717 07/06/04 09:40 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Perfect laugh

*saves in his regex snippets file*

#85718 07/06/04 09:50 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The part that wraps is every $regml(%i) apart from the first. So, you can check in the loop whether %i is bigger than 1 and stick a $chr(160) in front of $regml(%i) if it is:
Code:
alias kuran.output {
  !.echo -q $regex($2-,/(.{1,80})(?:\s|$)|(\S{80})/gs)
  var %i = 0, %a = $regml(0), %b = $chr(160)
  while %i &lt; %a { 
    inc %i
    sockwrite -n $1 $iif(%i &gt; 1,%b) $+ $regml(%i)
  }
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard