Browse Source

Update libutil

master
Jake Wakeling 11 months ago
parent
commit
15db0be8fb
  1. 15
      CMakeLists.txt
  2. 61
      src/lib/error.c
  3. 47
      src/lib/error.h
  4. 55
      src/lib/optget.h
  5. 5
      src/obfi.c
  6. 41
      src/util/error.c
  7. 68
      src/util/error.h
  8. 33
      src/util/optget.c
  9. 36
      src/util/optget.h
  10. 73
      src/util/util.h

15
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})

61
src/lib/error.c

@ -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); }

47
src/lib/error.h

@ -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

55
src/lib/optget.h

@ -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

5
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>

41
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); }

68
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

33
src/lib/optget.c → 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"

36
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

73
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
Loading…
Cancel
Save