rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 2e67f638ea031ce0138891b6356806b463f5e9af
parent e354cf4fd756584239e7778217ee8860009e6728
Author: Toby Goodwin <tjg@star.le.ac.uk>
Date:   Wed, 22 May 2002 14:25:10 +0100

candidate: rc-1.6c7

Diffstat:
MAUTHORS | 12++++++------
MCOPYING | 2+-
MChangeLog | 16++++++++++++++++
MINSTALL | 33++++++++++++++++++---------------
MNEWS | 8++++----
MREADME | 2+-
Mconfigure.ac | 2+-
Mexec.c | 5-----
Mhash.c | 35+++++++++++++++++++++++++++++------
Mhistory.1 | 15+++++++++++++--
Mhistory.c | 14+++++++++++---
Mmain.c | 6++++--
Mrc.1 | 145++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mrc.h | 9++++++++-
Mvar.c | 3+--
15 files changed, 183 insertions(+), 124 deletions(-)

diff --git a/AUTHORS b/AUTHORS @@ -29,9 +29,9 @@ version of rc presented here differs in some respects. Tim would like to thank these people for their contributions since he took over maintenance of rc. Aharon Robbins, Arvid Requate, Bengt Kleberg, Brynjulv Hauksson, Byron Rakitzis, Callum Gibson, Chris -Siebenmann, Dale Scheetz, David Luyer, David Swasey, Decklin Foster, -Donn Cave, Gary Carvell, Gerry Tomlinson, Gert-Jan Vons, Ian Lance -Taylor, Jeremy Fitzhardinge, Marc Moorcroft, Mark H Wilkinson, Mark K -Gardner, Raymond Venneker, Rich $alz, Rob Savoye, Scott Schwartz, -Stefan Dalibor, Steve Simon, Thomas Nordin, Tom Culliton, Tom Tromey, -Vincent Broman, Wolfgang Zekoll. +Siebenmann, Dale Scheetz, Dan Moniz, David Luyer, David Swasey, +Decklin Foster, Donn Cave, Erik Quanstrom, Gary Carvell, Gerry +Tomlinson, Gert-Jan Vons, Ian Lance Taylor, Jeremy Fitzhardinge, Marc +Moorcroft, Mark H Wilkinson, Mark K Gardner, Raymond Venneker, Rich +$alz, Rob Savoye, Scott Schwartz, Stefan Dalibor, Steve Simon, Thomas +Nordin, Tom Culliton, Tom Tromey, Vincent Broman, Wolfgang Zekoll. diff --git a/COPYING b/COPYING @@ -1,5 +1,5 @@ /* - * Copyright 1991, 2001 Byron Rakitzis. All rights reserved. + * Copyright 1991 by Byron Rakitzis. All rights reserved. * * This software is not subject to any license of the American Telephone * and Telegraph Company or of the Regents of the University of California. diff --git a/ChangeLog b/ChangeLog @@ -768,3 +768,19 @@ Changes since rc-1.5b2 Bug: yet more wrongly ordered header file includes. Release: rc-1.6c6. + +2002-04-03 + + Feature: make $version less magical, and exportable if it's changed + from its default value. Same for $prompt (thank Erik Quanstrom). + + Bug: make $bqstatus and $status not exportable. + + Feature: "stuttering" colons for multiple replacements in the + history programs (thanks Callum Gibson). + +2002-05-22 + + Documentation: possible warning in tripping.c (thanks Dan Moniz). + + Release: rc-1.6c7. diff --git a/INSTALL b/INSTALL @@ -15,8 +15,8 @@ to build rc in a different directory). BUILD AND CONFIGURATION OPTIONS There are lots of options you can give to configure to modify rc's -behaviour. You can also select a command line history library to -link against---see the README file for details of where to find these +behaviour. You can also select a command line history library to link +against---see the rc web page for details of where to find these libraries. For a summary of all options, run `sh configure --help'. You can specify Makefile variables by setting the corresponding @@ -31,7 +31,7 @@ descending order of usefulness. --with-editline - This option tells rc to use the editline package (see the README file + This option tells rc to use the editline package (see the web page for details) to provide EMACS style command line editing and history. If the editline library is not installed in a standard place, you can tell configure where to find it by setting the environment variable @@ -42,7 +42,7 @@ descending order of usefulness. --with-vrl - This option tells rc to use the vrl package (see the README file for + This option tells rc to use the vrl package (see the web page for details) to provide EMACS style command line editing and history. As for `--with-editline', you may need to set the environment variable LDFLAGS appropriately. @@ -61,13 +61,13 @@ descending order of usefulness. --with-history Use this option if you want to build and install the programs that - support a crude history mechanism. + support a crude command-line history mechanism. You can't use more than one of `--with-editline', `--with-vrl', and `--with-readline' at the same time. If you have any of these you probably don't want to bother with `--with-history'. - --prefix /path + --prefix=/path By default, `prefix' is /usr/local, which means that `make install' installs rc (and possibly the history programs) in /usr/local/bin, and @@ -94,10 +94,10 @@ probably don't want to bother with `--with-history'. --disable-def-interp --enable-def-interp=/bin/foo - By default, a program that fails with "Exec format error" is handed to - /bin/sh. This does the Right Thing for scripts that start with `:' to - indicate that they are sh scripts. You can disable this behaviour - entirely, or specify a different default interpreter. + By default, a program that fails with ENOEXEC (Exec format error) is + handed to /bin/sh. This does the Right Thing for scripts that start + with `:' to indicate that they are sh scripts. You can disable this + behaviour entirely, or specify a different default interpreter. --disable-def-path --enable-def-path "/usr/local/bin","/usr/bin" @@ -129,11 +129,11 @@ probably don't want to bother with `--with-history'. dying or discarding the variables. This option disables the default behaviour. You are unlikely to want this option on any Unix system. -After you've built rc, I recommend that you run it through a test script -to gain some confidence that all is working well. Type `make trip' to -do this. This will produce some output, and should end with "trip is -complete". If the trip instead ends with "trip took a wrong turn..." -please contact the maintainer. +After you've built rc, I recommend that you run it through the test +script to gain some confidence that all is working well. Type `make +trip' to do this. This will produce some output, and should end with +"trip is complete". If the trip instead ends with "trip took a wrong +turn..." please contact the maintainer. LARGE FILE SUPPORT @@ -181,6 +181,9 @@ On some systems there are warnings about "passing arg 2 of `getgroups' from incompatible pointer type" in which.c. I believe this is due to an incorrect declaration of `getgroups()' in those systems' header files. +The warning "left shift count >= width of type" in tripping.c may +occur if off_t is only 32 bits. + Any other warnings should be reported to the maintainer. diff --git a/NEWS b/NEWS @@ -1,7 +1,7 @@ Highlights of changes since rc-1.6. See ChangeLog for further details. -Portability. Many minor tweaks, including fixes for BeOS, CygWin, and -gcc-3. +Portability. Many minor tweaks, including fixes for BeOS, CygWin, +QNX, and gcc-3. Bug fixes. A number of bugs have been fixed. The serious ones were: a core dump, triggered by `~ () '*''; premature exit, triggered by @@ -13,7 +13,7 @@ New features. The following features are new: the `$version' variable replaces the `-V' flag; the `-I' flag (definitively not interactive) was added for compatibility with the Plan 9 rc; ASCII SOH (^A) is now handled transparently; support for large files; support for more -limits. +process resource limits. Documentation. Distributions of this rc used to include a PostScript paper given by Tom Duff to the UKUUG, describing the Plan 9 rc. This @@ -22,4 +22,4 @@ the web, both in its original PostScript version, and an updated HTML version. Tim Goodwin -2002-02-08 +2002-05-21 diff --git a/README b/README @@ -1,4 +1,4 @@ -This is release candidate rc-1.6c6. +This is release candidate rc-1.6c7. See COPYING for copying information. All files are diff --git a/configure.ac b/configure.ac @@ -8,7 +8,7 @@ dnl Automake stuff. dnl Use this one for snapshots... dnl AM_INIT_AUTOMAKE(rc, 1.6s`echo $RELDATE |sed 's/-//g'`) dnl ...and this one for releases -AM_INIT_AUTOMAKE(rc, 1.6c6) +AM_INIT_AUTOMAKE(rc, 1.6c7) AM_CONFIG_HEADER(config.h) diff --git a/exec.c b/exec.c @@ -7,11 +7,6 @@ #include "wait.h" -#include <errno.h> -#include <signal.h> - -#include "wait.h" - #include "rc.h" #include "wait.h" /* diff --git a/hash.c b/hash.c @@ -228,14 +228,37 @@ extern void initenv(char **envp) { } } +static char *neverexport[] = { + "apid", "apids", "bqstatus", "cdpath", "home", + "ifs", "path", "pid", "status", "*" +}; + +/* for a few variables that have default values, we export them only +if they've been explicitly set; maybeexport[n].flag is TRUE if this +has occurred. */ +struct nameflag { + char *name; + bool flag; +}; +static struct nameflag maybeexport[] = { + { "prompt", FALSE }, + { "version", FALSE } +}; + +void set_exportable(char *s, bool b) { + int i; + for (i = 0; i < arraysize(maybeexport); ++i) + if (maybeexport[i].flag != b && streq(s, maybeexport[i].name)) + maybeexport[i].flag = b; +} + static bool var_exportable(char *s) { - static char *notforexport[] = { - "apid", "apids", "cdpath", "home", "ifs", - "path", "pid", "version", "*" - }; int i; - for (i = 0; i < arraysize(notforexport); i++) - if (streq(s, notforexport[i])) + for (i = 0; i < arraysize(neverexport); i++) + if (streq(s, neverexport[i])) + return FALSE; + for (i = 0; i < arraysize(maybeexport); i++) + if (maybeexport[i].flag == FALSE && streq(s, maybeexport[i].name)) return FALSE; return TRUE; } diff --git a/history.1 b/history.1 @@ -176,13 +176,14 @@ matched before a command is selected. Substitutions may also be specified on the command line. These have the syntax: .Ds -.Ic old : new +.Ic old :[:...] new .De .PP (Note that the .I old pattern is used as a search-limiting pattern also.) -Substitutions happen on the first match. +Substitutions happen from left to right and are repeated according to the +number of colons specified. .PP Finally, if the program was invoked as .RI `` -- '' @@ -241,3 +242,13 @@ reinterpretation: .Cr " eval $comm" .Cr " }" .Cr "}" +.De +.PP +Stuttering the `:' in a substitution allows things like: +.Ds +; prog 1 2 3 abc > /very/long/path/abc.out +etc. +- prog abc::xyz +prog 1 2 3 xyz > /very/long/path/xyz.out +; +.De diff --git a/history.c b/history.c @@ -26,6 +26,7 @@ static const char id[] = "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $"; static struct { char *old, *new; + int reps; /* no. of repetitions. i.e. 1 means sub twice. */ } *replace; static char **search, *progname, *history; @@ -296,8 +297,12 @@ int main(int argc, char **argv) { search[nsearch++] = argv[i]; else { *(char *)s = '\0'; /* do we confuse ps too much? */ + replace[nreplace].reps = 0; + while(*(++s) == ':') { + replace[nreplace].reps++; + } replace[nreplace].old = argv[i]; - replace[nreplace].new = s + 1; + replace[nreplace].new = s; nreplace++; } @@ -312,8 +317,11 @@ next: s = getcommand(); for (i = 0; i < nreplace; i++) if (!isin(s, replace[i].old)) goto next; - else - s = sub(s, replace[i].old, replace[i].new); + else { + int j; + for (j = 0; j <= replace[i].reps; j++) + s = sub(s, replace[i].old, replace[i].new); + } if (editit) { s = edit(s); if (s == NULL) diff --git a/main.c b/main.c @@ -74,12 +74,13 @@ quitopts: initsignal(); inithash(); initparse(); - assigndefault("prompt", "; ", "", (void *)0); + assigndefault("ifs", " ", "\t", "\n", (void *)0); #ifdef DEFAULTPATH assigndefault("path", DEFAULTPATH, (void *)0); #endif - assigndefault("ifs", " ", "\t", "\n", (void *)0); assigndefault("pid", nprint("%d", rc_pid), (void *)0); + assigndefault("prompt", "; ", "", (void *)0); + assigndefault("version", VERSION, "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $", (void *)0); initenv(envp); initinput(); null[0] = NULL; @@ -112,6 +113,7 @@ static void assigndefault(char *name,...) { for (l = NULL; (v = va_arg(ap, char *)) != NULL;) l = append(l, word(v, NULL)); varassign(name, l, FALSE); + set_exportable(name, FALSE); if (streq(name, "path")) alias(name, l, FALSE); va_end(ap); diff --git a/rc.1 b/rc.1 @@ -161,7 +161,7 @@ .if !"\\$4"" .Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" .if "\\$4"" \\$3\fR\s10 .. -.TH RC 1 "2002-02-08" +.TH RC 1 "2002-05-21" .SH NAME rc \- shell .SH SYNOPSIS @@ -1200,10 +1200,38 @@ as its value. Several variables are known to .I rc and are treated specially. -In the following list, ``(read only)'' indicates that an attempt to set the -variable will silently have no effect. +In the following list, ``default'' indicates that +.I rc +gives the variable a default value on startup; ``no-export'' indicates +that the variable is never exported; and ``read-only'' indicates that +an attempt to set the variable will silently have no effect. +.PP +Also, ``alias'' means that the variable is aliased to the same name in +capitals. +For example, an assignment to +.Cr $cdpath +causes an automatic assignment to +.Cr $CDPATH , +and vice-versa. +If +.Cr $CDPATH +is set when +.I rc +is started, its value is imported into +.Cr $cdpath . +.Cr $cdpath +and +.Cr $path +are +.I rc +lists; +.Cr $CDPATH +and +.Cr $PATH +are colon-separated lists. +Only the names spelt in capitals are exported into the environment. .TP -.Cr * +.Cr * " (no-export)" The argument list of .IR rc . .Cr "$1, $2," @@ -1212,7 +1240,7 @@ etc. are the same as .Cr $*(2) , etc. .TP -.Cr 0 +.Cr 0 " (default no-export)" The variable .Cr $0 holds the value of @@ -1234,15 +1262,15 @@ is not an element of .Cr $* , and is never treated as one. .TP -.Cr apid +.Cr apid " (no-export)" The process ID of the last process started in the background. .TP -.Cr apids " (read only)" +.Cr apids " (no-export read-only)" A list whose elements are the process IDs of all background processes which are still alive, or which have died and have not been waited for yet. .TP -.Cr bqstatus +.Cr bqstatus " (no-export)" The exit status of the .I rc forked to execute the most recent backquote substitution. Note that, unlike @@ -1273,7 +1301,7 @@ prints .Cr "bqstatus=1" .De .TP -.Cr cdpath +.Cr cdpath " (alias)" A list of directories to search for the target of a .B cd command. @@ -1283,14 +1311,6 @@ Note that if the variable does not contain the current directory, then the current directory will not be searched; this allows directory searching to begin in a directory other than the current directory. -Note also that an assignment to -.Cr $cdpath -causes an automatic assignment to -.Cr $CDPATH , -and vice-versa. -Only -.Cr $CDPATH -is exported into the environment. .TP .Cr history .Cr $history @@ -1309,7 +1329,7 @@ is not set, then .I rc does not append commands to any file. .TP -.Cr home +.Cr home " (alias)" The default directory for the builtin .B cd command, and the directory in which @@ -1319,30 +1339,17 @@ looks to find its initialization file, if .I rc has been started up as a login shell. -Like -.Cr $cdpath -and -.Cr $CDPATH , -.Cr $home -and -.Cr $HOME -are aliased to each other. .TP -.Cr ifs +.Cr ifs " (default)" The internal field separator, used for splitting up the output of -backquote commands for digestion as a list. +backquote commands for digestion as a list. On startup, +.I rc +assigns the list containing the characters space, tab, and newline to +.Cr $ifs . .TP -.Cr path +.Cr path " (alias)" This is a list of directories to search in for commands. The empty string stands for the current directory. -Note that like -.Cr $cdpath -and -.Cr $CDPATH , -.Cr $path -and -.Cr $PATH -are aliased to each other. If neither .Cr $PATH nor @@ -1353,11 +1360,13 @@ assumes a default value suitable for your system. This is typically .Cr "(/usr/local/bin /usr/bin /usr/ucb /bin .)" .TP -.Cr pid -The process ID of the currently running +.Cr pid " (default no-export)" +On startup, +.Cr $pid +is initialized to the numeric process ID of the currently running .IR rc . .TP -.Cr prompt +.Cr prompt " (default)" This variable holds the two prompts (in list form, of course) that .I rc prints. @@ -1398,7 +1407,7 @@ If this function is defined, then it gets executed every time is about to print .Cr "$prompt(1)" . .TP -.Cr status " (read only)" +.Cr status " (no-export read-only)" The exit status of the last command. If the command exited with a numeric value, that number is the status. If the command died with a signal, the status is the name of that signal; @@ -1419,38 +1428,14 @@ usually sets to .Cr "(0 0)" . .TP -.Cr version " (read only)" -The first element of this list variable is a string which identifies this -version of +.Cr version " (default)" +On startup, the first element of this list variable is initialized to +a string which identifies this version of .IR rc . -The second element is a string which can be found by +The second element is initialized to a string which can be found by .B ident and .BR "sccs what" . -.PP -The values of -.Cr "$path" , -.Cr "$cdpath" , -and -.Cr $home -are derived from the environment -values of -.Cr "$PATH" , -.Cr "$CDPATH" , -and -.Cr "$HOME" . -Otherwise, they are derived from -the environment values of -.Cr $path , -.Cr $cdpath -and -.Cr $home . -This is for compatibility with other Unix programs, like -.IR sh (1). -.Cr $PATH -and -.Cr $CDPATH -are assumed to be colon-separated lists. .SH FUNCTIONS .I rc functions are identical to @@ -1490,7 +1475,7 @@ could be: .PP but not .Ds -.Cr "fn l { ls -FC }" +.Cr "fn l { ls -FC } # WRONG" .De .SH "INTERRUPTS AND SIGNALS" .I rc @@ -1579,7 +1564,7 @@ Thus from within a shell script, .De .TP \& -does the ``right'' thing. +does the ``right thing''. .TP .B break Breaks from the innermost @@ -1682,7 +1667,7 @@ Similar to the .IR csh (1) .B limit builtin, this command operates upon the -BSD-style limits of a process. +BSD-style resource limits of a process. The .Cr \-h flag displays/alters the hard @@ -1695,9 +1680,14 @@ The resources which can be shown or altered are .BR coredumpsize , .BR memoryuse , and, where supported, -.BR descriptors . -For -example: +.BR descriptors , +.BR memoryuse , +.BR memoryrss , +.BR maxproc , +.BR memorylocked , +and +.BR filelocks . +For example: .Ds .Cr "limit coredumpsize 0" .De @@ -2117,6 +2107,11 @@ keywords, the .B echo builtin, +the +.Cr bqstatus +and +.Cr rc_version +variables, the support for the GNU .IR readline (3) library and diff --git a/rc.h b/rc.h @@ -194,7 +194,13 @@ extern void sigint(int); /* exec.c */ extern void exec(List *, bool); -extern void doredirs(void); + +#if HASH_BANG +#define rc_execve execve +#else +/* execve.c */ +extern int my_execve(char *, char **, char **); +#endif #if HASH_BANG #define rc_execve execve @@ -251,6 +257,7 @@ extern void fnassign_string(char *); extern void fnrm(char *); extern void initenv(char **); extern void inithash(void); +extern void set_exportable(char *, bool); extern void setsigdefaults(bool); extern void inithandler(void); extern void varassign(char *, List *, bool); diff --git a/var.c b/var.c @@ -18,6 +18,7 @@ extern void varassign(char *name, List *def, bool stack) { new = get_var_place(name, stack); new->def = newdef; new->extdef = NULL; + set_exportable(name, TRUE); #if READLINE if (interactive && (streq(name, "TERM") || streq(name, "TERMCAP"))) rl_reset_terminal(NULL); @@ -68,8 +69,6 @@ extern List *varlookup(char *name) { return sgetapids(); if (streq(name, "status")) return sgetstatus(); - if (streq(name, "version")) - return &id1; if (*name != '\0' && (sub = a2u(name)) != -1) { /* handle $1, $2, etc. */ for (l = varlookup("*"); l != NULL && sub != 0; --sub) l = l->n;