utils

useful C functions with no dependencies
git clone https://github.com/TanguyAndreani/utils
Log | Files | Refs

commit 84afa5f81b756c69250e10fc3f8e4fb049867ca9
Author: Tanguy Andreani <tanguy.andreani@tuta.io>
Date:   Mon, 27 Jan 2020 00:09:48 +0100

first commit

adding basic_getopt.c, which can be used like system getopt, except it
does not handle flags argument

e.g:

    char c;
    while ((c = basic_getopt(ac, av)) != -1) {
        switch (c) {
        case 'h':
            print_usage();
            return (0);
	// ...
        }
    }

Diffstat:
Abasic_getopt.c | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/basic_getopt.c b/basic_getopt.c @@ -0,0 +1,21 @@ +char basic_getopt(int ac, char *av[]) +{ + static int i = 0, j = 1; + + if (i >= ac) + return (-1); + + if (!av[i][j]) { + j = 1; + i++; + return (basic_getopt(ac, av)); + } + + if (av[i][0] == '-') { + char c = av[i][j++]; + return (c); + } + + i++; + return (basic_getopt(ac, av)); +}+ \ No newline at end of file