From 150469a6467c7db615ac0999b042ffd5b7f62239 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Fri, 5 Jan 2001 21:13:14 +0000 Subject: [PATCH] Added do_browse_from(), called from do_writeout and do_insert, changed mallocstrcpy to *char git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@450 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 7 +++++-- files.c | 35 +++++++++++++++++++++++++++++++++-- proto.h | 4 +++- utils.c | 2 +- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9cbc263a..ec7c3e3d 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 8846ffae..facd2dcb 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 9c7b4b68..d4b1b732 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 3d0ea6d7..f624a103 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)