From: Romano <unobe@cpan.org>
To: 9front@9front.org
Subject: [9front] [PATCH 4/6] walk: quote name and path using N and P; use quotefmt and free()
Date: Thu, 28 Sep 2023 05:15:34 +0000 [thread overview]
Message-ID: <1868372285A59D67087D51999A641B33@smtp.pobox.com> (raw)
---
diff 47ddd324c0c118ca5d6662e82b094e94a1cfb771 c9c5d6455a6502ffb0f5490d5602396852261f4c
--- a/sys/man/1/walk
+++ b/sys/man/1/walk
@@ -81,8 +81,14 @@
.B n
final path element (name)
.TP
+.B N
+final path element (name), rc (1) quoted when necessary
+.TP
.B p
path
+.TP
+.B P
+path, rc (1) quoted when necessary
.TP
.B q
qid path.version.type (see
--- a/sys/src/cmd/walk.c
+++ b/sys/src/cmd/walk.c
@@ -43,7 +43,7 @@
void
dofile(char *path, Dir *f, int pathonly)
{
- char *p;
+ char *p, *q;
if(
(f == dotdir)
@@ -60,6 +60,7 @@
case 'a': Bprint(bout, "%uld", f->atime); break;
case 'm': Bprint(bout, "%uld", f->mtime); break;
case 'n': Bwrite(bout, f->name, strlen(f->name)); break;
+ case 'N': Bprint(bout, "%q", f->name); break;
case 'p':
if(path != dotpath)
Bwrite(bout, path, strlen(path));
@@ -69,6 +70,14 @@
Bwrite(bout, f->name, strlen(f->name));
}
break;
+ case 'P':
+ if(!pathonly && path != dotpath && ! (f->qid.type & QTDIR)){
+ q = smprint("%s/%s", path, f->name);
+ Bprint(bout, "%q", q);
+ free(q);
+ } else if(path != dotpath)
+ Bprint(bout, "%q", path);
+ break;
case 'q': Bprint(bout, "%ullx.%uld.%.2uhhx", f->qid.path, f->qid.vers, f->qid.type); break;
case 's': Bprint(bout, "%lld", f->length); break;
case 'x': Bprint(bout, "%M", f->mode); break;
@@ -243,7 +252,7 @@
if((stfmt = s_reset(stfmt)) == nil)
sysfatal("s_reset: %r");
s_append(stfmt, EARGF(usage()));
- i = strspn(s_to_c(stfmt), "UGMamnpqsxDT");
+ i = strspn(s_to_c(stfmt), "UGMamnNpPqsxDT");
if(i != s_len(stfmt))
sysfatal("bad stfmt: %s", s_to_c(stfmt));
break;
@@ -252,6 +261,7 @@
}ARGEND;
fmtinstall('M', dirmodefmt);
+ quotefmtinstall();
if((bout = Bfdopen(1, OWRITE)) == nil)
sysfatal("Bfdopen: %r");
@@ -316,7 +326,7 @@
dir->dev == dp->dev)
return 1;
if(c->n == c->max){
- if (c->max == 0)
+ if(c->max == 0)
c->max = 8;
else
c->max += c->max/2;
next reply other threads:[~2023-09-28 6:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 5:15 Romano [this message]
2023-09-28 7:02 ` unobe
2023-09-28 16:13 ` ori
2023-09-28 16:53 ` unobe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1868372285A59D67087D51999A641B33@smtp.pobox.com \
--to=unobe@cpan.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).