-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtungle.myr
69 lines (63 loc) · 1.44 KB
/
tungle.myr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* bsd license blah blah */
use bio
use std
use "crytype"
use "emojipasta"
use "misc"
const help = {err
std.fput(std.Err,
"flags:\n" \
" c crytype\n" \
" e emojipasta (work in progress)\n" \
" o owo\n" \
" r ratchet\n" \
" l lower\n" \
" u upper\n" \
" h this\n")
std.exit(err)
}
const parse = {args
if args.len == 1
var pipeline = std.slalloc(2)[:1]
pipeline[0] = [
fltr.crytype,
fltr.emojipasta,
fltr.owo,
fltr.ratchet,
][std.rand(0, 4)]
-> std.slpush(&pipeline, {l; std.put("{}\n", l); -> l})
elif args.len > 2
std.fput(std.Err, "too many args\n")
help(1)
;;
var pipeline = std.slalloc(args[1].len + 1)[:0]
for f : std.bychar(args[1][args[1][0] == ('-' : byte) ? 1 : 0:])
match f
| 'c': std.slpush(&pipeline, fltr.crytype)
| 'e': std.slpush(&pipeline, fltr.emojipasta)
| 'o': std.slpush(&pipeline, fltr.owo)
| 'r': std.slpush(&pipeline, fltr.ratchet)
| 'l': std.slpush(&pipeline, fltr.lower)
| 'u': std.slpush(&pipeline, fltr.upper)
| 'h': help(0)
| c: std.fatal("invalid flag: {}\n", c)
;;
;;
-> std.slpush(&pipeline, {l; std.put("{}\n", l); -> l})
}
const main = {args : byte[:][:]
var in = bio.mkfile(std.In, bio.Rd)
var pipeline = parse(args)
/* bio.byline automatically frees the line and we don't want this */
for ; ;
match bio.readln(in)
| `std.Ok l:
for f : pipeline
var l1 = f(l)
std.slfree(l)
l = l1
;;
| `std.Err _: break
;;
;;
}