Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/mtree add -j flag to indent directory blocks (from ...
details: https://anonhg.NetBSD.org/src/rev/d6146872efbf
branches: trunk
changeset: 781875:d6146872efbf
user: christos <christos%NetBSD.org@localhost>
date: Fri Oct 05 01:13:50 2012 +0000
description:
add -j flag to indent directory blocks (from brooks)
diffstat:
usr.sbin/mtree/create.c | 82 ++++++++++++++++++++++++++----------------------
usr.sbin/mtree/extern.h | 4 +-
usr.sbin/mtree/mtree.8 | 16 ++++++++-
usr.sbin/mtree/mtree.c | 9 +++-
4 files changed, 68 insertions(+), 43 deletions(-)
diffs (truncated from 330 to 300 lines):
diff -r a64119514210 -r d6146872efbf usr.sbin/mtree/create.c
--- a/usr.sbin/mtree/create.c Fri Oct 05 01:12:15 2012 +0000
+++ b/usr.sbin/mtree/create.c Fri Oct 05 01:13:50 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: create.c,v 1.62 2012/10/05 01:01:07 christos Exp $ */
+/* $NetBSD: create.c,v 1.63 2012/10/05 01:13:50 christos Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: create.c,v 1.62 2012/10/05 01:01:07 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.63 2012/10/05 01:13:50 christos Exp $");
#endif
#endif /* not lint */
@@ -90,10 +90,10 @@
#endif
static int dcmp(const FTSENT *FTS_CONST *, const FTSENT *FTS_CONST *);
-static void output(int *, const char *, ...)
- __attribute__((__format__(__printf__, 2, 3)));
+static void output(int, int *, const char *, ...)
+ __attribute__((__format__(__printf__, 3, 4)));
static int statd(FTS *, FTSENT *, uid_t *, gid_t *, mode_t *, u_long *);
-static void statf(FTSENT *);
+static void statf(int, FTSENT *);
void
cwalk(void)
@@ -105,6 +105,7 @@
const char *user;
char *argv[2];
char dot[] = ".";
+ int indent = 0;
argv[0] = dot;
argv[1] = NULL;
@@ -127,6 +128,8 @@
if ((t = fts_open(argv, ftsoptions, dcmp)) == NULL)
mtree_err("fts_open: %s", strerror(errno));
while ((p = fts_read(t)) != NULL) {
+ if (jflag)
+ indent = p->fts_level * 4;
if (check_excludes(p->fts_name, p->fts_path)) {
fts_set(t, p, FTS_SKIP);
continue;
@@ -136,11 +139,12 @@
if (!nflag)
printf("\n# %s\n", p->fts_path);
statd(t, p, &uid, &gid, &mode, &flags);
- statf(p);
+ statf(indent, p);
break;
case FTS_DP:
if (!nflag && p->fts_level > 0)
- printf("# %s\n..\n\n", p->fts_path);
+ printf("%*s# %s\n%*s..\n\n", indent, "",
+ p->fts_path, indent, "");
break;
case FTS_DNR:
case FTS_ERR:
@@ -150,7 +154,7 @@
break;
default:
if (!dflag)
- statf(p);
+ statf(indent, p);
break;
}
@@ -161,56 +165,59 @@
}
static void
-statf(FTSENT *p)
+statf(int indent, FTSENT *p)
{
u_int32_t len, val;
- int fd, indent;
+ int fd, offset;
const char *name;
#if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2)
char *digestbuf;
#endif
- indent = printf("%s%s",
+ offset = printf("%*s%s%s", indent, "",
S_ISDIR(p->fts_statp->st_mode) ? "" : " ", vispath(p->fts_name));
- if (indent > INDENTNAMELEN)
- indent = MAXLINELEN;
+ if (offset > (INDENTNAMELEN + indent))
+ offset = MAXLINELEN;
else
- indent += printf("%*s", INDENTNAMELEN - indent, "");
+ offset += printf("%*s", (INDENTNAMELEN + indent) - offset, "");
if (!S_ISREG(p->fts_statp->st_mode))
- output(&indent, "type=%s", inotype(p->fts_statp->st_mode));
+ output(indent, &offset, "type=%s",
+ inotype(p->fts_statp->st_mode));
if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) {
if (keys & F_UNAME &&
(name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL)
- output(&indent, "uname=%s", name);
+ output(indent, &offset, "uname=%s", name);
else /* if (keys & F_UID) */
- output(&indent, "uid=%u", p->fts_statp->st_uid);
+ output(indent, &offset, "uid=%u", p->fts_statp->st_uid);
}
if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) {
if (keys & F_GNAME &&
(name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL)
- output(&indent, "gname=%s", name);
+ output(indent, &offset, "gname=%s", name);
else /* if (keys & F_GID) */
- output(&indent, "gid=%u", p->fts_statp->st_gid);
+ output(indent, &offset, "gid=%u", p->fts_statp->st_gid);
}
if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode)
- output(&indent, "mode=%#o", p->fts_statp->st_mode & MBITS);
+ output(indent, &offset, "mode=%#o",
+ p->fts_statp->st_mode & MBITS);
if (keys & F_DEV &&
(S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode)))
- output(&indent, "device=%#llx",
+ output(indent, &offset, "device=%#llx",
(long long)p->fts_statp->st_rdev);
if (keys & F_NLINK && p->fts_statp->st_nlink != 1)
- output(&indent, "nlink=%u", p->fts_statp->st_nlink);
+ output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink);
if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode))
- output(&indent, "size=%lld", (long long)p->fts_statp->st_size);
+ output(indent, &offset, "size=%lld",
+ (long long)p->fts_statp->st_size);
if (keys & F_TIME)
#if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H)
- output(&indent, "time=%ld.%ld",
+ output(indent, &offset, "time=%ld.%ld",
(long)p->fts_statp->st_mtimespec.tv_sec,
p->fts_statp->st_mtimespec.tv_nsec);
#else
- output(&indent, "time=%ld.%ld",
+ output(indent, &offset, "time=%ld.%ld",
(long)p->fts_statp->st_mtime, (long)0);
#endif
if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
@@ -218,14 +225,14 @@
crc(fd, &val, &len))
mtree_err("%s: %s", p->fts_accpath, strerror(errno));
close(fd);
- output(&indent, "cksum=%lu", (long)val);
+ output(indent, &offset, "cksum=%lu", (long)val);
}
#ifndef NO_MD5
if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) {
if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: MD5File failed: %s", p->fts_accpath,
strerror(errno));
- output(&indent, "%s=%s", MD5KEY, digestbuf);
+ output(indent, &offset, "%s=%s", MD5KEY, digestbuf);
free(digestbuf);
}
#endif /* ! NO_MD5 */
@@ -234,7 +241,7 @@
if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: RMD160File failed: %s", p->fts_accpath,
strerror(errno));
- output(&indent, "%s=%s", RMD160KEY, digestbuf);
+ output(indent, &offset, "%s=%s", RMD160KEY, digestbuf);
free(digestbuf);
}
#endif /* ! NO_RMD160 */
@@ -243,7 +250,7 @@
if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: SHA1File failed: %s", p->fts_accpath,
strerror(errno));
- output(&indent, "%s=%s", SHA1KEY, digestbuf);
+ output(indent, &offset, "%s=%s", SHA1KEY, digestbuf);
free(digestbuf);
}
#endif /* ! NO_SHA1 */
@@ -252,7 +259,7 @@
if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: SHA256_File failed: %s", p->fts_accpath,
strerror(errno));
- output(&indent, "%s=%s", SHA256KEY, digestbuf);
+ output(indent, &offset, "%s=%s", SHA256KEY, digestbuf);
free(digestbuf);
}
#ifdef SHA384_BLOCK_LENGTH
@@ -260,7 +267,7 @@
if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: SHA384_File failed: %s", p->fts_accpath,
strerror(errno));
- output(&indent, "%s=%s", SHA384KEY, digestbuf);
+ output(indent, &offset, "%s=%s", SHA384KEY, digestbuf);
free(digestbuf);
}
#endif
@@ -268,17 +275,18 @@
if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: SHA512_File failed: %s", p->fts_accpath,
strerror(errno));
- output(&indent, "%s=%s", SHA512KEY, digestbuf);
+ output(indent, &offset, "%s=%s", SHA512KEY, digestbuf);
free(digestbuf);
}
#endif /* ! NO_SHA2 */
if (keys & F_SLINK &&
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
- output(&indent, "link=%s", vispath(rlink(p->fts_accpath)));
+ output(indent, &offset, "link=%s",
+ vispath(rlink(p->fts_accpath)));
#if HAVE_STRUCT_STAT_ST_FLAGS
if (keys & F_FLAGS && p->fts_statp->st_flags != flags) {
char *str = flags_to_string(p->fts_statp->st_flags, "none");
- output(&indent, "flags=%s", str);
+ output(indent, &offset, "flags=%s", str);
free(str);
}
#endif
@@ -427,7 +435,7 @@
}
void
-output(int *offset, const char *fmt, ...)
+output(int indent, int *offset, const char *fmt, ...)
{
va_list ap;
char buf[1024];
@@ -437,8 +445,8 @@
va_end(ap);
if (*offset + strlen(buf) > MAXLINELEN - 3) {
- printf(" \\\n%*s", INDENTNAMELEN, "");
- *offset = INDENTNAMELEN;
+ printf(" \\\n%*s", INDENTNAMELEN + indent, "");
+ *offset = INDENTNAMELEN + indent;
}
*offset += printf(" %s", buf) + 1;
}
diff -r a64119514210 -r d6146872efbf usr.sbin/mtree/extern.h
--- a/usr.sbin/mtree/extern.h Fri Oct 05 01:12:15 2012 +0000
+++ b/usr.sbin/mtree/extern.h Fri Oct 05 01:13:50 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.34 2012/10/05 01:05:14 christos Exp $ */
+/* $NetBSD: extern.h,v 1.35 2012/10/05 01:13:50 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -69,7 +69,7 @@
const char *rlink(const char *);
int verify(void);
-extern int dflag, eflag, iflag, lflag, mflag,
+extern int dflag, eflag, iflag, jflag, lflag, mflag,
nflag, qflag, rflag, sflag, tflag, uflag;
extern int mtree_Mflag, mtree_Sflag, mtree_Wflag;
extern size_t mtree_lineno;
diff -r a64119514210 -r d6146872efbf usr.sbin/mtree/mtree.8
--- a/usr.sbin/mtree/mtree.8 Fri Oct 05 01:12:15 2012 +0000
+++ b/usr.sbin/mtree/mtree.8 Fri Oct 05 01:13:50 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: mtree.8,v 1.57 2012/10/05 01:05:14 christos Exp $
+.\" $NetBSD: mtree.8,v 1.58 2012/10/05 01:13:50 christos Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -155,6 +155,20 @@
If no inclusion list is provided, the default is to display all files.
.It Fl i
If specified, set the schg and/or sappnd flags.
+.It Fl j
+Indent the output 4 spaces each time a directory level is descended when
+creating a specification with the
+.Fl c
+option.
+This does not affect either the /set statements or the comment before each
+directory.
+It does however affect the comment before the close of each directory.
+This is the equivalent of the
+.Fl i
+option in the
+.Fx
+version of
+.Nm .
.It Fl K Ar keywords
Add the specified (whitespace or comma separated) keywords to the current
set of keywords.
diff -r a64119514210 -r d6146872efbf usr.sbin/mtree/mtree.c
--- a/usr.sbin/mtree/mtree.c Fri Oct 05 01:12:15 2012 +0000
+++ b/usr.sbin/mtree/mtree.c Fri Oct 05 01:13:50 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mtree.c,v 1.39 2012/10/05 01:05:14 christos Exp $ */
+/* $NetBSD: mtree.c,v 1.40 2012/10/05 01:13:50 christos Exp $ */
Home |
Main Index |
Thread Index |
Old Index