From nobody Tue May 02 22:24:41 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q9vlK45xBz48FmS for ; Tue, 2 May 2023 22:24:45 +0000 (UTC) (envelope-from steffen@sdaoden.eu) Received: from sdaoden.eu (sdaoden.eu [217.144.132.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q9vlJ46Vzz3KG8 for ; Tue, 2 May 2023 22:24:44 +0000 (UTC) (envelope-from steffen@sdaoden.eu) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of steffen@sdaoden.eu designates 217.144.132.164 as permitted sender) smtp.mailfrom=steffen@sdaoden.eu; dmarc=none Date: Wed, 03 May 2023 00:24:41 +0200 Author: Steffen Nurpmeso From: Steffen Nurpmeso To: tech@openbsd.org, tech-userlevel@netbsd.org, freebsd-hackers@freebsd.org Subject: Re: usr.bin/mail: cmd3.c:bangexp(): "borked"?, and BSD fails POSIX compat Message-ID: <20230502222441.fUEOs%steffen@sdaoden.eu> In-Reply-To: <20230502214014._zIz6%steffen@sdaoden.eu> References: <20230502214014._zIz6%steffen@sdaoden.eu> Mail-Followup-To: tech@openbsd.org, tech-userlevel@netbsd.org, freebsd-hackers@freebsd.org User-Agent: s-nail v14.9.24-461-g2a5db04708 OpenPGP: id=EE19E1C1F2F7054F8D3954D8308964B51883A0DD; url=https://ftp.sdaoden.eu/steffen.asc; preference=signencrypt BlahBlahBlah: Any stupid boy can crush a beetle. But all the professors in the world can make no bugs. List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [0.31 / 15.00]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_SPAM_MEDIUM(0.71)[0.714]; R_SPF_ALLOW(-0.20)[+a]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_SHORT(-0.10)[-0.099]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DMARC_NA(0.00)[sdaoden.eu]; FROM_HAS_DN(0.00)[]; ASN(0.00)[asn:15987, ipnet:217.144.128.0/20, country:DE]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; SUBJECT_HAS_QUESTION(0.00)[] X-Rspamd-Queue-Id: 4Q9vlJ46Vzz3KG8 X-Spamd-Bar: / X-ThisMailContainsUnwantedMimeParts: N Steffen Nurpmeso wrote in <20230502214014._zIz6%steffen@sdaoden.eu>: |Hallo, and sorry for the cross-post, but so all in one (maybe) go. | |This is about a niche "feature" of mail, the shell command "bang" |(! / ~! in compose mode): ... |POSIX now says / will say | | If the bang variable is set, each unescaped occurrence of '!' in | command shall be replaced with the command executed by the | previous ! command or =CB=9C! command escape. | |thus | | - All commands entered for ! and ~! shall be stored. | | - If "bang" is set, an unquoted ! shall be replaced by that | storage. ... |It will fail to properly "bang" a second time[.] Eh, forget this please. Of course not, one simply inserts the old string without expansion. Since vim(1) offers the same "bang"ing, and merges \! to ! (source comment speaks of vi-compat) i keep it. (It actually requires '\!' or \\! ro avoid its expansion in ":echo BLA".) Ciao. static struct str last_bang; struct n_string xbang, *bang; char c; char const *cp_orig; boole bangit, changed; NYD_IN; bangit =3D ok_blook(bang); changed =3D FAL0; cp_orig =3D cp; for(bang =3D n_string_creat(&xbang); (c =3D *cp++) !=3D '\0';){ if(bangit && c =3D=3D '!'){ changed =3D TRU1; if(last_bang.l > 0) bang =3D n_string_push_buf(bang, last_bang.= s, last_bang.l); }else{ if(c =3D=3D '\\' && *cp =3D=3D '!'){ changed =3D TRU1; ++cp; c =3D '!'; } bang =3D n_string_push_c(bang, c); } } if(last_bang.s !=3D NIL) su_FREE(last_bang.s); last_bang.s =3D n_string_cp(bang); last_bang.l =3D bang->s_len; bang =3D n_string_drop_ownership(bang); n_string_gut(bang); if(bangit){ cp =3D last_bang.s; if(changed && (n_psonce & n_PSO_INTERACTIVE)) fprintf(n_stdout, "!%s\n", cp); }else cp =3D cp_orig; NYD_OU; return cp; --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt) |~~ |..and in spring, hear David Leonard sing.. | |The black bear, The black bear, |blithely holds his own holds himself at leisure |beating it, up and down tossing over his ups and downs with pleasure |~~ |Farewell, dear collar bear