aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/pudc/compiler.h22
-rw-r--r--include/pudc/print.h66
-rw-r--r--include/pudc/pudc.h32
3 files changed, 120 insertions, 0 deletions
diff --git a/include/pudc/compiler.h b/include/pudc/compiler.h
new file mode 100644
index 0000000..c1c3c87
--- /dev/null
+++ b/include/pudc/compiler.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+/*
+ * Copyright (C) 2024-Ω Miquel Sabaté Solà <mssola@mssola.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#define __noreturn __attribute__((__noreturn__))
+#define __unused(x) (void)x
diff --git a/include/pudc/print.h b/include/pudc/print.h
new file mode 100644
index 0000000..1a5436c
--- /dev/null
+++ b/include/pudc/print.h
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+/*
+ * Copyright (C) 2024-Ω Miquel Sabaté Solà <mssola@mssola.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+/**
+ * The type of output being delivered.
+ *
+ * NOTE: internal; use the 'pr_*' macros instead.
+ */
+enum print_type {
+ info,
+ error,
+ debug,
+};
+
+/**
+ * Print the given @message into the @stream while prefixing it with the given
+ * @type. The @should_halt boolean determines whether execution should halt or
+ * not after printing everything.
+ *
+ * NOTE: internal; use the 'pr_*' macros instead.
+ */
+void pr_out(bool should_halt, FILE *stream, enum print_type type, const char *const message, ...);
+
+/**
+ * Print the given @message to the standard output. This @message is formatted
+ * with stdargs and it will be prefixed with the current local time.
+ */
+#define pr_info(message, ...) pr_out(false, stdout, info, message, ##__VA_ARGS__)
+
+/**
+ * Like 'pr_info', but into the stderr. Moreover, the first argument
+ * @should_halt determines whether this function should halt
+ */
+#define pr_error(should_halt, message, ...) \
+ pr_out(should_halt, stderr, error, message, ##__VA_ARGS__)
+
+/**
+ * Like 'pr_info' but with "debug" as an @id and it only prints something if
+ * __DEBUG__ has been defined.
+ */
+#ifdef __DEBUG__
+#define pr_debug(message, ...) pr_out(false, stdout, debug, message, ##__VA_ARGS__)
+#else
+#define pr_debug(message, ...) (void)(message)
+#endif
diff --git a/include/pudc/pudc.h b/include/pudc/pudc.h
new file mode 100644
index 0000000..e76b43d
--- /dev/null
+++ b/include/pudc/pudc.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+/*
+ * Copyright (C) 2024-Ω Miquel Sabaté Solà <mssola@mssola.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+/**
+ * Version of pudc.
+ */
+#define PUDC_VERSION "0.1.0"
+
+/**
+ * Halt execution of the program by looping indefinitely.
+ */
+#define halt() \
+ for (;;) { \
+ ; \
+ }