hive-view
aien-dev/hive-view
Brought by drakestapleton
| 1 | note hive-view src/util.om: process-wide buffers and small byte helpers (names vw*, globals g*). |
| 2 | note Composed after seed/net/http.om, seed/net/notls.om and om/tls/sha2.om; see build.sh. |
| 3 | note Globals are never passed as arguments (omc error 19): helpers name them directly. |
| 4 | global ghome uchar 512 |
| 5 | global ghomel ulong 1 |
| 6 | global grun uchar 512 |
| 7 | global grunl ulong 1 |
| 8 | global gpth uchar 4096 |
| 9 | global gpl ulong 1 |
| 10 | global gpk uchar 4096 |
| 11 | global gpkl ulong 1 |
| 12 | global gpkr ulong 1 |
| 13 | global gob uchar 262144 |
| 14 | global gol ulong 1 |
| 15 | global goa ulong 1 |
| 16 | global gotr ulong 1 |
| 17 | global gsb uchar 393216 |
| 18 | global gsl ulong 1 |
| 19 | global gstb uchar 128 |
| 20 | global gpfd uchar 8 |
| 21 | global gwst uchar 4 |
| 22 | global ghd uchar 256 |
| 23 | global ghdl ulong 1 |
| 24 | global gjunk uchar 4096 |
| 25 | global gtok uchar 64 |
| 26 | global gport ulong 1 |
| 27 | text tdevnul "/dev/null" |
| 28 | text thexd "0123456789abcdef" |
| 29 | note ---- section builder gsb |
| 30 | fn vwsbc c uchar to void |
| 31 | n = get gsl 0 |
| 32 | if lt n len gsb |
| 33 | put gsb n c |
| 34 | put gsl 0 add n 1 |
| 35 | end |
| 36 | end |
| 37 | fn vwsbt t view uchar * to void |
| 38 | for i ulong len t |
| 39 | vwsbc get t i |
| 40 | end |
| 41 | end |
| 42 | fn vwsbd v ulong to void |
| 43 | d = new uchar 20 0 |
| 44 | i = ulong 20 |
| 45 | x = v |
| 46 | for it ulong 20 |
| 47 | i = sub i 1 |
| 48 | put d i uchar add rem x 10 48 |
| 49 | x = div x 10 |
| 50 | if eq x 0 |
| 51 | break |
| 52 | end |
| 53 | end |
| 54 | for k ulong sub 20 i |
| 55 | vwsbc get d add i k |
| 56 | end |
| 57 | end |
| 58 | note vwsbo: append gob[a, a+n) to gsb |
| 59 | fn vwsbo a ulong n ulong to void |
| 60 | for i ulong n |
| 61 | vwsbc get gob add a i |
| 62 | end |
| 63 | end |
| 64 | note vwsbol: append the command/file output gob[goa, gol) to gsb |
| 65 | fn vwsbol to void |
| 66 | a = get goa 0 |
| 67 | b = get gol 0 |
| 68 | if gt b a |
| 69 | vwsbo a sub b a |
| 70 | end |
| 71 | end |
| 72 | note ---- path builder gpth (at most 4095 bytes; a longer path ends the process with status 19 |
| 73 | note rather than opening a cut, different path) |
| 74 | fn vwpb to void |
| 75 | put gpl 0 0 |
| 76 | end |
| 77 | fn vwpc c uchar to void |
| 78 | n = get gpl 0 |
| 79 | if ge n 4095 |
| 80 | exit 19 |
| 81 | end |
| 82 | put gpth n c |
| 83 | put gpl 0 add n 1 |
| 84 | end |
| 85 | fn vwpt t view uchar * to void |
| 86 | for i ulong len t |
| 87 | vwpc get t i |
| 88 | end |
| 89 | end |
| 90 | fn vwph to void |
| 91 | for i ulong get ghomel 0 |
| 92 | vwpc get ghome i |
| 93 | end |
| 94 | end |
| 95 | fn vwpr to void |
| 96 | for i ulong get grunl 0 |
| 97 | vwpc get grun i |
| 98 | end |
| 99 | end |
| 100 | fn vwpd v ulong to void |
| 101 | d = new uchar 20 0 |
| 102 | i = ulong 20 |
| 103 | x = v |
| 104 | for it ulong 20 |
| 105 | i = sub i 1 |
| 106 | put d i uchar add rem x 10 48 |
| 107 | x = div x 10 |
| 108 | if eq x 0 |
| 109 | break |
| 110 | end |
| 111 | end |
| 112 | for k ulong sub 20 i |
| 113 | vwpc get d add i k |
| 114 | end |
| 115 | end |
| 116 | note ---- packed argument list gpk (u16 count, then u16 length + bytes per record) |
| 117 | fn vwkb to void |
| 118 | put gpk 0 0 |
| 119 | put gpk 1 0 |
| 120 | put gpkl 0 2 |
| 121 | end |
| 122 | fn vwkopen to void |
| 123 | n = get gpkl 0 |
| 124 | put gpkr 0 n |
| 125 | put gpk n 0 |
| 126 | put gpk add n 1 0 |
| 127 | put gpkl 0 add n 2 |
| 128 | c = add or ulong get gpk 0 shl ulong get gpk 1 8 1 |
| 129 | put gpk 0 uchar and c 255 |
| 130 | put gpk 1 uchar shr c 8 |
| 131 | end |
| 132 | fn vwkc c uchar to void |
| 133 | n = get gpkl 0 |
| 134 | if ge n 4095 |
| 135 | exit 19 |
| 136 | end |
| 137 | put gpk n c |
| 138 | put gpkl 0 add n 1 |
| 139 | r = get gpkr 0 |
| 140 | k = add or ulong get gpk r shl ulong get gpk add r 1 8 1 |
| 141 | put gpk r uchar and k 255 |
| 142 | put gpk add r 1 uchar shr k 8 |
| 143 | end |
| 144 | fn vwka t view uchar * to void |
| 145 | vwkopen |
| 146 | for i ulong len t |
| 147 | vwkc get t i |
| 148 | end |
| 149 | end |
| 150 | note ---- little-endian reads of the small global byte buffers |
| 151 | fn vwpfd i ulong to int |
| 152 | b = mul i 4 |
| 153 | v = or ulong get gpfd b shl ulong get gpfd add b 1 8 |
| 154 | v = or v shl ulong get gpfd add b 2 16 |
| 155 | v = or v shl ulong get gpfd add b 3 24 |
| 156 | ret int v |
| 157 | end |
| 158 | fn vwst64 o ulong to ulong |
| 159 | v = ulong 0 |
| 160 | for i ulong 8 |
| 161 | v = or v shl ulong get gstb add o i mul i 8 |
| 162 | end |
| 163 | ret v |
| 164 | end |
| 165 | fn vwst32 o ulong to ulong |
| 166 | v = ulong 0 |
| 167 | for i ulong 4 |
| 168 | v = or v shl ulong get gstb add o i mul i 8 |
| 169 | end |
| 170 | ret v |
| 171 | end |
| 172 | fn vwnowms to ulong |
| 173 | ret div ulong realns 1000000 |
| 174 | end |
| 175 | note ---- byte classes |
| 176 | fn vwdig c uchar to bool |
| 177 | ret and ge c 48 le c 57 |
| 178 | end |
| 179 | fn vwhex c uchar to bool |
| 180 | if vwdig c |
| 181 | ret true |
| 182 | end |
| 183 | ret and ge c 97 le c 102 |
| 184 | end |
| 185 | note vwnamec: a byte allowed in a session name we will target (tmux names are wider; we refuse the rest) |
| 186 | fn vwnamec c uchar to bool |
| 187 | if vwdig c |
| 188 | ret true |
| 189 | end |
| 190 | if and ge c 65 le c 90 |
| 191 | ret true |
| 192 | end |
| 193 | if and ge c 97 le c 122 |
| 194 | ret true |
| 195 | end |
| 196 | ret or eq c 45 eq c 95 |
| 197 | end |