A small, C99, single-header, zero-allocation, dependency-free, public domain argument parsing library
Find a file
2022-09-25 12:42:17 +02:00
test formatting 2022-09-25 12:42:17 +02:00
.clang-format formatting 2022-09-25 12:08:56 +02:00
.gitignore turn readopt into a single-header library 2022-09-25 12:40:12 +02:00
LICENSE initial commit 2021-02-08 17:07:25 +01:00
README.md correct name 2021-02-09 12:38:49 +01:00
readopt.h turn readopt into a single-header library 2022-09-25 12:40:12 +02:00

readopt

Overview

This is an option parsing library.

The following option formats are recognized:

  • -f
  • -fvalue
  • -f value
  • -asdf (grouped short options)
  • -asdfvalue
  • -asdf value
  • --file
  • --file value
  • --file=value
  • -f value1 -f value2 ... (multiple values are represented in an array)
  • -f value1 operand1 -f value2 operand2 (operands intermixed with options)

It permutes argv to handle multiple values for each option and to assign values to operands.

mdoc(7) SYNOPSIS sections and plaintext usage messages can be generated as well (via readopt_put_usage).

An example can be found in test/test.c.

Building

Build and install the library by either using

$ ninja
# ninja install

or

$ make
# make install

By default, the library will be installed to /usr/local/lib, which may not be in your library path. You can change this by modifying the $prefix in the config.ninja or by overriding the $(PREFIX) variable for the Makefile.