View | Details | Raw Unified | Return to bug 116425
Collapse All | Expand All

(-)ls.new/cmp.c (+32 lines)
Lines 183-185 Link Here
183
183
184
	return (sizecmp(b, a));
184
	return (sizecmp(b, a));
185
}
185
}
186
187
#define IS_FTS_DIR(x) ((x)->fts_info == FTS_D \
188
		       || (x)->fts_info == FTS_DOT \
189
		       || (x)->fts_info == FTS_DC \
190
		       || (x)->fts_info == FTS_DNR \
191
		       || (x)->fts_info == FTS_DP)
192
193
int
194
dirfcmp(const FTSENT *a, const FTSENT *b)
195
{
196
197
	if ((IS_FTS_DIR(a) && IS_FTS_DIR(b)) || (!IS_FTS_DIR(a) && !IS_FTS_DIR(b)))
198
		return (real_sortfcn(a, b));
199
	return (IS_FTS_DIR(a) ? -1 : 1);
200
}
201
202
int
203
revdirfcmp(const FTSENT *a, const FTSENT *b)
204
{
205
206
	if ((IS_FTS_DIR(a) && IS_FTS_DIR(b)) || (!IS_FTS_DIR(a) && !IS_FTS_DIR(b)))
207
		return (real_sortfcn(a, b));
208
	return (IS_FTS_DIR(b) ? -1 : 1);
209
}
210
int
211
checkisdir(const FTSENT *a)
212
{
213
	if (IS_FTS_DIR(a))
214
		return (0);
215
	else
216
		return (1);
217
}
(-)ls.new/extern.h (+6 lines)
Lines 42-47 Link Here
42
int	 revstatcmp(const FTSENT *, const FTSENT *);
42
int	 revstatcmp(const FTSENT *, const FTSENT *);
43
int	 sizecmp(const FTSENT *, const FTSENT *);
43
int	 sizecmp(const FTSENT *, const FTSENT *);
44
int	 revsizecmp(const FTSENT *, const FTSENT *);
44
int	 revsizecmp(const FTSENT *, const FTSENT *);
45
int	 dirfcmp(const FTSENT *, const FTSENT *);
46
int	 revdirfcmp(const FTSENT *, const FTSENT *);
47
int	 checkisdir(const FTSENT *);
48
49
/* save the real sortfcn when sorting directories first */
50
int (*real_sortfcn)(const FTSENT *, const FTSENT *);
45
51
46
void	 printcol(const DISPLAY *);
52
void	 printcol(const DISPLAY *);
47
void	 printlong(const DISPLAY *);
53
void	 printlong(const DISPLAY *);
(-)ls.new/ls.1 (-1 / +25 lines)
Lines 40-46 Link Here
40
.Nd list directory contents
40
.Nd list directory contents
41
.Sh SYNOPSIS
41
.Sh SYNOPSIS
42
.Nm
42
.Nm
43
.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1
43
.Op Fl ABCDFGHILNPRSTUVWZabcdefghiklmnopqrstuvwxz1
44
.Op Ar
44
.Op Ar
45
.Sh DESCRIPTION
45
.Sh DESCRIPTION
46
For each operand that names a
46
For each operand that names a
Lines 88-93 Link Here
88
is the numeric value of the character in octal.
88
is the numeric value of the character in octal.
89
.It Fl C
89
.It Fl C
90
Force multi-column output; this is the default when output is to a terminal.
90
Force multi-column output; this is the default when output is to a terminal.
91
.It Fl D
92
Sorts directories first. This is independent of the
93
.Fl r
94
option.
91
.It Fl F
95
.It Fl F
92
Display a slash
96
Display a slash
93
.Pq Ql /
97
.Pq Ql /
Lines 132-137 Link Here
132
This option cancels the
136
This option cancels the
133
.Fl P
137
.Fl P
134
option.
138
option.
139
.It Fl N
140
Negates sorting directories first or last (the
141
.Fl D
142
and
143
.Fl V
144
options).
135
.It Fl P
145
.It Fl P
136
If argument is a symbolic link, list the link itself rather than the
146
If argument is a symbolic link, list the link itself rather than the
137
object the link references.
147
object the link references.
Lines 154-159 Link Here
154
month, day, hour, minute, second, and year.
164
month, day, hour, minute, second, and year.
155
.It Fl U
165
.It Fl U
156
Use time when file was created for sorting or printing.
166
Use time when file was created for sorting or printing.
167
.It Fl V
168
Sorts directories last. This is independent of the
169
.Fl r
170
option.
157
.It Fl W
171
.It Fl W
158
Display whiteouts when scanning directories.
172
Display whiteouts when scanning directories.
159
.It Fl Z
173
.It Fl Z
Lines 173-178 Link Here
173
Use time when file status was last changed for sorting or printing.
187
Use time when file status was last changed for sorting or printing.
174
.It Fl d
188
.It Fl d
175
Directories are listed as plain files (not searched recursively).
189
Directories are listed as plain files (not searched recursively).
190
.It Fl e
191
List everything (not strictly, but negates the
192
.Fl v
193
and
194
.Fl z
195
options).
176
.It Fl f
196
.It Fl f
177
Output is not sorted.
197
Output is not sorted.
178
.It Fl g
198
.It Fl g
Lines 242-247 Link Here
242
.Pq Fl t
262
.Pq Fl t
243
or printing
263
or printing
244
.Pq Fl l .
264
.Pq Fl l .
265
.It Fl v
266
Lists only directories.
245
.It Fl w
267
.It Fl w
246
Force raw printing of non-printable characters.
268
Force raw printing of non-printable characters.
247
This is the default
269
This is the default
Lines 251-256 Link Here
251
.Fl C ,
273
.Fl C ,
252
except that the multi-column output is produced with entries sorted
274
except that the multi-column output is produced with entries sorted
253
across, rather than down, the columns.
275
across, rather than down, the columns.
276
.It Fl z
277
Lists only non-directories.
254
.It Fl 1
278
.It Fl 1
255
(The numeric digit
279
(The numeric digit
256
.Dq one . )
280
.Dq one . )
(-)ls.new/ls.c (-7 / +67 lines)
Lines 105-110 Link Here
105
/* flags */
105
/* flags */
106
       int f_accesstime;	/* use time of last access */
106
       int f_accesstime;	/* use time of last access */
107
       int f_birthtime;		/* use time of birth */
107
       int f_birthtime;		/* use time of birth */
108
static int f_dirfirstsort;	/* put directories first */
109
static int f_dirlastsort;	/* put directories last */
110
static int f_dirlistonly;	/* list directories only */
111
static int f_dirlistnone;	/* list non-directories only */
108
       int f_flags;		/* show flags associated with a file */
112
       int f_flags;		/* show flags associated with a file */
109
       int f_humanval;		/* show human-readable file sizes */
113
       int f_humanval;		/* show human-readable file sizes */
110
       int f_inode;		/* print inode */
114
       int f_inode;		/* print inode */
Lines 179-189 Link Here
179
183
180
	fts_options = FTS_PHYSICAL;
184
	fts_options = FTS_PHYSICAL;
181
 	while ((ch = getopt(argc, argv,
185
 	while ((ch = getopt(argc, argv,
182
	    "1ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx")) != -1) {
186
	    "1ABCDFGHILNPRSTUVWZabcdefghiklmnopqrstuvwxz")) != -1) {
183
		switch (ch) {
187
		switch (ch) {
184
		/*
188
		/*
185
		 * The -1, -C, -x and -l options all override each other so
189
		 * The -1, -C, -x and -l options all override each other,
186
		 * shell aliasing works right.
190
		 * as do also the -D and -Z options, and the -v and -z 
191
		 * options so shell aliasing works right.
187
		 */
192
		 */
188
		case '1':
193
		case '1':
189
			f_singlecol = 1;
194
			f_singlecol = 1;
Lines 198-203 Link Here
198
		case 'C':
203
		case 'C':
199
			f_sortacross = f_longform = f_singlecol = 0;
204
			f_sortacross = f_longform = f_singlecol = 0;
200
			break;
205
			break;
206
		case 'D':
207
			f_dirfirstsort = 1;
208
			f_dirlastsort = 0;
209
			break;
210
		case 'V':
211
			f_dirfirstsort = 0;
212
			f_dirlastsort = 1;
213
			break;
214
		case 'N':
215
			f_dirfirstsort = 0;
216
			f_dirlastsort = 0;
217
			break;
218
		case 'v':
219
			f_dirlistonly = 1;
220
			f_dirlistnone = 0;
221
			break;
222
		case 'z':
223
			f_dirlistonly = 0;
224
			f_dirlistnone = 1;
225
			break;
226
		case 'e':
227
			f_dirlistonly = 0;
228
			f_dirlistnone = 0;
229
			break;
201
		case 'l':
230
		case 'l':
202
			f_longform = 1;
231
			f_longform = 1;
203
			f_singlecol = 0;
232
			f_singlecol = 0;
Lines 376-387 Link Here
376
#endif
405
#endif
377
406
378
	/*
407
	/*
379
	 * If not -F, -i, -l, -s, -S or -t options, don't require stat
408
	 * If not -D, -V, -v, -z, -F, -i, -l, -s, -S or -t options, don't
380
	 * information, unless in color mode in which case we do
409
	 * require stat information, unless in color mode in which case 
381
	 * need this to determine which colors to display.
410
	 * we do need this to determine which colors to display.
382
	 */
411
	 */
383
	if (!f_inode && !f_longform && !f_size && !f_timesort &&
412
	if (!f_inode && !f_longform && !f_size && !f_timesort &&
384
	    !f_sizesort && !f_type
413
	    !f_sizesort && !f_type && !f_dirfirstsort && !f_dirlastsort &&
414
	    !f_dirlistonly && !f_dirlistnone
385
#ifdef COLORLS
415
#ifdef COLORLS
386
	    && !f_color
416
	    && !f_color
387
#endif
417
#endif
Lines 426-431 Link Here
426
			sortfcn = revsizecmp;
456
			sortfcn = revsizecmp;
427
		else		/* Use modification time. */
457
		else		/* Use modification time. */
428
			sortfcn = revmodcmp;
458
			sortfcn = revmodcmp;
459
		if (f_dirfirstsort) {
460
			real_sortfcn = sortfcn;
461
			sortfcn = dirfcmp;
462
		} else if (f_dirlastsort) {
463
			real_sortfcn = sortfcn;
464
			sortfcn = revdirfcmp;
465
		}
466
429
	} else {
467
	} else {
430
		if (!f_timesort && !f_sizesort)
468
		if (!f_timesort && !f_sizesort)
431
			sortfcn = namecmp;
469
			sortfcn = namecmp;
Lines 439-444 Link Here
439
			sortfcn = sizecmp;
477
			sortfcn = sizecmp;
440
		else		/* Use modification time. */
478
		else		/* Use modification time. */
441
			sortfcn = modcmp;
479
			sortfcn = modcmp;
480
		if (f_dirfirstsort) {
481
			real_sortfcn = sortfcn;
482
			sortfcn = dirfcmp;
483
		} else if (f_dirlastsort) {
484
			real_sortfcn = sortfcn;
485
			sortfcn = revdirfcmp;
486
		}
487
442
	}
488
	}
443
489
444
	/* Select a print function. */
490
	/* Select a print function. */
Lines 653-658 Link Here
653
			cur->fts_number = NO_PRINT;
699
			cur->fts_number = NO_PRINT;
654
			rval = 1;
700
			rval = 1;
655
			continue;
701
			continue;
702
		}
703
		/*
704
		* Tell to print (only dirs|no dirs) if set 
705
		*/
706
		if (f_dirlistonly) {
707
			if (checkisdir(cur)) {
708
				cur->fts_number = NO_PRINT;
709
				continue;
710
			}
711
		} else if (f_dirlistnone) {
712
			if (! checkisdir(cur)) {
713
				cur->fts_number = NO_PRINT;
714
				continue;
715
			}
656
		}
716
		}
657
		/*
717
		/*
658
		 * P is NULL if list is the argv list, to which different rules
718
		 * P is NULL if list is the argv list, to which different rules
(-)ls.new/util.c (-2 / +2 lines)
Lines 222-230 Link Here
222
{
222
{
223
	(void)fprintf(stderr,
223
	(void)fprintf(stderr,
224
#ifdef COLORLS
224
#ifdef COLORLS
225
	"usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1]"
225
	"usage: ls [-ABCDFGHILNPRSTUVWZabcdefghiklmnopqrstuvwxz1]"
226
#else
226
#else
227
	"usage: ls [-ABCFHILPRSTUWZabcdfghiklmnopqrstuwx1]"
227
	"usage: ls [-ABCDFHILNPRSTUVWZabcdefghiklmnopqrstuvwxz1]"
228
#endif
228
#endif
229
		      " [file ...]\n");
229
		      " [file ...]\n");
230
	exit(1);
230
	exit(1);

Return to bug 116425