summaryrefslogtreecommitdiffhomepage
path: root/docs/coption_api.md
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2021-11-10 12:39:26 +0100
committerTyge Lovset <[email protected]>2021-11-10 12:39:26 +0100
commit36c1ed31c7376a48d60ee709e84f7aa1acaf0867 (patch)
tree53043f554501dc3e9ed17d23cc4e31baefe4927e /docs/coption_api.md
parent888a3ac3c43b49a9fdd1f5e29dcb6b4cdbf3b262 (diff)
downloadSTC-modified-36c1ed31c7376a48d60ee709e84f7aa1acaf0867.tar.gz
STC-modified-36c1ed31c7376a48d60ee709e84f7aa1acaf0867.zip
Updated coption.
Diffstat (limited to 'docs/coption_api.md')
-rw-r--r--docs/coption_api.md38
1 files changed, 18 insertions, 20 deletions
diff --git a/docs/coption_api.md b/docs/coption_api.md
index 7a62ddea..b7eebc43 100644
--- a/docs/coption_api.md
+++ b/docs/coption_api.md
@@ -7,35 +7,33 @@ See [getopt_long](https://www.freebsd.org/cgi/man.cgi?getopt_long(3)) for a simi
## Types
```c
-enum {
- coption_no_argument = 0,
- coption_required_argument = 1,
- coption_optional_argument = 2
-};
-typedef struct {
- int ind; /* equivalent to posix optind */
- int opt; /* equivalent to posix optopt */
- const char *arg; /* equivalent to posix optarg */
- const char *badopt; /* points to the bad option, if any */
- int longindex; /* index of long option; or -1 if short */
- ...
-} coption;
+typedef enum {
+ coption_no_argument,
+ coption_required_argument,
+ coption_optional_argument
+} coption_type;
typedef struct {
const char *name;
- int has_arg;
+ coption_type type;
int val;
} coption_long;
-const coption coption_inits;
+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);
+coption coption_init(void);
+int coption_get(coption *opt, int argc, char *argv[],
+ const char *shortopts, const coption_long *longopts);
```
## Example
@@ -70,10 +68,10 @@ int main(int argc, char *argv[]) {
printf("filename: %s\n", opt.arg);
break;
case ':':
- printf("option %s needs a value\n", opt.badopt);
+ printf("option %s needs a value\n", opt.optstr);
break;
case '?':
- printf("unknown option: %s\n", opt.badopt);
+ printf("unknown option: %s\n", opt.optstr);
break;
}
}