From: Karel Zak Date: Tue, 27 Jan 2009 13:48:32 +0000 (+0100) Subject: namei: add --vertical option X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3ecdb3ea40f32eb4ef1517d01f93e8912f27cce;p=util-linux namei: add --vertical option Signed-off-by: Karel Zak --- diff --git a/misc-utils/namei.1 b/misc-utils/namei.1 index e35f870b..838c0ae3 100644 --- a/misc-utils/namei.1 +++ b/misc-utils/namei.1 @@ -46,6 +46,8 @@ Show the mode bits of each file type in the style of ls(1), for example 'rwxr-xr-x'. .IP "\fB\-n, \-\-nosymlinks\fP" Don't follow symlinks. +.IP "\fB\-v, \-\-vertical\fP" +Vertical align of modes and owners. .SH AUTHOR The original .B namei diff --git a/misc-utils/namei.c b/misc-utils/namei.c index e2d4f7e6..b8930cdf 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -51,6 +51,7 @@ #define NAMEI_MODES (1 << 2) #define NAMEI_MNTS (1 << 3) #define NAMEI_OWNERS (1 << 4) +#define NAMEI_VERTICAL (1 << 5) struct namei { @@ -369,13 +370,16 @@ print_namei(struct namei *nm, char *path) prev->st.st_dev != nm->st.st_dev) md[0] = 'D'; - for (i = 0; i < nm->level; i++) - fputs(" ", stdout); + if (!(flags & NAMEI_VERTICAL)) { + for (i = 0; i < nm->level; i++) + fputs(" ", stdout); + fputc(' ', stdout); + } if (flags & NAMEI_MODES) - printf(" %s", md); + printf("%s", md); else - printf(" %c", md[0]); + printf("%c", md[0]); if (flags & NAMEI_OWNERS) { printf(" %-*s", uwidth, @@ -383,6 +387,11 @@ print_namei(struct namei *nm, char *path) printf(" %-*s", gwidth, get_id(gcache, nm->st.st_gid)->name); } + + if (flags & NAMEI_VERTICAL) + for (i = 0; i < nm->level; i++) + fputs(" ", stdout); + if (S_ISLNK(nm->st.st_mode)) printf(" %s -> %s\n", nm->name, nm->abslink + nm->relstart); @@ -407,8 +416,9 @@ usage(int rc) " -x, --mountpoints show mount point directories with a 'D'\n" " -m, --modes show the mode bits of each file\n" " -o, --owners show owner and group name of each file\n" - " -l, --long use a long listing format (-m -o)\n" - " -n, --nosymlinks don't follow symlinks\n")); + " -l, --long use a long listing format (-m -o -v) \n" + " -n, --nosymlinks don't follow symlinks\n" + " -v, --vertical vertical align of modes and owners\n")); printf(_("\nFor more information see namei(1).\n")); exit(rc); @@ -422,6 +432,7 @@ struct option longopts[] = { "owners", 0, 0, 'o' }, { "long", 0, 0, 'l' }, { "nolinks", 0, 0, 'n' }, + { "vertical", 0, 0, 'v' }, { NULL, 0, 0, 0 }, }; @@ -438,14 +449,14 @@ main(int argc, char **argv) if (argc < 2) usage(EXIT_FAILURE); - while ((c = getopt_long(argc, argv, "+h?lmnox", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "+h?lmnovx", longopts, NULL)) != -1) { switch(c) { case 'h': case '?': usage(EXIT_SUCCESS); break; case 'l': - flags |= (NAMEI_OWNERS | NAMEI_MODES); + flags |= (NAMEI_OWNERS | NAMEI_MODES | NAMEI_VERTICAL); break; case 'm': flags |= NAMEI_MODES; @@ -459,6 +470,8 @@ main(int argc, char **argv) case 'x': flags |= NAMEI_MNTS; break; + case 'v': + flags |= NAMEI_VERTICAL; } }