9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] awk: add %q format for quoted strings (see quote(2))
@ 2021-08-11 21:24 james palmer
  2021-08-12 21:29 ` Steve Simon
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: james palmer @ 2021-08-11 21:24 UTC (permalink / raw)
  To: 9front mailing list

[-- Attachment #1: Type: text/plain, Size: 98 bytes --]

this one comes in handy for building bulk rename scripts.
patch for git/import attached.

- james

[-- Attachment #2.1: Type: text/plain, Size: 327 bytes --]

from postmaster@1ess:
The following attachment had content that we can't
prove to be harmless.  To avoid possible automatic
execution, we changed the content headers.
The original header was:

	Content-Disposition: attachment;filename="awk.patch"
	Content-Type: text/x-patch; name="awk.patch"
	Content-Transfer-Encoding: BASE64

[-- Attachment #2.2: awk.patch.suspect --]
[-- Type: application/octet-stream, Size: 1509 bytes --]

From: james palmer <james@biobuf.link>
Date: Tue, 03 Aug 2021 14:33:24 +0000
Subject: [PATCH] awk: add %q format for quoted strings (see quote(2))

---
diff 223daf6104b5fd73a6214fc3b2fcbd237ffbe666 0a401c48ef82bbb8bdafc93a6107cc3a35ada4ee
--- a/sys/src/cmd/awk/main.c	Sat Jul 31 19:29:39 2021
+++ b/sys/src/cmd/awk/main.c	Tue Aug  3 15:33:24 2021
@@ -60,6 +60,8 @@
 	Binit(&stdout, 1, OWRITE);
 	Binit(&stderr, 2, OWRITE);
 
+	quotefmtinstall();
+
 	cmdname = argv[0];
 	if (argc == 1) {
 		Bprint(&stderr, "usage: %s [-F fieldsep] [-d] [-mf n] [-mr n] [-safe] [-v var=value] [-f programfile | 'program'] [file ...]\n", cmdname);
--- a/sys/src/cmd/awk/run.c	Sat Jul 31 19:29:39 2021
+++ b/sys/src/cmd/awk/run.c	Tue Aug  3 15:33:24 2021
@@ -836,7 +836,7 @@
 int format(char **pbuf, int *pbufsize, char *s, Node *a)	/* printf-like conversions */
 {
 	char *fmt;
-	char *p, *t, *os;
+	char *p, *t, *os, *tmp;
 	Cell *x;
 	int flag, n;
 	int fmtwd; /* format width */
@@ -915,6 +915,9 @@
 		case 'c':
 			flag = 5;
 			break;
+		case 'q':
+			flag = 6;
+			break;
 		default:
 			WARNING("weird printf conversion %s", fmt);
 			flag = 0;
@@ -964,6 +967,14 @@
 					p++;
 				*p = '\0';
 			}
+			break;
+		case 6:
+			t = getsval(x);
+			tmp = t;
+			while(*tmp++) { if(*tmp == '\'') { n++; } n++; }
+			if(!adjbuf(&buf, &bufsize, 3+n+p-buf, recsize, &p, 0))
+				FATAL("huge string/format (%d chars) in printf %.30s... ran format() out of memory", n, t);
+			sprint(p, fmt, t);
 			break;
 		}
 		if (istemp(x))

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

end of thread, other threads:[~2021-08-24 10:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11 21:24 [9front] [PATCH] awk: add %q format for quoted strings (see quote(2)) james palmer
2021-08-12 21:29 ` Steve Simon
2021-08-18 13:23   ` james palmer
2021-08-24  9:45     ` [9front] " Pavel Renev
2021-08-13  6:43 ` unobe
2021-08-18 13:10   ` james palmer
2021-08-23 16:55 ` ori
2021-08-24  4:31   ` ori

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