Coder Social home page Coder Social logo

ul's Introduction

Documentation


Table of contents

  1. <UL/types.h>
  2. <UL/assert.h>
    1. log_err
    2. log_warn
    3. assertf
    4. assertf_to
    5. assert
    6. assert_to
  3. <UL/str.h>
    1. is_ascii
    2. nbr_of_digits
    3. iarrtos
    4. farrtos
    5. strcnt
    6. CSV_iarr
    7. CSV_farr
  4. <UL/IO.h>
    1. get_filesize
    2. read_sfile
    3. read_file
    4. remove_file
    5. create_file
    6. rename_file
    7. file_exists
    8. file_can_read
    9. file_can_write
    10. file_can_exec
    11. write_file
    12. nwrite_file
    13. append_file
    14. nappend_file
    15. hexdump
  5. <UL/math.h>
    1. constants
    2. low/high words
    3. low/high bytes
    4. min/max
    5. sin2/cos2
    6. rad/deg
    7. clamp
    8. sign
    9. rand
    10. remap
  6. <UL/macro.h>

<UL/types.h>

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

<UL/assert.h>

The <UL/assert.h> header contains assert macros aswell as macros for printing errors and warnings.


log_err

#define log_err(format, ...)

prints [Error]: format to the stderr output buffer

log_warn

#define log_warn(format, ...)

prints [Warning]: format to the stdout output buffer

assertf

#define assertf(assertion, format, ...)

if @assertion is false, print [Error]: format to stderr and call exit(-1):

assertf_to

#define assertf_to(assertion, label, format, ...)

if @assertion is false, print [Error]: format to stderr and goto label

assert

#define assert(assertion)

if @assertion is false, print [Error]: assertion error to stderr and call exit(-1):

assert_to

#define assert_to(assertion, label)

if @assertion is false, print [Error]: assertion error to stderr and goto label


<UL/str.h>

The <UL/str.h> header contains various useful string functions.


is_ascii

bool is_ascii(i32_t i);

if @i is a ascii character return true else return false.

nbr_of_digits

u32_t nbr_of_digits(u64_t n, u32_t base);

returns the number of digits needed to represent @n in the base @base.

iarrtos

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.

iarrtos

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.

strcnt

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.

CSV_iarr

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.

CSV_farr

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.


<UL/IO.h>

The <UL/IO.h> header contains I/O functions mainly for making working whith files easier.


get_filesize

i64_t get_filesize(const char *fname);

returns number the size of the file named @fname in bytes.

read_file

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).

read_sfile

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.

remove_file

BOOL remove_file(const char *fname);

returns if the file named @fname was removed.

create_file

void create_file(const char *fname);

creates the file named @fname.

rename_file

BOOL rename_file(const char *src, const char *fname);

renames the file named @src file to @fname and returns if this was successful.

file_exists

BOOL file_exists(const char *fname);

returns true if the file named @fname exists.

file_can_read

BOOL file_can_read(const char *fname);

returns true if the program can read the file named @fname.

file_can_write

BOOL file_can_write(const char *fname);

returns true if the program can write to the file named @fname.

file_can_exec

BOOL file_can_exec(const char *fname);

returns true if the program can execute the file named @fname.

write_file

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.

nwrite_file

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.

append_file

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.

nappend_file

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.

hexdump

void hexdump(const u8_t *data, u64_t len);

prints the first @len bytes of data in @data formated similar to hexdump


<UL/math.h>

The <UL/math.h> header file contains various math related macros


constants

#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

low/high words

#define LOW_16(address)
#define HIGH_16(address)

returns the low / high u16_t values of the u32_t @address

low/high bytes

#define LOW_8(word)
#define HIGH_8(word)

returns the low / high u8_t bytes of the u16_t @word

min/max bytes

#define MAX(a, b)
#define MIN(a, b)

returns the largest / smallest value of @a and @b

cos2/sin2

#define COS2F(_x)
#define SIN2F(_x)

returns quadratic sin/cos of @_x as a f32_t

rad/deg

#define deg_to_rad(_x)
#define rad_to_deg(_x)

returns @_x in radians/degrees

clamp

#define clamp(v, min, max)

returns @v clamped between @min and @max

sign

#define sign(v)

returns -1 if @vis negative else 1

rand

#define randf(min, max)
#define randi(min, max)

returns a random f64_t / i32_t between @min andi @max.

remap

#define remap(v,a1,a2,b1,b2)

returns @v remaped from the range @a1->@a2 to the range @b1->@b2.


<UL/macro.h>

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.