Projects / rlib

git clone https://molodetz.nl/retoor/rlib.git

Files

RLIB

Collection of frequently used C functions by me.

It contains

  • An advanced benchmark system.
  • An alternative to printf supporting printing of time between messages for e.g. benchmarking. and colors.
  • Super fast tree map (much faster than hash table).
  • Stdout redirection.
  • Terminal progress bar.
  • Multi purpose lexer.
  • Custom malloc for counting allocations and free's.
  • Simple test library that works like assert that also checks memory if rmalloc is used and creates summary and provides exit code.
  • Several time functions supporting nano seconds.
  • Several math functions for if not available by std (on termux for example).
  • Arena blazing fast memory.

Extensive tested and benchmarked

All files get merged together to one file called rlib.c that can be used as a header file. The result is a single header framework. Gif of build process

ENVIRONMENT VARIABLES

Disabling color

Set env RDISABLE_COLORS = 1 to disable color on stdout. stderr will still have colors for gui.

Compiler and Flags

  • CC = gcc : Specifies the C compiler (GCC).
  • CFLAGS = -Wall -Wextra -Ofast : Compiler flags:
    • -Wall : Enable all warnings.
    • -Wextra : Enable extra warnings.
    • -Ofast : Optimize for speed.
  • LDFLAGS = -lm : Linker flags to link with the math library.

Main Targets

all:

Runs the following steps in sequence:

  • Testing ( test_* targets).
  • Formatting code ( format_all ).
  • Building the project ( build ).
  • Installing executables ( install ).

format_all:

Runs clang-format to format all .c , .h , and .cpp files in the directory.

build:

Builds the rlib shared library ( librlib.so ) and an executable rlibso that uses this library:

  • Compiles rlib.c into librlib.so .
  • Compiles rlibso.c linking it with librlib.so .
  • Runs the rlibso executable.

install:

Installs the rmerge and clean executables to /usr/bin using sudo .

Testing Targets ( test_* )

Each test_* target follows these steps:

build_*:

Compiles a specific .c file into an executable in the ./build directory.

run_*:

Runs the corresponding executable.

Example for rlexer :

  • build_rlexer: Compiles rlexer.c to ./build/rlexer .
  • run_rlexer: Runs ./build/rlexer .

Backup

backup:

Compresses the source files, Makefile, and additional project files into a rlib.rzip archive.

Special Cases

test_rbench_cpp:

Builds and runs a C++ benchmark program:

  • Compiles rbench.cpp along with other necessary files.
  • Runs the resulting executable.

Other Targets

format_rlib_c:

Specifically formats the rlib.c file.

build_*:

Targets that compile source files into executables.

run_*:

Targets that run the compiled executables.

Files

  • Makefile 4.8 KB raw
  • README.md 2.8 KB raw
  • _rlib.h 1.4 KB raw
  • arena.c 1.4 KB raw
  • arena.h 1.4 KB raw
  • license.h 1.3 KB raw
  • main.h 1.7 KB raw
  • nsock.c 474 B raw
  • nsock.h 13.4 KB raw
  • r.c 814 B raw
  • rargs.h 1.5 KB raw
  • rautocomplete.c 2.5 KB raw
  • rautocomplete.h 2.8 KB raw
  • rbench.c 13.1 KB raw
  • rbench.cpp 6.5 KB raw
  • rbench.h 15.0 KB raw
  • rbuffer.c 3.1 KB raw
  • rbuffer.h 6.1 KB raw
  • rcase.c 425 B raw
  • rcase.h 3.7 KB raw
  • rcat.c 1.4 KB raw
  • rcat.h 834 B raw
  • rcov.c 319 B raw
  • rcov.h 2.9 KB raw
  • reditor.c 4.3 KB raw
  • remo.c 348 B raw
  • remo.h 9.3 KB raw
  • resources
  • rfalloc.c 2.7 KB raw
  • rhashtable.c 497 B raw
  • rhashtable.h 2.6 KB raw
  • rhttp.c 2.3 KB raw
  • rhttp.h 19.6 KB raw
  • rhttpc.c 514 B raw
  • ricli.c 10.4 KB raw
  • rinterp.c 1.2 KB raw
  • rio.c 1.4 KB raw
  • rio.h 3.6 KB raw
  • rjson.c 1.0 KB raw
  • rjson.h 4.0 KB raw
  • rkeytable.c 493 B raw
  • rkeytable.h 1.4 KB raw
  • rlexer.c 6.3 KB raw
  • rlexer.h 10.0 KB raw
  • rlib.c 460 B raw
  • rlib.h 249.9 KB raw
  • rlibrlibso.c 249.9 KB raw
  • rlibso.c 754 B raw
  • rliza.c 6.2 KB raw
  • rliza.h 23.8 KB raw
  • rliza.py 1.0 KB raw
  • rmalloc.c 2.6 KB raw
  • rmalloc.h 4.7 KB raw
  • rmath.h 2.0 KB raw
  • rmerge.c 1.4 KB raw
  • rmerge.h 4.1 KB raw
  • rnet.c 1.7 KB raw
  • rnet.h 12.9 KB raw
  • rprint.c 2.2 KB raw
  • rprint.h 8.3 KB raw
  • rrex3.c 438 B raw
  • rrex3.h 33.9 KB raw
  • rrex4.c 5.8 KB raw
  • rrex4.h 18.5 KB raw
  • rstring.c 5.6 KB raw
  • rstring.h 11.9 KB raw
  • rstring_list.c 1.1 KB raw
  • rstring_list.h 1.1 KB raw
  • rtemp.c 980 B raw
  • rtemp.h 2.0 KB raw
  • rterm.c 2.1 KB raw
  • rterm.h 7.9 KB raw
  • rterminal.c 1.3 KB raw
  • rterminal.h 5.2 KB raw
  • rtest.h 5.8 KB raw
  • rtime.c 1.1 KB raw
  • rtime.h 3.4 KB raw
  • rtree.c 2.1 KB raw
  • rtree.h 1.9 KB raw
  • rtypes.c 726 B raw
  • rtypes.h 647 B raw
  • uuid.h 1.1 KB raw