OBFI

Brainfuck Interpreter
git clone http://git.omkov.net/OBFI
Log | Tree | Refs | README | LICENCE | Download

AuthorJakob Wakeling <[email protected]>
Date2021-02-17 22:46:41
Commite37e00e437871817b5b8e29a4f951642ef74b32e
Parent9d8e220a1ebd2cffb52d9e8eee0ea1615f7b0769

Update lib/error to version 1.0.2

Diffstat

M CMakeLists.txt | 3 ---
M src/lib/error.c | 12 +++++++++---
M src/lib/error.h | 8 ++++++--

3 files changed, 15 insertions, 8 deletions

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cfe3d2c..1f998d0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,3 @@
-# CMakeLists.txt
-# CMakeLists file for OBFI
-
 CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
 PROJECT(OBFI VERSION 1.0.3 LANGUAGES C)
 
diff --git a/src/lib/error.c b/src/lib/error.c
index f246723..e0c80d3 100644
--- a/src/lib/error.c
+++ b/src/lib/error.c
@@ -1,4 +1,4 @@
-// error.c, version 1.0.1
+// error.c, version 1.0.2
 // Error source file for OMKOV lib
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -34,22 +34,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 
 #include <errno.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdnoreturn.h>
 #include <string.h>
 
 char *A0 = NULL;
+bool warned = false;
 
-_Noreturn void error(int status, const char *format, ...) {
+/* Print an error message and exit */
+noreturn void error(int status, const char *format, ...) {
 	fflush(stdout); if (A0) { fputs(A0, stderr); fputs(": ", stderr); }
 	va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap);
 	fputc('\n', stderr); exit(status);
 }
 
+/* Print a warning message and set the warned flag */
 void warn(const char *format, ...) {
 	fflush(stdout); if (A0) { fputs(A0, stderr); fputs(": ", stderr); }
 	va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap);
-	fputc('\n', stderr); return;
+	fputc('\n', stderr); warned = true; return;
 }
 
+/* Shorthand for strerror(errno) */
 char *serr(void) { return strerror(errno); }
diff --git a/src/lib/error.h b/src/lib/error.h
index d0d4585..16db9cf 100644
--- a/src/lib/error.h
+++ b/src/lib/error.h
@@ -1,4 +1,4 @@
-// error.h, version 1.0.1
+// error.h, version 1.0.2
 // Error header file for OMKOV lib
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -33,9 +33,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #ifndef OMKOV_LIB_ERROR_H_38W06M3W
 #define OMKOV_LIB_ERROR_H_38W06M3W
 
+#include <stdbool.h>
+#include <stdnoreturn.h>
+
 extern char *A0;
+extern bool warned;
 
-extern _Noreturn void error(int status, const char *format, ...);
+extern noreturn void error(int status, const char *format, ...);
 extern void warn(const char *format, ...);
 
 extern char *serr(void);