summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorAiden Gall <aiden@aidengall.xyz>2024-02-04 14:43:37 +0000
committerAiden Gall <aiden@aidengall.xyz>2024-02-04 14:46:37 +0000
commitc44d2805ba480fc7c2faf8ae07f2c1c9febf7e34 (patch)
tree0171574e51da53dbe2664360949cc78259b2da0b /src/util.c
parent5ff9d6184771970c14e682ecf55cbd9d27b2fada (diff)
render with raylib
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c168
1 files changed, 24 insertions, 144 deletions
diff --git a/src/util.c b/src/util.c
index bf06bca..dcf3212 100644
--- a/src/util.c
+++ b/src/util.c
@@ -13,19 +13,18 @@ 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 <http://www.gnu.org/licenses/>. */
-#include <CL/cl.h>
-#include <CL/cl_platform.h>
-#include <CL/cl_version.h>
+#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
void warn(const char *fmt, ...);
void die(const char *fmt, ...);
void efwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
-const char *cl_strerror(cl_int err);
+long argtonum(const char *arg, long minval, long maxval);
void
warn(const char *const fmt, ...)
@@ -57,145 +56,26 @@ efwrite(const void *const ptr, const size_t size, const size_t nmemb,
die("fwrite: Write failed\n");
}
-const char *
-cl_strerror(const cl_int err)
+long
+argtonum(const char *const arg, const long minval, const long maxval)
{
- switch (err) {
- case CL_SUCCESS:
- return "CL_SUCCESS";
- case CL_DEVICE_NOT_FOUND:
- return "CL_DEVICE_NOT_FOUND";
- case CL_DEVICE_NOT_AVAILABLE:
- return "CL_DEVICE_NOT_AVAILABLE";
- case CL_COMPILER_NOT_AVAILABLE:
- return "CL_COMPILER_NOT_AVAILABLE";
- case CL_MEM_OBJECT_ALLOCATION_FAILURE:
- return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
- case CL_OUT_OF_RESOURCES:
- return "CL_OUT_OF_RESOURCES";
- case CL_OUT_OF_HOST_MEMORY:
- return "CL_OUT_OF_HOST_MEMORY";
- case CL_PROFILING_INFO_NOT_AVAILABLE:
- return "CL_PROFILING_INFO_NOT_AVAILABLE";
- case CL_MEM_COPY_OVERLAP:
- return "CL_MEM_COPY_OVERLAP";
- case CL_IMAGE_FORMAT_MISMATCH:
- return "CL_IMAGE_FORMAT_MISMATCH";
- case CL_IMAGE_FORMAT_NOT_SUPPORTED:
- return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
- case CL_BUILD_PROGRAM_FAILURE:
- return "CL_BUILD_PROGRAM_FAILURE";
- case CL_MAP_FAILURE:
- return "CL_MAP_FAILURE";
- case CL_INVALID_VALUE:
- return "CL_INVALID_VALUE";
- case CL_INVALID_DEVICE_TYPE:
- return "CL_INVALID_DEVICE_TYPE";
- case CL_INVALID_PLATFORM:
- return "CL_INVALID_PLATFORM";
- case CL_INVALID_DEVICE:
- return "CL_INVALID_DEVICE";
- case CL_INVALID_CONTEXT:
- return "CL_INVALID_CONTEXT";
- case CL_INVALID_QUEUE_PROPERTIES:
- return "CL_INVALID_QUEUE_PROPERTIES";
- case CL_INVALID_COMMAND_QUEUE:
- return "CL_INVALID_COMMAND_QUEUE";
- case CL_INVALID_HOST_PTR:
- return "CL_INVALID_HOST_PTR";
- case CL_INVALID_MEM_OBJECT:
- return "CL_INVALID_MEM_OBJECT";
- case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
- return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
- case CL_INVALID_IMAGE_SIZE:
- return "CL_INVALID_IMAGE_SIZE";
- case CL_INVALID_SAMPLER:
- return "CL_INVALID_SAMPLER";
- case CL_INVALID_BINARY:
- return "CL_INVALID_BINARY";
- case CL_INVALID_BUILD_OPTIONS:
- return "CL_INVALID_BUILD_OPTIONS";
- case CL_INVALID_PROGRAM:
- return "CL_INVALID_PROGRAM";
- case CL_INVALID_PROGRAM_EXECUTABLE:
- return "CL_INVALID_PROGRAM_EXECUTABLE";
- case CL_INVALID_KERNEL_NAME:
- return "CL_INVALID_KERNEL_NAME";
- case CL_INVALID_KERNEL_DEFINITION:
- return "CL_INVALID_KERNEL_DEFINITION";
- case CL_INVALID_KERNEL:
- return "CL_INVALID_KERNEL";
- case CL_INVALID_ARG_INDEX:
- return "CL_INVALID_ARG_INDEX";
- case CL_INVALID_ARG_VALUE:
- return "CL_INVALID_ARG_VALUE";
- case CL_INVALID_ARG_SIZE:
- return "CL_INVALID_ARG_SIZE";
- case CL_INVALID_KERNEL_ARGS:
- return "CL_INVALID_KERNEL_ARGS";
- case CL_INVALID_WORK_DIMENSION:
- return "CL_INVALID_WORK_DIMENSION";
- case CL_INVALID_WORK_GROUP_SIZE:
- return "CL_INVALID_WORK_GROUP_SIZE";
- case CL_INVALID_WORK_ITEM_SIZE:
- return "CL_INVALID_WORK_ITEM_SIZE";
- case CL_INVALID_GLOBAL_OFFSET:
- return "CL_INVALID_GLOBAL_OFFSET";
- case CL_INVALID_EVENT_WAIT_LIST:
- return "CL_INVALID_EVENT_WAIT_LIST";
- case CL_INVALID_EVENT:
- return "CL_INVALID_EVENT";
- case CL_INVALID_OPERATION:
- return "CL_INVALID_OPERATION";
- case CL_INVALID_GL_OBJECT:
- return "CL_INVALID_GL_OBJECT";
- case CL_INVALID_BUFFER_SIZE:
- return "CL_INVALID_BUFFER_SIZE";
- case CL_INVALID_MIP_LEVEL:
- return "CL_INVALID_MIP_LEVEL";
- case CL_INVALID_GLOBAL_WORK_SIZE:
- return "CL_INVALID_GLOBAL_WORK_SIZE";
-#ifdef CL_VERSION_1_1
- case CL_MISALIGNED_SUB_BUFFER_OFFSET:
- return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
- case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST:
- return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
- case CL_INVALID_PROPERTY:
- return "CL_INVALID_PROPERTY";
-#endif
-#ifdef CL_VERSION_1_2
- case CL_COMPILE_PROGRAM_FAILURE:
- return "CL_COMPILE_PROGRAM_FAILURE";
- case CL_LINKER_NOT_AVAILABLE:
- return "CL_LINKER_NOT_AVAILABLE";
- case CL_LINK_PROGRAM_FAILURE:
- return "CL_LINK_PROGRAM_FAILURE";
- case CL_DEVICE_PARTITION_FAILED:
- return "CL_DEVICE_PARTITION_FAILED";
- case CL_KERNEL_ARG_INFO_NOT_AVAILABLE:
- return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
- case CL_INVALID_IMAGE_DESCRIPTOR:
- return "CL_INVALID_IMAGE_DESCRIPTOR";
- case CL_INVALID_COMPILER_OPTIONS:
- return "CL_INVALID_COMPILER_OPTIONS";
- case CL_INVALID_LINKER_OPTIONS:
- return "CL_INVALID_LINKER_OPTIONS";
- case CL_INVALID_DEVICE_PARTITION_COUNT:
- return "CL_INVALID_DEVICE_PARTITION_COUNT";
-#endif
-#ifdef CL_VERSION_2_0
- case CL_INVALID_PIPE_SIZE:
- return "CL_INVALID_PIPE_SIZE";
- case CL_INVALID_DEVICE_QUEUE:
- return "CL_INVALID_DEVICE_QUEUE";
-#endif
-#ifdef CL_VERSION_2_2
- case CL_INVALID_SPEC_ID:
- return "CL_INVALID_SPEC_ID";
- case CL_MAX_SIZE_RESTRICTION_EXCEEDED:
- return "CL_MAX_SIZE_RESTRICTION_EXCEEDED";
-#endif
- default:
- return "OpenCL unknown error";
- }
+ long ret;
+ char *endptr;
+
+ if (minval > maxval)
+ die("argtonum: Invalid range\n");
+ if (!arg)
+ die("argtonum: Missing argument\n");
+
+ errno = 0;
+ ret = strtol(arg, &endptr, 10);
+ if (errno)
+ die("strtol: %s\n", strerror(errno));
+ if (arg == endptr || *endptr)
+ die("strtol: Invalid integer\n");
+
+ if (ret < minval || ret > maxval)
+ die("argtonum: Argument out of range\n");
+
+ return ret;
}