interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / tools / bring / src / 90main.om

177 lines · 2992 bytes Raw Blame History
1text tbring "bring"
2text tget "get"
3text twithdr "withdraw"
4text tpack "pack"
5text tunpack "unpack"
6text tpatch "patch"
7text tvarg "--version"
8text tusage "usage: interplane bring [folder] | get <page or rid> | withdraw <page or rid> | patch [--base REF] [--title T] [--message-file F] [--yes] OWNER/REPO | pack <folder> <archive> | unpack <archive> <folder>"
9text tconsent "Your project will be published on an open network called Radicle, through Interplane.\nPublishing is permanent: copies may stay on other computers even if you withdraw it later.\nType yes to publish it, anything else to stop:\n"
10text ttty "/dev/tty"
11text tyes "yes"
12text tno "Nothing sent.\n"
13note consent: q is printed, then one line from /dev/tty (never stdin): true only for exactly "yes"
14fn consent q view uchar * to bool
15say q
16fd = pl_open ttty 4 0
17if lt fd 0
18ret false
19end
20b = new uchar 1 0
21a = new uchar 3 0
22n = ulong 0
23ok = true
24while true bound 9223372036854775807
25r = read int fd b 0 1
26if eq r -4
27continue
28end
29if le r 0
30ok = false
31break
32end
33if eq get b 0 10
34break
35end
36if lt n 3
37put a n get b 0
38else
39ok = false
40end
41n = add n 1
42end
43pl_close int fd
44ret and ok and eq n 3 beq a tyes
45end
46fn prepare folder view uchar * to void
47r = pl_cd folder
48if lt r 0
49die terrdir
50end
51tmpsetup
52put grecfd 0 topen tfiles 2
53put gspool 0 topen tkeep 2
54walk part tdot 0 0
55pl_close get grecfd 0
56pl_close get gspool 0
57sortfiles
58mkname
59say tname
60wname 1
61say tnl
62say tcnt
63sayd get gcount 0
64say tnl
65say tbytes
66sayd get gbytes 0
67say tnl
68end
69fn getarg i ulong b edit uchar * to ulong
70n = pl_arg i b
71if lt n 0
72die tusage
73end
74ret ulong n
75end
76fn main to int
77cmd = new uchar 4096 0
78folder = new uchar 4096 0
79archivep = new uchar 4096 0
80ac = pl_argc
81if lt ac 2
82die tusage
83end
84n = getarg 1 cmd
85if beq part cmd 0 n tvarg
86say tver
87ret 0
88end
89if beq part cmd 0 n tpatch
90ret patchflow ulong ac
91end
92if beq part cmd 0 n tunpack
93if ne ac 4
94die tusage
95end
96an = getarg 2 archivep
97fnl = getarg 3 folder
98fd = pl_open part archivep 0 an 0 0
99if lt fd 0
100die terrio
101end
102tarwalk int fd false
103r = pl_seek int fd 0
104r = pl_mkdir part folder 0 fnl 448
105if ne r 0
106die texists
107end
108r = pl_cd part folder 0 fnl
109if lt r 0
110die terrdir
111end
112tarwalk int fd true
113pl_close int fd
114ret 0
115end
116if beq part cmd 0 n tpack
117if ne ac 4
118die tusage
119end
120fnl = getarg 2 folder
121an = getarg 3 archivep
122fd = pl_open part archivep 0 an 3 384
123if lt fd 0
124die texists
125end
126prepare part folder 0 fnl
127archive int fd
128pl_close int fd
129cleanup
130ret 0
131end
132if beq part cmd 0 n tbring
133if gt ac 3
134die tusage
135end
136fnl = ulong 1
137put folder 0 46
138if eq ac 3
139fnl = getarg 2 folder
140end
141prepare part folder 0 fnl
142if not consent tconsent
143say tno
144cleanup
145ret 1
146end
147bringflow part folder 0 fnl
148cleanup
149ret 0
150end
151if beq part cmd 0 n tget
152if ne ac 3
153die tusage
154end
155fnl = getarg 2 folder
156tmpsetup
157getflow part folder 0 fnl
158cleanup
159ret 0
160end
161if beq part cmd 0 n twithdr
162if ne ac 3
163die tusage
164end
165fnl = getarg 2 folder
166tmpsetup
167if not wdflow part folder 0 fnl
168say tno
169cleanup
170ret 1
171end
172cleanup
173ret 0
174end
175die tusage
176ret 1
177end