lib

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

commit 4e4034bfbbf660ac9bb2a2b2ef55371b41239b4d
parent 7c01733afb68b836d696de636c168a74b803838a
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 17 Jan 2017 14:38:38 +0100

Add(Template): And some code

Diffstat:
AMakefile | 38++++++++++++++++++++++++++++++++++++++
Ainc/m_print.h | 31+++++++++++++++++++++++++++++++
Ainc/m_types.h | 32++++++++++++++++++++++++++++++++
Ainc/morphux.h | 23+++++++++++++++++++++++
Asrc/m_print.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 194 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,38 @@ +################################### LICENSE #################################### +# Copyright 2016 Morphux # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +NAME= libmorphux.a +CC = gcc +LIB = ar +CFLAGS = -Wall -Wextra -Werror -O3 -I inc/ +LFLAGS = -cq +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:%.c=%.o) + +all: $(NAME) + +$(NAME): $(OBJS) + $(LIB) $(LFLAGS) $(NAME) $(OBJS) + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: fclean clean all diff --git a/inc/m_print.h b/inc/m_print.h @@ -0,0 +1,31 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + +#ifndef M_PRINT_H +# define M_PRINT_H + +# include <stdarg.h> +# include <stdio.h> +# include <fcntl.h> +# include <string.h> +# include <unistd.h> + +void m_panic(const char *str, ...); +void m_error(const char *str, ...); +void m_warning(const char *str, ...); +void m_info(const char *str, ...); + +#endif /* M_PRINT_H */ diff --git a/inc/m_types.h b/inc/m_types.h @@ -0,0 +1,32 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + +#ifndef M_TYPES_H +# define M_TYPES_H + +/* Generic types */ + +typedef signed char s8_t; +typedef signed short s16_t; +typedef signed int s32_t; +typedef signed long long s64_t; + +typedef unsigned char us8_t; +typedef unsigned short u16_t; +typedef unsigned int u32_t; +typedef unsigned long long u64_t; + +#endif /* M_TYPES_H */ diff --git a/inc/morphux.h b/inc/morphux.h @@ -0,0 +1,23 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + +#ifndef MORPHUX_H +# define MORPHUX_H + +# include <m_types.h> +# include <m_print.h> + +#endif /* MORPHUX_H */ diff --git a/src/m_print.c b/src/m_print.c @@ -0,0 +1,70 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + +#include <m_print.h> + +/*! + * \brief Print a string in an error fomat, then call _exit with 1 + * \note Support printf format + */ +void m_panic(const char *str, ...) { + va_list ap; + + write(2, "\033[0;31m> \033[0m", 13); + va_start(ap, str); + vfprintf(stderr, str, ap); + if (str[strlen(str) - 1] != '\n') + fprintf(stderr, "\n"); + _exit(1); +} + +/*! + * \brief Print a string with an error format + * \note Support printf format + */ +void m_error(const char *str, ...) { + va_list ap; + + write(2, "\033[0;31m> \033[0m", 13); + va_start(ap, str); + vfprintf(stderr, str, ap); + if (str[strlen(str) - 1] != '\n') + fprintf(stderr, "\n"); +} + +/*! + * \brief Print a string with a warning format + * \note Support printf format + */ +void m_warning(const char *str, ...) { + va_list ap; + + write(2, "\033[0;31m> \033[0m", 13); + va_start(ap, str); + vfprintf(stderr, str, ap); +} + +/*! + * \brief Print a string with an information format + * \note Support printf format + */ +void m_info(const char *str, ...) { + va_list ap; + + write(1, "\033[0;34m> \033[0m", 13); + va_start(ap, str); + vprintf(str, ap); +}