Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ulises-jeremias/simple-parse
Simple, stupid and portable C argument (argv) parser.
https://github.com/ulises-jeremias/simple-parse
Last synced: 20 days ago
JSON representation
Simple, stupid and portable C argument (argv) parser.
- Host: GitHub
- URL: https://github.com/ulises-jeremias/simple-parse
- Owner: ulises-jeremias
- License: mit
- Created: 2018-02-14T06:11:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-01T04:09:55.000Z (over 5 years ago)
- Last Synced: 2024-10-13T02:09:52.243Z (about 1 month ago)
- Language: C
- Size: 15.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-parse
Mac OS and |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Travis CI: [![Build Status](https://travis-ci.org/ulises-jeremias/simple-parse.svg?branch=master)](https://travis-ci.org/ulises-jeremias/simple-parse) | AppVeyor: [![Build status](https://ci.appveyor.com/api/projects/status/mpc8xk0odl5er0lk/branch/master?svg=true)](https://ci.appveyor.com/project/ulises-jeremias/simple-parse/branch/master)Simple, stupid and portable C argument (argv) parser. SParse is inspired by [cargo](https://github.com/funlibs/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:
```sh
$ ./configure
$ make
```## Example
To handle the following program arguments:
```sh
./myprog --flag1 --flag2= --flag3=hello --flag4="Hello world"
```You could write this:
```c
#include
#includeint 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;
}
```