aboutsummaryrefslogtreecommitdiffstats

What is this?

This is just a collection of (usually single-purpose) header files that I use refularly in my code

Common conventions

  • As these are header-only libraries, there is a macro in form HEADER_NAME_IMPLEMENTATION that has to be defined before including the header. A header can only be included once while this macro is defined, otherwise you get multiple definition errors.
  • Names starting with underscores are kind of private-use for this libraries, but they may be declared not static because they are used in macros that expose API.
  • snake_case
  • Function-like macros are not all-caps.
  • For now i only support GCC-based compilers. I will consider removing this dependency in future (e.g. getting rid of all typeof uses)

Descriptions for heders:

container.h

  • Summary: originally was several headers, but since hash_map.h used dynarray.h, which itself used utility.h, it was too complex to work with. So i combined everything in a single header.
  • How to use: Define CONTAINER_IMPLEMENTATION macro before including container.h. It's probably better to #undef it after inclusion as well. To use some functions (__default_int_cmp and alikes), define CONTAINER_EXPOSE_HELPERS.
  • Examples: See tests
  • Notes: if compiled in shared object, must be compiled with -fPIC

Additional macros

  • SHRINK_RESIGING_ARRAY: Reallocate the array to smaller capacity when it's size becomes too small. Not impelemented at the moment.
  • Disable parts of the library: CONTAINER_DISABLE_HMAP and CONTAINER_DISABLE_HSET will disable hash map and hash set implementation correspondingly. CONTAINER_DISABLE_LINKED_LIST will disable linked list, and since hmap and hset depend on it, will disable them as well. CONTAINER_DISABLE_HASH will disable both hash set and hash map. CONTAINER_DISABLE_ARRAY will disable array implementation (and hmap and hset as a consequence). CONTAINER_DISABLE_UTILITY will disable utilities, which will in turn disable everything else. CONTAINER_DISABLE_ALL will not disable anything else but will leave you with unuseable header. Not useful, huh?

rstypes.h

  • Summary: rust type aliases (like u32, f128 e.t.c.)
  • How to use: if you don't need i128 or u128, then just include the header. If you do need them, define macro RS_TYPES_USE_128.
  • Examples: See tests.
  • Notes: Not many compilers support 128-bit wide integers, and ones which DO support them tend to warn you that these are non ISO-C. That's why I've put them behind a macro. If they are not supported, their usage will fail with compilation error.

embed.h [[NOT IN DEVELOPMENT]]

  • Summary: Code generator for embedding resources directly into an executable.
  • How to use: It exposes C interface, so in order to use it, you will need to have a C program that builds resources for you. It has it's own repo, but i will be adding CLI to there soon.
  • Examples: see this repo

jacson.h

  • Summary: Spec-compliant json serializer and parser
  • How to use: define JACSON_IMPLEMENTATION macro. CONTAINER_IMPLEMENTATION MUST be defined as well; either somewhere earlier in the code before including container.h or just before jacson.h. this JSON implementation uses array and hash_set.
  • Macros: JACSON_EXPORT_RSNPRINTF will make symbols __jacson_rsnprintf and __jacson_rsnputc visible. These 2 functions allow for appending a string to a buffer obtained from malloc and resizing it (realloc) if needed. They're not visible by default because they do not have obvious friendly signature.

stringbuilder.h

  • Summary: string builder. Quite simple.
  • How to use: include the header, define STRINGBUILDER_IMPLEMENTATION. Done.
  • Notes: Pretty small at the moment, but I plan on expanding it on-demand. The interfaces are called jac_sb despite the header being called stringbuilder.h. You wouldn't want to type struct stringbuilder on your keyboard each time, would you? but sb.h it too vague, it could be sucking_balls.h, sizeable_breasts.h, system_breaker.h e.t.c.

build.h

TODO for now. * Summary: a build system based on C. To compile something under it, you do something like cc -o builder builder.c && ./builder. The idea is stolen from Tsoding # Warning! Everything here is written by a relatively inexperienced student (me), so I guarantee basically nothing. Memory leaks? I am sorry for them, but also not responsible. Security? Haven't heard of that either. That's just how it is. But I try to make everything as good as possible, so you can use the code after a careful review. # License The Unlicense license. Also known as fuck google employees license (nothing personal), equivalent to BSD0, CC0 or Public Domain.

ste/

Please refer to README in ste subdirectory.