Coffee Space


Listen:

Smol Libs

Preview Image

I’ve been sitting on this for quite a while and wanted to show a friend some part of the library, when I thought “why not just publish it?”. I previously showed off xgui, but now I am releasing the other repositories: https://gitlab.com/danbarry16/smol-libs/

The aim of the project is to create:

A series of small C libraries contained within source code of 80x25 characters.

A small example calculator

Why? Because I believe in the Unix philosophy, namely (in the words of Doug McIlroy):

  1. Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new “features”.

And from Peter Salus:

And from Ken Thompson and Dennis Ritchie:

The 80x25 arbitrary ‘limitation’1 on these small libraries is simply a piece of code that could be reasonably read and understood over a cup of coffee. They are naturally limited by this constraint and avoid issues of bloat. Ultimately, one must pick what is really important to achieving some goal. There is zero room for additional features.

Libraries

As is documented (currently) on the readme:

  • git - Library that allows reading git repositories and performing basic actions on them.
  • json - Parse JSON files from strings and disk, dumping changes as a string.
  • ppm - Read and write PPM and PGM files. Doesn’t support comments in files.
  • prop - Read and write property files. Similar to Bash variables and Java Properties files.
  • serv - Basic multi-threaded HTTP web server that parses headers.
  • xgui - A simple X11 window that offers strings (with fonts), buttons, images and input events.

Getting these libraries into a small size was not easy, and some sacrifices were made. By far the one I wasn’t even sure would be possible was the JSON library, which abuses some tricks to get into the footprint.

Future libraries I will consider writing (when I get time - hah!) are:

  • Hash Map - A simple hash map implementation.
  • Logging - Multi-threaded logging.
  • SVG - Write SVG files to disk.
  • Testing - Compile time unit testing.
  • TUI - Simple text user interface.
  • WAV - Read and write WAV files.

Maybe I could also consider:

Usage

At the time of writing, serv, json and git are all being actively used to run the Git server here: https://coffeespace.org.uk/git/. The source code of this is not ready to be released, but let’s say you would not be disappointed:

0001 $ ls -lah git_serv
0002 -rwxrwxr-x 1 dan dan 45K Feb 21 23:24 git_serv

I am also considering writing:


  1. Which is broken lightly when required.↩︎