From: "james palmer" <james@biobuf.link>
To: "9front mailing list" <9front@9front.org>
Subject: [9front] [PATCH] awk: add %q format for quoted strings (see quote(2))
Date: Wed, 11 Aug 2021 21:24:02 +0000 [thread overview]
Message-ID: <8b7fd75a-c7f2-476a-8872-aa42e6d07eb0@www.fastmail.com> (raw)
[-- 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))
next reply other threads:[~2021-08-12 1:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-11 21:24 james palmer [this message]
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
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=8b7fd75a-c7f2-476a-8872-aa42e6d07eb0@www.fastmail.com \
--to=james@biobuf.link \
--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).