Skip to content

Repository files navigation

GETARG LIB

Description

C'est une lib pour parser les arguments du main type argparse le user au debut definit une liste d'option qu'il veut elle doit se finir par .type=GETARG_OPTS_END

t_getarg_optionopts[] = {
{.name_short='a', .name_long="add", .type=GETARG_BOOL, .target=&value, .optional=true, .help="add something"}
{.type=GETARG_OPTS_END}
};

Il y as 4 type de t_getarg_type :

  • GETARG_INT
  • GETARG_BOOL
  • GETARG_DOUBLE
  • GETARG_STRING

Attention

en verite ya encore GETARG_HELP qui est pour moi pour pas que vous deviez l'ecrire, plus tard j'aimerai que vous aiez l'option de rajouter votre propre help func si vous le souhaitez

Support syntaxique pour :

  • -s
  • --long
  • --long=value
  • -s value
  • --long value
  • -abc ( si elles sont toutes des bools )

la fonction a utiliser c'est getarg_parse(int argc, char **argv, t_getarg_option *opts). c'est elle qui vas parser tout ca et ensuite si elle retourne GETARG_OK, normalement les targets devraient etre rempli si le user les as valide.

Installation

pour installer un simple sudo make install / uninstall. si vous voulez l'installer en local tu peux faire make install / uninstall PREFIX=/path/you/whant

Exemple

#include<getarg/getarg.h.
// Let's say argc == 5 and argv == {"prog_name", "--x-value=10", "-y", "3", '--add'}// This program would output : 13intmain(intargc, char**argv)
{
intadd;
intsubstract;
intfirst_value;
intsecond_value;
t_getarg_optionopts[] = {
{'a', "add", GETARG_BOOL, true, "add x and y"},
{'s', "substract", GETARG_BOOL, true, "substract y from x"},
{'x', "x-value", GETARG_INT, false, "the x value of the equation"},
{'y', "y-value", GETARG_INT, false, "the y value of the equation"},
{.type=GETARG_OPTS_END}
};
if (getarg_parse(argc, argv,) !=GETARG_OK)
// whould shout if -x or -y arent present or other errorsreturn1;
if (add==1)
printf("%d\n", x+y);
if (substract==1)
printf("%d\n", x-y);
return0;
}

Testing

Si tu veux tester alors faut avoir criterion sur ta machine. je l'utilise c'est tip top !

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages