From c5740d05f8ca4be768c82f320414920452cfffdb Mon Sep 17 00:00:00 2001 From: a bellenir Date: Wed, 23 Jul 2014 23:50:35 +0000 Subject: [PATCH] here's to the new cd. just like the old cd. --- source/input.c | 2 +- source/screen.c | 14 ++++++++++---- source/workdir.c | 11 +++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/input.c b/source/input.c index 26979c6..c615c97 100644 --- a/source/input.c +++ b/source/input.c @@ -13,7 +13,7 @@ void input_handle_key(char ch) { break; case 'j': workdir_next(state_get_focused_frame()->workdir); break; case 'k': workdir_prev(state_get_focused_frame()->workdir); break; - //case 'e': workdir_cd(state_get_focused_frame()->workdir); break; + case 'e': workdir_cd(state_get_focused_frame()->workdir); break; case 'n': screen_open(); break; case 'c': screen_close(); diff --git a/source/screen.c b/source/screen.c index 89aed2b..44262a1 100644 --- a/source/screen.c +++ b/source/screen.c @@ -1,12 +1,18 @@ -#include "screen.h" -#include "state.h" -#include "aardvark.h" -#include "workdir.h" +/* external libraries */ #include #include +#include + +/* internal libraries */ #include "vec.h" #include "mem.h" +/* internal headers */ +#include "screen.h" +#include "state.h" +#include "aardvark.h" +#include "workdir.h" + static void screen_place_windows(void); static frame_t* screen_frame_new(void); static void screen_frame_free(void* p_frame); diff --git a/source/workdir.c b/source/workdir.c index 80d54e4..7977a51 100644 --- a/source/workdir.c +++ b/source/workdir.c @@ -76,10 +76,9 @@ char* workdir_cd_up(WorkDir_T* wd){ } else { newpath = mem_allocate(sizeof(char)*last_slash, NULL); strncpy(newpath, wd->path, last_slash); - newpath[last_slash-1]=0; + newpath[last_slash] = 0; } - mem_release(wd->path); - wd->path = newpath; + return newpath; } //go down a directory: append '/subdir' to path @@ -94,14 +93,14 @@ char* workdir_cd_down(WorkDir_T* wd){ } void workdir_cd(WorkDir_T* wd) { - char* newpath = (wd->idx == 0) ? workdir_cd_up(wd) : workdir_cd_down(wd); + char* newpath = (wd->idx == 0) ? workdir_cd_up(wd) : workdir_cd_down(wd); if(is_dir(newpath)){ - mem_release(wd->path); + //TODO: this segfaults: mem_release(wd->path); wd->path = newpath; wd->idx = 0; wd->top_index = 0; } - //TODO: refresh file list + workdir_ls(wd); } void workdir_ls(WorkDir_T* wd){ -- 2.54.0