42_Scale

a small software to create and edit 42 (.yaml) scale files easily
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/42_Scale

commit f94f0b9237bbdea5c35fc2cf02775fd61e38ea9b
parent f958842ceb1770a939adbe16855ec4f49ff74964
Author: Ne02ptzero <louis@goliath.lan>
Date:   Fri, 22 Apr 2016 21:05:49 +0200

Fix(Backtrace): Enhance backtrace log form

Diffstat:
M.ycm_extra_conf.py | 2++
MMakefile | 14+++++++++++---
Minc/scale.h | 2+-
Msrcs/helpers.c | 33+++++++++++++++++++++++++++++----
Msrcs/main.c | 2+-
5 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py @@ -90,6 +90,8 @@ flags = [ '-fno-stack-protector', '-nostdlib', '-nodefaultlibs', +'-I', 'inc', +'-I', 'inc/nuklear' ] diff --git a/Makefile b/Makefile @@ -1,12 +1,20 @@ NAME = 42_scale CC = gcc -CFLAGS = -Wall -Wextra -Werror -g -O2 -LIBS = -lglfw3 -framework OpenGL -lm -lGLEW -LIBS_DIR = -L ~/.brew/lib +CFLAGS = -Wall -Wextra -Werror -g -O2 -std=c99 -rdynamic + INCS = -I inc/ -I inc/nuklear/ -I ~/.brew/include SRCS = $(wildcard srcs/*.c) OBJS = $(SRCS:%.c=%.o) +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Darwin) + LIBS = -lglfw3 -framework OpenGL -lm -lGLEW + LIBS_DIR = -L ~/.brew/lib +else + LIBS = -lglfw -lGL -lm -lGLU -lGLEW +endif + + %.o: %.c $(CC) $(CFLAGS) $(INCS) -o $@ -c $^ diff --git a/inc/scale.h b/inc/scale.h @@ -8,7 +8,7 @@ # include <execinfo.h> # include <unistd.h> -# define ERROR(str) printf("\033[1;31mFATAL ERROR:\033[0m 42_scale must stop. \n\033[0;32m> Reason: \033[0m %s\n", str); print_trace(); _exit(1); +# define ERROR(...) printf("\033[1;31mFATAL ERROR:\033[0m 42_scale must stop. \n\033[0;31m> Reason: \033[0m"); printf(__VA_ARGS__); print_trace(); _exit(1); /* HELPERS (helpers.c) */ diff --git a/srcs/helpers.c b/srcs/helpers.c @@ -4,13 +4,38 @@ void print_trace(void) { void *array[10]; size_t size; char **strings; + int f_tab = 0, s_tab = 0, j, k; size = backtrace(array, 10); strings = backtrace_symbols(array, size); - printf("\033[0;32m> \033[0m Printing backtrace ...\n\e[37m"); -# define NK_IMPLEMENTATION - for (size_t i = 0; i < size; i++) - printf("%s\n", strings[i]); + printf("\033[0;31m> \033[0mPrinting backtrace ...\n\e[37m"); + for (size_t i = 0; i < size; i++) { + for (j = 0; strings[i][j] && strings[i][j] != '('; j++); + if (j > f_tab) + f_tab = j; + for (k = j; strings[i][j] && strings[i][j] != ')'; j++); + if ((j - k) > s_tab) + s_tab = (j - k) + 2; + } + for (size_t i = 0; i < size; i++) { + for (j = 0; strings[i][j] && strings[i][j] != '('; write(1, &strings[i][j], 1), j++); + if (j < f_tab) + for (k = j; k < f_tab; write(1, " ", 1), k++); + write(1, " ", 1); + for (k = j; strings[i][j] && strings[i][j] != ')'; write(1, &strings[i][j], 1), j++) { + if (strings[i][j] == '+' || (j && strings[i][j - 1] == '+')) + write(1, " ", 1); + } + write(1, ")", 1); + if ((j - k) < s_tab) { + if ((j - k) == 1) + write(1, " ", 2); + for (k = (j - k); k < s_tab; write(1, " ", 1), k++); + } + write(1, " ", 1); + for (j++; strings[i][j]; write(1, &strings[i][j], 1), j++); + write(1, "\n", 1); + } free(strings); printf("\033[0m"); } diff --git a/srcs/main.c b/srcs/main.c @@ -2,7 +2,7 @@ int main(int ac, char **av) { if (ac == 1 || !av) { - ERROR("Need an argument !"); + ERROR("Need an argument !\n"); } return 0; }