Project

General

Profile

Actions

Bug #5113

closed

/did -i should allow inserting empty lines

Added by westor (GR) about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Scripting
Target version:
Start date:
08/20/2020
Due date:
% Done:

0%

Estimated time:
Operative System:
All
Regression:
No

Description

Hello,

After some time spend to reproduce and provide a test code, i can say that is a bug due /did and -i flag.

Reproduce code:

alias test {
  hfree -w testing
  hfree -w test*

  ; normal -->>>

  hadd -m test1 item1 data1
  hadd -m test2 item2 data2
  hadd -m test3 item3 data3

  ; bug -->>>

  hadd -m testing item1 $null
  hadd -m testing item2 2
  hadd -m testing item3 3
  hadd -m testing item4 4
  hadd -m testing item5 5
  hadd -m testing item6 6
  hadd -m testing item7 7
  hadd -m testing item8 8
  hadd -m testing item9 9
  hadd -m testing item10 10
}

; >>> a simple hash table viewer (that using /did -i on init)

menu status,channel,menubar {
  -
  Hash Tables:dialog -md Hash Hash
}
dialog Hash {
  title "Hash Dialog" 
  size -1 -1 294 171
  option dbu
  list 1, 8 11 83 107, size hsbar vsbar
  box "Hash Tables", 2, 4 3 92 149
  button "New Table", 3, 8 126 35 9
  button "Del Table", 4, 55 126 35 9
  box "Table Items", 5, 101 3 92 149
  button "New Item", 6, 105 126 35 9
  button "Del Item", 7, 152 126 35 9
  list 8, 105 11 83 107, size hsbar vsbar
  box "Item Data", 9, 198 3 92 149
  list 10, 202 11 83 107, size hsbar vsbar
  button "New Data", 11, 202 126 35 9
  button "Del Data", 12, 249 126 35 9
  button "Edit Table", 13, 31 139 35 9
  button "Edit Item", 14, 129 139 35 9
  button "Edit Data", 15, 226 139 35 9
  button "...", 16, 181 155 11 12
  edit "Input Search Term Here", 17, 4 155 135 12
  button "Search", 18, 141 155 37 12
  text "Hash Dialog Created by Zeta of SwiftIRC", 19, 194 157 99 8
  button "OK", 20, 245 153 29 8
  button "Cancel", 21, 245 161 29 8
  edit "", 22, 173 155 68 10
  edit "100", 23, 99 155 42 11, center
  text "Number of Slots (Default of 100)", 24, 20 157 79 8
  text "Table Name", 25, 142 157 29 8
  text "New Data", 27, 142 157 25 8
  edit "", 26, 70 155 68 10
  text "New Item", 28, 43 157 25 8
}
on *:DIALOG:Hash:INIT:0:{
  did -h Hash 20-28
  var %Hget $hget(0)
  var %X 1
  while (%X <= %Hget) {
    did -i Hash 1 %X $hget(%X)
    inc %X
  }
  did -z Hash 1
  did -b Hash 4,6,7,11,12,13,14,15
}
on *:DIALOG:Hash:SCLICK:1,8,10:{
  if ($did == 1) {
    if ($did(Hash, 1).sel) {
      did -h Hash 20-28
      did -v Hash 16-19
      did -r Hash 8,10
      did -e Hash 4,6,11,13
      did -b Hash 7,14,12,15
      var %Item $hget($did(Hash, 1).seltext,0).item
      var %X 1
      while (%X <= %Item) {
        ;var -s %item = $hget($did(Hash, 1).seltext,%X).item
        ;var -s %data = $hget($did(Hash, 1).seltext,%X).data
        ;echo -s did -i Hash 8 %X %item
        ;echo -s did -i Hash 10 %X %data

        did -i Hash 8 %X $hget($did(Hash, 1).seltext,%X).item
        did -i Hash 10 %X $hget($did(Hash, 1).seltext,%X).data

        inc %X
      }
      did -z Hash 8,10
    }
  }
  if ($did == 8) {
    if ($did(Hash, 8).sel) {
      did -h Hash 20-28
      did -v Hash 16-19
      did -c Hash 10 $did(Hash, 8).sel
      did -e Hash 7,14,12,15
    }
  }
  if ($did == 10) {
    if ($did(Hash, 10).sel) {
      did -h Hash 20-28
      did -v Hash 16-19
      did -c Hash 8 $did(Hash, 10).sel
      did -e Hash 7,14,12,15
    }
  }
}
;Numbers are so I wouldn't forget what $dids to put :>
on *:DIALOG:Hash:SCLICK:3,4,6,7,11-16,18,20-25:{
  if ($did == 3) {
    did -h Hash 16-19,26-28
    did -v Hash 20-25
    did -r Hash 22
    did -r Hash 23
    did -a Hash 23 100
  }
  if ($did == 4) {
    noop $input(Are you sure you would like to delete the table $+(',$did(Hash, 1).seltext,',?) $crlf $chr(160) $chr(160) $chr(160) $chr(160) There's no way of restoring it if you do.,w,Delete Warning)
    if ($! == $true) {
      hfree $did(Hash, 1).seltext 
      did -d Hash 1 $did(Hash, 1).sel
      did -b Hash 6,7,11-15
      did -r Hash 8,10
      did -z Hash 1
    }
  }
  if ($did == 6) {
    did -h Hash 16-25
    did -v Hash 20-22,26-28
  }
  if ($did == 7) {
    noop $input(Are you sure you would like to delete the item $+(',$did(Hash, 8).seltext,') from the $crlf $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) table $+(',$did(Hash, 1).seltext,'?) $crlf $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) There's no way of restoring it if you do.,w,Delete Warning)
    if ($! == $true) {
      hdel $did(Hash, 1).seltext $did(Hash, 8).seltext
      did -d Hash 8,10 $did(Hash, 8).sel
      did -b Hash 7,11-15
    }
  }
  if ($did == 11) {
    did -h Hash 16-25
    did -v Hash 20-22,26-28
  }
  if ($did == 12) {
    noop $input(Are you sure you would like to delete the data $+(',$did(Hash, 10).seltext,') from the $crlf $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) table $+(',$did(Hash, 1).seltext,'?) $crlf $chr(160) $chr(160) $chr(160) $chr(160) $chr(160) There's no way of restoring it if you do.,w,Delete Warning)
    if ($! == $true) {
      hdel $did(Hash, 1).seltext $did(Hash, 8).seltext
      did -d Hash 8,10 $did(Hash, 8).sel
      did -b Hash 7,11-15
    }  
  }
  if ($did == 13) {
    did -h Hash 16-19,23,24,26-28
    did -v Hash 20-22,25
    did -r Hash 22
    did -a Hash 22 $did(Hash, 1).seltext
  }
  if ($did == 14) {
    did -h Hash 16-25
    did -v Hash 20-22,26-28
    did -r Hash 22,26
    did -a Hash 22 $did(Hash, 10).seltext
    did -a Hash 26 $did(Hash, 8).seltext
  }
  if ($did == 15) {
    did -h Hash 16-25
    did -v Hash 20-22,26-28
    did -r Hash 22,26
    did -a Hash 22 $did(Hash, 10).seltext
    did -a Hash 26 $did(Hash, 8).seltext
  }
  if ($did == 16) {
    did -z Hash 1
    did -b Hash 4,6,7,11,12,13,14,15
    did -r Hash 1,8,10
    did -u Hash 1 $did(Hash, 1).sel
    did -r Hash 17
    did -a Hash 17 Input Search Term Here
    var %Hget $hget(0)
    var %Z 1
    while (%Z <= %Hget) {
      did -i Hash 1 %Z $hget(%Z)
      inc %Z
    }
  }
  if ($did == 18) {
    if ($did(Hash, 17).edited) {
      did -r Hash 1,8,10
      var %X 1
      var %Y $hget(0)
      while (%X <= %Y) {
        if ($replace($did(Hash, 17).text,$chr(32),_) isin $hget(%X)) {
          did -a Hash 1 $hget(%X)
          inc %X
        }
        else {
          inc %X
        }
      }
      did -z Hash 1
    }
  }
  if ($did == 20) {
    if ($did(Hash, 27).visible == $true) {
      if (!$did(Hash, 8).sel) || (!$did(Hash, 10).sel) {
        hadd $did(Hash, 1).seltext $replace($did(Hash, 26).text,$chr(32),_) $did(Hash, 22).text
        did -i Hash 8 1 $replace($did(Hash, 26).text,$chr(32),_)
        did -i Hash 10 1 $did(Hash, 22).text
      }
      elseif ($did(Hash, 22).edited) || ($did(Hash, 26).edited) {
        if (!$did(Hash, 22).text) || (!$did(hash, 26).text) {
          noop $input(Please put an item and data!,h,Error)
        }
        else {
          hdel $did(Hash, 1).seltext $did(Hash, 8).seltext
          hadd $did(Hash, 1).seltext $replace($did(Hash, 22).text,$chr(32),_) $replace($did(Hash, 26).text,$chr(32),_)
          did -d Hash 8,10 $did(Hash, 8).sel
          did -i Hash 8 1 $replace($did(Hash, 22).text,$chr(32),_)
          did -i Hash 10 1 $replace($did(Hash, 26).text,$chr(32),_)
          did -h Hash 20-28
          did -v Hash 1-19
        }
      }
    }
    if ($did(Hash, 24).visible != $true) && ($did(Hash, 25).visible == $true) {
      if ($did(Hash, 22).edited) {
        if (!$did(Hash, 22).text) {
          noop $input(Please put a new table name!,h,Error)
        }
        else {
          hsave -b $did(Hash, 1).seltext ht.temp
          hfree $did(Hash, 1).seltext
          hmake $replace($did(Hash, 22).text,$chr(32),_)
          hload -b $replace($did(Hash, 22).text,$chr(32),_) ht.temp
          remove ht.temp
          did -d Hash 1 $did(Hash, 1).sel
          did -i Hash 1 1 $replace($did(Hash, 22).text,$chr(32),_)
          did -r Hash 8,10
          did -h Hash 20-28
          did -v Hash 1-19
        }
      }
    }
    if ($did(Hash, 24).visible == $true) && ($did(Hash, 25).visible == $true) {
      if (!$did(Hash, 22).text) || (!$did(hash, 23).text) {
        noop $input(Please put a table name and number of slots!,h,Error)
      }
      else {
        hmake $did(Hash, 22).text $did(Hash, 23).text
        did -r Hash 8,10
        did -h Hash 20-28
        did -v Hash 1-19
        did -i Hash 1 1 $replace($did(Hash, 22).text,$chr(32),_)
      }
    }
  }
  if ($did == 21) {
    did -h Hash 20-28
    did -a Hash 22,26
    did -v Hash 1-19
  }
}

Error Image:

Correct Image:

- Thanks!

Actions #1

Updated by Per Amundsen about 4 years ago

Please provide a small example that reproduces the problem.

Actions #2

Updated by westor (GR) about 4 years ago

Ok i did a better reproduce code, i hope this will make you find the bug, use /test then try to click from the left listbox dialog a hash name to view the items + data, you are going to see that it fails on "testing" hash name.

I can thing 2 cases that it bugs here (probably i am wrong here but i mention them just in case it is).

1 = It fails because /did -i uses the same value for N and TEXT
2 = It breaks the loop because a $hget().data was $null and trying to add via /did -i there.

alias test {
  hfree -w testing
  hfree -w test*

  hadd -m test1 item1 data1
  hadd -m test2 item2 data2
  hadd -m test3 item3 data3

  hadd -m testing item1 $null
  hadd -m testing item2 2
  hadd -m testing item3 3
  hadd -m testing item4 4
  hadd -m testing item5 5
  hadd -m testing item6 6
  hadd -m testing item7 7
  hadd -m testing item8 8
  hadd -m testing item9 9
  hadd -m testing item10 10

  hash_viewer
}

dialog -l Hash {
  title "Hash Dialog" 
  size -1 -1 294 171
  option dbu
  list 1, 8 11 83 107, size hsbar vsbar
  box "Hash Tables", 2, 4 3 92 149
  button "New Table", 3, 8 126 35 9
  button "Del Table", 4, 55 126 35 9
  box "Table Items", 5, 101 3 92 149
  button "New Item", 6, 105 126 35 9
  button "Del Item", 7, 152 126 35 9
  list 8, 105 11 83 107, size hsbar vsbar
  box "Item Data", 9, 198 3 92 149
  list 10, 202 11 83 107, size hsbar vsbar
  button "New Data", 11, 202 126 35 9
  button "Del Data", 12, 249 126 35 9
  button "Edit Table", 13, 31 139 35 9
  button "Edit Item", 14, 129 139 35 9
  button "Edit Data", 15, 226 139 35 9
  button "...", 16, 181 155 11 12
  edit "Input Search Term Here", 17, 4 155 135 12
  button "Search", 18, 141 155 37 12
  text "Hash Dialog Created by Zeta of SwiftIRC", 19, 194 157 99 8
  button "OK", 20, 245 153 29 8
  button "Cancel", 21, 245 161 29 8
  edit "", 22, 173 155 68 10
  edit "100", 23, 99 155 42 11, center
  text "Number of Slots (Default of 100)", 24, 20 157 79 8
  text "Table Name", 25, 142 157 29 8
  text "New Data", 27, 142 157 25 8
  edit "", 26, 70 155 68 10
  text "New Item", 28, 43 157 25 8
}

ON *:DIALOG:Hash:SCLICK:1,8,10:{
  if ($did == 1) {
    if ($did($did).sel) {
      did -h $dname 20-28
      did -v $dname 16-19
      did -r $dname 8,10
      did -e $dname 4,6,11,13
      did -b $dname 7,14,12,15

      var %t = $hget($did($did).seltext,0).item

      var %i 1
      while (%i <= %t) {
        var -s %m = $hget($did($did).seltext,%i).item
        var -s %d = $hget($did($did).seltext,%i).data

        ; Here is the bug
        ; ->>>>>>
        did -i $dname 8 %i %m
        did -i $dname 10 %i %d
        ; <<<<<<-

        inc %i
      }

      did -z $dname 8,10
    }
  }
}

ON *:DIALOG:Hash:INIT:0:{
  did -h Hash 20-28

  var %t = $hget(0)

  var %i 1
  while (%i <= %t) {
    did -i $dname 1 %i $hget(%i)

    inc %i
  }

  did -z $dname 1
  did -b $dname 4,6,7,11,12,13,14,15
}

alias hash_viewer { dialog $iif($dialog(Hash),-ve,-md) Hash Hash }

- Thanks!

Actions #3

Updated by Per Amundsen about 4 years ago

  • Subject changed from /did -i sometimes not working to /did -i should allow inserting empty lines
  • Status changed from New to Resolved

Next time please make a shorter script, in this case only this was needed "/did -i hash 10 1" to showcase the issue.

mirc apparently allows inserting empty lines.

Actions #4

Updated by Per Amundsen about 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF