The <UL/types.h>
header file includes useful standard typedefs.
typedef _Bool BOOL;
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned int u32_t;
typedef unsigned long long u64_t;
typedef signed char i8_t;
typedef signed short i16_t;
typedef signed int i32_t;
typedef signed long i64_t;
typedef float f32_t;
typedef double f64_t;
typedef i32_t (*compare_f)(const void *a, const void *b);
The <UL/assert.h>
header contains assert macros aswell as macros for printing errors and warnings.
#define log_err(format, ...)
prints [Error]: format
to the stderr
output buffer
#define log_warn(format, ...)
prints [Warning]: format
to the stdout
output buffer
#define assertf(assertion, format, ...)
if @assertion
is false, print [Error]: format
to stderr
and call exit(-1):
#define assertf_to(assertion, label, format, ...)
if @assertion
is false, print [Error]: format
to stderr
and goto label
#define assert(assertion)
if @assertion
is false, print [Error]: assertion error
to stderr
and call exit(-1):
#define assert_to(assertion, label)
if @assertion
is false, print [Error]: assertion error
to stderr
and goto label
The <UL/str.h>
header contains various useful string functions.
bool is_ascii(i32_t i);
if @i
is a ascii
character return true
else return false
.
u32_t nbr_of_digits(u64_t n, u32_t base);
returns the number of digits needed to represent @n
in the base @base
.
char * iarrtos(i32_t * data, i64_t length);
'int array to string', allocates and returns a comma delimited string representation of the first @length
i32_t´s in @data
.
char * farrtos(f64_t * data, i64_t length);
'double array to string', allocates and returns a comma delimited string representation of the first @length
f64_t´s in @data
.
i64_t strcnt(const char * buff, char delim);
returns the number of words in @buff
separated by @delim
,
useful for example to count number of values in a csv file eg. strcnt("data.csv", ',');
or the number of arguments in a string command.
i64_t CSV_iarr(i32_t ** res, char * data, char del);
converts @data
: a string whith integer values separated by @del
, into a array of values: *@res
and returns the number of values in @res
.
i64_t CSV_farr(f64_t ** res, char * data, char del);
converts @data
: a string whith float values separated by @del
, into a array of values: *@res
and returns the number of values in @res
.
The <UL/IO.h>
header contains I/O functions mainly for making working whith files easier.
i64_t get_filesize(const char *fname);
returns number the size of the file named @fname
in bytes.
u8_t * read_file(const char *fname, i64_t *len);
allocates and returns a u8_t*
containing the contents of the file named @fname
. if @len
is not NULL
it is set to the length of the read file in bytes (allocated size is length of the read file + 1 in order to enable the addition of a \0
char to convert it to a string).
char * read_sfile(const char *fname, i64_t *len);
allocates and returns a \0
terminated string containing the contents of the file named @fname
. if @len
is not NULL
it is set to the length of the read file in bytes.
BOOL remove_file(const char *fname);
returns if the file named @fname
was removed.
void create_file(const char *fname);
creates the file named @fname
.
BOOL rename_file(const char *src, const char *fname);
renames the file named @src
file to @fname
and returns if this was successful.
BOOL file_exists(const char *fname);
returns true if the file named @fname
exists.
BOOL file_can_read(const char *fname);
returns true if the program can read the file named @fname
.
BOOL file_can_write(const char *fname);
returns true if the program can write to the file named @fname
.
BOOL file_can_exec(const char *fname);
returns true if the program can execute the file named @fname
.
void write_file(const char *fname, const char *str);
write the contents of the string @str
to the file named @fname
if no such files exists it is created.
void nwrite_file(const char *fname, const char *str u64_t n);
write the first @n
bytes of the string @str
to the file named @fname
if no such files exists it is created.
void append_file(const char *fname, const char *str);
appends the contents of the string @str
to the file named @fname
if no such files exists it is created.
void nappend_file(const char *fname, const char *str u64_t n);
appends the first @n
bytes of the string @str
to the file named @fname
if no such files exists it is created.
void hexdump(const u8_t *data, u64_t len);
prints the first @len
bytes of data in @data
formated similar to hexdump
The <UL/math.h>
header file contains various math related macros
#define PI_HALF 1.57079632679489661923132169163975144
#define PI 3.14159265358979323846264338327950288
#define TWO_PI 6.28318530717958647692528676655900576
#define RAD_IN_DEG 57.295779513082320876798154814105170408 // RAD_IN_DEG = 180 / PI
#define DEG_IN_RAD 0.017453292519943295769236907684886127 // DEG_IN_RAD = PI / 180
math constants
#define LOW_16(address)
#define HIGH_16(address)
returns the low / high u16_t values of the u32_t @address
#define LOW_8(word)
#define HIGH_8(word)
returns the low / high u8_t bytes of the u16_t @word
#define MAX(a, b)
#define MIN(a, b)
returns the largest / smallest value of @a
and @b
#define COS2F(_x)
#define SIN2F(_x)
returns quadratic sin/cos of @_x
as a f32_t
#define deg_to_rad(_x)
#define rad_to_deg(_x)
returns @_x
in radians/degrees
#define clamp(v, min, max)
returns @v
clamped between @min
and @max
#define sign(v)
returns -1 if @v
is negative else 1
#define randf(min, max)
#define randi(min, max)
returns a random f64_t / i32_t between @min
andi @max
.
#define remap(v,a1,a2,b1,b2)
returns @v
remaped from the range @a1->@a2
to the range @b1->@b2
.
The <UL/macro.h
header contains some less common specialized macros for example gcc __attribute__
macros like:
#define PACKED __attribute__((__packed__))
#define WUNUSED __attribute__((warn_unused_result))
#define ALWAYS_INLINE __attribute__((always_inline))
#define COLD __attribute__((cold))
#define CONST __attribute__ ((const))
#define DEPRICIATED __attribute__ ((deprecated))
#define PURE __attribute__ ((pure))