]> git.mdlowis.com Git - archive/afm.git/commitdiff
initialize cwd
authora bellenir <a@bellenir.com>
Sun, 20 Jul 2014 03:24:30 +0000 (03:24 +0000)
committera bellenir <a@bellenir.com>
Sun, 20 Jul 2014 03:24:30 +0000 (03:24 +0000)
source/main.c
source/workdir.c
source/workdir.h

index 4b1cdfd76ea00326dffb9725afa5df00419e68ab..7a6cdbea4099871663baaf9b86f53acf6beddd0a 100644 (file)
 #include "state.h"
 #include "input.h"
 #include "screen.h"
+#include "workdir.h"
 
 
-
-//
-///* TODO redraw less frequently */
-///* TODO detect filesystem changes */
-//
-//void get_files(int windex){
-//    /*free existing contents*/
-//    int i=0;
-//    if(Windows[windex].files){
-//        /*fuck memory (this is broken)
-//        while(Files[i]){
-//            free(Files[i]);
-//            i++;
-//        }*/
-//        free(Windows[windex].files);
-//    }
-//    /* TODO: malloc smartly, instead of tapping out at 1024 files */
-//    Windows[windex].files = malloc(sizeof(char*) * 1024);
-//    Windows[windex].files[0] = ".."; /* parent directory; TODO only add if cwd!=/ */
-//    char cmd[1028] = "ls ";
-//    strcpy(&cmd[3], Windows[windex].cwd);
-//    FILE* ls = popen(cmd, "r");
-//    size_t len = 0;
-//    ssize_t read;
-//    i = 1;
-//    while ((read = getline(&Windows[windex].files[i], &len, ls)) != -1){
-//        if(Windows[windex].files[i][read-1] == '\n') Windows[windex].files[i][read-1] = 0;
-//        i++;
-//        if(i>1022) break;
-//    }
-//    Windows[windex].file_count = i-1;
-//    Windows[windex].files[i] = 0; /*always end with nullpointer; since file_count is a thing, can probably do without this*/
-//}
-//
-//void cd(int windex){
-//    int last_slash=0, i=0;
-//    bool ends_with_slash = false;
-//    while(Windows[windex].cwd[i] != 0){
-//        if(Windows[windex].cwd[i] == '/')
-//            last_slash = i;
-//        i++;
-//    }
-//    ends_with_slash = (last_slash == (i-1)); /* should only be true for root */
-//    if(Windows[windex].idx == 0) { /* up */
-//        //truncate cwd including the last slash
-//        Windows[windex].cwd[last_slash]=0;
-//        if(last_slash==0){ //at root. fixitfixitfixit.
-//            Windows[windex].cwd[0]='/';
-//            Windows[windex].cwd[1]=0;
-//        }
-//    }else{
-//        //add file to cwd:
-//        int cwdend = i;
-//        if(!ends_with_slash){
-//            Windows[windex].cwd[i] = '/';
-//            i++;
-//        }
-//        strcpy(&Windows[windex].cwd[i], Windows[windex].files[Windows[windex].idx]);
-//        Windows[windex].idx = 0;
-//        Windows[windex].top_index = 0;
-//        //if not a directory, revert
-//        if(!is_dir(Windows[windex].cwd)) Windows[windex].cwd[cwdend]=0;
-//    }
-//}
-//
-//void list_files(int windex) {
-//    get_files(windex);
-//    int i = Windows[windex].top_index;
-//    int rows, cols;
-//    getmaxyx(stdscr, rows, cols);
-//    attron(A_UNDERLINE);
-//    mvaddnstr(1, 1, Windows[windex].cwd, cols-2);
-//    attroff(A_UNDERLINE);
-//    while (Windows[windex].files[i] != 0){
-//        if(i==Windows[windex].idx){
-//            attron(A_STANDOUT);
-//            attron(A_BOLD);
-//        }
-//        mvaddnstr(TopBuffer+i-Windows[windex].top_index, 1, Windows[windex].files[i], cols-2);
-//        if(i == Windows[windex].idx){
-//            attroff(A_STANDOUT);
-//            attroff(A_BOLD);
-//        }
-//        i++;
-//        if((TopBuffer+i-Windows[windex].top_index+BotBuffer) > rows) break;
-//    }
-//}
-
 void handle_signal(int sig) {
     signal(SIGWINCH, handle_signal);
     state_set_screen_dirty(true);
     state_set_screen_resized(true);
 }
 
-void init_window_t(windex){
-    //Windows[windex].idx = 0;
-    //getcwd(Windows[windex].cwd, 1024);
-}
 
 int main(int argc, char** argv) {
-    init_window_t(0);
+       workdir_init(0);
     /* Handle terminal resizing */
     signal(SIGWINCH, handle_signal);
     /* Initialize ncurses and user input settings */
index 9d644f9fd6ab61718c0286993925b79f51c462a7..fd2f9768911fa10062acc4c2cf1f5e23a8de707e 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 typedef struct {
     int idx;
@@ -31,6 +32,11 @@ static bool is_dir(char* path) {
     return false;
 }
 
+void workdir_init(int windex) {
+    Windows[windex].idx = 0;
+    getcwd(Windows[windex].cwd, 1024);
+}
+
 void workdir_next(void) {
     int index = state_get_focused_frame();
     //do nothing if at the end of the file list
index 6a6802fad5362b6615b115240c014a41215f273c..1b28aa50d1abcbf00985250dc7ea081e7bf4c603 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef WORKDIR_H
 #define WORKDIR_H
 
+void workdir_init(int windex);
+
 void workdir_prev(void);
 
 void workdir_next(void);