From: Daniel Liu Date: Sat, 6 Feb 2021 20:24:59 +0000 (-0500) Subject: debugging seg X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=8b6f14fe02e0bb9a851cf0e134fc109f311c2e4d;p=taskasaur.git debugging seg --- diff --git a/headers/menu.h b/headers/menu.h index 10a739f..f1bac0e 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -3,6 +3,7 @@ #define __MENU_H__ #include +#include /* ncurses doesn't support multiline menu items, * so i wrote my own menu lib */ diff --git a/makefile b/makefile index 62337a7..ac7d51b 100644 --- a/makefile +++ b/makefile @@ -1,25 +1,16 @@ + CC=gcc +CFLAGS=-g -Wall -Wno-unused-variable -Wno-switch make: taskasaur all: taskasaur -parser.o: parser.c headers/parser.h - $(CC) -c parser.c - -render.o: render.c headers/render.h - $(CC) -c render.c - -menu.o: menu.c headers/menu.h - $(CC) -c menu.c - -utils.o: utils.c headers/utils.h - $(CC) -c utils.c - -# include config.h as depend +%.o: %.c headers/%.h config.h + $(CC) $(CFLAGS) -c $< -taskasaur: taskasaur.c parser.o render.o menu.o utils.o config.h - $(CC) -o $@ $^ -lncurses -lmd4c +taskasaur: taskasaur.c menu.o parser.o render.o utils.o + $(CC) $(CFLAGS) -o $@ $^ -lncurses -lmd4c clean: rm taskasaur *.o diff --git a/menu.c b/menu.c index eadfefb..67ca8e2 100644 --- a/menu.c +++ b/menu.c @@ -139,11 +139,9 @@ delete_item(Menu* menu, int index) if (index < 0 || index > menu->menu_length-1) return -1; int temp_size = (menu->menu_length-index-1)*sizeof(MenuItem*); - MenuItem* temp[temp_size]; /* might break if last item? */ - memcpy(temp, menu->menu_items[index+1], temp_size); - memcpy(menu->menu_items[index], temp, temp_size); + memmove(menu->menu_items[index], menu->menu_items[index+1], temp_size); menu->menu_items = realloc(menu->menu_items, menu->menu_length*sizeof(MenuItem*)); menu->menu_items[menu->menu_length-1] = 0; // preserve null at end @@ -167,30 +165,22 @@ insert_item(Menu* menu, int index) // remember null char /* new_content = malloc((MAX_CONTENTS_LENGTH+1)*sizeof(char)); */ - new_content = malloc(10); - new_content = "abcdefghi"; + new_content = strdup("lmao"); new_menuitem = create_menuitem(new_content); /* resize array and insert */ - /* char out[100]; */ - /* sprintf(out, "%d\n", menu->menu_length); */ - /* mvprintw(0, 0, out); */ - /* menu->menu_items = realloc(menu->menu_items, (menu->menu_length+1)*sizeof(MenuItem*)); */ + menu->menu_items = realloc(menu->menu_items, (menu->menu_length+2)*sizeof(MenuItem*)); - /* int temp_size = (menu->menu_length-index)*sizeof(MenuItem*); */ - /* MenuItem* temp[temp_size]; */ - - /* memcpy(temp, menu->menu_items[index], temp_size); */ - /* menu->menu_items[index] = new_menuitem; */ - /* memcpy(menu->menu_items[index+1], temp, temp_size); */ - - /* menu->menu_items[menu->menu_length] = 0; // remember null at end */ - /* menu->menu_length += 1; */ + int temp_size = menu->menu_length-index*sizeof(MenuItem*); + memmove(menu->menu_items[index], menu->menu_items[index+1], temp_size); + menu->menu_items[index] = new_menuitem; + menu->menu_items[menu->menu_length+1] = 0; // remember null at end + menu->menu_length += 1; /* move cursor pos */ - /* menu->selected_item = index; */ + menu->selected_item = index; return 0; }