aboutsummaryrefslogtreecommitdiff
path: root/docs/tools
diff options
context:
space:
mode:
Diffstat (limited to 'docs/tools')
-rw-r--r--docs/tools/docs.tl74
-rw-r--r--docs/tools/lfs.d.tl82
2 files changed, 156 insertions, 0 deletions
diff --git a/docs/tools/docs.tl b/docs/tools/docs.tl
new file mode 100644
index 00000000..502de3c4
--- /dev/null
+++ b/docs/tools/docs.tl
@@ -0,0 +1,74 @@
1local lfs = require("lfs")
2
3local args = {...}
4
5if not args[1] then
6 print("missing argument: <dirname>")
7 os.exit(1)
8end
9
10local dirname = args[1]
11
12local function path(filename: string): string
13 return dirname .. "/" .. filename
14end
15
16local function process_md(filename: string)
17 local data = assert(io.open(path(filename))):read("*a")
18 local missing = {}
19 for link in data:gmatch("%]%(([^)]*%.md)[^)]*%)") do
20 if not lfs.attributes(path(link)) then
21 table.insert(missing, { at = filename, link = link })
22 end
23 end
24
25 if #missing == 0 then
26 return
27 end
28
29 print("Broken links:")
30
31 for _, link in ipairs(missing) do
32 print("* At " .. link.at .. " : " .. link.link)
33 end
34
35 os.exit(1)
36end
37
38local function check_index(filename: string, all_pages: {string: boolean})
39 local data = assert(io.open(path(filename))):read("*a")
40 for link in data:gmatch("%]%(([^)]*%.md)[^)]*%)") do
41 all_pages[link] = nil
42 end
43
44 if not next(all_pages) then
45 return
46 end
47
48 local missing = {}
49 for k, _ in pairs(all_pages) do
50 table.insert(missing, k)
51 end
52 table.sort(missing)
53
54 print("Pages not referenced in index:")
55
56 for _, page in ipairs(missing) do
57 print("* " .. page)
58 end
59
60 os.exit(1)
61end
62
63local all_pages = {}
64for f in lfs.dir(args[1]) do
65 if f:match("%.md$") then
66 process_md(f)
67 all_pages[f] = true
68 end
69end
70
71check_index("index.md", all_pages)
72
73print("All ok!")
74
diff --git a/docs/tools/lfs.d.tl b/docs/tools/lfs.d.tl
new file mode 100644
index 00000000..12535ca4
--- /dev/null
+++ b/docs/tools/lfs.d.tl
@@ -0,0 +1,82 @@
1local record lfs
2
3 enum FileMode
4 "file"
5 "directory"
6 "link"
7 "socket"
8 "named pipe"
9 "char device"
10 "block device"
11 "other"
12 end
13
14 record Attributes
15 dev: number
16 ino: number
17 mode: FileMode
18 nlink: number
19 uid: number
20 gid: number
21 rdev: number
22 access: number
23 modification: number
24 change: number
25 size: number
26 permissions: string
27 blocks: number
28 blksize: number
29 end
30
31 enum OpenFileMode
32 "binary"
33 "text"
34 end
35
36 enum LockMode
37 "r"
38 "w"
39 end
40
41 record Lock
42 free: function()
43 end
44
45 dir: function(string): function(): string
46
47 chdir: function(string): boolean, string
48
49 lock_dir: function(string, number): Lock, string
50
51 -- returns number on success, really!? this should be fixed in the lfs library
52 link: function(string, string, boolean): number, string
53
54 mkdir: function(string): boolean, string
55
56 rmdir: function(string): boolean, string
57
58 setmode: function(string, OpenFileMode): boolean, string
59
60 currentdir: function(): string
61
62 attributes: function(string): Attributes
63 attributes: function(string, string): string
64 attributes: function(string, string): number
65 attributes: function(string, string): FileMode
66 attributes: function(string, Attributes): Attributes
67
68 symlinkattributes: function(string): Attributes
69 symlinkattributes: function(string, string): string
70 symlinkattributes: function(string, string): number
71 symlinkattributes: function(string, string): FileMode
72 symlinkattributes: function(string, Attributes): Attributes
73
74 touch: function(string, number, number): boolean, string
75
76 -- TODO: FILE needs to be renamed to io.FILE in tl itself
77 lock: function(FILE, LockMode, number, number): boolean, string
78 unlock: function(FILE, number, number): boolean, string
79
80end
81
82return lfs