lib

morphux C utility library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/lib

commit 64bc83890178c71e4cf5ba9f14ec5ad4ce027b2f
parent 0ccc542cff1bd02457bb60012c324264ea8953d6
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Thu,  2 Mar 2017 23:02:51 +0100

Merge branch 'master' into unstable

Diffstat:
MMakefile | 11+++++++++--
Msrc/m_args.c | 12++++++++----
Mtests/Makefile | 12++++++++++--
Mtests/test_args.c | 2+-
4 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile @@ -14,7 +14,7 @@ # limitations under the License. # ################################################################################ -NAME= libmorphux.a +NAME = libmorphux.a CC = gcc LIB = ar CFLAGS = -Wall -Wextra -Werror -Wno-unused-result -I inc/ -std=c99 -g -O3 @@ -22,6 +22,13 @@ LFLAGS = -cq SRCS = $(wildcard src/*.c) OBJS = $(SRCS:%.c=%.o) +OSTYPE = $(shell uname) +ifeq ($(OSTYPE), Linux) +COVFLAGS = "-Wall -Wextra -Wno-unused-result -I inc/ -std=c99 -g -O0 -coverage -lgcov" +else ifeq ($(OSTYPE), Darwin) +COVFLAGS = "-Wall -Wextra -Wno-unused-result -I inc/ -std=c99 -g -O0 -coverage" +endif + all: $(NAME) $(NAME): $(OBJS) @@ -34,7 +41,7 @@ doc: doxygen docs/doxyfile coverage: - $(MAKE) fclean all CFLAGS="-Wall -Wextra -Werror -Wno-unused-result -I inc/ -std=c99 -g -O0 -coverage -lgcov" + $(MAKE) fclean all CFLAGS=$(COVFLAGS) make -C tests coverage check gcov -o src/ $(SRCS) diff --git a/src/m_args.c b/src/m_args.c @@ -15,6 +15,10 @@ \******************************************************************************/ #include <m_args.h> +#define LIB_OPT_TOKEN_HELP 'h' +#define LIB_OPT_STRING_HELP "help" +#define LIB_OPT_TOKEN_VERSION 'V' +#define LIB_OPT_STRING_VERSION "version" /*! * \brief Read the options given by the program @@ -63,9 +67,9 @@ u32_t read_opt(const int ac, char **av, const margs_t *args) { } /* Builtins options */ - if (av[i][1] == 'h') + if (av[i][1] == LIB_OPT_TOKEN_HELP) opt_help(args, 0); - else if (av[i][1] == 'v') + else if (av[i][1] == LIB_OPT_TOKEN_VERSION) p_version(0); /* Search the option in the args array */ @@ -105,9 +109,9 @@ u32_t read_opt(const int ac, char **av, const margs_t *args) { } /* Builtins options */ - if (strcmp(&(av[i][2]), "help") == 0) + if (strcmp(&(av[i][2]), LIB_OPT_STRING_HELP) == 0) opt_help(args, 0); - else if (strcmp(&(av[i][2]), "version") == 0) + else if (strcmp(&(av[i][2]), LIB_OPT_STRING_VERSION) == 0) p_version(0); /* Look for an argument */ diff --git a/tests/Makefile b/tests/Makefile @@ -1,9 +1,17 @@ NAME = test CC = gcc -CFLAGS = -Wall -Wextra -Wno-unused-result -g -O3 -I../inc -lmorphux +CFLAGS = -Wall -Wextra -Wno-unused-result -g -O3 -I../inc +LDFLAGS = -lmorphux SRCS = $(wildcard *.c) OBJS = $(SRCS:%.c=%.o) +OSTYPE = $(shell uname) +ifeq ($(OSTYPE), Linux) +COVFLAGS = "-Wall -Wextra -Wno-unused-result -g -O0 -I../inc -coverage -lgcov" +else ifeq ($(OSTYPE), Darwin) +COVFLAGS = "-Wall -Wextra -Wno-unused-result -g -O0 -I../inc -coverage" +endif + all: $(NAME) $(NAME): $(OBJS) @@ -16,7 +24,7 @@ valgrind: $(NAME) valgrind --leak-check=full --error-exitcode=1 ./$(NAME) coverage: - $(MAKE) fclean all CFLAGS="-Wall -Wextra -Wno-unused-result -g -O0 -coverage -I../inc -lmorphux -lgcov" + $(MAKE) fclean all CFLAGS=$(COVFLAGS) clean: rm -f $(OBJS) diff --git a/tests/test_args.c b/tests/test_args.c @@ -230,7 +230,7 @@ TEST(args_version_1) { {'z', "zoiberg", "No idea.", false, NULL}, ARGS_EOL }; - char *av[] = {"./test", "-v"}; + char *av[] = {"./test", "-V"}; int st, fd[2]; pid_t pid;