Skip to content

Simple, stupid and portable C argument (argv) parser.

License

Notifications You must be signed in to change notification settings

ScientificC/simple-parse

 
 

Repository files navigation

simple-parse

Mac OS and
Travis CI: Build Status AppVeyor: Build status

Simple, stupid and portable C argument (argv) parser. SParse is inspired by cargo. The idea is to expand the functionalities that this library offers, reimplement them and add new ones.

Build

Just include sparse.h to your project.

SParse tests are built with CMake for all platforms. You can also use the fake configure script provided to set it up on unix:

$ ./configure
$ make

Example

To handle the following program arguments:

./myprog --flag1 --flag2= --flag3=hello --flag4="Hello world"

You could write this:

#include <stdlib.h>
#include <sparse.h>

int main(int argc, char* argv[])
{
    char *f1 = sparse_flag("flag1", "FALSE", argc, argv);         /* f1 = "TRUE" */
    char *f2 = sparse_flag("flag2", "defaultval", argc, argv);    /* f2 = "" */
    char *f3 = sparse_flag("flag3", "bye", argc, argv);           /* f3 = "hello" */
    char *f4 = sparse_flag("flag4", "Bye world", argc, argv);     /* f4 = "Hello world" */
    char *f5 = sparse_flag("flag5", "default", argc, argv);       /* f5 = "default" */
    char *f6 = sparse_flag("flag6", "FALSE", argc, argv);         /* f6 = "FALSE" */

    return 0;
}

About

Simple, stupid and portable C argument (argv) parser.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 81.4%
  • CMake 18.6%