- /*
- * check for .xxx files. Note can't get listalways without
- * listall being set
- */
- if (argv[curname][0] == '.' && !listallflag) {
- continue;
- }
- /* and now for listalways: . and .. */
- if ((argv[curname][0] == '.' && argv[curname][1] == '\0') ||
- (argv[curname][0] == '.' && argv[curname][1] == '.' &&
- argv[curname][2] == '\0')) {
- if (!listalwaysflag)
- continue;
- }
- } /* end of not firsttimethru test */
- if (firsttimethruflag || longformflag || recursiveflag || timesortflag || sizeflag || inodeflag || fancyflag) {
- if (statfcn(argv[curname], &stats[goodcount].lstat) == -1) {
- if (errno == ENOENT) {
- (void) fprintf(stderr, "%s not found\n", argv[curname]);
- continue;
- } else {
- perror(argv[curname]);
- exit(1);
- }
- } /* end of stat error check */
- }
- stats[goodcount].name = argv[curname];
- goodcount++;
- } /* end of per name loop */
-
- /* sort the names */
- if (goodcount > 1 && !specialdirflag) {
- if (reversesortflag) {
- if (!timesortflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), revnamecmp);
- } else {
- if (accesstimeflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), revacccmp);
- } else {
- if (modtimeflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), revmodcmp);
- } else {
- if (statustimeflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), revstatcmp);
- } else {
- }
- }
- }
- }
- } else {
- if (!timesortflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), namecmp);
- } else {
- if (accesstimeflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), acccmp);
- } else {
- if (modtimeflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), modcmp);
- } else {
- if (statustimeflag) {
- qsort((char *) stats, goodcount, sizeof(struct lsstruct), statcmp);
- } else {
- }
- }
- }
- }
- }
- } /* end of sort conditionals */
- prindir(stats, goodcount);
-
- if ((firsttimethruflag && !listdirflag) || recursiveflag) {
- for (i = 0; i < goodcount; ++i) {
- /* recurse on directories */
- if ((stats[i].lstat.st_mode & S_IFMT) == S_IFDIR) {
- /* don't recurse on . or .. */
- if ((stats[i].name[0] == '.' && stats[i].name[1] == '\0') ||
- (stats[i].name[0] == '.' && stats[i].name[1] == '.' && stats[i].name[2] == '\0')) {
- if (!firsttimethruflag) {
- continue;
- }
- }
- if (chdir(stats[i].name) == -1) {
- perror(stats[i].name);
- break;
- }
- if (goodcount > 1 || !firsttimethruflag || recursiveflag) {
- /* add current name to path */
- if ((midpt = strchr(curpath, (int) '\0')) != curpath) {
- if (midpt[-1] != '/') {
- *midpt++ = '/';
- }
- }
- (void) strcpy(midpt, stats[i].name);
-
- if (goodcount > 1 || !firsttimethruflag) {
- (void) printf("\n%s:\n", curpath);
- }
- }
- recursedir(&stats[i]);
- if (goodcount > 1 || !firsttimethruflag) {
- *midpt = '\0';
- }
- if (chdir("..") == -1) {
- perror(stats[i].name);
- }
- }
- } /* end of for loop looking for directories */
- firsttimethruflag = 0;