From owner-freebsd-standards Sat Feb 23 21:28:47 2002 Delivered-To: freebsd-standards@freebsd.org Received: from descent.robbins.dropbear.id.au (133.c.008.mel.iprimus.net.au [210.50.88.133]) by hub.freebsd.org (Postfix) with ESMTP id 5E93737B416 for ; Sat, 23 Feb 2002 21:28:13 -0800 (PST) Received: (from tim@localhost) by descent.robbins.dropbear.id.au (8.11.6/8.11.6) id g1O5ROf60233 for freebsd-standards@FreeBSD.ORG; Sun, 24 Feb 2002 16:27:24 +1100 (EST) (envelope-from tim) Date: Sun, 24 Feb 2002 16:27:24 +1100 From: Tim Robbins To: freebsd-standards@FreeBSD.ORG Subject: sh -h (-o trackall) option patch Message-ID: <20020224162724.A60220@descent.robbins.dropbear.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Here's a patch to add the -h (-o trackall) option to sh. The P1003.1-2001 specification about this option is flawed, but I'm confident this is what was intended. (The flaw is that the -h option is listed in the SYNOPSIS section but not in the OPTIONS section. It should be listed along with the other options to the "set" builtin.) The name accepted by the -o option, trackall, is not specified by the standard, but is the traditional Korn Shell name for it. Index: options.h =================================================================== RCS file: /home/ncvs/src/bin/sh/options.h,v retrieving revision 1.11 diff -u -r1.11 options.h --- options.h 2002/02/02 06:50:47 1.11 +++ options.h 2002/02/24 05:23:22 @@ -65,8 +65,9 @@ #define uflag optlist[14].val #define privileged optlist[15].val #define Tflag optlist[16].val +#define hflag optlist[17].val -#define NOPTS 17 +#define NOPTS 18 struct optent { const char *name; @@ -93,6 +94,7 @@ { "nounset", 'u', 0 }, { "privileged", 'p', 0 }, { "trapsasync", 'T', 0 }, + { "trackall", 'h', 0 }, }; #else extern struct optent optlist[NOPTS]; Index: parser.c =================================================================== RCS file: /home/ncvs/src/bin/sh/parser.c,v retrieving revision 1.38 diff -u -r1.38 parser.c --- parser.c 2002/02/02 06:50:47 1.38 +++ parser.c 2002/02/24 05:23:25 @@ -60,6 +60,7 @@ #include "alias.h" #include "show.h" #include "eval.h" +#include "exec.h" #ifndef NO_HISTORY #include "myhistedit.h" #endif @@ -97,6 +98,7 @@ struct heredoc *heredoc; int quoteflag; /* set if (part of) last token was quoted */ int startlinno; /* line # where last token started */ +int funclevel; /* nesting level of functions */ /* XXX When 'noaliases' is set to one, no alias expansion takes place. */ static int noaliases = 0; @@ -530,6 +532,7 @@ STATIC union node * simplecmd(union node **rpp, union node *redir) { + struct cmdentry entry; union node *args, **app; union node **orig_rpp = rpp; union node *n = NULL, *n2; @@ -561,6 +564,9 @@ n->type = NARG; n->narg.text = wordtext; n->narg.backquote = backquotelist; + if (app == &args && funclevel > 0 && hflag) + /* Add hash entry for this command (-h option) */ + find_command(wordtext, &entry, 0, pathval()); *app = n; app = &n->narg.next; } else if (lasttoken == TREDIR) { @@ -577,7 +583,9 @@ synerror("Bad function name"); #endif n->type = NDEFUN; + funclevel++; n->narg.next = command(); + funclevel--; goto checkneg; } else { tokpushback++; Index: sh.1 =================================================================== RCS file: /home/ncvs/src/bin/sh/sh.1,v retrieving revision 1.58 diff -u -r1.58 sh.1 --- sh.1 2001/11/20 18:41:01 1.58 +++ sh.1 2002/02/24 05:23:31 @@ -43,7 +43,7 @@ .Nd command interpreter (shell) .Sh SYNOPSIS .Nm -.Op Fl /+abCEefIimnpsTuVvx +.Op Fl /+abCEefIhimnpsTuVvx .Op Fl /+o Ar longname .Op Fl c Ar string .Op Ar arg ...\& @@ -218,6 +218,9 @@ Ignore .Dv EOF Ns ' Ns s from input when in interactive mode. +.It Fl h Li trackall +Create tracked aliases for commands invoked by functions as they are defined. +By default, tracked aliases are created when the functions are executed. .It Fl i Li interactive Force the shell to behave interactively. .It Fl m Li monitor To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message