Skip to content

Commit bf93437

Browse files
committed
Added the README.md file
1 parent f40e6a0 commit bf93437

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Introduction
2+
3+
argparse is a simple parser for the command line options, that implements the parser for the standart Unix-like options
4+
5+
## Example
6+
7+
```c
8+
/* <this_example> --verbose -cj --move "/some/where/" test_project */
9+
#include "argparse.h"
10+
#include <stdio.h>
11+
12+
static char is_verbose = 0;
13+
static char jump = 0;
14+
static char jump_last = 0;
15+
static char should_create = 0;
16+
static char project_name [5000];
17+
18+
int main (int argc, char ** argv) {
19+
if (argc == 1) {
20+
return 0;
21+
}
22+
char buffer[5000] = { 0x0 };
23+
arg_list list = {
24+
{ 'v', "verbose", NULL, &is_verbose },
25+
{ 'c', "create", NULL, &should_create },
26+
{ 'j', "jump", NULL, &jump },
27+
{ 'J', "jump-last", NULL, &jump_last },
28+
{ 'm', "move", arg_string_handler, buffer },
29+
{ 0 }
30+
};
31+
32+
arg_return code;
33+
char ** ptr;
34+
35+
/* buffer for elements, that are not keys */
36+
char * nk_buffer[3];
37+
/* size of the written buffer */
38+
size_t buf_size;
39+
40+
if ((ptr = arg_parse (argc, argv, list, nk_buffer, &buf_size, &code)) != NULL) {
41+
printf ("An error occured here: %s", *ptr);
42+
return code;
43+
}
44+
45+
if (nk_buffer[0]) {
46+
ARG_STRCPY(project_name, nk_buffer[0]);
47+
}
48+
49+
printf ("Name: %s\nCreate? %i\nVerbose? %i\nJump? %i\nJump-last? %i\nMove to: %s\n", (const char *)project_name, should_create, is_verbose, jump, jump_last, buffer);
50+
51+
return 0;
52+
}
53+
```
54+
55+
## Installation
56+
57+
To install argparse on a unix system just type `make && doas make install`

0 commit comments

Comments
 (0)