More browser and misc fixes by Matthias Andree that Chris screwed around with

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@585 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2001-04-03 01:02:38 +00:00
parent b2c4cbebab
commit 90d307413b
2 changed files with 48 additions and 24 deletions

View File

@ -10,14 +10,23 @@ CVS -
- faq.html: - faq.html:
- Fixed typo in section 6.1 (discovered by Bob Farmer). - Fixed typo in section 6.1 (discovered by Bob Farmer).
- files.c: - files.c:
- fix two typos in comments, one in ChangeLog (Matthias Andree)
diralphasort() diralphasort()
- Stop abort on symlinks (Matthias Andree) - Stop abort on symlinks (Matthias Andree)
fielstat(), do_browse() - use strcasecmp to sort directory if available, pilot does that
as well (Matthias Andree)
filestat(), do_browse()
- Changed lstat calls to stat, which fixes the browser not - Changed lstat calls to stat, which fixes the browser not
following links to directories. We only use lstat() when following links to directories. We only use lstat() when
printing the details of the file, and if it is a link, then printing the details of the file, and if it is a link, then
check via lstat() for link to a directory. If it is check via lstat() for link to a directory. If it is
a directory, display (dir), else use the normal "--". a directory, display (dir), else use the normal "--".
do_browser()
- Fix broken size suffix off-by-one errors (Matthias Andree)
cwd_tab_completion(), do_browse_from()
- Use PATH_MAX instead of 0 arg to getcwd (Matthias Andree).
- Changed above to use PATH_MAX only when defined on the
system, as the HURD e.g. does not support it.
- intl/Makefile.in: - intl/Makefile.in:
distclean distclean
- added intl/libintl.h to the rm -f rule, should fix the unresolved - added intl/libintl.h to the rm -f rule, should fix the unresolved

61
files.c
View File

@ -736,7 +736,13 @@ char **cwd_tab_completion(char *buf, int *num_matches)
dirName[tmp - buf] = 0; dirName[tmp - buf] = 0;
} else { } else {
#ifdef PATH_MAX
if ((dirName = getcwd(NULL, PATH_MAX+1)) == NULL)
#else
/* The better, but aparently segfault-causing way */
if ((dirName = getcwd(NULL, 0)) == NULL) if ((dirName = getcwd(NULL, 0)) == NULL)
#endif /* PATH_MAX */
return matches; return matches;
else else
tmp = buf; tmp = buf;
@ -1003,22 +1009,20 @@ struct stat filestat(const char *path) {
int diralphasort(const void *va, const void *vb) { int diralphasort(const void *va, const void *vb) {
struct stat file1info, file2info; struct stat file1info, file2info;
char *a = *(char **)va, *b = *(char **)vb; char *a = *(char **)va, *b = *(char **)vb;
int answer = 0; int aisdir, bisdir;
if ((stat(a, &file1info) != -1) && (stat(b, &file2info) != -1)) { aisdir = (stat(a, &file1info) != -1) && S_ISDIR(file1info.st_mode);
/* If is a is a dir and b isn't, return -1. bisdir = (stat(b, &file2info) != -1) && S_ISDIR(file2info.st_mode);
Else if b is a dir and a isn't, return 0.
Else return a < b */
if (S_ISDIR(file1info.st_mode) && !S_ISDIR(file2info.st_mode)) if (aisdir && !bisdir) return -1;
return -1; if (!aisdir && bisdir) return 1;
else if (!S_ISDIR(file1info.st_mode) && S_ISDIR(file2info.st_mode))
return 1; #ifdef HAVE_STRCASECMP
else return(strcasecmp(a,b));
answer = strcmp(a, b); #else
} return(strcmp(a,b));
#endif
return(answer);
} }
@ -1300,14 +1304,18 @@ char *do_browser(char *inpath)
strcpy(foo + longest - 5, "(dir)"); strcpy(foo + longest - 5, "(dir)");
else else
strcpy(foo + longest - 2, "--"); strcpy(foo + longest - 2, "--");
} else if (st.st_size < 1024) /* less than 1 K */ } else if (st.st_size < (1 << 10)) /* less than 1 K */
sprintf(foo + longest - 7, "%4d B", (int) st.st_size); sprintf(foo + longest - 7, "%4d B",
else if (st.st_size > 1073741824) /* at least 1 gig */ (int) st.st_size >> 10);
sprintf(foo + longest - 7, "%4d GB", (int) st.st_size / 1073741824); else if (st.st_size >= (1 << 30)) /* at least 1 gig */
else if (st.st_size > 1048576) /* at least 1 meg */ sprintf(foo + longest - 7, "%4d GB",
sprintf(foo + longest - 7, "%4d MB", (int) st.st_size / 1048576); (int) st.st_size >> 30);
else if (st.st_size >= (1 << 20)) /* at least 1 meg */
sprintf(foo + longest - 7, "%4d MB",
(int) st.st_size >> 20);
else /* Its more than 1 k and less than a meg */ else /* Its more than 1 k and less than a meg */
sprintf(foo + longest - 7, "%4d KB", (int) st.st_size / 1024); sprintf(foo + longest - 7, "%4d KB",
(int) st.st_size >> 10);
} }
/* Hilight the currently selected file/dir */ /* Hilight the currently selected file/dir */
@ -1345,7 +1353,7 @@ char *do_browser(char *inpath)
return retval; return retval;
} }
/* Browser fron't end, checks to see if inpath has a dir in it and if so /* Browser front end, checks to see if inpath has a dir in it and if so
starts do_browser from there, else from the current dir */ starts do_browser from there, else from the current dir */
char *do_browse_from(char *inpath) char *do_browse_from(char *inpath)
{ {
@ -1354,9 +1362,16 @@ char *do_browse_from(char *inpath)
tmp = mallocstrcpy(tmp, inpath); tmp = mallocstrcpy(tmp, inpath);
/* If there's no / in the string, we may was well start from . */ /* If there's no / in the string, we may was well start from . */
if (tmp == NULL || !strstr(tmp, "/")) if (tmp == NULL || *tmp == '\0' || !strstr(tmp, "/")) {
return do_browser(getcwd(NULL, 0)); #ifdef PATH_MAX
char *from = getcwd(NULL, PATH_MAX+1);
#else
char *from = getcwd(NULL, 0));
#endif /* PATH_MAX */
return do_browser(from ? from : "./");
}
/* If the string is a directory, pass do_browser that */ /* If the string is a directory, pass do_browser that */
st = filestat(tmp); st = filestat(tmp);