diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..d9a2413 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,10 @@ +CFLAGS=-Wall +OBJECTS1=example1.o ../src/argparse.o + +all: example1 + +%.o: %.c + gcc $(CFLAGS) -c -o $@ $< + +example1: $(OBJECTS1) + gcc -o $@ $(OBJECTS1) diff --git a/examples/example1.c b/examples/example1.c new file mode 100644 index 0000000..f9026bd --- /dev/null +++ b/examples/example1.c @@ -0,0 +1,68 @@ +/* +YAAP - Yet Another Argument Parser + +Copyright (C) 2018 Dominik Meyer + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/** +* @file example1.c +* @brief brief example on using YAAP +* @author Dominik Meyer +* @copyright 2018 by Dominik Meyer +*/ + +#include "../src/argparse.h" +#include + +/* +* @brief example command +*/ +int test1(int argc, char **argv) +{ + printf("Test\n"); + return 0; +} + + +/* +* @brief main function for this example +*/ +int main (int argc, char **argv) +// initialize the parsing context +{ + struct arg_parse_ctx *argparse_ctx = argparse_init(); + + // create a command argument + struct arg_parse_cmd test_cmd= { + {0,1,0}, // 1 = mandatory element + 0, + "test", // command name + "simple test", // command description + &test1 // if found call this function + }; + + /// add the argument command to context + argparse_add_command(argparse_ctx, &test_cmd); + + /// parse the commandline + int ret=argparse_parse(argparse_ctx, argc, argv); + + /// free context + argparse_free(argparse_ctx); + + return ret; + +}