diff --git a/ChangeLog b/ChangeLog index 9cbc263acf3c4bbffdf85271f97650c3355cfe2e..ec7c3e3d57b06a5ba1d4b83237ed0d2de17f40a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,8 +3,7 @@ General - - New file browser code. New functions in files.c:do_browser(), helper functions browser_init(), tail(), striponedir(), filestat(). New shortcut list browser_list. Some new - strings to translate. Chris needs to add comments to his - code. + strings to translate. Added function do_browse_from(). - We only call keypad() once now for each window, at the beginning. FINALLY! No more keypad_on(), no more individual calls in main(), do_help(), do_browser(), etc etc etc. Removed call to @@ -32,6 +31,10 @@ General - - Spell Erik Andersen's name right. titlebar() - Now takes an arg, needed for browser function. +- utils.c: + mallocstrcpy() + - Takes char pointers now instead of void (makes debugging a + helluva lot easier) - es.po: - Updates for file browser (Jordi). diff --git a/files.c b/files.c index 8846ffae2883445b71aee7789a6f6e346b28ecd7..facd2dcb44c16b5d31b8977fcaddd7d0ab663634 100644 --- a/files.c +++ b/files.c @@ -273,7 +273,8 @@ int do_insertfile(void) #if !defined(DISABLE_BROWSER) && !defined(NANO_SMALL) if (i == NANO_TOFILES_KEY) { - char *tmp = do_browser(getcwd(NULL, 0)); + + char *tmp = do_browse_from(realname); #ifdef DISABLE_TABCOMP realname = NULL; @@ -526,7 +527,8 @@ int do_writeout(int exiting) #if !defined(DISABLE_BROWSER) && !defined(NANO_SMALL) if (i == NANO_TOFILES_KEY) { - char *tmp = do_browser(getcwd(NULL, 0)); + + char *tmp = do_browse_from(answer); if (tmp != NULL) answer = mallocstrcpy(answer, tmp); @@ -1404,5 +1406,34 @@ char *do_browser(char *inpath) free(foo); return retval; } + +/* Browser fron't end, checks to see if inpath has a dir in it and if so + starts do_browser from there, else from the current dir */ +char *do_browse_from(char *inpath) +{ + struct stat st; + char *tmp = NULL; + + tmp = mallocstrcpy(tmp, inpath); + + /* If there's no / in the string, we may was well start from . */ + if (tmp == NULL || !strstr(tmp, "/")) + return do_browser(getcwd(NULL, 0)); + + /* If the string is a directory, pass do_browser that */ + st = filestat(tmp); + if (S_ISDIR(st.st_mode)) + return do_browser(tmp); + + /* Okay, there's a dir in there, but not at the end of the string... + try stripping it off */ + striponedir(tmp); + align(&tmp); + return do_browser(tmp); + +} + + + #endif diff --git a/proto.h b/proto.h index 9c7b4b683fa9c5e885855d4741eeb42eaa8448b9..d4b1b73259329832ef9e077245f8866d9d83e24e 100644 --- a/proto.h +++ b/proto.h @@ -119,7 +119,7 @@ void center_cursor(void); void bottombars(shortcut s[], int slen); void blank_statusbar_refresh(void); void *nmalloc (size_t howmuch); -void *mallocstrcpy(void *dest, void *src); +void *mallocstrcpy(char *dest, char *src); void wrap_reset(void); void display_main_list(void); void nano_small_msg(void); @@ -154,6 +154,8 @@ int do_replace(void), do_help(void), do_enter_void(void); #if !defined(DISABLE_BROWSER) && !defined(NANO_SMALL) char *do_browser(char *path); +struct stat filestat(const char *path); +char *do_browse_from(char *inpath); #endif filestruct *copy_node(filestruct * src); diff --git a/utils.c b/utils.c index 3d0ea6d76b0a2a9542cdba602c0195a8a4294976..f624a103810ec9ed0389c7769b4d8592e7290eab 100644 --- a/utils.c +++ b/utils.c @@ -123,7 +123,7 @@ void *nrealloc(void *ptr, size_t howmuch) Should be used as dest = mallocstrcpy(dest, src); */ -void *mallocstrcpy(void *dest, void *src) +void *mallocstrcpy(char *dest, char *src) { if (dest != NULL)