OBFI

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

AuthorJakob Wakeling <[email protected]>
Date2022-03-09 09:34:21
Commit6740ebe77cb396d090a6e0e1cec8e2aa72389fee
Parent248476e97279c9a253c95b797e514edb5b6e04ca

Update libutil

Diffstat

M CMakeLists.txt | 12 +++++-------
D src/lib/error.c | 61 -------------------------------------------------------------
D src/lib/error.h | 47 -----------------------------------------------
R src/lib/optget.c -> src/util/optget.c | 32 ++------------------------------
D src/lib/optget.h | 55 -------------------------------------------------------
M src/obfi.c | 5 +++--
A src/util/error.c | 41 +++++++++++++++++++++++++++++++++++++++++
A src/util/error.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A src/util/optget.h | 36 ++++++++++++++++++++++++++++++++++++
A src/util/util.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

10 files changed, 228 insertions, 202 deletions

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 136cee5..8462fd1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,9 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
-PROJECT(OBFI VERSION 1.0.4 LANGUAGES C)
+cmake_minimum_required(VERSION 3.12)
+project(OBFI VERSION 1.0.4 LANGUAGES C)
 
-SET(CMAKE_C_STANDARD 11)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
+add_compile_definitions(PROJECT_VERSION="${PROJECT_VERSION}")
 
-SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
-ADD_COMPILE_DEFINITIONS(PROJECT_VERSION="${PROJECT_VERSION}")
+file(GLOB SRC ${PROJECT_SOURCE_DIR}/src/*.c ${PROJECT_SOURCE_DIR}/src/**/*.c)
 
-FILE(GLOB SOURCES ${CMAKE_SOURCE_DIR}/src/*)
-FILE(GLOB LIBSRC ${CMAKE_SOURCE_DIR}/src/lib/*)
-
-ADD_EXECUTABLE(obfi ${SOURCES} ${LIBSRC})
+add_executable(obfi ${SRC})
diff --git a/src/lib/error.c b/src/lib/error.c
deleted file mode 100644
index e0c80d3..0000000
--- a/src/lib/error.c
+++ /dev/null
@@ -1,61 +0,0 @@
-// error.c, version 1.0.2
-// Error source file for OMKOV lib
-// Copyright (C) 2020, Jakob Wakeling
-// All rights reserved.
-
-/*
-OMKOV Permissive Licence, version 1.0
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal with
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-* Redistributions of source code must retain the above copyright notice, this
-  list of conditions and the following disclaimers.
-* Redistributions in binary form must reproduce the above copyright notice, this
-  list of conditions and the following disclaimers in the documentation and/or
-  other materials provided with the distribution.
-* Neither the names of the copyright holders, nor the names of its contributors
-  may be used to endorse or promote products derived from this Software without
-  specific prior written permission.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
-HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
-*/
-
-#include "error.h"
-
-#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;
-
-/* 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); 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
deleted file mode 100644
index 16db9cf..0000000
--- a/src/lib/error.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// error.h, version 1.0.2
-// Error header file for OMKOV lib
-// Copyright (C) 2020, Jakob Wakeling
-// All rights reserved.
-
-/*
-OMKOV Permissive Licence, version 1.0
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal with
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-* Redistributions of source code must retain the above copyright notice, this
-  list of conditions and the following disclaimers.
-* Redistributions in binary form must reproduce the above copyright notice, this
-  list of conditions and the following disclaimers in the documentation and/or
-  other materials provided with the distribution.
-* Neither the names of the copyright holders, nor the names of its contributors
-  may be used to endorse or promote products derived from this Software without
-  specific prior written permission.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
-HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-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 void warn(const char *format, ...);
-
-extern char *serr(void);
-
-#endif // OMKOV_LIB_ERROR_H_38W06M3W
diff --git a/src/lib/optget.h b/src/lib/optget.h
deleted file mode 100644
index f83d132..0000000
--- a/src/lib/optget.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// optget.h, version 1.6.0
-// optget header file for OMKOV lib
-// Copyright (C) 2020, Jakob Wakeling
-// All rights reserved.
-
-/*
-OMKOV Permissive Licence, version 1.0
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal with
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-* Redistributions of source code must retain the above copyright notice, this
-  list of conditions and the following disclaimers.
-* Redistributions in binary form must reproduce the above copyright notice, this
-  list of conditions and the following disclaimers in the documentation and/or
-  other materials provided with the distribution.
-* Neither the names of the copyright holders, nor the names of its contributors
-  may be used to endorse or promote products derived from this Software without
-  specific prior written permission.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
-HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
-*/
-
-#ifndef OMKOV_LIB_OPTGET_H_W3LIZK1S
-#define OMKOV_LIB_OPTGET_H_W3LIZK1S
-
-#define ARG_NUL 0
-#define ARG_REQ 1
-#define ARG_OPT 2
-
-struct lop {
-	char *str;
-	int arg, val;
-};
-
-struct opt {
-	int ind, opt, pos, nop;
-	char *arg, *lop, *str;
-	struct lop *lops;
-};
-
-extern const struct opt OPTGET_INIT;
-
-extern int optget(struct opt *opt, char *av[], int flags);
-
-#endif // OMKOV_LIB_OPTGET_H_W3LIZK1S
diff --git a/src/obfi.c b/src/obfi.c
index eca6d3f..df0d22e 100644
--- a/src/obfi.c
+++ b/src/obfi.c
@@ -34,8 +34,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 	FIXME Segfault with large tape lengths and certain programs.
 */
 
-#include "lib/error.h"
-#include "lib/optget.h"
+#include "util/error.h"
+#include "util/optget.h"
+#include "util/util.h"
 
 #include <stddef.h>
 #include <stdint.h>
diff --git a/src/util/error.c b/src/util/error.c
new file mode 100644
index 0000000..68f230b
--- /dev/null
+++ b/src/util/error.c
@@ -0,0 +1,41 @@
+// util/error.h, version 1.1.2
+// Error source file from libutil
+// Copyright (C) 2020, Jakob Wakeling
+// MIT Licence
+
+#include "error.h"
+
+#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;
+
+/* 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); warned = true; return;
+}
+
+/* Print a warning message but do not set the warned flag. */
+void alert(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;
+}
+
+/* Shorthand for strerror(errno). DEPRECIATED, use the SERR macro. */
+char *serr(void) { return strerror(errno); }
diff --git a/src/util/error.h b/src/util/error.h
new file mode 100644
index 0000000..1dbe3a2
--- /dev/null
+++ b/src/util/error.h
@@ -0,0 +1,68 @@
+// util/error.h, version 1.1.2
+// Error header file from libutil
+// Copyright (C) 2020, Jakob Wakeling
+// MIT Licence
+
+#ifndef UTIL_ERROR_H_38W06M3W
+#define UTIL_ERROR_H_38W06M3W
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdnoreturn.h>
+#include <string.h>
+
+/* Warn and then return status */
+#define WARN_R(status, format, ...) do { \
+	warn(format, __VA_ARGS__); return status; \
+} while (0)
+
+/* Warn and then reset errno */
+#define WARN_E(format, ...) do { \
+	warn(format, __VA_ARGS__); errno = 0; \
+} while (0)
+
+/* Warn, reset errno, and then return status */
+#define WARN_RE(status, format, ...) do { \
+	warn(format, __VA_ARGS__); errno = 0; return status; \
+} while (0)
+
+/* Alert and then return status */
+#define ALERT_R(status, format, ...) do { \
+	alert(format, __VA_ARGS__); return status; \
+} while (0)
+
+/* Alert and then reset errno */
+#define ALERT_E(format, ...) do { \
+	alert(format, __VA_ARGS__); errno = 0; \
+} while (0)
+
+/* Alert, reset errno, and then return status */
+#define ALERT_RE(status, format, ...) do { \
+	alert(format, __VA_ARGS__); errno = 0; return status; \
+} while (0)
+
+/* Shorthand for strerror(serrno). */
+#define SERR (strerror(errno))
+
+extern char *A0;
+extern bool warned;
+
+/* Print an error message and exit. */
+extern noreturn void error(int status, const char *format, ...);
+/* Print a warning message and set the warned flag. */
+extern void warn(const char *format, ...);
+/* Print a warning message but do not set the warned flag. */
+extern void alert(const char *format, ...);
+
+/* Shorthand for strerror(errno). DEPRECIATED, use the SERR macro. */
+extern char *serr(void);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // UTIL_ERROR_H_38W06M3W
diff --git a/src/lib/optget.c b/src/util/optget.c
similarity index 61%
rename from src/lib/optget.c
rename to src/util/optget.c
index da61ebd..62b6272 100644
--- a/src/lib/optget.c
+++ b/src/util/optget.c
@@ -1,34 +1,7 @@
-// optget.h, version 1.6.0
-// optget source file for OMKOV lib
+// util/optget.h, version 1.6.2
+// optget source file from libutil
 // Copyright (C) 2020, Jakob Wakeling
-// All rights reserved.
-
-/*
-OMKOV Permissive Licence, version 1.0
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal with
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-* Redistributions of source code must retain the above copyright notice, this
-  list of conditions and the following disclaimers.
-* Redistributions in binary form must reproduce the above copyright notice, this
-  list of conditions and the following disclaimers in the documentation and/or
-  other materials provided with the distribution.
-* Neither the names of the copyright holders, nor the names of its contributors
-  may be used to endorse or promote products derived from this Software without
-  specific prior written permission.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
-HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
-*/
+// MIT Licence
 
 #include "error.h"
 #include "optget.h"
diff --git a/src/util/optget.h b/src/util/optget.h
new file mode 100644
index 0000000..0ee1b84
--- /dev/null
+++ b/src/util/optget.h
@@ -0,0 +1,36 @@
+// util/optget.h, version 1.6.2
+// optget header file from libutil
+// Copyright (C) 2020, Jakob Wakeling
+// MIT Licence
+
+#ifndef UTIL_OPTGET_H_W3LIZK1S
+#define UTIL_OPTGET_H_W3LIZK1S
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ARG_NUL 0
+#define ARG_REQ 1
+#define ARG_OPT 2
+
+struct lop {
+	char *str;
+	int arg, val;
+};
+
+struct opt {
+	int ind, opt, pos, nop;
+	char *arg, *lop, *str;
+	struct lop *lops;
+};
+
+extern const struct opt OPTGET_INIT;
+
+extern int optget(struct opt *opt, char *av[], int flags);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // UTIL_OPTGET_H_W3LIZK1S
diff --git a/src/util/util.h b/src/util/util.h
new file mode 100644
index 0000000..3d85789
--- /dev/null
+++ b/src/util/util.h
@@ -0,0 +1,73 @@
+// util/util.h, version 1.0.1
+// Utility header file from libutil
+// Copyright (C) 2021, Jakob Wakeling
+// MIT Licence
+
+#ifndef UTIL_UTIL_H_KP8NS9DC
+#define UTIL_UTIL_H_KP8NS9DC
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <assert.h>
+#include <float.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/* Type Definitions */
+typedef uint8_t   u8;
+typedef uint16_t  u16;
+typedef uint32_t  u32;
+typedef uint64_t  u64;
+typedef uintptr_t UINT;
+
+typedef int8_t   s8;
+typedef int16_t  s16;
+typedef int32_t  s32;
+typedef int64_t  s64;
+typedef intptr_t sint;
+
+typedef float       f32;
+typedef double      f64;
+typedef long double f128;
+
+/* Type Limits */
+#define U8_MIN   UINT8_MIN
+#define U8_MAX   UINT8_MAX
+#define U16_MIN  UINT16_MIN
+#define U16_MAX  UINT16_MAX
+#define U32_MIN  UINT32_MIN
+#define U32_MAX  UINT32_MAX
+#define U64_MIN  UINT64_MIN
+#define U64_MAX  UINT64_MAX
+#define UINT_MIN UINTPTR_MIN
+#define UINT_MAX UINTPTR_MAX
+
+#define S8_MIN   INT8_MIN
+#define S8_MAX   INT8_MAX
+#define S16_MIN  INT16_MIN
+#define S16_MAX  INT16_MAX
+#define S32_MIN  INT32_MIN
+#define S32_MAX  INT32_MAX
+#define S64_MIN  INT64_MIN
+#define S64_MAX  INT64_MAX
+#define SINT_MIN INTPTR_MIN
+#define SINT_MAX INTPTR_MAX
+
+#define F32_MIN  FLT_MIN
+#define F32_MAX  FLT_MAX
+#define F64_MIN  DBL_MIN
+#define F64_MAX  DBL_MAX
+#define F128_MIN LDBL_MIN
+#define F128_MAX LDBL_MAX
+
+/* Miscellaneous */
+#define BIT(x) (1 << (x))
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // UTIL_UTIL_H_KP8NS9DC