· 8 months ago · Feb 09, 2025, 12:21 PM
1menu status,menubar {
2 • Hash:hedit
3}
4alias hedit { dialog -m hedit hedit }
5dialog hedit {
6 title Hash Table Editor
7 size -1 -1 260 142
8 option dbu
9
10 edit "Coded By: SaNCaK", 1, 0 131 260 11, read right autohs
11
12 box "Tables", 2, 2 3 75 125
13 list 3, 7 13 65 94, vsbar sort
14 button "Add", 4, 7 101 32 11
15 button "Remove", 5, 40 101 32 11
16 button "Rename", 6, 7 113 32 11
17 button "Clear", 7, 40 113 32 11
18
19 box "Items", 8, 80 3 178 125
20 list 9, 85 13 65 102, vsbar sort
21
22 button "Add", 10, 85 113 32 11
23 button "Remove", 11, 118 113 32 11
24
25 box "Data", 12, 155 9 98 63
26 text "Item", 13, 158 17 50 9
27 edit "",14, 158 25 92 11, autohs
28 text "Data", 15, 158 37 50 9
29 edit "", 16, 158 45 92 11, autohs
30 button "Update", 17, 189 58 30 11
31
32 box "Search", 18, 155 74 98 51
33 check "Data", 19, 179 83 24 9
34 check "Table", 20, 207 83 24 9
35 edit "", 21, 158 95 92 11, autohs
36 check "Regular Ex.", 22, 158 111 35 9
37 button "Clear", 23, 215 109 35 11
38}
39
40on *:Dialog:hedit:*:*:{
41 if ($devent == init) {
42 var %x = $hget(0)
43 did -o $dname 2 1 Tables $+($chr(40),%x,$chr(41))
44 did -b $dname 5-23
45 while (%x) {
46 did -a $dname 3 $hget(%x)
47 dec %x
48 }
49 did -f $dname 3
50 }
51 if ($devent == sclick) {
52 var %tb = $did($dname,3).seltext
53 var %it = $did($dname,9).seltext
54
55 If ($did == 1) { did -j $dname 3 }
56
57 ; // Click On Table List //
58 If ($did == 3) && (%tb) {
59 did -e $dname 5-10
60 did -u $dname 9
61 iu
62 If ($did($dname,21).text) { itemsearch }
63 did -o $dname 1 1 Table: ' $+ %tb $+ ' Items: $hget(%tb,0).item Size: $hget(%tb).size
64 }
65
66 ; // Click On Item List //
67 If ($did == 9) && ($did($dname,$did).seltext) {
68 did -e $dname 11-17
69 var %t = $did($dname,3).seltext
70 var %i = $did($dname,9).seltext
71 did -o $dname 14 1 %i
72 did -o $dname 16 1 $hget(%t,%i)
73 }
74
75 ; // ADD NEW HASH TABLE BUTTON //
76 If ($did == 4) {
77 var %n = $input(Hash Table Name:,equd,New Hash Table)
78 If (%n == $null) { derror -c No Name Given }
79 ElseIf ($regex(%n,/ /)) { derror -c Hash Table Name Can Not Contain Spaces }
80 ElseIf ($hget(%n)) { derror -c Hash Table Name Already Exists }
81 Else {
82 var %s = $input(Hash Table Size:,equd,New Hash Table,100)
83 If (%s == $null) { derror -c No Size Specified }
84 ElseIf (%s !isnum 1-) || (%s != $int(%s)) { derror -c Invalid Size Specified }
85 Else {
86 hmake %n %s
87 did -o $dname 1 1 Success: Made Hash Table.
88 did -a $dname 3 %n
89 did -o $dname 2 1 Tables $+($chr(40),$hget(0),$chr(41))
90 }
91 }
92 }
93
94 ; // Remove Hash table //
95 If ($did == 5) {
96 If ($input(Are You Sure You Want To Remove Hash Table ' $+ %tb $+ ', wudy, Remove Table)) {
97 hfree %tb
98 did -o $dname 1 1 Success: Removed Hash Table.
99 did -d $dname 3 $did($dname,3).sel
100 did -r $dname 14,16,9,21
101 did -b $dname 5-23
102 did -o $dname 2 1 Tables $+($chr(40),$hget(0),$chr(41))
103 did -o $dname 8 1 Items
104 }
105 }
106
107 ; // Rename Hash Table
108 If ($did == 6) {
109 var %n = $input(Hash Table's New Name:,equd,Rename Hash Table)
110 If (%n == $null) { derror -r No New Name Specified }
111 ElseIf ($regex(%n,/ /)) { derror -r Hash Table Name Can Not Contain Spaces }
112 Else {
113 did -o $dname 1 1 Success: Renamed Hash Table.
114 hrename %tb %n
115 did -d $dname 3 $did($dname,3).sel
116 did -ac $dname 3 %n
117 }
118 }
119
120 ; // Clear Hash Table //
121 If ($did == 7) {
122 var %c = $input(Are You Sure You Want To Clear All Items From ' $+ %tb $+ '?, wudy, Clear Table)
123 If (%c) { hdel -w %tb * | iu | did -o $dname 1 1 Success: Removed Hash Table. }
124 }
125
126 ; // Add item to table //
127 If ($did = 10) {
128 var %ni = $input(New Item Name:,equd,Add Item)
129 If (%ni == $null) { derror -a No Item Name Specified }
130 ElseIf ($regex(%ni,/ /)) { derror -a Item Name Can Not Contain Spaces }
131 ElseIf ($hget(%tb,%ni)) { derror -a Item Already Exists }
132 Else {
133 var %nd = $input(New Item Data:,equdv,Add Item)
134 If (%nd == $cancel) { derror -a Cancelled }
135 Else {
136 hadd %tb %ni %nd
137 did -o $dname 1 1 Success: Added Item.
138 itemsearch
139 }
140 }
141 }
142
143 ; // Remove an item from the table //
144 If ($did = 11) {
145 var %yn = $input(Are You Sure You Want To Delete ' $+ %it $+ '.,wdyu,Remove Item)
146 if (%yn) {
147 hdel %tb %it
148 itemsearch
149 did -o $dname 1 1 Success: Removed Item.
150 }
151 }
152
153 ; // Update an item //
154 If ($did == 17) {
155 var %ni = $did($dname,14).text
156 If (%ni == $null) { derror -u No Item Name Given }
157 ElseIf ($regex(%ni,/ /)) { derror -u Item Name Can Not Contain Spaces }
158 Else {
159 did -o $dname 1 1 Success: Updated Item.
160 hdel %tb %it
161 hadd %tb %ni $did($dname,16).text
162 did -d $dname 9 $did($dname,9).sel
163 did -ac $dname 9 %ni
164 If ($did($dname,21).text) { itemsearch }
165 }
166 }
167 If ($did == 19) { if ($did($dname,21).text) { itemsearch } }
168 If ($did == 20) { if ($did($dname,21).text) { itemsearch } }
169 If ($did == 22) { if ($did($dname,21).text) { itemsearch } }
170 If ($did == 23) { did -r $dname 21 | did -u $dname 19,20,22 | itemsearch }
171 }
172
173 If ($devent == edit) {
174 If ($did = 21) { itemsearch | did -f $dname 21 }
175 }
176}
177
178alias -l itemsearch {
179 If ($did($dname,21).text) {
180 var %t = $did($dname,3).seltext
181 var %sel = $did($dname,9).seltext
182 var %f = $iif($did($dname,22).state,r,w)
183 var %f = $iif($did($dname,20).state,$upper(%f),$lower(%f))
184 var %d = $iif($did($dname,19).state,.$true,)
185 var %s = $did($dname,21).text
186 var %x = $iif(%d,$hfind(%t,%s,0,%f).data,$hfind(%t,%s,0,%f))
187 did -o $dname 8 1 Items $+($chr(40),%x,/,$hget(%t,0).item,$chr(41))
188 did -r $dname 9
189 while (%x) {
190 if (%d) var %st = $hfind(%t,%s,%x,%f).data
191 else var %st = $hfind(%t,%s,%x,%f)
192 did -a $dname 9 %st
193 dec %x
194 }
195 If (%sel) && ($didreg($dname,9,/^ $+ %sel $+ $/)) { did -c $dname 9 $v1 }
196 Else {
197 did -r $dname 14,16
198 did -b $dname 11-17
199 }
200 }
201 Else {
202 iu
203 }
204}
205
206alias -l iu {
207 var %tb = $did($dname,3).seltext
208 var %it = $did($dname,9).seltext
209 var %x = $hget(%tb,0).item
210 did -r $dname 9
211 did -o $dname 8 1 Items $+($chr(40),%x,$chr(41))
212 did -e $dname 18-23
213 while (%x) { did -a $dname 9 $hget(%tb,%x).item | dec %x }
214 If (%it) && ($didreg($dname,9,/^ $+ %it $+ $/)) { did -c $dname 9 $v1 }
215 Else {
216 did -r $dname 14,16
217 did -b $dname 11-17
218 }
219}
220
221alias hrename {
222 var %t1 = $1, %t2 = $2
223 hmake %t2 $hget(%t1).size
224 var %x = $hget(%t1,0).item
225 while (%x) {
226 hadd %t2 $hget(%t1,%x).item $hget(%t1,%x).data
227 dec %x
228 }
229 hfree %t1
230}
231
232alias -l derror {
233 If ($1 == -c) { did -o $dname 1 1 Error: Unable To Create Hash Table. ( $+ $2- $+ ) }
234 ElseIf ($1 == -r) { did -o $dname 1 1 Error: Unable To Rename Hash Table. ( $+ $2- $+ ) }
235 ElseIf ($1 == -a) { did -o $dname 1 1 Error: Unable To Add Item. ( $+ $2- $+ ) }
236 ElseIf ($1 == -u) { did -o $dname 1 1 Error: Unable To Update Item. ( $+ $2- $+ ) }
237}
238