* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)print.c 5.30 (Berkeley) %G%";
static char *flags_from_fid
__P((long));
static int printaname
__P((FTSENT
*));
static void printlink
__P((FTSENT
*));
static void printtime
__P((time_t));
static int printtype
__P((u_int
));
#define IS_NOPRINT(e) ((e)->fts_number == NO_PRINT)
printscol(dlist
, entries
, btotal
, maxlen
)
for (p
= dlist
; p
; p
= p
->fts_link
)
printlong(dlist
, entries
, btotal
, maxlen
)
register struct stat
*sp
;
char modep
[15], *user_from_uid(), *group_from_gid();
if (dlist
->fts_level
!= FTS_ROOTLEVEL
&& (f_longform
|| f_size
))
(void)printf("total %lu\n",
f_kblocks
? howmany(btotal
, 2) : btotal
);
for (p
= dlist
; p
; p
= p
->fts_link
) {
(void)printf("%6lu ", sp
->st_ino
);
(void)printf("%4ld ", f_kblocks
?
howmany(sp
->st_blocks
, 2) : sp
->st_blocks
);
(void)strmode(sp
->st_mode
, modep
);
(void)printf("%s %3u %-*s ", modep
, sp
->st_nlink
,
UT_NAMESIZE
, user_from_uid(sp
->st_uid
, 0));
UT_NAMESIZE
, group_from_gid(sp
->st_gid
, 0));
FLAGSWIDTH
, flags_from_fid(sp
->st_flags
));
if (S_ISCHR(sp
->st_mode
) ||
(void)printf("%3d, %3d ",
major(sp
->st_rdev
), minor(sp
->st_rdev
));
(void)printf("%8ld ", sp
->st_size
);
(void)printf("%s", p
->fts_name
);
(void)printtype(sp
->st_mode
);
if (S_ISLNK(sp
->st_mode
))
printcol(dlist
, entries
, btotal
, maxlen
)
static int lastentries
= -1;
register 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 (entries
> lastentries
) {
realloc(array
, entries
* sizeof(FTSENT
*))) == NULL
) {
err(0, "%s", strerror(errno
));
printscol(dlist
, entries
, btotal
, maxlen
);
for (p
= dlist
, num
= 0; p
; p
= p
->fts_link
)
if (p
->fts_number
!= NO_PRINT
)
colwidth
= (colwidth
+ TAB
) & ~(TAB
- 1);
if (termwidth
< 2 * colwidth
) {
printscol(dlist
, 0, 0, 0);
numcols
= termwidth
/ colwidth
;
if (dlist
->fts_level
!= FTS_ROOTLEVEL
&& (f_longform
|| f_size
))
(void)printf("total %lu\n",
f_kblocks
? howmany(btotal
, 2) : btotal
);
for (row
= 0; row
< numrows
; ++row
) {
for (base
= row
, chcnt
= col
= 0; col
< numcols
; ++col
) {
chcnt
+= printaname(array
[base
]);
if ((base
+= numrows
) >= num
)
while ((cnt
= (chcnt
+ TAB
& ~(TAB
- 1))) <= endcol
) {
* print [inode] [size] name
* return # of characters printed, no trailing characters.
chcnt
+= printf("%5lu ", sp
->st_ino
);
chcnt
+= printf("%4ld ", f_kblocks
?
howmany(sp
->st_blocks
, 2) : sp
->st_blocks
);
chcnt
+= printf("%s", p
->fts_name
);
chcnt
+= printtype(sp
->st_mode
);
longstring
= ctime((time_t *)&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((time_t *)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
, MAXPATHLEN
, "%s", p
->fts_name
);
MAXPATHLEN
, "%s/%s", p
->fts_parent
->fts_name
, p
->fts_name
);
if ((lnklen
= readlink(name
, path
, MAXPATHLEN
)) == -1) {
(void)fprintf(stderr
, "\nls: %s: %s\n", name
, strerror(errno
));
(void)printf(" -> %s", path
);
static char buf
[FLAGSWIDTH
+ 1];
if (size
&& (flags
& NODUMP
)) {
strncat(buf
, "nodump", size
);
strncat(buf
, "dump", size
);
if (size
&& (flags
& IMMUTABLE
)) {
strncat(buf
, ",nochg", size
);
if (size
&& (flags
& ARCHIVED
)) {
strncat(buf
, ",arch", size
);