SCCS-vsn: bin/ls/ls.c 5.15
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)ls.c 5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c 5.15 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
argc -= optind;
argv += optind;
argc -= optind;
argv += optind;
- /* -f turns off -l, -t, -s, -r, turns on -a */
+ /* -f turns off -F, -R, -l, -t, -s, -r, turns on -a */
- f_longform = f_timesort = f_size = f_reversesort =
- f_recursive = f_type = 0;
+ f_longform = f_recursive = f_reversesort = f_size =
+ f_timesort = f_type = 0;
f_listdot = f_listalldot = 1;
}
f_listdot = f_listalldot = 1;
}
-/**
- * curdir --
- * no arguments, list the current directory; this is the
- * most common case, so it must run labooh.
- */
curdir()
{
LS local, *stats;
curdir()
{
LS local, *stats;
-/**
- * args --
- * handle arguments; this is separated out since we want to do the
- * files first, then the directories, plus we must return to the
- * current directory each time.
- */
+static char path[MAXPATHLEN + 1];
+static char *endofpath = path;
+
args(argc, argv)
int argc;
char **argv;
args(argc, argv)
int argc;
char **argv;
(void)putchar('\n');
}
if (dircnt) {
(void)putchar('\n');
}
if (dircnt) {
if (dircnt > 1)
qsort((char *)dstats, dircnt, sizeof(LS), sortfcn);
if (dircnt > 1)
qsort((char *)dstats, dircnt, sizeof(LS), sortfcn);
- for (cnt = 0; cnt < dircnt; ++cnt)
+ for (cnt = 0; cnt < dircnt; ++cnt) {
+ for (endofpath = path, p = dstats->name;
+ *endofpath = *p++; ++endofpath);
ls_dir(dstats++, cnt, regcnt || dircnt > 1);
ls_dir(dstats++, cnt, regcnt || dircnt > 1);
}
#ifdef whybother
(void)free((char *)rstats);
}
#ifdef whybother
(void)free((char *)rstats);
LS *stats;
register int num;
{
LS *stats;
register int num;
{
+ register char *p, *savedpath;
LS *lp;
if (num > 1 && !f_specialdir)
LS *lp;
if (num > 1 && !f_specialdir)
+ if (f_recursive) {
+ savedpath = endofpath;
for (lp = stats; num--; ++lp) {
if (!S_ISDIR(lp->lstat.st_mode))
continue;
p = lp->name;
if (p[0] == '.' && (!p[1] || p[1] == '.' && !p[2]))
continue;
for (lp = stats; num--; ++lp) {
if (!S_ISDIR(lp->lstat.st_mode))
continue;
p = lp->name;
if (p[0] == '.' && (!p[1] || p[1] == '.' && !p[2]))
continue;
+ if (endofpath != path && endofpath[-1] != '/')
+ *endofpath++ = '/';
+ for (; *endofpath = *p++; ++endofpath);
+ *(endofpath = savedpath) = '\0';
}
ls_dir(lp, newline, tag)
LS *lp;
int newline, tag;
{
}
ls_dir(lp, newline, tag)
LS *lp;
int newline, tag;
{
- static char path[MAXPATHLEN + 1];
- register char *p;
- char *endofname, *names;
-
- /* add current name to path */
- p = index(path, '\0');
- if (p != path && p[-1] != '/')
- *p++ = '/';
- (void)strcpy(p, lp->name);
- endofname = p;
if (newline)
(void)putchar('\n');
if (newline)
(void)putchar('\n');
}
if (num = buildstats(lp, &stats, &names))
ls(stats, num);
}
if (num = buildstats(lp, &stats, &names))
ls(stats, num);
(void)free((char *)stats);
(void)free((char *)names);
if (chdir("..")) {
(void)free((char *)stats);
(void)free((char *)names);
if (chdir("..")) {
*names++ = '\0';
++cnt;
}
*names++ = '\0';
++cnt;
}