Date: Wed, 03 May 2023 00:24:41 +0200 From: Steffen Nurpmeso <steffen@sdaoden.eu> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20230502222441.fUEOs%steffen>