Loading...
Searching...
No Matches
ArgParse.h
Go to the documentation of this file.
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Joel Hoener
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#ifndef ZYCORE_ARGPARSE_H
#define ZYCORE_ARGPARSE_H
#include <Zycore/Types.h>
#include <Zycore/Status.h>
#include <Zycore/Vector.h>
#include <Zycore/String.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Structs and other types */
/* ============================================================================================== */
typedef struct ZyanArgParseDefinition_
{
const char* name;
ZyanBool boolean;
ZyanBool required;
} ZyanArgParseDefinition;
typedef struct ZyanArgParseConfig_
{
const char** argv;
ZyanUSize argc;
ZyanUSize min_unnamed_args;
ZyanUSize max_unnamed_args;
ZyanArgParseDefinition* args;
} ZyanArgParseConfig;
typedef struct ZyanArgParseArg_
{
const ZyanArgParseDefinition* def;
ZyanBool has_value;
ZyanStringView value;
} ZyanArgParseArg;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
#ifndef ZYAN_NO_LIBC
ZYCORE_EXPORT ZyanStatus ZyanArgParse(const ZyanArgParseConfig *cfg, ZyanVector* parsed,
const char** error_token);
#endif
ZYCORE_EXPORT ZyanStatus ZyanArgParseEx(const ZyanArgParseConfig *cfg, ZyanVector* parsed,
const char** error_token, ZyanAllocator* allocator);
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_ARGPARSE_H */
ZyanAllocator
struct ZyanAllocator_ ZyanAllocator
ZyanArgParse
ZYCORE_EXPORT ZyanStatus ZyanArgParse(const ZyanArgParseConfig *cfg, ZyanVector *parsed, const char **error_token)
ZyanArgParseConfig
struct ZyanArgParseConfig_ ZyanArgParseConfig
ZyanArgParseDefinition
struct ZyanArgParseDefinition_ ZyanArgParseDefinition
ZyanArgParseArg
struct ZyanArgParseArg_ ZyanArgParseArg
ZyanArgParseEx
ZYCORE_EXPORT ZyanStatus ZyanArgParseEx(const ZyanArgParseConfig *cfg, ZyanVector *parsed, const char **error_token, ZyanAllocator *allocator)
ZYCORE_EXPORT
#define ZYCORE_EXPORT
Definition Defines.h:244
Status.h
ZyanStatus
ZyanU32 ZyanStatus
Definition Status.h:48
String.h
ZyanStringView
struct ZyanStringView_ ZyanStringView
Types.h
ZyanBool
ZyanU8 ZyanBool
Definition Types.h:296
Vector.h
ZyanVector
struct ZyanVector_ ZyanVector
ZyanArgParseArg_
Definition ArgParse.h:105
ZyanArgParseArg_::value
ZyanStringView value
Definition ArgParse.h:121
ZyanArgParseArg_::has_value
ZyanBool has_value
Definition ArgParse.h:115
ZyanArgParseArg_::def
const ZyanArgParseDefinition * def
Definition ArgParse.h:111
ZyanArgParseConfig_
Definition ArgParse.h:74
ZyanArgParseConfig_::max_unnamed_args
ZyanUSize max_unnamed_args
Definition ArgParse.h:90
ZyanArgParseConfig_::argc
ZyanUSize argc
Definition ArgParse.h:82
ZyanArgParseConfig_::args
ZyanArgParseDefinition * args
Definition ArgParse.h:98
ZyanArgParseConfig_::argv
const char ** argv
Definition ArgParse.h:78
ZyanArgParseConfig_::min_unnamed_args
ZyanUSize min_unnamed_args
Definition ArgParse.h:86
ZyanArgParseDefinition_
Definition ArgParse.h:52
ZyanArgParseDefinition_::boolean
ZyanBool boolean
Definition ArgParse.h:63
ZyanArgParseDefinition_::name
const char * name
Definition ArgParse.h:59
ZyanArgParseDefinition_::required
ZyanBool required
Definition ArgParse.h:67