GVM User Suite
User tools for the GVM open source project.
cargs.h
Go to the documentation of this file.
1 /*
2 MIT License
3 
4 Copyright (c) 2022 Leonard IklĂ©
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23  */
24 #pragma once
25 
32 #ifndef CAG_LIBRARY_H
33 #define CAG_LIBRARY_H
34 
35 #include <stdbool.h>
36 #include <stddef.h>
37 #include <stdio.h>
38 
39 #if defined(_WIN32) || defined(__CYGWIN__)
40 #define CAG_EXPORT __declspec(dllexport)
41 #define CAG_IMPORT __declspec(dllimport)
42 #elif __GNUC__ >= 4
43 #define CAG_EXPORT __attribute__((visibility("default")))
44 #define CAG_IMPORT __attribute__((visibility("default")))
45 #else
46 #define CAG_EXPORT
47 #define CAG_IMPORT
48 #endif
49 
50 #if defined(CAG_SHARED)
51 #if defined(CAG_EXPORTS)
52 #define CAG_PUBLIC CAG_EXPORT
53 #else
54 #define CAG_PUBLIC CAG_IMPORT
55 #endif
56 #else
57 #define CAG_PUBLIC
58 #endif
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
68 typedef struct cag_option
69 {
70  const char identifier;
71  const char *access_letters;
72  const char *access_name;
73  const char *value_name;
74  const char *description;
76 
81 typedef struct cag_option_context
82 {
83  const struct cag_option *options;
84  size_t option_count;
85  int argc;
86  char **argv;
87  int index;
89  bool forced_end;
90  char identifier;
91  char *value;
93 
97 #define CAG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
98 
109 CAG_PUBLIC void cag_option_print(const cag_option *options, size_t option_count,
110  FILE *destination);
111 
127  const cag_option *options, size_t option_count, int argc, char **argv);
128 
145 
155 CAG_PUBLIC char cag_option_get(const cag_option_context *context);
156 
166 CAG_PUBLIC const char *cag_option_get_value(const cag_option_context *context);
167 
180 
181 #ifdef __cplusplus
182 } // extern "C"
183 #endif
184 
185 #endif
CAG_PUBLIC char cag_option_get(const cag_option_context *context)
Gets the identifier of the option.
Definition: cargs.c:444
CAG_PUBLIC void cag_option_prepare(cag_option_context *context, const cag_option *options, size_t option_count, int argc, char **argv)
Prepare argument options context for parsing.
Definition: cargs.c:134
CAG_PUBLIC bool cag_option_fetch(cag_option_context *context)
Fetches an option from the argument list.
Definition: cargs.c:389
CAG_PUBLIC const char * cag_option_get_value(const cag_option_context *context)
Gets the value from the option.
Definition: cargs.c:450
struct cag_option_context cag_option_context
CAG_PUBLIC int cag_option_get_index(const cag_option_context *context)
Gets the current index of the context.
Definition: cargs.c:456
#define CAG_PUBLIC
Definition: cargs.h:57
struct cag_option cag_option
CAG_PUBLIC void cag_option_print(const cag_option *options, size_t option_count, FILE *destination)
Prints all options to the terminal.
Definition: cargs.c:103
static struct cag_option options[]
Definition: gvm-cli.cpp:45
char ** argv
Definition: cargs.h:86
char * value
Definition: cargs.h:91
char identifier
Definition: cargs.h:90
size_t option_count
Definition: cargs.h:84
const struct cag_option * options
Definition: cargs.h:83
bool forced_end
Definition: cargs.h:89
const char * access_name
Definition: cargs.h:72
const char * access_letters
Definition: cargs.h:71
const char * value_name
Definition: cargs.h:73
const char * description
Definition: cargs.h:74
const char identifier
Definition: cargs.h:70