mIRC Homepage
Posted By: couresel Table formatting script - 17/02/04 06:36 PM
I thought this would come in very handy, so I whipped it up in my spare time.

$table(data) // Use that to call the alias.

The data should be formatted in this manner:
Name[td]Address[td]City[td]Phone[tr]teh-awpZor[td]#script[td]GameSurge[td]1-800-GETALIFE
where [td] means new column and [tr] means new row.

      [td]             [td]           [td]              [td]
[tr] Name          Address     City             Phone

[tr] teh-awpZor  #script      GameSurge  1-800-GETALIFE

The information returned will look like this:
Name        Address  City       Phone[tr]teh-awpZor  #script  GameSurge  1-800-GETALIFE
which when broken down will be:
Name        Address  City       Phone
teh-awpZor  #script  GameSurge  1-800-GETALIFE


alias table {
  ; // Changes [tr] and [td] into single, easiliy distinguished characters
  var %i = $replace($remove($1-,$chr(157),$chr(158)),[tr],$chr(157),[td],$chr(158))
  ; // Establishes the length for 9 columns
  var %col = 0 0 0 0 0 0 0 0 0
  var %x = 0
  ; // Establishes the longest possible length for each column.
  while (%x < $gettok(%i,0,157)) {
    inc %x | var %y = 0
    while (%y < $gettok($gettok(%i,%x,157),0,158)) {
      inc %y
      if ($len($gettok($gettok(%i,%x,157),%y,158)) > $gettok(%col,%y,32)) var %col = $puttok(%col,$($len($gettok($gettok(%i,%x,157),%y,158))),%y,32)
    }
  }
  ; // Modifies the length of each column in each row to be exact to other cells in the same column. Then expands those column lengths by 2 non-breaking characters.
  var %x = 0
  while (%x < $gettok(%i,0,157)) {
    inc %x | var %y = 0 | var %z = $gettok(%i,%x,157)
    while (%y < $gettok($gettok(%i,%x,157),0,158)) {
      inc %y
      var %c = $calc($gettok(%col,%y,32) - $len($gettok($gettok(%i,%x,157),%y,158)) + 2)
      var %z = $puttok(%z,$($gettok(%z,%y,158) $+ $str($chr(160),%c)),%y,158)
    }
    var %i = $puttok(%i,%z,%x,157)
  }
  ; // Removes unnecessary [tr] markers.
  var %i = $iif($left(%i,1) == $chr(157),$right(%i,-1),%i) | var %i = $iif($right(%i,1) == $chr(157),$left(%i,-1),%i)
  ; // Replaces [tr] substitute characters with '[tr]'
  return $remove($replace(%i,$chr(157),[tr]),$chr(158))
}

*Note: Do not pass ascii character 157 OR 158 through the alias, you won't get them back :o.
*Note: The alias will work for UP TO 9 rows. If you feel you'll need more add more 0's to var %col separated by a space. e.g. '0 0 0 0 0'

<teh-awpZor> yep, I like it. Hope you do too.
Posted By: DaveC Re: Table formatting script - 17/02/04 09:47 PM
only works on fixed width fonts.
Posted By: couresel Re: Table formatting script - 24/02/04 12:07 AM
This maybe tru, I haven't tested it against other fonts, however I would assume that chr(160) would consume the same character size as other fonts within a font group
Posted By: DaveC Re: Table formatting script - 24/02/04 10:18 AM
The font image for the letter I and W are different widths in most fonts, so using $chr(160) which is normally a space, well only result in x number of spaces, which wont equal the width of the text, it might be wider or skinnier, dependent on the font used for the text,

aka, well only work with fixed width fonts, font that have the same width for each character.
Posted By: couresel Re: Table formatting script - 28/02/04 08:27 PM
understood, and thanx for the insight laugh

This cannot be fixed unless the much more coding is added to evaulate the lengths of the strings accoring to the font specified and the characters present. Needless to say I won't be doing that however, as for making all the strings similar lengths in characters, the script does exactly that. Sorry to anyone who looked foward to using this and have encountered any problems. If you find a permanent fix :x be sure to post it.

imo however that'll require a lot of math.
Posted By: DaveC Re: Table formatting script - 01/03/04 11:12 PM
thats what $width is for (also see $wrap)
© mIRC Discussion Forums