9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH 4/6] walk: quote name and path using N and P; use quotefmt and free()
@ 2023-09-28  5:15 Romano
  2023-09-28  7:02 ` unobe
  0 siblings, 1 reply; 4+ messages in thread
From: Romano @ 2023-09-28  5:15 UTC (permalink / raw)
  To: 9front

---
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;



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-28 16:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-28  5:15 [9front] [PATCH 4/6] walk: quote name and path using N and P; use quotefmt and free() Romano
2023-09-28  7:02 ` unobe
2023-09-28 16:13   ` ori
2023-09-28 16:53     ` unobe

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).