Skip to content

Commit

Permalink
make flag option more dynamic instead the default one
Browse files Browse the repository at this point in the history
  • Loading branch information
Jukoo committed Dec 1, 2024
1 parent c03b0dd commit a895fcd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build/*
lib/*
example/bin/*
example/build/*
TODO.md
51 changes: 50 additions & 1 deletion arghlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <libgen.h>
#include <stdio.h>
#include <string.h>

#include <ctype.h>
#include "arghlp.h"

char __usage[USAGE_BUFF] = {0} ;
Expand Down Expand Up @@ -169,3 +169,52 @@ static struct option * extract_getopt_option(struct option * g_opt)
return g_opt ;
}

char *optentry(char *const *av , int ac ,int optindex)
{

if(ac == optindex)
return optarg ;

char *optfname= (char *) *(av + (optindex -1)) ;

if(0x2d == (*optfname & 0xff) && 0x2d != (*(optfname +1) & 0xff ))
return optarg ;

//! looking for equal symbol "="

char *equ_symb= strchr(optfname , 0x3d & 0xff ) ;
if (equ_symb)
{
size_t symb_offset= equ_symb - optfname ;
char *next= equ_symb+1;
if (*next == '\0')
{
goto __maybe_next;
}

//! --option=argument
return strdup(next) ;
}
goto __maybe_next;

__maybe_next:
char *optfname_value = (char *) *(av+optindex);

if(0x2d == (*optfname_value & 0xff)) return optarg ;

//! --option =args
if(0x3d == (*optfname_value & 0xff))
{
optfname_value++ ;
if (0 == (*optfname_value & 0xff))
{
optindex++ ;
goto __maybe_next ;
}
return strdup(optfname_value) ;
}

//! --option= args
return strdup(optfname_value) ;

}
17 changes: 5 additions & 12 deletions arghlp.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,12 @@ struct arghlp {
ARGHLP static char * get_program_basename(char *const * __argument_vector) __wur __nonnull((1));
ARGHLP static void * set_option( char * __shortopt , int __has_arg ) ;
ARGHLP static char * build_short_option(const struct optionx * __raw_optionx) __wur __nonnull((1));

ARGHLP void static build_usage_helper(char* flags_t ,
const char * __flag_description) __nonnull((1 ,2));

ARGHLP static char * make_sysnopsys(char *__basename ,
struct arghlp * __synopsys,
char * __usage_body) __nonnull((1,2,3)) ;

ARGHLP void static build_usage_helper(char* flags_t, const char * __flag_description) __nonnull((1,2));
ARGHLP static char * make_sysnopsys(char *__basename, struct arghlp * __synopsys, char * __usage_body) __nonnull((1,2,3)) ;
ARGHLP static struct option * extract_getopt_option(struct option * __g_option) __nonnull(()) ;
ARGHLP void *arghlp_context ( int __argcounter, char * const *__argvector ,
const struct arghlp *__arghlp , void * __wur __argxtra) __nonnull((2,3));

ARGHLP void *arghlp_context ( int __argcounter ,
char * const *__argvector ,
const struct arghlp *__arghlp , void * __wur __argxtra)
__nonnull((2,3));
ARGHLP char *optentry(char * const * __av ,int __ac , int __optindex) ;

#endif //!__argument_helper
3 changes: 2 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ void * argparse(int ac ,char * const * av , const char *shortopt , struct opt
fprintf(stdout, "input -> %s\n" , input) ;
break;
case 'o':
char *output = optarg ;

char *output = optentry( av , ac , optind) ;
fprintf(stdout, "output -> %s\n" , output) ;
break;

Expand Down

0 comments on commit a895fcd

Please sign in to comment.