From 43c1802f880471c5b69f8c622314827790aad0b8 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 26 Sep 2025 23:04:36 +0200 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- include/pudc/compiler.h | 22 +++++++++++++++++ include/pudc/print.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ include/pudc/pudc.h | 32 ++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 include/pudc/compiler.h create mode 100644 include/pudc/print.h create mode 100644 include/pudc/pudc.h (limited to 'include') 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à + * + * 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 . + */ + +#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à + * + * 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 . + */ + +#pragma once + +#include +#include +#include + +/** + * 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à + * + * 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 . + */ + +#pragma once + +/** + * Version of pudc. + */ +#define PUDC_VERSION "0.1.0" + +/** + * Halt execution of the program by looping indefinitely. + */ +#define halt() \ + for (;;) { \ + ; \ + } -- cgit v1.2.3