From f5c5db5a7378d97a6f261ffaa10c84e2005bfc4e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 5 Jan 2025 21:40:39 -0300 Subject: docs: import Wiki docs into the main repo --- docs/tools/docs.tl | 74 +++++++++++++++++++++++++++++++++++++++++++++++ docs/tools/lfs.d.tl | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 docs/tools/docs.tl create mode 100644 docs/tools/lfs.d.tl (limited to 'docs/tools') 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 @@ +local lfs = require("lfs") + +local args = {...} + +if not args[1] then + print("missing argument: ") + os.exit(1) +end + +local dirname = args[1] + +local function path(filename: string): string + return dirname .. "/" .. filename +end + +local function process_md(filename: string) + local data = assert(io.open(path(filename))):read("*a") + local missing = {} + for link in data:gmatch("%]%(([^)]*%.md)[^)]*%)") do + if not lfs.attributes(path(link)) then + table.insert(missing, { at = filename, link = link }) + end + end + + if #missing == 0 then + return + end + + print("Broken links:") + + for _, link in ipairs(missing) do + print("* At " .. link.at .. " : " .. link.link) + end + + os.exit(1) +end + +local function check_index(filename: string, all_pages: {string: boolean}) + local data = assert(io.open(path(filename))):read("*a") + for link in data:gmatch("%]%(([^)]*%.md)[^)]*%)") do + all_pages[link] = nil + end + + if not next(all_pages) then + return + end + + local missing = {} + for k, _ in pairs(all_pages) do + table.insert(missing, k) + end + table.sort(missing) + + print("Pages not referenced in index:") + + for _, page in ipairs(missing) do + print("* " .. page) + end + + os.exit(1) +end + +local all_pages = {} +for f in lfs.dir(args[1]) do + if f:match("%.md$") then + process_md(f) + all_pages[f] = true + end +end + +check_index("index.md", all_pages) + +print("All ok!") + 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 @@ +local record lfs + + enum FileMode + "file" + "directory" + "link" + "socket" + "named pipe" + "char device" + "block device" + "other" + end + + record Attributes + dev: number + ino: number + mode: FileMode + nlink: number + uid: number + gid: number + rdev: number + access: number + modification: number + change: number + size: number + permissions: string + blocks: number + blksize: number + end + + enum OpenFileMode + "binary" + "text" + end + + enum LockMode + "r" + "w" + end + + record Lock + free: function() + end + + dir: function(string): function(): string + + chdir: function(string): boolean, string + + lock_dir: function(string, number): Lock, string + + -- returns number on success, really!? this should be fixed in the lfs library + link: function(string, string, boolean): number, string + + mkdir: function(string): boolean, string + + rmdir: function(string): boolean, string + + setmode: function(string, OpenFileMode): boolean, string + + currentdir: function(): string + + attributes: function(string): Attributes + attributes: function(string, string): string + attributes: function(string, string): number + attributes: function(string, string): FileMode + attributes: function(string, Attributes): Attributes + + symlinkattributes: function(string): Attributes + symlinkattributes: function(string, string): string + symlinkattributes: function(string, string): number + symlinkattributes: function(string, string): FileMode + symlinkattributes: function(string, Attributes): Attributes + + touch: function(string, number, number): boolean, string + + -- TODO: FILE needs to be renamed to io.FILE in tl itself + lock: function(FILE, LockMode, number, number): boolean, string + unlock: function(FILE, number, number): boolean, string + +end + +return lfs -- cgit v1.2.3-55-g6feb