diff options
| author | Tyge Løvset <[email protected]> | 2022-05-31 15:04:52 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-05-31 15:04:52 +0200 |
| commit | eb9821bec4a292458499042392924595b3338085 (patch) | |
| tree | 90b6286619deefc2eaf72fce4fc67d5959c84557 /docs/coption_api.md | |
| parent | 0a92ec2235b5f42e93012be14938bb11e3f3650a (diff) | |
| download | STC-modified-eb9821bec4a292458499042392924595b3338085.tar.gz STC-modified-eb9821bec4a292458499042392924595b3338085.zip | |
1) REMOVED files/modules not relevant: makes lib more focused:
- threads.h/threads.c (external lib)
- coptions.h - will be kept as a gist.
- more will follow, (examples, some benchmarks, etc).
2) Replaced UTF8 decoder with Björn Höhrmann's DFA decoder.
Diffstat (limited to 'docs/coption_api.md')
| -rw-r--r-- | docs/coption_api.md | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/docs/coption_api.md b/docs/coption_api.md deleted file mode 100644 index be0d0978..00000000 --- a/docs/coption_api.md +++ /dev/null @@ -1,71 +0,0 @@ -# STC [coption](../include/stc/coption.h): Command line argument parsing - -This describes the API of the *coption_get()* function for command line argument parsing. - -See [getopt_long](https://www.freebsd.org/cgi/man.cgi?getopt_long(3)) for a similar posix function. - -## Types - -```c -typedef enum { - coption_no_argument, - coption_required_argument, - coption_optional_argument -} coption_type; - -typedef struct { - const char *name; - coption_type type; - int val; -} coption_long; - -typedef struct { - int ind; /* equivalent to posix optind */ - int opt; /* equivalent to posix optopt */ - const char *optstr; /* points to the option string, if any */ - const char *arg; /* equivalent to posix optarg */ - ... -} coption; -``` - -## Methods - -```c -coption coption_init(void); -int coption_get(coption *opt, int argc, char *argv[], - const char *shortopts, const coption_long *longopts); -``` - -## Example - -```c -#include <stdio.h> -#include <stc/coption.h> - -int main(int argc, char *argv[]) { - coption_long longopts[] = { - {"foo", coption_no_argument, 'f'}, - {"bar", coption_required_argument, 'b'}, - {"opt", coption_optional_argument, 'o'}, - {0} - }; - const char* shortopts = "xy:z::123"; - if (argc == 1) - printf("Usage: program -x -y ARG -z [ARG] -1 -2 -3 --foo --bar ARG --opt [ARG] [ARGUMENTS]\n", argv[0]); - coption opt = coption_init(); - int c; - while ((c = coption_get(&opt, argc, argv, shortopts, longopts)) != -1) { - switch (c) { - case '?': printf("error: unknown option: %s\n", opt.optstr); break; - case ':': printf("error: missing argument for %s\n", opt.optstr); break; - default: printf("option: %c [%s]\n", opt.opt, opt.arg ? opt.arg : ""); break; - } - } - printf("\nNon-option arguments:"); - for (int i = opt.ind; i < argc; ++i) - printf(" %s", argv[i]); - putchar('\n'); -} - return 0; -} -``` |
