interplane.Get Omega
Read in your language

hive-view

aien-dev/hive-view

Brought by drakestapleton

branch main Branches Tags History

hive-view / src / util.om

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