ADD: added first example

master
Dominik Meyer 5 years ago
parent b55d76b925
commit 366dba82ca
Signed by: byterazor
GPG Key ID: B4C312B600606B64

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

@ -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;
}
Loading…
Cancel
Save