From 49e9b176e4ad9117c4522725cc171c71d985da6d Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 23 Jul 2014 22:33:19 -0400 Subject: [PATCH] vector to list --- source/main.c | 2 ++ source/main.mf | 3 +++ source/screen.c | 45 +++++++++++++++++++++++++++++---------------- source/screen.h | 1 + source/workdir.c | 4 ++++ source/workdir.h | 2 ++ 6 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 source/main.mf diff --git a/source/main.c b/source/main.c index 8417d56..bbbbb28 100644 --- a/source/main.c +++ b/source/main.c @@ -37,6 +37,8 @@ int main(int argc, char** argv) { erase(); refresh(); endwin(); + screen_deinit(); + workdir_deinit(); return 0; } diff --git a/source/main.mf b/source/main.mf new file mode 100644 index 0000000..4695857 --- /dev/null +++ b/source/main.mf @@ -0,0 +1,3 @@ +source/main.o: source/main.c source/aardvark.h source/state.h \ + source/screen.h source/workdir.h \ + modules/data-structures/source/vector/vec.h source/input.h diff --git a/source/screen.c b/source/screen.c index 0f02328..e5bfc06 100644 --- a/source/screen.c +++ b/source/screen.c @@ -3,7 +3,7 @@ #include "aardvark.h" #include "workdir.h" #include -#include "vec.h" +#include "list.h" #include "mem.h" typedef struct { @@ -14,12 +14,15 @@ static void screen_place_windows(void); static frame_t* screen_frame_new(void); static void screen_frame_free(void* p_frame); -static frame_t* Master; -static vec_t* Screen_List; +static list_t* Screen_List; void screen_init(void) { - Master = screen_frame_new(); - Screen_List = vec_new(0); + Screen_List = list_new(); + list_push_back(Screen_List, screen_frame_new()); +} + +void screen_deinit(void) { + mem_release(Screen_List); } void screen_update(void) { @@ -37,40 +40,50 @@ void screen_update(void) { } void screen_open(void) { - vec_push_back(Screen_List, screen_frame_new()); + list_push_back(Screen_List, screen_frame_new()); } void screen_close(void) { - vec_erase(Screen_List, 0, 0); + int num_frames = list_size(Screen_List); + if(num_frames > 1) + list_delete(Screen_List, 0); } static void screen_place_windows(void) { frame_t* p_frame; - int i, lines, cols; + int id, pos, lines, cols; + int num_frames = list_size(Screen_List); + list_node_t* p_node; getmaxyx(stdscr, lines, cols); /* Print the master frame */ - p_frame = Master; + p_frame = list_at(Screen_List,0)->contents; mvwin(p_frame->p_win, 0, 0); - wresize(p_frame->p_win, lines, (vec_size(Screen_List) > 0) ? cols/2 : cols); + wresize(p_frame->p_win, lines, (num_frames > 1) ? cols/2 : cols); wclear(p_frame->p_win); box(p_frame->p_win, 0 , 0); wrefresh(p_frame->p_win); /* Print any other frames we might have */ - int pos = 0; - for(i = 0; i < vec_size(Screen_List); i++) { - int remain = (lines % vec_size(Screen_List)); - int height = (lines / vec_size(Screen_List)) + (i < remain ? 1 : 0); - p_frame = (frame_t*)vec_at(Screen_List, i); + p_node = list_at(Screen_List,1); + pos = 0; + id = 1; + while(p_node != NULL) { + /* Get the frame and it's properties */ + int remain = (lines % (num_frames-1)); + int height = (lines / (num_frames-1)) + (id <= remain ? 1 : 0); + p_frame = p_node->contents; + /* Place the frame */ mvwin(p_frame->p_win, pos, cols/2); wresize(p_frame->p_win, height, cols/2); wclear(p_frame->p_win); wmove(p_frame->p_win, 1, 1); - wprintw(p_frame->p_win, "(%d, %d)", i*height, cols/2); box(p_frame->p_win, 0 , 0); wrefresh(p_frame->p_win); + /* Get the next one */ + id++; pos += height; + p_node = p_node->next; } } diff --git a/source/screen.h b/source/screen.h index 44f7114..5e40eed 100644 --- a/source/screen.h +++ b/source/screen.h @@ -8,6 +8,7 @@ #define SCREEN_H void screen_init(void); +void screen_deinit(void); void screen_update(void); void screen_open(void); void screen_close(void); diff --git a/source/workdir.c b/source/workdir.c index fd2f976..8a508a7 100644 --- a/source/workdir.c +++ b/source/workdir.c @@ -37,6 +37,10 @@ void workdir_init(int windex) { getcwd(Windows[windex].cwd, 1024); } +void workdir_deinit(void) { + free(Windows[0].files); +} + void workdir_next(void) { int index = state_get_focused_frame(); //do nothing if at the end of the file list diff --git a/source/workdir.h b/source/workdir.h index 1b28aa5..0b3afd6 100644 --- a/source/workdir.h +++ b/source/workdir.h @@ -9,6 +9,8 @@ void workdir_init(int windex); +void workdir_deinit(void); + void workdir_prev(void); void workdir_next(void); -- 2.52.0