summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-06-26 00:45:11 +0200
committerAki <please@ignore.pl>2024-06-26 00:46:00 +0200
commite2690e1cce87be317dd8169e93a59318b42e3b82 (patch)
tree266f382e7634d929ce077cf42690bd66464c5475
downloadheaders-e2690e1cce87be317dd8169e93a59318b42e3b82.zip
headers-e2690e1cce87be317dd8169e93a59318b42e3b82.tar.gz
headers-e2690e1cce87be317dd8169e93a59318b42e3b82.tar.bz2
Implemented dumb database for standard C headers
-rw-r--r--db/c.lua55
-rw-r--r--db/posix.lua85
-rwxr-xr-xheaders.lua130
3 files changed, 270 insertions, 0 deletions
diff --git a/db/c.lua b/db/c.lua
new file mode 100644
index 0000000..adc6bd7
--- /dev/null
+++ b/db/c.lua
@@ -0,0 +1,55 @@
+aliases "ISO/IEC 9899:1990" {"ANSI X3.159-1989", "C89", "C90", "ANSI C"}
+aliases "ISO/IEC 9899:1990/Amd 1:1995" {"C95"}
+aliases "ISO/IEC 9899:1999" {"C99"}
+aliases "ISO/IEC 9899:2011" {"C11"}
+aliases "ISO/IEC 9899:2018" {"C17"}
+aliases "ISO/IEC 9899:2024" {"C23", "C"}
+headers "C89" {
+ "assert.h",
+ "ctype.h",
+ "errno.h",
+ "float.h",
+ "limits.h",
+ "locale.h",
+ "math.h",
+ "setjmp.h",
+ "signal.h",
+ "stdarg.h",
+ "stddef.h",
+ "stdio.h",
+ "stdlib.h",
+ "string.h",
+ "time.h",
+}
+headers "C95" {
+ include "C89",
+ "iso646.h",
+ "wchar.h",
+ "wctype.h",
+}
+headers "C99" {
+ include "C95",
+ "complex.h",
+ "fenv.h",
+ "inttypes.h",
+ "stdbool.h",
+ "stdint.h",
+ "tgmath.h",
+}
+headers "C11" {
+ include "C99",
+ "stdalign.h",
+ "stdatomic.h",
+ "stdnoreturn.h",
+ "threads.h",
+ "uchar.h",
+}
+headers "C17" {
+ include "C11",
+}
+headers "C23" {
+ include "C17",
+ -- remove "stdnoreturn.h", -- deprecated
+ "stdbit.h",
+ "stdckdint.h",
+}
diff --git a/db/posix.lua b/db/posix.lua
new file mode 100644
index 0000000..3757a7d
--- /dev/null
+++ b/db/posix.lua
@@ -0,0 +1,85 @@
+aliases "IEEE Std 1003.1-2008" {"POSIX"}
+headers "POSIX" {
+ "aio.h",
+ "arpa/inet.h",
+ "assert.h",
+ "complex.h",
+ "cpio.h",
+ "ctype.h",
+ "dirent.h",
+ "dlfcn.h",
+ "errno.h",
+ "fcntl.h",
+ "fenv.h",
+ "float.h",
+ "fmtmsg.h",
+ "fnmatch.h",
+ "ftw.h",
+ "glob.h",
+ "grp.h",
+ "iconv.h",
+ "inttypes.h",
+ "iso646.h",
+ "langinfo.h",
+ "libgen.h",
+ "limits.h",
+ "locale.h",
+ "math.h",
+ "monetary.h",
+ "mqueue.h",
+ "ndbm.h",
+ "net/if.h",
+ "netdb.h",
+ "netinet/in.h",
+ "netinet/tcp.h",
+ "nl_types.h",
+ "poll.h",
+ "pthread.h",
+ "pwd.h",
+ "regex.h",
+ "sched.h",
+ "search.h",
+ "semaphore.h",
+ "setjmp.h",
+ "signal.h",
+ "spawn.h",
+ "stdarg.h",
+ "stdbool.h",
+ "stddef.h",
+ "stdint.h",
+ "stdio.h",
+ "stdlib.h",
+ "string.h",
+ "strings.h",
+ "stropts.h",
+ "sys/ipc.h",
+ "sys/mman.h",
+ "sys/msg.h",
+ "sys/resource.h",
+ "sys/select.h",
+ "sys/sem.h",
+ "sys/shm.h",
+ "sys/socket.h",
+ "sys/stat.h",
+ "sys/statvfs.h",
+ "sys/time.h",
+ "sys/times.h",
+ "sys/types.h",
+ "sys/uio.h",
+ "sys/un.h",
+ "sys/utsname.h",
+ "sys/wait.h",
+ "syslog.h",
+ "tar.h",
+ "termios.h",
+ "tgmath.h",
+ "time.h",
+ "trace.h",
+ "ulimit.h",
+ "unistd.h",
+ "utime.h",
+ "utmpx.h",
+ "wchar.h",
+ "wctype.h",
+ "wordexp.h",
+}
diff --git a/headers.lua b/headers.lua
new file mode 100755
index 0000000..13d98a9
--- /dev/null
+++ b/headers.lua
@@ -0,0 +1,130 @@
+#!/usr/bin/env lua
+--- For example:
+---
+--- $ ./headers.lua db/c.lua C23
+--- assert.h
+--- ctype.h
+--- ...
+local public = {}
+local private = {}
+private.tags = {}
+private.tags_lookup = {}
+private.headers = {}
+
+
+local tag do
+ local methods = {}
+ function methods:add (header)
+ table.insert(self.headers_, header)
+ end
+ local function headers (self)
+ local result = {}
+ for _, value in pairs(self.headers_) do
+ if type(value) == "function" then
+ value(result)
+ else
+ table.insert(result, value)
+ end
+ end
+ return result
+ end
+ local mt = {
+ __tostring=function (self) return self.name end,
+ __index=function (self, key)
+ if key == "headers" then
+ return headers(self)
+ end
+ return methods[key]
+ end,
+ }
+ function tag (name)
+ return setmetatable({name=name, headers_={}}, mt)
+ end
+end
+
+
+local alias do
+ local mt = {
+ __tostring = function (self) return string.format("%s (%s)", self.name, tostring(self.tag)) end,
+ __index = function (self, key) return self.tag[key] end,
+ }
+ function alias (name, tag)
+ return setmetatable({name=name, tag=tag}, mt)
+ end
+end
+
+
+local function include (source)
+ return function (target)
+ for _, header in pairs(source.headers) do
+ table.insert(target, header)
+ end
+ end
+end
+
+
+local function remove (header)
+ return function (target)
+ for key, value in pairs(target) do
+ if value == header then
+ table.remove(target, key)
+ end
+ end
+ end
+end
+
+
+local function get_or_create_tag (name)
+ local found = private.tags_lookup[name]
+ if not found then
+ found = tag(name)
+ table.insert(private.tags, found)
+ private.tags_lookup[name] = found
+ end
+ return found
+end
+
+
+function public.aliases (name)
+ local tag = get_or_create_tag(name)
+ return function (aliases)
+ for _, name in pairs(aliases) do
+ private.tags_lookup[name] = alias(name, tag)
+ end
+ end
+end
+
+
+function public.headers (name)
+ local tag = get_or_create_tag(name)
+ return function (filenames)
+ for _, header in pairs(filenames) do
+ tag:add(header)
+ end
+ end
+end
+
+
+function public.include (tag)
+ tag = private.tags_lookup[tag] or error("invalid tag: " .. tag, 2)
+ return include(tag)
+end
+
+
+function public.remove (header)
+ return remove(header)
+end
+
+
+local db = loadfile(arg[1], nil, public)
+db()
+if arg[2] then
+ local tag = private.tags_lookup[arg[2]]
+ for _, header in pairs(tag.headers) do
+ print(header)
+ end
+else
+ for _, tag in pairs(private.tags_lookup) do
+ print(tag)
+ end
+end