ls fix
This commit is contained in:
parent
6a631cf9c0
commit
9c277b7cad
|
@ -79,7 +79,6 @@ struct d_node **list(const char *path, size_t *nfiles) {
|
|||
return NULL;
|
||||
|
||||
*nfiles = files;
|
||||
|
||||
dir = malloc((files + 1) * sizeof(struct d_node *));
|
||||
if (dir == NULL) {
|
||||
fprintf(stderr, "ls: malloc failed\n");
|
||||
|
@ -163,6 +162,7 @@ void col_print(struct d_node **node, size_t files, struct winsize w) {
|
|||
if (strlen(node[i]->name) > maxlen)
|
||||
maxlen = strlen(node[i]->name) + 3;
|
||||
|
||||
/* Calc */
|
||||
size_t ncols = w.ws_col / maxlen;
|
||||
size_t nrows = files;
|
||||
if (ncols > 1)
|
||||
|
@ -172,20 +172,19 @@ void col_print(struct d_node **node, size_t files, struct winsize w) {
|
|||
int nexttab = 0;
|
||||
|
||||
/* Mc print */
|
||||
for (size_t i = 0; i < nrows; i++) {
|
||||
for (size_t i = 0; i < nrows + 1; i++) {
|
||||
for (size_t j = 0; j < ncols; j++) {
|
||||
if (i < files) {
|
||||
if (col > 0) {
|
||||
nexttab -= col;
|
||||
for (int k = 0; k < nexttab; k++)
|
||||
putchar(' ');
|
||||
if (node[i * ncols + j] == NULL)
|
||||
break;
|
||||
|
||||
col += nexttab;
|
||||
}
|
||||
|
||||
nexttab = col + (int)maxlen;
|
||||
col += print(node[i * ncols + j]);
|
||||
if (col > 0) {
|
||||
nexttab -= col;
|
||||
printf("%*s", nexttab, "");
|
||||
col += nexttab;
|
||||
}
|
||||
|
||||
nexttab = col + (int)maxlen;
|
||||
col += print(node[i * ncols + j]);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
|
|
Loading…
Reference in New Issue