ArgPar-C v1.0.0-build
Simple and powerful Argument Parser for C
Loading...
Searching...
No Matches
APC_ArgParser.h
Go to the documentation of this file.
1#ifndef INCLUDE_LIB_APC_ARGPARSER_H_
2#define INCLUDE_LIB_APC_ARGPARSER_H_
3
4#include <stdbool.h>
5
6#include "../../../vendor/cvec/inc/cvec/cvec.h"
7
8#ifdef __cplusplus
9# define __APC_CPP_GUARD_OPEN extern "C" {
10# define __APC_CPP_GUARD_CLOSE }
11#else
12# define __APC_CPP_GUARD_OPEN
13# define __APC_CPP_GUARD_CLOSE
14#endif // __cplusplus
15
17
26
27typedef struct
28{
30
31 char *id;
32 char *param;
33 char *sparam;
34 char *help;
35
36 CVEC aliases; // CVEC of: const char*
38
39typedef struct
40{
42
43 int argc;
44
45 char *fullHelp;
47
48 CVEC args; // CVEC of APC_ArgInfo
49
50 char **argv;
52
53typedef struct
54{
56
57 unsigned int r;
58 unsigned int g;
59 unsigned int b;
60} APC_RGB;
61
62/**
63 * @brief Initialize parser with argc and argv from the `main()` function
64 * @param argc Number of arguments
65 * @param argv Argument values
66 * @return Constructed APC_ArgParser with all the recommended data
67 */
68APC_ArgParser apc_init(int argc, char *argv[]);
69
70/**
71 * @brief Initialize information for params
72 * * Constructed empty aliases
73 * * `required` defaults to `false`
74 * @return Initialized APC_ArgInfo with default values
75 */
77
78/**
79 * @brief Convert the default RGB format to a valid RGB struct and parse all extended commands
80 * * ${r,g,b}
81 * * ${R}
82 * * ${BOLD}
83 * @return New APC_RGB with RGB data and extended data type (italic, bold, reset, ...)
84 */
85APC_RGB __apc_rgbToRGBStruct(const char *rgbStr);
86
87/**
88 * @brief Free all allocated data for argument parser
89 * @param argpar Argument parser to free from memory
90 */
91void apc_destroy(APC_ArgParser *argpar);
92
93/**
94 * @brief Automatically generate help and pass it to the string to return
95 * @param argpar Argument parser to generate help from
96 * @param title Title of the help
97 * @param topInfo Top information (eg: Little intro of the tool)
98 * @param lowerInfo Lower information (eg: License, ...)
99 * @return Generated help with escape characters for colors (if enabled)
100 */
101char *apc_generateHelp(APC_ArgParser *argpar,
102 const char *title,
103 const char *topInfo,
104 const char *lowerInfo
105);
106
107/**
108 * @brief Format color;
109 * * Remove color commands if color disabled
110 * * Convert to color ANSI escape code if enabled
111 * @param argpar Argument to format color and get data from
112 * @param msg Message to format
113 */
114char *__apc_colorFormat(APC_ArgParser *argpar, const char *msg);
115
116/**
117 * @brief Convert RGB to ANSI escape code
118 * @param r Red color
119 * @param g Green color
120 * @param b Blue color
121 * @return Constructed ANSI escape code
122 */
123char *__apc_setRGB(int r, int g, int b);
124
125/**
126 * @brief Setup Arg Information to the `argpar`
127 * @param argpar Argument Parser to modify information from
128 * @param info Create information about the param
129 * @return false if fail, true if success
130 */
131bool apc_add(APC_ArgParser *argpar, APC_ArgInfo info);
132
133/**
134 * @brief Get if there is an argument present
135 * @param argpar Get parameters from argpar
136 * @param id ID to fetch
137 * @return false if fail, true if success
138 */
139bool apc_get(APC_ArgParser *argpar, const char *id);
140
142
143#undef __APC_CPP_GUARD_OPEN
144#undef __APC_CPP_GUARD_CLOSE
145
146#endif // INCLUDE_LIB_APC_ARGPARSER_H_
147
bool apc_get(APC_ArgParser *argpar, const char *id)
Get if there is an argument present.
APC_RGB __apc_rgbToRGBStruct(const char *rgbStr)
Convert the default RGB format to a valid RGB struct and parse all extended commands.
char * apc_generateHelp(APC_ArgParser *argpar, const char *title, const char *topInfo, const char *lowerInfo)
Automatically generate help and pass it to the string to return.
bool apc_add(APC_ArgParser *argpar, APC_ArgInfo info)
Setup Arg Information to the argpar.
char * __apc_colorFormat(APC_ArgParser *argpar, const char *msg)
Format color;.
APC_ArgParser apc_init(int argc, char *argv[])
Initialize parser with argc and argv from the main() function.
APC_ArgInfo apc_initInfo(void)
Initialize information for params.
APC_RGB_Command
@ APC_RGB_Command_Underline
@ APC_RGB_Command_Italic
@ APC_RGB_Command_Reset
@ APC_RGB_Command_None
@ APC_RGB_Command_Bold
void apc_destroy(APC_ArgParser *argpar)
Free all allocated data for argument parser.
char * __apc_setRGB(int r, int g, int b)
Convert RGB to ANSI escape code.
#define __APC_CPP_GUARD_OPEN
Definition APC_config.h:5
#define __APC_CPP_GUARD_CLOSE
Definition APC_config.h:6
char * helpDescription
unsigned int g
unsigned int b
enum APC_RGB_Command __externalAction
unsigned int r