annotate toys/ls.c @ 459:1dbe91079950

Second drop of ls from Andre, adds -l.
author Rob Landley <rob@landley.net>
date Mon, 13 Feb 2012 21:27:50 -0600
parents 9786a697d5aa
children d10b58563cff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * ls.c - list files
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2012 Andre Renaud <andre@bluewatersys.com>
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
7 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
9 USE_LS(NEWTOY(ls, "lF1a", TOYFLAG_BIN))
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config LS
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "ls"
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 default y
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
15 usage: ls [-l] [-F] [-a] [-1] [directory...]
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 list files
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
17
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 -F append a character as a file type indicator
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 -a list all files
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 -1 list one file per line
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
21 -l show full details for each file
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 */
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
23
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 #include "toys.h"
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
25
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 #define FLAG_a 1
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 #define FLAG_1 2
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 #define FLAG_F 4
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
29 #define FLAG_l 8
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
30
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 static int dir_filter(const struct dirent *d)
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 {
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 /* Skip over the . & .. entries unless -a is given */
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 if (!(toys.optflags & FLAG_a))
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 if (d->d_name[0] == '.')
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 return 0;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 return 1;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 }
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
39
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 static void do_ls(int fd, char *name)
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 {
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 struct dirent **entries;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 int nentries;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
44 int i;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 int maxwidth = -1;
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
46 int ncolumns = 1;
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
47
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
48 if (!name || strcmp(name, "-") == 0)
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 name = ".";
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
50
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
51 /* Get all the files in this directory */
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 nentries = scandir(name, &entries, dir_filter, alphasort);
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 if (nentries < 0)
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 perror_exit("ls: cannot access %s'", name);
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
55
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
56
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 /* Determine the widest entry so we can flow them properly */
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 if (!(toys.optflags & FLAG_1)) {
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 int columns;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
60 char *columns_str;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
61
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 for (i = 0; i < nentries; i++) {
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 struct dirent *ent = entries[i];
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
64 int width;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
65
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
66 width = strlen(ent->d_name);
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 if (width > maxwidth)
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
68 maxwidth = width;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 }
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
70 /* We always want at least a single space for each entry */
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
71 maxwidth++;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
72 if (toys.optflags & FLAG_F)
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
73 maxwidth++;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
74
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 columns_str = getenv("COLUMNS");
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
76 columns = columns_str ? atoi(columns_str) : 80;
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
77 ncolumns = maxwidth ? columns / maxwidth : 1;
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
78 }
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
79
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
80 for (i = 0; i < nentries; i++) {
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
81 struct dirent *ent = entries[i];
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
82 int len = strlen(ent->d_name);
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
83 struct stat st;
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
84 int stat_valid = 0;
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
85
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
86 /* Provide the ls -l long output */
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
87 if (toys.optflags & FLAG_l) {
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
88 char type;
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
89 char timestamp[64];
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
90 struct tm mtime;
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
91
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
92 if (lstat(ent->d_name, &st))
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
93 perror_exit("Can't stat %s", ent->d_name);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
94 stat_valid = 1;
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
95 if (S_ISDIR(st.st_mode))
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
96 type = 'd';
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
97 else if (S_ISCHR(st.st_mode))
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
98 type = 'c';
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
99 else if (S_ISBLK(st.st_mode))
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
100 type = 'b';
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
101 else if (S_ISLNK(st.st_mode))
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
102 type = 'l';
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
103 else
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
104 type = '-';
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
105
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
106 xprintf("%c%c%c%c%c%c%c%c%c%c ", type,
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
107 (st.st_mode & S_IRUSR) ? 'r' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
108 (st.st_mode & S_IWUSR) ? 'w' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
109 (st.st_mode & S_IXUSR) ? 'x' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
110 (st.st_mode & S_IRGRP) ? 'r' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
111 (st.st_mode & S_IWGRP) ? 'w' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
112 (st.st_mode & S_IXGRP) ? 'x' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
113 (st.st_mode & S_IROTH) ? 'r' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
114 (st.st_mode & S_IWOTH) ? 'w' : '-',
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
115 (st.st_mode & S_IXOTH) ? 'x' : '-');
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
116
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
117 xprintf("%2d ", st.st_nlink);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
118 /* FIXME: We're never looking up uid/gid numbers */
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
119 xprintf("%4d ", st.st_uid);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
120 xprintf("%4d ", st.st_gid);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
121 if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
122 xprintf("%3d, %3d ", major(st.st_rdev), minor(st.st_rdev));
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
123 else
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
124 xprintf("%8ld ", st.st_size);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
125
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
126 localtime_r(&st.st_mtime, &mtime);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
127
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
128 strftime(timestamp, sizeof(timestamp), "%b %e %H:%M", &mtime);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
129 xprintf("%s ", timestamp);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
130 }
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
131
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
132 xprintf("%s", ent->d_name);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
133
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
134 /* Append the file-type indicator character */
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
135 if (toys.optflags & FLAG_F) {
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
136 if (!stat_valid) {
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
137 if (lstat(ent->d_name, &st))
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
138 perror_exit("Can't stat %s", ent->d_name);
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
139 stat_valid = 1;
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
140 }
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
141 if (S_ISDIR(st.st_mode)) {
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
142 xprintf("/");
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
143 len++;
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
144 } else if (S_ISREG(st.st_mode) &&
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
145 (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
146 xprintf("*");
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
147 len++;
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
148 } else if (S_ISLNK(st.st_mode)) {
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
149 xprintf("@");
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
150 len++;
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
151 }
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
152 }
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
153 if (toys.optflags & FLAG_1) {
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
154 xprintf("\n");
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
155 } else {
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
156 if (i % ncolumns == ncolumns - 1)
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
157 xprintf("\n");
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
158 else
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
159 xprintf("%*s", maxwidth - len, "");
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
160 }
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
161 }
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
162 /* Make sure we put at a trailing new line in */
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
163 if (!(toys.optflags & FLAG_1) && (i % ncolumns))
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
164 xprintf("\n");
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
165 }
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
166
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
167 void ls_main(void)
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
168 {
459
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
169 /* Long output must be one-file per line */
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
170 if (toys.optflags & FLAG_l)
1dbe91079950 Second drop of ls from Andre, adds -l.
Rob Landley <rob@landley.net>
parents: 458
diff changeset
171 toys.optflags |= FLAG_1;
458
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
172 loopfiles(toys.optargs, do_ls);
9786a697d5aa Add ls from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
173 }