unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob 64751df4ada125de6fcbf8d0353e8617e9e40372 1886 bytes (raw)
name: test/arg-test.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
#include <stdio.h>
#include "command-line-arguments.h"


int main(int argc, char **argv){

    int opt_index=1;

    int kw_val=0;
    int fl_val=0;
    int int_val=0;
    const char *pos_arg1=NULL;
    const char *pos_arg2=NULL;
    const char *string_val=NULL;
    notmuch_bool_t bool_val = FALSE;
    notmuch_bool_t fl_set = FALSE, int_set = FALSE, bool_set = FALSE,
	kw_set = FALSE, string_set = FALSE, pos1_set = FALSE, pos2_set = FALSE;

    notmuch_opt_desc_t parent_options[] = {
	{ .opt_flags = &fl_val, .name = "flag", .present = &fl_set, .keywords =
	  (notmuch_keyword_t []){ { "one",   1 << 0},
				  { "two",   1 << 1 },
				  { "three", 1 << 2 },
				  { 0, 0 } } },
	{ .opt_int = &int_val, .name = "int", .present = &int_set },
	{ }
    };

    notmuch_opt_desc_t options[] = {
	{ .opt_bool = &bool_val, .name = "boolean", .present = &bool_set },
	{ .opt_keyword = &kw_val, .name = "keyword", .present = &kw_set, .keywords =
	  (notmuch_keyword_t []){ { "zero", 0 },
				  { "one", 1 },
				  { "two", 2 },
				  { 0, 0 } } },
	{ .opt_inherit = parent_options },
	{ .opt_string = &string_val, .name = "string", .present = &string_set },
	{ .opt_position = &pos_arg1, .present = &pos1_set },
	{ .opt_position = &pos_arg2, .present = &pos2_set },
	{ }
    };

    opt_index = parse_arguments(argc, argv, options, 1);

    if (opt_index < 0)
	return 1;

    if (bool_set)
	printf("boolean %d\n", bool_val);

    if (kw_set)
	printf("keyword %d\n", kw_val);

    if (fl_set)
	printf("flags %d\n", fl_val);

    if (int_set)
	printf("int %d\n", int_val);

    if (string_set)
	printf("string %s\n", string_val);

    if (pos1_set)
	printf("positional arg 1 %s\n", pos_arg1);

    if (pos2_set)
	printf("positional arg 2 %s\n", pos_arg2);


    for ( ; opt_index < argc ; opt_index ++) {
	printf("non parsed arg %d = %s\n", opt_index, argv[opt_index]);
    }

    return 0;
}

debug log:

solving 64751df4ada1 ...
found 64751df4ada1 in https://yhetil.org/notmuch.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).