]> git.mdlowis.com Git - archive/afm.git/commitdiff
vector to list
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 24 Jul 2014 02:33:19 +0000 (22:33 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 24 Jul 2014 02:33:19 +0000 (22:33 -0400)
source/main.c
source/main.mf [new file with mode: 0644]
source/screen.c
source/screen.h
source/workdir.c
source/workdir.h

index 8417d56869499672a36964138796a3e993ed8dba..bbbbb28b6d2316f425c81007b93cebfd2ec0e9db 100644 (file)
@@ -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 (file)
index 0000000..4695857
--- /dev/null
@@ -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
index 0f023285eeb493d4b1149d368fd5000d4ba5bb92..e5bfc06036050468eae90e0f7f12bda50739fdd1 100644 (file)
@@ -3,7 +3,7 @@
 #include "aardvark.h"
 #include "workdir.h"
 #include <ncurses.h>
-#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;
     }
 }
 
index 44f7114f70926ff9eb25fda956bdaf62e16b4e7d..5e40eedb05f6b86d41daad44f9db38b6eaa86c4a 100644 (file)
@@ -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);
index fd2f9768911fa10062acc4c2cf1f5e23a8de707e..8a508a7b878d6d61fff15cd3877ff93cc721ceb4 100644 (file)
@@ -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
index 1b28aa50d1abcbf00985250dc7ea081e7bf4c603..0b3afd6057c67b4b2d049ba846b58f78ad52c691 100644 (file)
@@ -9,6 +9,8 @@
 
 void workdir_init(int windex);
 
+void workdir_deinit(void);
+
 void workdir_prev(void);
 
 void workdir_next(void);