ADD: added first example

This commit is contained in:
Dominik Meyer 2018-03-31 00:43:37 +02:00
parent b55d76b925
commit 366dba82ca
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
2 changed files with 78 additions and 0 deletions

10
examples/Makefile Normal file
View File

@ -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)

68
examples/example1.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/**
* @file example1.c
* @brief brief example on using YAAP
* @author Dominik Meyer <dmeyer@federationhq.de>
* @copyright 2018 by Dominik Meyer
*/
#include "../src/argparse.h"
#include <stdio.h>
/*
* @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;
}