ArgPar-C v1.0.0-build
Simple and powerful Argument Parser for C
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1#include <stdio.h>
2
5
6int main(int argc, char *argv[])
7{
8 APC_ArgParser parser = apc_init(argc, argv);
9
10 {
12 info.id = "version";
13 info.param = "--version";
14 info.sparam = "-v";
15 info.help = "Version information for ArgParser-C";
16
17 apc_add(&parser, info);
18 }
19
20 {
22 info.id = "help";
23 info.param = "--help";
24 info.sparam = "-h";
25 info.help = "Show this help";
26
27 cvec_push(&info.aliases, const char *, "-?");
28
29 apc_add(&parser, info);
30 }
31
32 if (apc_get(&parser, "version"))
33 {
34 printf("== VERSION INFO\n");
35 printf("- VERSION: %i.%i.%i\n",
39 printf("- VERSION STANDARD: %ld\n", APC_VERSION_STD);
40 printf("- VERSION STATE: %s\n", APC_VERSION_STATE);
41 }
42
43 else if (apc_get(&parser, "help"))
44 {
45 const char *licenseMessage =
46 "\nArgPar-C Copyright (C) 2026 pcannon09\n"
47 "This program comes with ABSOLUTELY NO WARRANTY; for details type `./run.sh --help'.\n"
48 "This is free software, and you are welcome to redistribute it\n"
49 "under certain conditions; type `./run.sh --help' for details.";
50
51 char *helpMsg = apc_generateHelp(
52 &parser,
53 "APC Help",
54 "ArgParser-C help information and demo\nCheck the code for more information\n",
55 licenseMessage);
56
57 printf("%s\n", helpMsg);
58
59 APC_FREE(helpMsg);
60 }
61
62 apc_destroy(&parser);
63
64 return 0;
65}
66
bool apc_get(APC_ArgParser *argpar, const char *id)
Get if there is an argument present.
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.
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.
void apc_destroy(APC_ArgParser *argpar)
Free all allocated data for argument parser.
#define APC_VERSION_MINOR
#define APC_FREE(x)
#define APC_VERSION_MAJOR
#define APC_VERSION_PATCH
#define APC_VERSION_STATE
#define APC_VERSION_STD
int main(int argc, char *argv[])
Definition main.c:6