diff options
author | turret <turret@duck.com> | 2023-11-19 18:57:55 -0600 |
---|---|---|
committer | turret <turret@duck.com> | 2023-11-19 18:57:55 -0600 |
commit | a8b2282eb88f24c3c5f461e1557fa2cf76ebc251 (patch) | |
tree | 67544659f7df20e0286cb82e17aa47520a601f14 /include | |
download | discord-bot-skeleton-a8b2282eb88f24c3c5f461e1557fa2cf76ebc251.tar.gz discord-bot-skeleton-a8b2282eb88f24c3c5f461e1557fa2cf76ebc251.tar.bz2 discord-bot-skeleton-a8b2282eb88f24c3c5f461e1557fa2cf76ebc251.zip |
Initial commit
- create subsystem system using clone syscall, shared memory, shared
file descriptors
- printk-like logging facility (TODO: console loglevel)
- initcall system (like linux kernel)
TODO: determine license
factors: linker.ld, linux kernel licensing (some ideas are more
liberally taken rather than paraphrased)
Diffstat (limited to 'include')
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | include/init.h | 23 | ||||
-rw-r--r-- | include/log.h | 42 | ||||
-rw-r--r-- | include/subsys.h | 7 | ||||
-rw-r--r-- | include/util.h | 5 |
5 files changed, 81 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..4254edc --- /dev/null +++ b/include/config.h @@ -0,0 +1,4 @@ +#define VERSION "0.0.1" +#define NAME_SHORTHAND "TCDBF" +#define NAME "turret.'s C Discord Bot Framework" + diff --git a/include/init.h b/include/init.h new file mode 100644 index 0000000..c9d8cba --- /dev/null +++ b/include/init.h @@ -0,0 +1,23 @@ +#ifndef __INIT_H +#define __INIT_H + +typedef int (*initcall_t)(void); +typedef initcall_t initcall_entry_t; + +#define __define_initcall(fn, id) \ + static initcall_t __initcall_##fn##id \ + __attribute__((used)) \ + __attribute__((section(".initcall" #id ".init"))) = fn + +#define l1_initcall(fn) __define_initcall(fn, 1) +#define l2_initcall(fn) __define_initcall(fn, 2) +#define l3_initcall(fn) __define_initcall(fn, 3) +#define l4_initcall(fn) __define_initcall(fn, 4) +#define l5_initcall(fn) __define_initcall(fn, 5) + +static inline initcall_t initcall_from_entry(initcall_entry_t *entry) +{ + return *entry; +} + +#endif diff --git a/include/log.h b/include/log.h new file mode 100644 index 0000000..52d45ff --- /dev/null +++ b/include/log.h @@ -0,0 +1,42 @@ + +#define LOG_SOH "\001" +#define LOG_SOH_ASCII '\001' + +#define LOG_EMERG LOG_SOH "0" +#define LOG_ALERT LOG_SOH "1" +#define LOG_CRIT LOG_SOH "2" +#define LOG_ERR LOG_SOH "3" +#define LOG_WARNING LOG_SOH "4" +#define LOG_NOTICE LOG_SOH "5" +#define LOG_INFO LOG_SOH "6" +#define LOG_DEBUG LOG_SOH "7" + +#define LOG_DEFAULT "" + +int print(const char *fmt, ...); + +#define ANSI_CSI "\x1b[" + +#define ANSI_BOLD ANSI_CSI "1m" +#define ANSI_ITALIC ANSI_CSI "3m" +#define ANSI_BLINK ANSI_CSI "5m" +#define ANSI_REVERSE ANSI_CSI "7m" +#define ANSI_RESET ANSI_CSI "0m" + +#define ANSI_BLACK ANSI_CSI "30m" +#define ANSI_RED ANSI_CSI "31m" +#define ANSI_GREEN ANSI_CSI "32m" +#define ANSI_YELLOW ANSI_CSI "33m" +#define ANSI_BLUE ANSI_CSI "34m" +#define ANSI_MAGENTA ANSI_CSI "35m" +#define ANSI_CYAN ANSI_CSI "36m" +#define ANSI_WHITE ANSI_CSI "37m" + +#define ANSI_BRIGHT_BLACK ANSI_CSI "90m" +#define ANSI_BRIGHT_RED ANSI_CSI "91m" +#define ANSI_BRIGHT_GREEN ANSI_CSI "92m" +#define ANSI_BRIGHT_YELLOW ANSI_CSI "93m" +#define ANSI_BRIGHT_BLUE ANSI_CSI "94m" +#define ANSI_BRIGHT_MAGENTA ANSI_CSI "95m" +#define ANSI_BRIGHT_CYAN ANSI_CSI "96m" +#define ANSI_BRIGHT_WHITE ANSI_CSI "97m" diff --git a/include/subsys.h b/include/subsys.h new file mode 100644 index 0000000..1515293 --- /dev/null +++ b/include/subsys.h @@ -0,0 +1,7 @@ +#ifndef __SUBSYS_H +#define __SUBSYS_H + +int __impl_start_subsystem(char *name, int (*fn)(void)); +#define start_subsystem(fn) __impl_start_subsystem(#fn, fn) + +#endif diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..97435be --- /dev/null +++ b/include/util.h @@ -0,0 +1,5 @@ +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +void die(const char *fmt, ...); + +#define writeputs(str) write(STDOUT_FILENO, str, strlen(str)); |