Add -O (only leaf files) and -P (print full path), from tls@diff -r1.72 -r1.73 src/bin/ls/ls.1
(christos)
--- src/bin/ls/ls.1 2012/11/20 12:37:29 1.72
+++ src/bin/ls/ls.1 2014/02/20 18:56:36 1.73
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: ls.1,v 1.72 2012/11/20 12:37:29 abs Exp $ | 1 | .\" $NetBSD: ls.1,v 1.73 2014/02/20 18:56:36 christos Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 | 3 | .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 | |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | 5 | .\" | |
6 | .\" This code is derived from software contributed to Berkeley by | 6 | .\" This code is derived from software contributed to Berkeley by | |
7 | .\" the Institute of Electrical and Electronics Engineers, Inc. | 7 | .\" the Institute of Electrical and Electronics Engineers, Inc. | |
8 | .\" | 8 | .\" | |
9 | .\" Redistribution and use in source and binary forms, with or without | 9 | .\" Redistribution and use in source and binary forms, with or without | |
10 | .\" modification, are permitted provided that the following conditions | 10 | .\" modification, are permitted provided that the following conditions | |
11 | .\" are met: | 11 | .\" are met: | |
12 | .\" 1. Redistributions of source code must retain the above copyright | 12 | .\" 1. Redistributions of source code must retain the above copyright | |
13 | .\" notice, this list of conditions and the following disclaimer. | 13 | .\" notice, this list of conditions and the following disclaimer. | |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
@@ -22,35 +22,35 @@ | @@ -22,35 +22,35 @@ | |||
22 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 22 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 23 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 24 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 25 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 26 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 27 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 28 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 29 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. | |
32 | .\" | 32 | .\" | |
33 | .\" @(#)ls.1 8.7 (Berkeley) 7/29/94 | 33 | .\" @(#)ls.1 8.7 (Berkeley) 7/29/94 | |
34 | .\" | 34 | .\" | |
35 | .Dd November 20, 2012 | 35 | .Dd February 20, 2014 | |
36 | .Dt LS 1 | 36 | .Dt LS 1 | |
37 | .Os | 37 | .Os | |
38 | .Sh NAME | 38 | .Sh NAME | |
39 | .Nm ls | 39 | .Nm ls | |
40 | .Nd list directory contents | 40 | .Nd list directory contents | |
41 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS | |
42 | .Nm | 42 | .Nm | |
43 | .Op Fl 1AaBbCcdFfghikLlMmnopqRrSsTtuWwx | 43 | .Op Fl 1AaBbCcdFfghikLlMmnOoPpqRrSsTtuWwx | |
44 | .Op Ar | 44 | .Op Ar | |
45 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION | |
46 | For each | 46 | For each | |
47 | .Ar file | 47 | .Ar file | |
48 | operand that names a file of a type other than | 48 | operand that names a file of a type other than | |
49 | directory, | 49 | directory, | |
50 | .Nm | 50 | .Nm | |
51 | displays its name as well as any requested, | 51 | displays its name as well as any requested, | |
52 | associated information. | 52 | associated information. | |
53 | For each | 53 | For each | |
54 | .Ar file | 54 | .Ar file | |
55 | operand that names a file of type directory, | 55 | operand that names a file of type directory, | |
56 | .Nm | 56 | .Nm | |
@@ -173,36 +173,40 @@ commas (or a locale appropriate separato | @@ -173,36 +173,40 @@ commas (or a locale appropriate separato | |||
173 | output. | 173 | output. | |
174 | Overrides | 174 | Overrides | |
175 | .Fl h ; | 175 | .Fl h ; | |
176 | does not override | 176 | does not override | |
177 | .Fl k . | 177 | .Fl k . | |
178 | .It Fl m | 178 | .It Fl m | |
179 | Stream output format; list files across the page, separated by commas. | 179 | Stream output format; list files across the page, separated by commas. | |
180 | .It Fl n | 180 | .It Fl n | |
181 | The same as | 181 | The same as | |
182 | .Fl l , | 182 | .Fl l , | |
183 | except that | 183 | except that | |
184 | the owner and group IDs are displayed numerically rather than converting | 184 | the owner and group IDs are displayed numerically rather than converting | |
185 | to a owner or group name. | 185 | to a owner or group name. | |
186 | .It Fl O | |||
187 | Output only leaf files (not directories), eliding other ls output. | |||
186 | .It Fl o | 188 | .It Fl o | |
187 | Include the file flags in a long | 189 | Include the file flags in a long | |
188 | .Pq Fl l | 190 | .Pq Fl l | |
189 | output. | 191 | output. | |
190 | If no file flags are set, | 192 | If no file flags are set, | |
191 | .Dq - | 193 | .Dq - | |
192 | is displayed. | 194 | is displayed. | |
193 | (See | 195 | (See | |
194 | .Xr chflags 1 | 196 | .Xr chflags 1 | |
195 | for a list of possible flags and their meanings.) | 197 | for a list of possible flags and their meanings.) | |
198 | .It Fl P | |||
199 | Print the full pathname for each file. | |||
196 | .It Fl p | 200 | .It Fl p | |
197 | Display a slash | 201 | Display a slash | |
198 | .Pq Sq \&/ | 202 | .Pq Sq \&/ | |
199 | immediately after each pathname that is a directory. | 203 | immediately after each pathname that is a directory. | |
200 | .It Fl q | 204 | .It Fl q | |
201 | Force printing of non-printable characters in file names as | 205 | Force printing of non-printable characters in file names as | |
202 | the character | 206 | the character | |
203 | .Sq \&? ; | 207 | .Sq \&? ; | |
204 | this is the default when output is to a terminal. | 208 | this is the default when output is to a terminal. | |
205 | .It Fl R | 209 | .It Fl R | |
206 | Recursively list subdirectories encountered. | 210 | Recursively list subdirectories encountered. | |
207 | See also | 211 | See also | |
208 | .Fl d . | 212 | .Fl d . |
--- src/bin/ls/ls.c 2012/11/20 12:37:29 1.70
+++ src/bin/ls/ls.c 2014/02/20 18:56:36 1.71
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ls.c,v 1.70 2012/11/20 12:37:29 abs Exp $ */ | 1 | /* $NetBSD: ls.c,v 1.71 2014/02/20 18:56:36 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1989, 1993, 1994 | 4 | * Copyright (c) 1989, 1993, 1994 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Michael Fischbein. | 8 | * Michael Fischbein. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -32,27 +32,27 @@ | @@ -32,27 +32,27 @@ | |||
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include <sys/cdefs.h> | 35 | #include <sys/cdefs.h> | |
36 | #ifndef lint | 36 | #ifndef lint | |
37 | __COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\ | 37 | __COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\ | |
38 | The Regents of the University of California. All rights reserved."); | 38 | The Regents of the University of California. All rights reserved."); | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #ifndef lint | 41 | #ifndef lint | |
42 | #if 0 | 42 | #if 0 | |
43 | static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94"; | 43 | static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94"; | |
44 | #else | 44 | #else | |
45 | __RCSID("$NetBSD: ls.c,v 1.70 2012/11/20 12:37:29 abs Exp $"); | 45 | __RCSID("$NetBSD: ls.c,v 1.71 2014/02/20 18:56:36 christos Exp $"); | |
46 | #endif | 46 | #endif | |
47 | #endif /* not lint */ | 47 | #endif /* not lint */ | |
48 | 48 | |||
49 | #include <sys/param.h> | 49 | #include <sys/param.h> | |
50 | #include <sys/types.h> | 50 | #include <sys/types.h> | |
51 | #include <sys/stat.h> | 51 | #include <sys/stat.h> | |
52 | #include <sys/ioctl.h> | 52 | #include <sys/ioctl.h> | |
53 | 53 | |||
54 | #include <dirent.h> | 54 | #include <dirent.h> | |
55 | #include <err.h> | 55 | #include <err.h> | |
56 | #include <errno.h> | 56 | #include <errno.h> | |
57 | #include <fts.h> | 57 | #include <fts.h> | |
58 | #include <locale.h> | 58 | #include <locale.h> | |
@@ -101,26 +101,28 @@ int f_nosort; /* don't sort output */ | @@ -101,26 +101,28 @@ int f_nosort; /* don't sort output */ | |||
101 | int f_numericonly; /* don't convert uid/gid to name */ | 101 | int f_numericonly; /* don't convert uid/gid to name */ | |
102 | int f_octal; /* print octal escapes for nongraphic characters */ | 102 | int f_octal; /* print octal escapes for nongraphic characters */ | |
103 | int f_octal_escape; /* like f_octal but use C escapes if possible */ | 103 | int f_octal_escape; /* like f_octal but use C escapes if possible */ | |
104 | int f_recursive; /* ls subdirectories also */ | 104 | int f_recursive; /* ls subdirectories also */ | |
105 | int f_reversesort; /* reverse whatever sort is used */ | 105 | int f_reversesort; /* reverse whatever sort is used */ | |
106 | int f_sectime; /* print the real time for all files */ | 106 | int f_sectime; /* print the real time for all files */ | |
107 | int f_singlecol; /* use single column output */ | 107 | int f_singlecol; /* use single column output */ | |
108 | int f_size; /* list size in short listing */ | 108 | int f_size; /* list size in short listing */ | |
109 | int f_statustime; /* use time of last mode change */ | 109 | int f_statustime; /* use time of last mode change */ | |
110 | int f_stream; /* stream format */ | 110 | int f_stream; /* stream format */ | |
111 | int f_type; /* add type character for non-regular files */ | 111 | int f_type; /* add type character for non-regular files */ | |
112 | int f_typedir; /* add type character for directories */ | 112 | int f_typedir; /* add type character for directories */ | |
113 | int f_whiteout; /* show whiteout entries */ | 113 | int f_whiteout; /* show whiteout entries */ | |
114 | int f_fullpath; /* print full pathname, not filename */ | |||
115 | int f_leafonly; /* when recursing, print leaf names only */ | |||
114 | 116 | |||
115 | __dead static void | 117 | __dead static void | |
116 | usage(void) | 118 | usage(void) | |
117 | { | 119 | { | |
118 | 120 | |||
119 | (void)fprintf(stderr, | 121 | (void)fprintf(stderr, | |
120 | "usage: %s [-1AaBbCcdFfghikLlMmnopqRrSsTtuWwx] [file ...]\n", | 122 | "usage: %s [-1AaBbCcdFfghikLlMmnopqRrSsTtuWwx] [file ...]\n", | |
121 | getprogname()); | 123 | getprogname()); | |
122 | exit(EXIT_FAILURE); | 124 | exit(EXIT_FAILURE); | |
123 | /* NOTREACHED */ | 125 | /* NOTREACHED */ | |
124 | } | 126 | } | |
125 | 127 | |||
126 | int | 128 | int | |
@@ -139,27 +141,27 @@ ls_main(int argc, char *argv[]) | @@ -139,27 +141,27 @@ ls_main(int argc, char *argv[]) | |||
139 | if (isatty(STDOUT_FILENO)) { | 141 | if (isatty(STDOUT_FILENO)) { | |
140 | if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && | 142 | if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && | |
141 | win.ws_col > 0) | 143 | win.ws_col > 0) | |
142 | termwidth = win.ws_col; | 144 | termwidth = win.ws_col; | |
143 | f_column = f_nonprint = 1; | 145 | f_column = f_nonprint = 1; | |
144 | } else | 146 | } else | |
145 | f_singlecol = 1; | 147 | f_singlecol = 1; | |
146 | 148 | |||
147 | /* Root is -A automatically. */ | 149 | /* Root is -A automatically. */ | |
148 | if (!getuid()) | 150 | if (!getuid()) | |
149 | f_listdot = 1; | 151 | f_listdot = 1; | |
150 | 152 | |||
151 | fts_options = FTS_PHYSICAL; | 153 | fts_options = FTS_PHYSICAL; | |
152 | while ((ch = getopt(argc, argv, "1ABCFLMRSTWabcdfghiklmnopqrstuwx")) != -1) { | 154 | while ((ch = getopt(argc, argv, "1ABCFLMOPRSTWabcdfghiklmnopqrstuwx")) != -1) { | |
153 | switch (ch) { | 155 | switch (ch) { | |
154 | /* | 156 | /* | |
155 | * The -1, -C, -l, -m and -x options all override each other so | 157 | * The -1, -C, -l, -m and -x options all override each other so | |
156 | * shell aliasing works correctly. | 158 | * shell aliasing works correctly. | |
157 | */ | 159 | */ | |
158 | case '1': | 160 | case '1': | |
159 | f_singlecol = 1; | 161 | f_singlecol = 1; | |
160 | f_column = f_columnacross = f_longform = f_stream = 0; | 162 | f_column = f_columnacross = f_longform = f_stream = 0; | |
161 | break; | 163 | break; | |
162 | case 'C': | 164 | case 'C': | |
163 | f_column = 1; | 165 | f_column = 1; | |
164 | f_columnacross = f_longform = f_singlecol = f_stream = | 166 | f_columnacross = f_longform = f_singlecol = f_stream = | |
165 | 0; | 167 | 0; | |
@@ -243,29 +245,35 @@ ls_main(int argc, char *argv[]) | @@ -243,29 +245,35 @@ ls_main(int argc, char *argv[]) | |||
243 | f_humanize = 1; | 245 | f_humanize = 1; | |
244 | kflag = 0; | 246 | kflag = 0; | |
245 | f_commas = 0; | 247 | f_commas = 0; | |
246 | break; | 248 | break; | |
247 | case 'M': | 249 | case 'M': | |
248 | f_humanize = 0; | 250 | f_humanize = 0; | |
249 | f_commas = 1; | 251 | f_commas = 1; | |
250 | break; | 252 | break; | |
251 | case 'n': | 253 | case 'n': | |
252 | f_numericonly = 1; | 254 | f_numericonly = 1; | |
253 | f_longform = 1; | 255 | f_longform = 1; | |
254 | f_column = f_columnacross = f_singlecol = f_stream = 0; | 256 | f_column = f_columnacross = f_singlecol = f_stream = 0; | |
255 | break; | 257 | break; | |
258 | case 'O': | |||
259 | f_leafonly = 1; | |||
260 | break; | |||
256 | case 'o': | 261 | case 'o': | |
257 | f_flags = 1; | 262 | f_flags = 1; | |
258 | break; | 263 | break; | |
264 | case 'P': | |||
265 | f_fullpath = 1; | |||
266 | break; | |||
259 | case 'p': | 267 | case 'p': | |
260 | f_typedir = 1; | 268 | f_typedir = 1; | |
261 | break; | 269 | break; | |
262 | /* The -q option turns off the -B, -b and -w options. */ | 270 | /* The -q option turns off the -B, -b and -w options. */ | |
263 | case 'q': | 271 | case 'q': | |
264 | f_nonprint = 1; | 272 | f_nonprint = 1; | |
265 | f_octal = 0; | 273 | f_octal = 0; | |
266 | f_octal_escape = 0; | 274 | f_octal_escape = 0; | |
267 | break; | 275 | break; | |
268 | case 'r': | 276 | case 'r': | |
269 | f_reversesort = 1; | 277 | f_reversesort = 1; | |
270 | break; | 278 | break; | |
271 | case 'S': | 279 | case 'S': | |
@@ -436,31 +444,33 @@ traverse(int argc, char *argv[], int opt | @@ -436,31 +444,33 @@ traverse(int argc, char *argv[], int opt | |||
436 | warnx("%s: %s", p->fts_name, strerror(p->fts_errno)); | 444 | warnx("%s: %s", p->fts_name, strerror(p->fts_errno)); | |
437 | rval = EXIT_FAILURE; | 445 | rval = EXIT_FAILURE; | |
438 | break; | 446 | break; | |
439 | case FTS_D: | 447 | case FTS_D: | |
440 | if (p->fts_level != FTS_ROOTLEVEL && | 448 | if (p->fts_level != FTS_ROOTLEVEL && | |
441 | p->fts_name[0] == '.' && !f_listdot) | 449 | p->fts_name[0] == '.' && !f_listdot) | |
442 | break; | 450 | break; | |
443 | 451 | |||
444 | /* | 452 | /* | |
445 | * If already output something, put out a newline as | 453 | * If already output something, put out a newline as | |
446 | * a separator. If multiple arguments, precede each | 454 | * a separator. If multiple arguments, precede each | |
447 | * directory with its name. | 455 | * directory with its name. | |
448 | */ | 456 | */ | |
449 | if (output) | 457 | if (!f_leafonly) { | |
450 | (void)printf("\n%s:\n", p->fts_path); | 458 | if (output) | |
451 | else if (argc > 1) { | 459 | (void)printf("\n%s:\n", p->fts_path); | |
452 | (void)printf("%s:\n", p->fts_path); | 460 | else if (argc > 1) { | |
453 | output = 1; | 461 | (void)printf("%s:\n", p->fts_path); | |
462 | output = 1; | |||
463 | } | |||
454 | } | 464 | } | |
455 | 465 | |||
456 | chp = fts_children(ftsp, ch_options); | 466 | chp = fts_children(ftsp, ch_options); | |
457 | display(p, chp); | 467 | display(p, chp); | |
458 | 468 | |||
459 | if (!f_recursive && chp != NULL) | 469 | if (!f_recursive && chp != NULL) | |
460 | (void)fts_set(ftsp, p, FTS_SKIP); | 470 | (void)fts_set(ftsp, p, FTS_SKIP); | |
461 | break; | 471 | break; | |
462 | } | 472 | } | |
463 | error = errno; | 473 | error = errno; | |
464 | (void)fts_close(ftsp); | 474 | (void)fts_close(ftsp); | |
465 | errno = error; | 475 | errno = error; | |
466 | if (errno) | 476 | if (errno) |
--- src/bin/ls/ls.h 2011/03/15 03:52:38 1.18
+++ src/bin/ls/ls.h 2014/02/20 18:56:36 1.19
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ls.h,v 1.18 2011/03/15 03:52:38 erh Exp $ */ | 1 | /* $NetBSD: ls.h,v 1.19 2014/02/20 18:56:36 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1989, 1993 | 4 | * Copyright (c) 1989, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Michael Fischbein. | 8 | * Michael Fischbein. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -43,26 +43,28 @@ extern int f_flags; /* show flags assoc | @@ -43,26 +43,28 @@ extern int f_flags; /* show flags assoc | |||
43 | extern int f_grouponly; /* long listing without owner */ | 43 | extern int f_grouponly; /* long listing without owner */ | |
44 | extern int f_humanize; /* humanize size field */ | 44 | extern int f_humanize; /* humanize size field */ | |
45 | extern int f_commas; /* separate size field with commas */ | 45 | extern int f_commas; /* separate size field with commas */ | |
46 | extern int f_inode; /* print inode */ | 46 | extern int f_inode; /* print inode */ | |
47 | extern int f_longform; /* long listing format */ | 47 | extern int f_longform; /* long listing format */ | |
48 | extern int f_octal; /* print octal escapes for nongraphic characters */ | 48 | extern int f_octal; /* print octal escapes for nongraphic characters */ | |
49 | extern int f_octal_escape; /* like f_octal but use C escapes if possible */ | 49 | extern int f_octal_escape; /* like f_octal but use C escapes if possible */ | |
50 | extern int f_sectime; /* print the real time for all files */ | 50 | extern int f_sectime; /* print the real time for all files */ | |
51 | extern int f_size; /* list size in short listing */ | 51 | extern int f_size; /* list size in short listing */ | |
52 | extern int f_statustime; /* use time of last mode change */ | 52 | extern int f_statustime; /* use time of last mode change */ | |
53 | extern int f_type; /* add type character for non-regular files */ | 53 | extern int f_type; /* add type character for non-regular files */ | |
54 | extern int f_typedir; /* add type character for directories */ | 54 | extern int f_typedir; /* add type character for directories */ | |
55 | extern int f_nonprint; /* show unprintables as ? */ | 55 | extern int f_nonprint; /* show unprintables as ? */ | |
56 | extern int f_fullpath; /* print full pathname, not filename */ | |||
57 | extern int f_leafonly; /* when recursing, print leaf names only */ | |||
56 | 58 | |||
57 | typedef struct { | 59 | typedef struct { | |
58 | FTSENT *list; | 60 | FTSENT *list; | |
59 | u_int64_t btotal; | 61 | u_int64_t btotal; | |
60 | u_int64_t stotal; | 62 | u_int64_t stotal; | |
61 | int entries; | 63 | int entries; | |
62 | unsigned int maxlen; | 64 | unsigned int maxlen; | |
63 | int s_block; | 65 | int s_block; | |
64 | int s_flags; | 66 | int s_flags; | |
65 | int s_group; | 67 | int s_group; | |
66 | int s_inode; | 68 | int s_inode; | |
67 | int s_nlink; | 69 | int s_nlink; | |
68 | int s_size; | 70 | int s_size; |
--- src/bin/ls/print.c 2013/05/02 22:43:55 1.52
+++ src/bin/ls/print.c 2014/02/20 18:56:36 1.53
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: print.c,v 1.52 2013/05/02 22:43:55 zafer Exp $ */ | 1 | /* $NetBSD: print.c,v 1.53 2014/02/20 18:56:36 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1989, 1993, 1994 | 4 | * Copyright (c) 1989, 1993, 1994 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Michael Fischbein. | 8 | * Michael Fischbein. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include <sys/cdefs.h> | 35 | #include <sys/cdefs.h> | |
36 | #ifndef lint | 36 | #ifndef lint | |
37 | #if 0 | 37 | #if 0 | |
38 | static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94"; | 38 | static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94"; | |
39 | #else | 39 | #else | |
40 | __RCSID("$NetBSD: print.c,v 1.52 2013/05/02 22:43:55 zafer Exp $"); | 40 | __RCSID("$NetBSD: print.c,v 1.53 2014/02/20 18:56:36 christos Exp $"); | |
41 | #endif | 41 | #endif | |
42 | #endif /* not lint */ | 42 | #endif /* not lint */ | |
43 | 43 | |||
44 | #include <sys/param.h> | 44 | #include <sys/param.h> | |
45 | #include <sys/stat.h> | 45 | #include <sys/stat.h> | |
46 | 46 | |||
47 | #include <err.h> | 47 | #include <err.h> | |
48 | #include <errno.h> | 48 | #include <errno.h> | |
49 | #include <fts.h> | 49 | #include <fts.h> | |
50 | #include <grp.h> | 50 | #include <grp.h> | |
51 | #include <pwd.h> | 51 | #include <pwd.h> | |
52 | #include <stdio.h> | 52 | #include <stdio.h> | |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> | |
@@ -62,50 +62,84 @@ __RCSID("$NetBSD: print.c,v 1.52 2013/05 | @@ -62,50 +62,84 @@ __RCSID("$NetBSD: print.c,v 1.52 2013/05 | |||
62 | 62 | |||
63 | extern int termwidth; | 63 | extern int termwidth; | |
64 | 64 | |||
65 | static int printaname(FTSENT *, int, int); | 65 | static int printaname(FTSENT *, int, int); | |
66 | static void printlink(FTSENT *); | 66 | static void printlink(FTSENT *); | |
67 | static void printtime(time_t); | 67 | static void printtime(time_t); | |
68 | static void printtotal(DISPLAY *dp); | 68 | static void printtotal(DISPLAY *dp); | |
69 | static int printtype(u_int); | 69 | static int printtype(u_int); | |
70 | 70 | |||
71 | static time_t now; | 71 | static time_t now; | |
72 | 72 | |||
73 | #define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT) | 73 | #define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT) | |
74 | 74 | |||
75 | static int | |||
76 | safe_printpath(const FTSENT *p) { | |||
77 | int chcnt; | |||
78 | ||||
79 | if (f_fullpath) { | |||
80 | chcnt = safe_print(p->fts_path); | |||
81 | chcnt += safe_print("/"); | |||
82 | } else | |||
83 | chcnt = 0; | |||
84 | return chcnt + safe_print(p->fts_name); | |||
85 | } | |||
86 | ||||
87 | static int | |||
88 | printescapedpath(const FTSENT *p) { | |||
89 | int chcnt; | |||
90 | ||||
91 | if (f_fullpath) { | |||
92 | chcnt = printescaped(p->fts_path); | |||
93 | chcnt += printescaped("/"); | |||
94 | } else | |||
95 | chcnt = 0; | |||
96 | ||||
97 | return chcnt + printescaped(p->fts_name); | |||
98 | } | |||
99 | ||||
100 | static int | |||
101 | printpath(const FTSENT *p) { | |||
102 | if (f_fullpath) | |||
103 | return printf("%s/%s", p->fts_path, p->fts_name); | |||
104 | else | |||
105 | return printf("%s", p->fts_path); | |||
106 | } | |||
107 | ||||
75 | void | 108 | void | |
76 | printscol(DISPLAY *dp) | 109 | printscol(DISPLAY *dp) | |
77 | { | 110 | { | |
78 | FTSENT *p; | 111 | FTSENT *p; | |
79 | 112 | |||
80 | for (p = dp->list; p; p = p->fts_link) { | 113 | for (p = dp->list; p; p = p->fts_link) { | |
81 | if (IS_NOPRINT(p)) | 114 | if (IS_NOPRINT(p)) | |
82 | continue; | 115 | continue; | |
83 | (void)printaname(p, dp->s_inode, dp->s_block); | 116 | (void)printaname(p, dp->s_inode, dp->s_block); | |
84 | (void)putchar('\n'); | 117 | (void)putchar('\n'); | |
85 | } | 118 | } | |
86 | } | 119 | } | |
87 | 120 | |||
88 | void | 121 | void | |
89 | printlong(DISPLAY *dp) | 122 | printlong(DISPLAY *dp) | |
90 | { | 123 | { | |
91 | struct stat *sp; | 124 | struct stat *sp; | |
92 | FTSENT *p; | 125 | FTSENT *p; | |
93 | NAMES *np; | 126 | NAMES *np; | |
94 | char buf[20], szbuf[5]; | 127 | char buf[20], szbuf[5]; | |
95 | 128 | |||
96 | now = time(NULL); | 129 | now = time(NULL); | |
97 | 130 | |||
98 | printtotal(dp); /* "total: %u\n" */ | 131 | if (!f_leafonly) | |
132 | printtotal(dp); /* "total: %u\n" */ | |||
99 | 133 | |||
100 | for (p = dp->list; p; p = p->fts_link) { | 134 | for (p = dp->list; p; p = p->fts_link) { | |
101 | if (IS_NOPRINT(p)) | 135 | if (IS_NOPRINT(p)) | |
102 | continue; | 136 | continue; | |
103 | sp = p->fts_statp; | 137 | sp = p->fts_statp; | |
104 | if (f_inode) | 138 | if (f_inode) | |
105 | (void)printf("%*lu ", dp->s_inode, | 139 | (void)printf("%*lu ", dp->s_inode, | |
106 | (unsigned long)sp->st_ino); | 140 | (unsigned long)sp->st_ino); | |
107 | if (f_size) { | 141 | if (f_size) { | |
108 | if (f_humanize) { | 142 | if (f_humanize) { | |
109 | if ((humanize_number(szbuf, sizeof(szbuf), | 143 | if ((humanize_number(szbuf, sizeof(szbuf), | |
110 | sp->st_blocks * S_BLKSIZE, | 144 | sp->st_blocks * S_BLKSIZE, | |
111 | "", HN_AUTOSCALE, | 145 | "", HN_AUTOSCALE, | |
@@ -141,31 +175,31 @@ printlong(DISPLAY *dp) | @@ -141,31 +175,31 @@ printlong(DISPLAY *dp) | |||
141 | (void)printf("%*s ", dp->s_size, szbuf); | 175 | (void)printf("%*s ", dp->s_size, szbuf); | |
142 | } else { | 176 | } else { | |
143 | (void)printf(f_commas ? "%'*llu " : "%*llu ", | 177 | (void)printf(f_commas ? "%'*llu " : "%*llu ", | |
144 | dp->s_size, (unsigned long long) | 178 | dp->s_size, (unsigned long long) | |
145 | sp->st_size); | 179 | sp->st_size); | |
146 | } | 180 | } | |
147 | if (f_accesstime) | 181 | if (f_accesstime) | |
148 | printtime(sp->st_atime); | 182 | printtime(sp->st_atime); | |
149 | else if (f_statustime) | 183 | else if (f_statustime) | |
150 | printtime(sp->st_ctime); | 184 | printtime(sp->st_ctime); | |
151 | else | 185 | else | |
152 | printtime(sp->st_mtime); | 186 | printtime(sp->st_mtime); | |
153 | if (f_octal || f_octal_escape) | 187 | if (f_octal || f_octal_escape) | |
154 | (void)safe_print(p->fts_name); | 188 | (void)safe_printpath(p); | |
155 | else if (f_nonprint) | 189 | else if (f_nonprint) | |
156 | (void)printescaped(p->fts_name); | 190 | (void)printescapedpath(p); | |
157 | else | 191 | else | |
158 | (void)printf("%s", p->fts_name); | 192 | (void)printpath(p); | |
159 | 193 | |||
160 | if (f_type || (f_typedir && S_ISDIR(sp->st_mode))) | 194 | if (f_type || (f_typedir && S_ISDIR(sp->st_mode))) | |
161 | (void)printtype(sp->st_mode); | 195 | (void)printtype(sp->st_mode); | |
162 | if (S_ISLNK(sp->st_mode)) | 196 | if (S_ISLNK(sp->st_mode)) | |
163 | printlink(p); | 197 | printlink(p); | |
164 | (void)putchar('\n'); | 198 | (void)putchar('\n'); | |
165 | } | 199 | } | |
166 | } | 200 | } | |
167 | 201 | |||
168 | void | 202 | void | |
169 | printcol(DISPLAY *dp) | 203 | printcol(DISPLAY *dp) | |
170 | { | 204 | { | |
171 | static FTSENT **array; | 205 | static FTSENT **array; | |
@@ -336,31 +370,31 @@ printaname(FTSENT *p, int inodefield, in | @@ -336,31 +370,31 @@ printaname(FTSENT *p, int inodefield, in | |||
336 | if (f_humanize) { | 370 | if (f_humanize) { | |
337 | if ((humanize_number(szbuf, sizeof(szbuf), sp->st_size, | 371 | if ((humanize_number(szbuf, sizeof(szbuf), sp->st_size, | |
338 | "", HN_AUTOSCALE, | 372 | "", HN_AUTOSCALE, | |
339 | (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1) | 373 | (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1) | |
340 | err(1, "humanize_number"); | 374 | err(1, "humanize_number"); | |
341 | chcnt += printf("%*s ", sizefield, szbuf); | 375 | chcnt += printf("%*s ", sizefield, szbuf); | |
342 | } else { | 376 | } else { | |
343 | chcnt += printf(f_commas ? "%'*llu " : "%*llu ", | 377 | chcnt += printf(f_commas ? "%'*llu " : "%*llu ", | |
344 | sizefield, (unsigned long long) | 378 | sizefield, (unsigned long long) | |
345 | howmany(sp->st_blocks, blocksize)); | 379 | howmany(sp->st_blocks, blocksize)); | |
346 | } | 380 | } | |
347 | } | 381 | } | |
348 | if (f_octal || f_octal_escape) | 382 | if (f_octal || f_octal_escape) | |
349 | chcnt += safe_print(p->fts_name); | 383 | chcnt += safe_printpath(p); | |
350 | else if (f_nonprint) | 384 | else if (f_nonprint) | |
351 | chcnt += printescaped(p->fts_name); | 385 | chcnt += printescapedpath(p); | |
352 | else | 386 | else | |
353 | chcnt += printf("%s", p->fts_name); | 387 | chcnt += printpath(p); | |
354 | if (f_type || (f_typedir && S_ISDIR(sp->st_mode))) | 388 | if (f_type || (f_typedir && S_ISDIR(sp->st_mode))) | |
355 | chcnt += printtype(sp->st_mode); | 389 | chcnt += printtype(sp->st_mode); | |
356 | return (chcnt); | 390 | return (chcnt); | |
357 | } | 391 | } | |
358 | 392 | |||
359 | static void | 393 | static void | |
360 | printtime(time_t ftime) | 394 | printtime(time_t ftime) | |
361 | { | 395 | { | |
362 | int i; | 396 | int i; | |
363 | const char *longstring; | 397 | const char *longstring; | |
364 | 398 | |||
365 | if ((longstring = ctime(&ftime)) == NULL) { | 399 | if ((longstring = ctime(&ftime)) == NULL) { | |
366 | /* 012345678901234567890123 */ | 400 | /* 012345678901234567890123 */ |