* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)print.c 8.2 (Berkeley) %G%";
static int printaname
__P((FTSENT
*, u_long
, u_long
));
static void printlink
__P((FTSENT
*));
static void printtime
__P((time_t));
static int printtype
__P((u_int
));
#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
for (p
= dp
->list
; p
; p
= p
->fts_link
) {
(void)printaname(p
, dp
->s_inode
, dp
->s_block
);
if (dp
->list
->fts_level
!= FTS_ROOTLEVEL
&& (f_longform
|| f_size
))
(void)printf("total %lu\n", howmany(dp
->btotal
, blocksize
));
for (p
= dp
->list
; p
; p
= p
->fts_link
) {
(void)printf("%*lu ", dp
->s_inode
, sp
->st_ino
);
dp
->s_block
, howmany(sp
->st_blocks
, blocksize
));
(void)strmode(sp
->st_mode
, buf
);
(void)printf("%s %*u %-*s %-*s ", buf
, dp
->s_nlink
,
sp
->st_nlink
, dp
->s_user
, np
->user
, dp
->s_group
,
(void)printf("%-*s ", dp
->s_flags
, np
->flags
);
if (S_ISCHR(sp
->st_mode
) || S_ISBLK(sp
->st_mode
))
(void)printf("%3d, %3d ",
major(sp
->st_rdev
), minor(sp
->st_rdev
));
8 - dp
->s_size
, "", dp
->s_size
, sp
->st_size
);
(void)printf("%*qd ", dp
->s_size
, sp
->st_size
);
(void)printf("%s", p
->fts_name
);
(void)printtype(sp
->st_mode
);
if (S_ISLNK(sp
->st_mode
))
static int lastentries
= -1;
int base
, chcnt
, cnt
, col
, colwidth
, num
;
int endcol
, numcols
, numrows
, row
;
* Have to do random access in the linked list -- build a table
if (dp
->entries
> lastentries
) {
lastentries
= dp
->entries
;
realloc(array
, dp
->entries
* sizeof(FTSENT
*))) == NULL
) {
for (p
= dp
->list
, num
= 0; p
; p
= p
->fts_link
)
if (p
->fts_number
!= NO_PRINT
)
colwidth
+= dp
->s_inode
+ 1;
colwidth
+= dp
->s_block
+ 1;
colwidth
= (colwidth
+ TAB
) & ~(TAB
- 1);
if (termwidth
< 2 * colwidth
) {
numcols
= termwidth
/ colwidth
;
if (dp
->list
->fts_level
!= FTS_ROOTLEVEL
&& (f_longform
|| f_size
))
(void)printf("total %lu\n", howmany(dp
->btotal
, blocksize
));
for (row
= 0; row
< numrows
; ++row
) {
for (base
= row
, chcnt
= col
= 0; col
< numcols
; ++col
) {
chcnt
+= printaname(array
[base
], dp
->s_inode
,
if ((base
+= numrows
) >= num
)
while ((cnt
= (chcnt
+ TAB
& ~(TAB
- 1))) <= endcol
) {
* print [inode] [size] name
* return # of characters printed, no trailing characters.
printaname(p
, inodefield
, sizefield
)
u_long sizefield
, inodefield
;
chcnt
+= printf("%*lu ", (int)inodefield
, sp
->st_ino
);
(int)sizefield
, howmany(sp
->st_blocks
, blocksize
));
chcnt
+= printf("%s", p
->fts_name
);
chcnt
+= printtype(sp
->st_mode
);
longstring
= ctime(&ftime
);
(void)putchar(longstring
[i
]);
#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY)
for (i
= 11; i
< 24; i
++)
(void)putchar(longstring
[i
]);
else if (ftime
+ SIXMONTHS
> time(NULL
))
for (i
= 11; i
< 16; ++i
)
(void)putchar(longstring
[i
]);
for (i
= 20; i
< 24; ++i
)
(void)putchar(longstring
[i
]);
if (mode
& (S_IXUSR
| S_IXGRP
| S_IXOTH
)) {
char name
[MAXPATHLEN
+ 1], path
[MAXPATHLEN
+ 1];
if (p
->fts_level
== FTS_ROOTLEVEL
)
(void)snprintf(name
, sizeof(name
), "%s", p
->fts_name
);
(void)snprintf(name
, sizeof(name
),
"%s/%s", p
->fts_parent
->fts_accpath
, p
->fts_name
);
if ((lnklen
= readlink(name
, path
, sizeof(path
) - 1)) == -1) {
(void)fprintf(stderr
, "\nls: %s: %s\n", name
, strerror(errno
));
(void)printf(" -> %s", path
);