xref: /inferno-os/module/fslib.m (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1Fslib: module {
2	PATH: con "/dis/lib/fslib.dis";
3	Value: adt {
4		x:	fn(v: self ref Value): ref Value.X;
5		p:	fn(v: self ref Value): ref Value.P;
6		s:	fn(v: self ref Value): ref Value.S;
7		c:	fn(v: self ref Value): ref Value.C;
8		t:	fn(v: self ref Value): ref Value.T;
9		v:	fn(v: self ref Value): ref Value.V;
10		m:	fn(v: self ref Value): ref Value.M;
11		typec: fn(v: self ref Value): int;
12		discard: fn(v: self ref Value);
13		pick {
14		X =>
15			i: Fschan;
16		T =>
17			i: Entrychan;
18		P =>
19			i: Gatechan;
20		C =>
21			i: ref Sh->Cmd;
22		S =>
23			i: string;
24		V =>
25			i: chan of int;		# sync channel for void-valued processes
26		M =>
27			i: Cmpchan;
28		}
29	};
30	init:			fn();
31	typecompat:	fn(t, act: string): int;
32	sendnulldir:	fn(c: Fschan): int;
33	quit:			fn(errorc: chan of string);
34	report:		fn(errorc: chan of string, err: string);
35	copy:		fn(src, dst: Fschan): int;
36
37	cmdusage:	fn(cmd, t: string): string;
38	type2s:		fn(t: int): string;
39	opttypes:		fn(opt: int, opts: string): (int, string);
40	splittype:		fn(t: string): (int, string, string);
41
42	Report: adt {
43
44		reportc: chan of string;
45		startc: chan of (string, chan of string);
46		enablec: chan of int;
47
48		new:		fn(): ref Report;
49		enable:	fn(r: self ref Report);
50		start:		fn(r: self ref Report, name: string): chan of string;
51	};
52	Option: adt {
53		opt: int;
54		args: list of ref Value;
55	};
56	Entrychan: adt {
57		sync: chan of int;
58		c: chan of Entry;
59	};
60	Cmpchan: type chan of (ref Sys->Dir, ref Sys->Dir, chan of int);
61	Entry: type (ref Sys->Dir, string, int);
62	Gatequery: type (Entry, chan of int);
63	Gatechan: type chan of Gatequery;
64	Fsdata: adt {
65		dir: ref Sys->Dir;
66		data: array of byte;
67	};
68	Fschan: type chan of (Fsdata, chan of int);
69	Next, Down, Skip, Quit: con iota;
70
71	Nilentry: con (nil, nil, 0);
72};
73
74Fsmodule: module {
75	types: fn(): string;
76	init:	fn();
77	run: fn(ctxt: ref Draw->Context, r: ref Fslib->Report,
78		opts: list of Fslib->Option, args: list of ref Fslib->Value): ref Fslib->Value;
79};
80
81Fsfilter: module {
82	PATH: con "/dis/lib/fsfilter.dis";
83	filter: fn[T](t: T, src, dst: Fslib->Fschan)
84		for{
85		T =>
86			query: fn(t: self T, d: ref Sys->Dir, name: string, depth: int): int;
87		};
88};
89