From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2282 invoked from network); 25 Jan 2009 08:41:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 25 Jan 2009 08:41:52 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 60010 invoked from network); 25 Jan 2009 08:41:48 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Jan 2009 08:41:48 -0000 Received: (qmail 26587 invoked by alias); 25 Jan 2009 08:41:43 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26425 Received: (qmail 26575 invoked from network); 25 Jan 2009 08:41:43 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 25 Jan 2009 08:41:43 -0000 Received: from mail-ew0-f16.google.com (mail-ew0-f16.google.com [209.85.219.16]) by bifrost.dotsrc.org (Postfix) with ESMTP id BEA3880271F0 for ; Sun, 25 Jan 2009 09:41:38 +0100 (CET) Received: by ewy9 with SMTP id 9so380678ewy.21 for ; Sun, 25 Jan 2009 00:41:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :user-agent:references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id; bh=g2VBL3T2ehNM2f6rYG+gWyioWFhIg2GzEpqwznEQDG4=; b=FV/ICYWsDYUnE8KXxVQD3Ef9tmUYr5UXEsNvJZzxjZCQ/CcR9vkl3g42u8/A+/eEAZ 6Fex6K2MYCRxfyWkSPjLNhwLVIxhSM+SPXvLkhlQ4ywHKazdcrNT8PGtMG/WeAFKI1Z3 AVwz8qJD9d8BrIu5lOmN+wI8a/lWckkyzXeiA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:references:in-reply-to:mime-version :content-type:content-transfer-encoding:message-id; b=mI5YkGYqc2PvuDDcdLnCzZLATQpoc7MoqTR26Ng4CGhsm6GtcykHERUCiPCgWnlB/O C+3OIhc1yTnMLD50xjD1jGlK4yYRUp6q0j4wM8m1ssKozVfJc/2/3Uf5qBdNMSj1NYvn oLUogEQrb7FAMuFQCQ3ucYjOpYMNxhm8kjpMI= Received: by 10.210.36.8 with SMTP id j8mr5802866ebj.99.1232872897442; Sun, 25 Jan 2009 00:41:37 -0800 (PST) Received: from cooker.localnet (ppp91-77-239-56.pppoe.mtu-net.ru [91.77.239.56]) by mx.google.com with ESMTPS id 5sm13371996eyf.57.2009.01.25.00.41.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 25 Jan 2009 00:41:36 -0800 (PST) From: Andrey Borzenkov To: zsh-workers@sunsite.dk Subject: Re: sourcing a sh file in zsh Date: Sun, 25 Jan 2009 11:40:52 +0300 User-Agent: KMail/1.11.0 (Linux/2.6.29-rc2-1avb; KDE/4.1.96; i686; ; ) References: <200901241859.30029.arvidjaar@gmail.com> <090124151113.ZM24112@torch.brasslantern.com> In-Reply-To: <090124151113.ZM24112@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart137000093.mjjkIKEKzL"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200901251141.21647.arvidjaar@gmail.com> X-Virus-Scanned: ClamAV 0.92.1/8900/Sun Jan 25 03:40:27 2009 on bifrost X-Virus-Status: Clean --nextPart137000093.mjjkIKEKzL Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 25 =D1=8F=D0=BD=D0=B2=D0=B0=D1=80=D1=8F 2009 02:11:13 Bart Schaefer wrot= e: > > I'm still undecided on (1) whether "-E" should either require or > always imply -L, and (2) whether I like "-c" better, as in > > emulate sh -c 'source file.sh' > > As to (1), in what circumstances would you want to eval a command > under emulation and then leave the emulation in place? If you were > going to leave emulation turned on anyway, why wouldn't you write > it as > > emulate sh > source file.sh > > ?? > I did not want to shut the door. But you are right, implying -L makes both= =20 code and documentation simpler. I do not think requiring it makes sense - - LE implies that -E is possible, which is not. I personally would flag -LE as error then for the same reason as well as=20 do not confuse user who reads manuals. Let -L just always set=20 LOCAL_OPTIONS. > (2) is a nit. Mainly it affects whether emulate accepts only one > argument to be eval'd. Note that a) -c cannot be an option. It would be yet another argument. Not a=20 problem (actually, it even simplifies parsing). b) this makes impression that emulate sh -c "some command" arg1 arg2 ... is valid (it is with shell, is not it?) This could be added later if=20 someone finds usage case. Yes, I am more and more inclined to make it "-c ..." ... OK to commit? Index: Doc/Zsh/builtins.yo =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.114 diff -u -p -r1.114 builtins.yo =2D-- Doc/Zsh/builtins.yo 18 Dec 2008 09:49:04 -0000 1.114 +++ Doc/Zsh/builtins.yo 25 Jan 2009 08:37:08 -0000 @@ -338,8 +338,11 @@ cindex(compatibility, csh) cindex(sh, compatibility) cindex(ksh, compatibility) cindex(csh, compatibility) =2Ditem(tt(emulate) [ tt(-LR) ] {tt(zsh)|tt(sh)|tt(ksh)|tt(csh)})( =2DSet up zsh options to emulate the specified shell as much as possible. +item(tt(emulate) [ tt(-LR) ] [ {tt(zsh)|tt(sh)|tt(ksh)|tt(csh)} [ tt(-c)=20 tt(arg) ] ])( +Without any argument print current emulation mode. + +With single argument set up zsh options to emulate the specified shell +as much as possible. bf(csh) will never be fully emulated. If the argument is not one of the shells listed above, tt(zsh) will be used as a default; more precisely, the tests performed on the @@ -351,16 +354,21 @@ the section `Compatibility' in zmanref(z ifnzman(\ noderef(Compatibility) )\ =2D. If the tt(-R) option is given, all options +. + +If tt(-c) tt(arg) is given, evaluate tt(arg) after temporary setting +requested emulation. Emulation will be restored before tt(emulate) returns. + +If the tt(-R) option is given, all options are reset to their default value corresponding to the specified emulation mode, except for certain options describing the interactive environment; otherwise, only those options likely to cause portability =2Dproblems in scripts and functions are altered. If the tt(-L) option =2Dis given, the options tt(LOCAL_OPTIONS) and tt(LOCAL_TRAPS) will be set = as +problems in scripts and functions are altered. If the tt(-L) option is=20 given, +the options tt(LOCAL_OPTIONS) and tt(LOCAL_TRAPS) will be set as well, causing the effects of the tt(emulate) command and any tt(setopt) and tt(trap) commands to be local to the immediately surrounding shell function, if any; normally these options are turned off in all emulation =2Dmodes except tt(ksh). +modes except tt(ksh). The tt(-L) and tt(-c) are mutually exclusive. ) findex(enable) cindex(enabling commands) Index: Src/builtin.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.218 diff -u -p -r1.218 builtin.c =2D-- Src/builtin.c 12 Nov 2008 12:57:26 -0000 1.218 +++ Src/builtin.c 25 Jan 2009 08:37:08 -0000 @@ -58,7 +58,7 @@ static struct builtin builtins[] =3D BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmrs", NULL), BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL), BUILTIN("echo", BINF_SKIPINVALID, bin_print, 0, -1, BIN_ECHO, "neE",=20 "-"), =2D BUILTIN("emulate", 0, bin_emulate, 1, 1, 0, "LR", NULL), + BUILTIN("emulate", 0, bin_emulate, 0, 3, 0, "LR", NULL), BUILTIN("enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmrs", NULL), BUILTIN("eval", BINF_PSPECIAL, bin_eval, 0, -1, BIN_EVAL, NULL, NULL), BUILTIN("exit", BINF_PSPECIAL, bin_break, 0, 1, BIN_EXIT, NULL, NULL), @@ -4744,24 +4744,12 @@ bin_dot(char *name, char **argv, UNUSED( return ret ? ret : lastval; } =20 =2D/**/ =2Dint =2Dbin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func= )) =2D{ =2D emulate(*argv, OPT_ISSET(ops,'R')); =2D if (OPT_ISSET(ops,'L')) =2D opts[LOCALOPTIONS] =3D opts[LOCALTRAPS] =3D 1; =2D return 0; =2D} =2D =2D/* eval: simple evaluation */ =2D =2D/**/ =2Dmod_export int ineval; +/* + * common for bin_emulate and bin_eval + */ =20 =2D/**/ =2Dint =2Dbin_eval(UNUSED(char *nam), char **argv, UNUSED(Options ops), UNUSED(int= =20 func)) +static int +eval(char **argv) { Eprog prog; char *oscriptname =3D scriptname; @@ -4838,6 +4826,79 @@ bin_eval(UNUSED(char *nam), char **argv, return lastval; } =20 +/* emulate: set emulation mode and optionally evaluate shell code */ + +/**/ +int +bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) +{ + int opt_L =3D OPT_ISSET(ops, 'L'); + int opt_R =3D OPT_ISSET(ops, 'R'); + int saveemulation ; + int ret; + char saveopts[OPT_SIZE]; + + /* without arguments just print current emulation */ + if (!*argv) { + if (opt_L || opt_R) { + zwarnnam("emulate", "not enough arguments"); + return 1; + } + + printf("%s\n", emulation =3D=3D EMULATE_CSH ? "csh" : + emulation =3D=3D EMULATE_KSH ? "ksh" : + emulation =3D=3D EMULATE_SH ? "sh" : + "zsh"); + return 0; + } + + /* with single argument set current emulation */ + if (!argv[1]) { + emulate(*argv, OPT_ISSET(ops,'R')); + if (OPT_ISSET(ops,'L')) + opts[LOCALOPTIONS] =3D opts[LOCALTRAPS] =3D 1; + return 0; + } + + /* If "-c command" is given, evaluate command using specified + * emulation mode. + */ + if (strcmp(argv[1], "-c")) { + zwarnnam("emulate", "unknown argument %s", argv[1]); + return 1; + } + + if (!argv[2]) { + zwarnnam("emulate", "not enough arguments"); + return 1; + } + + if (opt_L) { + zwarnnam("emulate", "option -L incompatible with -c"); + return 1; + } + + memcpy(saveopts, opts, sizeof(opts)); + saveemulation =3D emulation; + emulate(*argv, OPT_ISSET(ops,'R')); + ret =3D eval(argv+2); + memcpy(opts, saveopts, sizeof(opts)); + emulation =3D saveemulation; + return ret; +} + +/* eval: simple evaluation */ + +/**/ +mod_export int ineval; + +/**/ +int +bin_eval(UNUSED(char *nam), char **argv, UNUSED(Options ops), UNUSED(int=20 func)) +{ + return eval(argv); +} + static char *zbuf; static int readfd; =20 --nextPart137000093.mjjkIKEKzL Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAkl8JZoACgkQR6LMutpd94yXAgCfcfkEcy4FGOKnP75pjYZSA2i/ 9BMAnApMZsnwzpi+EdaFeu8+OA8U2mbN =DFXi -----END PGP SIGNATURE----- --nextPart137000093.mjjkIKEKzL--