fix ls
This commit is contained in:
parent
9c277b7cad
commit
0a259a4dce
|
@ -1,3 +1,5 @@
|
|||
/* Bugs: unicode strlen, -l flag col */
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <time.h>
|
||||
|
@ -165,21 +167,29 @@ void col_print(struct d_node **node, size_t files, struct winsize w) {
|
|||
/* Calc */
|
||||
size_t ncols = w.ws_col / maxlen;
|
||||
size_t nrows = files;
|
||||
if (ncols > 1)
|
||||
if (ncols > 1) {
|
||||
nrows = files / ncols;
|
||||
if (nrows * ncols < files)
|
||||
nrows++;
|
||||
}
|
||||
|
||||
else
|
||||
ncols = 1;
|
||||
|
||||
int col = 0;
|
||||
int nexttab = 0;
|
||||
|
||||
/* Mc print */
|
||||
for (size_t i = 0; i < nrows + 1; i++) {
|
||||
for (size_t i = 0; i < nrows; i++) {
|
||||
for (size_t j = 0; j < ncols; j++) {
|
||||
if (node[i * ncols + j] == NULL)
|
||||
break;
|
||||
|
||||
if (col > 0) {
|
||||
nexttab -= col;
|
||||
printf("%*s", nexttab, "");
|
||||
for (int k = 0; k < nexttab; k++)
|
||||
putchar(' ');
|
||||
|
||||
col += nexttab;
|
||||
}
|
||||
|
||||
|
@ -234,7 +244,7 @@ int main(int argc, char **argv) {
|
|||
break;
|
||||
|
||||
default:
|
||||
printf("ls [path]\n\t[-a Show hidden files] [-l Use a long listing format]\n\t[-F Append indicator to names]\n");
|
||||
printf("ls [path]\n\t[-a Show hidden files]\n\t[-l Use a long listing format]\n\t[-F Append indicator to names]\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue