xref: /aosp_15_r20/external/bcc/libbpf-tools/android/argp.h (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <errno.h>
20 #include <stdio.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define ARGP_ERR_UNKNOWN -1
27 
28 #define ARGP_HELP_STD_HELP 0
29 
30 #define ARGP_KEY_ARG '\0'
31 #define ARGP_KEY_END 256
32 
33 #define OPTION_HIDDEN 1
34 
35 struct argp_option {
36     const char *name;
37     const int key;
38     const char *argname;
39     int n;
40     const char *docstring;
41 };
42 
43 struct argp_state {
44     int arg_num;
45     void *input;
46     const struct argp *argp;
47 };
48 
49 typedef int error_t;
50 
51 struct argp {
52     const struct argp_option *options;
53     error_t (*parser)(int key, char *arg, struct argp_state *state);
54     const char *doc;
55     const char *args_doc;
56 };
57 
58 error_t argp_parse(const struct argp *argp, int argc, char **argv, int, void*, void*);
59 void argp_usage(struct argp_state*);
60 void argp_state_help(struct argp_state*, FILE *fd, int);
61 
62 #ifdef __cplusplus
63 }
64 #endif
65