mIRC Homepage
Posted By: da_hype what's the best way too.. - 27/01/05 01:12 PM
what's the best way too.. rename the items in a hash table...

example

item data
global.text.1.kick #help
global.text.2.kickban #ms
global.text.3.op #bla
global.text.4.voice #[censored]
global.text.5.time #damn
global.text.6.test #hi


if i wanted to rename every item starting from global.text.2.kick till global.text.6.test

basically delete global.text.2.kick 1st, then rename the rest.

any ideas?
Posted By: DaveC Re: what's the best way too.. - 27/01/05 09:26 PM
Code:
alias blah1234 {
  ; $1 = number to make number 1 ( no bounds checks occur add them if u want )
  ;
  var %i = $1 | dec %i
  while (%i) {
    hdel -s hashtablename $hfind(hashtablename,global.text. $+ %i $+ .*,1,w)
    dec %i
  }
  var %i = $1
  while ($hfind(hashtablename,global.text. $+ %i $+ .*,1,w)) {
    var -s %old.item = $ifmatch
    var -s %old.item.value = $hget(hashtablename,%old.item)
    hadd -s hashtablename $puttok(%old.item, $calc(%i - $1 + 1) , 3,46) %old.item.value
    hdel -s hashtablename %old.item
    inc %i
  }
}


The above makes some assumptions about the hash table, that it only ever contains one item that starts with global.text.N. (N being a number), ie inly one global.text.1.* , only one global.text.2.* etc
Posted By: da_hype Re: what's the best way too.. - 28/01/05 01:56 AM
think i didn't explain it very well.

Quote:
what's the best way too.. rename the items in a hash table...

example

item data
global.text.1.kick #help
global.text.2.kickban #ms
global.text.3.op #bla
global.text.4.voice #[censored]
global.text.5.time #damn
global.text.6.test #hi


if i wanted to rename every item starting from global.text.2.kick till global.text.6.test
basically delete global.text.2.kick 1st, then rename the rest while keeping the same data.

item data
global.text.1.kick #help
global.text.2.op #bla
global.text.3.voice #[censored]
global.text.4.time #damn
global.text.5.test #hi


any ideas?
Posted By: DaveC Re: what's the best way too.. - 28/01/05 06:33 AM
Code:
alias blah1234 {
  ; $1 = number to delete, all higher numbers move down one
  ;
  if ($hfind(hashtablename,global.text. $+ $1 $+ .*,1,w)) {
    hdel hashtablename $ifmatch
    var %i = $1 | inc %i
    while ($hfind(hashtablename,global.text. $+ %i $+ .*,1,w)) {
      var -s %old.item = $ifmatch
      var -s %old.item.value = $hget(hashtablename,%old.item)
      hadd -s hashtablename $puttok(%old.item, $calc(%i - 1) , 3,46) %old.item.value
      hdel -s hashtablename %old.item
      inc %i
    }
  }
}


Assuptions I have made are, that there is only ever one item named global.text.N.* (N being a number), and that the numbering well not have gaps.
© mIRC Discussion Forums