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

* Re: [9front] [PATCH 4/6] walk: quote name and path using N and P; use quotefmt and free()
  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
  0 siblings, 1 reply; 4+ messages in thread
From: unobe @ 2023-09-28  7:02 UTC (permalink / raw)
  To: 9front

I had sent an earlier version of this around August 10.  Moody helped
me on gridchat with some finer points, and figured I'd send it out
again along with the other patches I've been accumulating.

Quoth Romano <unobe@cpan.org>:
> ---
> 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

* Re: [9front] [PATCH 4/6] walk: quote name and path using N and P; use quotefmt and free()
  2023-09-28  7:02 ` unobe
@ 2023-09-28 16:13   ` ori
  2023-09-28 16:53     ` unobe
  0 siblings, 1 reply; 4+ messages in thread
From: ori @ 2023-09-28 16:13 UTC (permalink / raw)
  To: 9front

Quoth unobe@cpan.org:
> I had sent an earlier version of this around August 10.  Moody helped
> me on gridchat with some finer points, and figured I'd send it out
> again along with the other patches I've been accumulating.

I think the last time this was brought up, I wasn't convinced
of the need for a change here; the motivating example didn't
actualy work. `{} doesn't evaluate quotes.

How do you plan to use this?


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

* Re: [9front] [PATCH 4/6] walk: quote name and path using N and P; use quotefmt and free()
  2023-09-28 16:13   ` ori
@ 2023-09-28 16:53     ` unobe
  0 siblings, 0 replies; 4+ messages in thread
From: unobe @ 2023-09-28 16:53 UTC (permalink / raw)
  To: 9front

Quoth ori@eigenstate.org:
> Quoth unobe@cpan.org:
> > I had sent an earlier version of this around August 10.  Moody helped
> > me on gridchat with some finer points, and figured I'd send it out
> > again along with the other patches I've been accumulating.
> 
> I think the last time this was brought up, I wasn't convinced
> of the need for a change here; the motivating example didn't
> actualy work. `{} doesn't evaluate quotes.
> 
> How do you plan to use this?
> 

For one, it has made it easier to plumb/send files.  It's not perfect
when a quote is in the filename because rio/acme doesn't span two
singlequotes when selecting, but it does make it faster for files with
other quoted characters, like spaces.  Most often through no fault of
my own, I have to deal with alien file names that have spaces.  So
when creating a script still using `\n like below, having the
output quoted makes it easy to select the file to plumb/send:
for (f in `'
'{walk-n 1 -emNs -f /usr/glenda}) echo $f
1660336534 acme.dump 0
1695882474 diff.patch 654
1695918225 'test this out' 0

Perhaps that could be why ls(1) has the default as quoting the file
name when needed, and yet does provide -Q for cases when that's not
desired.  This would give walk(1) a similar knob to turn.


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