hash viewer

By tank59 on Sep 17, 2005

This is a dialog I made to help me learn hash tables. It's just kind of a visual editor for the hash and i found it kinda nice. Any bugs let me know. Hopefully you can use it. Type '/hview' to open it.

alias hview { dialog -md hview hview }
dialog hview {
  title "Hash Viewer by tank59"
  size -1 -1 272 197
  option dbu
  box "Viewer", 1, 1 0 225 143
  box "Options", 2, 229 0 41 110
  button "Load Table", 3, 232 30 35 10, flat
  button "Close Table", 5, 232 90 35 10, flat
  button "Save Table", 6, 232 50 35 10, flat
  button "Delete Table", 7, 232 70 35 10, flat
  button "Delete Item", 10, 69 147 35 10, flat
  button "Edit Item", 11, 114 147 35 10, flat
  box "Hash Tables", 12, 1 144 64 51
  edit "", 13, 69 166 170 10, hide autohs
  box "Editor", 14, 67 159 175 20, hide
  button "Save", 15, 200 182 20 10, hide flat
  button "Add Item", 16, 159 147 35 10, flat
  button "Cancel", 17, 222 182 20 10, hide flat
  button "New Table", 18, 232 10 35 10, flat
  list 8, 4 7 219 133, size
  list 9, 3 152 60 41, size
}
on *:dialog:hview:close:0:{
  unset %hash
}
on *:dialog:hview:init:0:{
  var %h 1
  while (%h <= $hget(0)) {  
    did -a hview 9 $hget(%h)
    inc %h
  }
}
on *:dialog:hview:sclick:*:{
  if ($did == 3) && ($did(9).sel != $null) {
    set %hash $did(9).seltext 
    did -r hview 8     
    did -ra hview 1 %hash
    if ($hget(%hash,0).data != $null) || ($hget(%hash,0).item != $null) {    
      var %h 1      
      while (%h <= $hget(%hash,0).data) {
        while (%h <= $hget(%hash,0).item) {     
          did -a hview 8 $hget(%hash,%h).item $hget(%hash,%h).data
          inc %h
        }
      }
    }
  }
  elseif ($did == 7) && ($did(9).sel != $null) {
    hfree $did(9).seltext
    did -d hview 9 $did(9).sel
    did -r hview 8
    did -ra hview 1 Viewer 
    unset %hash
  }
  elseif ($did == 10) && ($did(8).sel != $null) {
    hdel %hash $did(8).seltext
    did -d hview 8 $did(8).sel
  }
  elseif ($did == 11) && ($did(8).sel != $null) {
    set %item $did(8).sel    
    did -v hview 13,15,14,17    
    did -ra hview 13 $did(8).seltext
  } 
  elseif ($did == 15) {
    if (!%add) {
      did -h hview 13,15,14,17    
      did -o hview 8 %item $did(13)
      hadd %hash $did(13)
      unset %item    
    }
    else {
      hadd %hash $did(13)
      did -a hview 8 $did(13)
      did -h hview 13,15,14,17
      unset %add
    }
  }
  elseif ($did == 16) {
    if (%hash) {
      set %add bleh
      did -r hview 13    
      did -v hview 13,15,14,17
    }  
  }
  elseif ($did == 17) {
    unset %item
    unset %add
    did -h hview 13,15,14,17
  }
  elseif ($did == 18) {
    dialog -m opt opt
    did -v opt 5
    did -v opt 6    
    did -ra opt 1 What would you like to name the hash table and how big?
  }
  elseif ($did == 5) {
    did -r hview 8
    did -ra hview 1 Viewer
    unset %hash  
  }
  elseif ($did == 6) {
    if (!$var(%hash,1)) { 
      halt
    }
    else {   
      dialog -m opt opt
      did -v opt 4
      did -ra opt 1 What would you like to save this hash table as?
    }
  }
}
on *:dialog:hview:dclick:8:{
  clipboard $did(8).seltext
}
dialog opt {
  title "Hash Option"
  size -1 -1 100 60
  option dbu
  text "", 1, 1 1 97 29 
  edit "Name", 5, 5 30 40 10, hide
  edit "Size", 6, 55 30 40 10, hide
  edit "", 4, 5 30 90 10, hide
  button "Ok", 2, 10 45 35 10, ok
  button "Cancel", 3, 55 45 35 10, cancel
}
on *:dialog:opt:sclick:*:{  
  if ($did(5).visible == $true) && ($did(6).visible == $true) {
    if ($did == 2) {
      hmake $did(5) $did(6)
      did -a hview 9 $hget($did(5))
    }
  }
  elseif ($did(4).visible == $true) {
    if ($did == 2) {
      hsave -o %hash $did(4)
    }
  }
}

Comments

Sign in to comment.
Yoinx   -  Sep 21, 2005

$crlf is just basically a line return. I asked because your dialog shows everything as one line for each item. I dont Believe it would be able to handle that $crlf or $lf (i think both work) unless it doesnt evaluate it. I dont have time to test it though because Im getting deployed here shortly.

 Respond  
tank59   -  Sep 20, 2005

Ah, good question Yoinx. lol I\'m not familiar with $crlf and I assume that it has something to do with the &Binvar that can be assigned to a hash table. I assumed though that if you assigned an Binvar to the hash table it would still be a part of the data of the item. :/

 Respond  
Yoinx   -  Sep 18, 2005

actually, I did find one large bug. You can store $crlf in a hashtable data entry. With the way you display it in a single line how is it handling that?

 Respond  
PCTech   -  Sep 18, 2005

Very nice, I\'ll for sure use it!

 Respond  
tank59   -  Sep 18, 2005

Thanks for the good comments guys. I agree yoinx, that would make it nicer to like list the items in the hash and then if the item contains data you can doubleclick the item to view the data. If I have a minute I might try something like that. Great suggestion.

 Respond  
timer   -  Sep 18, 2005

The size of the hash tables dialog isnt correct (box left under)
Handy tool tank59 :)

 Respond  
Yoinx   -  Sep 18, 2005

Not bad, Could be made a little neater by seperating the data and item values. Personally I still like hashsandwich,

 Respond  
Noutrious   -  Sep 18, 2005

Good job dude! This really was useful for me cause i dont know much in .hsh system.. :) Thanks!

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.