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
This commit is contained in:
Chris Allegretta 2001-01-05 21:13:14 +00:00
parent 544347c08a
commit 150469a646
4 changed files with 42 additions and 6 deletions

View File

@ -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).

35
files.c
View File

@ -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

View File

@ -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);

View File

@ -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)