Commit Graph

3639 Commits

Author SHA1 Message Date
kre 70a37837ef PR bin/52458
Avoid mangling history when editing is enabled, and the prompt contains a \n

Also, allow empty input lines into history when they are being appended to
a previous (partial) command (but not when they would just make an empty entry).

For all the gory details, see the PR.

Note nothing here actually makes prompts containing \n work correctly
when editing is enabled, that's a libedit issue, which will be addressed
some other time.
2017-08-05 11:33:05 +00:00
kre fab2da9b21 PR bin/48498 PR bin/52426
Don't ignore unexpected reserved words after ';'
Don't allow any random token type as a case stmt pattern, only a word.
	Those are ancient ash bugs and do not affect correct scripts.

Don't ignore redirects in a case stmt list where the list is nothing but
redirects (if the pattern matches, the redirects should be performed).
	That was introduced when a redirect only case stmt list was allowed
	(older shells had generated a syntax error.)

Random cleanups/refactoring taken from or inspired by the FreeBSD sh
parser ...  use makename() consistently to create a NARG node - we
were using it in a couple of places but most NARG node creation was open
coded.  Introduce consumetoken() (from FreeBSD) to handle the fairly
common case where exactly one token type must come next, and we need to
check that, and skip past it when found (or error) and linebreak() (new)
to handle places where optional \n's are permitted.
Both previously open coded.

Simplify list() by removing its second arg, which was only ever used when
handling the end of a `` (old style command substitution).  Simply move
the code from inside list() to just after its call in the `` case (from
FreeBSD.)
2017-07-26 23:09:41 +00:00
kre 0915509c52 Add a comment explaining the ordering reltionship of the tokens
(operators all come first, then TWORD, then keywords), and switch
from using TIF to define KWDOFFSET to using TWORD (the barrier,
rather than the token that happens to be first after it.)
2017-07-26 03:46:54 +00:00
kre 4e19051c4d NFC: DEBUG mode change - add a couple more TRACE macros to allow for
conditional (apart from the normal debug conditions) tracing.
2017-07-26 03:44:43 +00:00
wiz bbff3c2815 Remove trailing whitespace. 2017-07-25 08:37:48 +00:00
kre ed2c7aaa15 Implement the "pipefail" option (same semantics as in other shells)
to cause (when set, which it is not by default) the exit status of a
pipe to be 0 iff all commands in the pipe exited with status 0, and
otherwise, the status of the rightmost command to exit with a non-0
status.

In the doc, while describing this, also reword some of the text about
commands in general, how they are structured, and when they are executed.
2017-07-24 14:17:11 +00:00
kre 59695ae2d7 NFC: DEBUG mode only change - add a little more tracing. 2017-07-24 13:36:15 +00:00
kre e79133b55e Add support for ++ and -- (pre & post) and ',' to arithmetic. 2017-07-24 13:21:14 +00:00
kre a304c3b3a5 Document the times builtin command, reported as lost in space
by rudolf at eq.cz on tech-userlevel (July 15, 2017.)

Also correct a typo, de-correct some entirely proper English so
the doc remains written in American instead.  And note that
interactive mode is set when stdin & stderr are terminals, not
stding and stdout.
2017-07-24 12:36:02 +00:00
kre a373e69a19 PR standards/52406
Absent other information, the shell should be interactive if reading
from stdin, and stdin and stderr are ttys, not stdin and stdout.

So sayeth the great lord posix.
2017-07-24 12:35:37 +00:00
kre a2d92a0059 PR bin/52348
Avoid a reference after free (detected by asan) - harmless here, but
easy to fix.
2017-07-24 12:35:12 +00:00
kre 4401d6e524 PR bin/52348
Silence nuisance testing environments - avoid << of a negative number
(a signed char -- in a hash function, the result is irrelevant, as long
as it is repeatable).
2017-07-24 12:34:45 +00:00
christos 397b110260 Add a variant that passes the format, so that time(1) can use it. 2017-07-15 14:35:55 +00:00
kre cdfea65894 Fix a reference after free (and consequent nonsense diagnostic for
attempts to set readonly variables) I added in 1.60 by incompletely
copying the FreeBSD fix for the lost memory issue.
2017-07-12 19:06:16 +00:00
kre 2eafa75298 DEBUG only changes. Convert the TRACE() calls in the remaining files
that still used it to the new format.   NFC.
2017-07-05 20:00:27 +00:00
kre 9006b74112 DEBUG changes: convert DEBUG TRACE() calls to new format.
ALso, cause exec failures to always cause the shell to exit with
status 126 or 127, whatever the cause.  127 is intended for lookup
failures (and is used that way), 126 is used for anything else that
goes wrong (as in several other shells.)  We no longer use 2 (more easily
confused with an exit status of the command exec'd) for shell exec failures.
2017-07-05 19:58:10 +00:00
kre ae375f0127 Mostly DEBUG and white space changes. Convert DEEBUG TRACE() calls to
the new format.   Also #if 0 a function definition that is used nowhere.
While here, change the function of pushfile() slightly - it now sets
the buf pointer in the top (new) input descriptor to NULL, instead of
simply leaving it - code that needs a buffer always (before and after)
must malloc() one and assign it after the call.  But code which does not
(which will be reading from a string or similar) now does not have to
explicitly set it to NULL (cleaner interface.)   NFC intended (or observed.)
2017-07-05 19:54:21 +00:00
kre 2e1a04e9a7 DEBUG and white space changes only. Convert TRACE() calls for DEBUg mode
to the new style.   NFC (when not debugging sh).
2017-07-05 19:47:11 +00:00
wiz ee3d656c82 Use Ex. 2017-07-04 06:50:04 +00:00
wiz 285e86b675 Use Ex. Remove superfluous Pp. 2017-07-04 06:49:35 +00:00
wiz 39b251a71c Use Ex. 2017-07-04 06:46:51 +00:00
wiz 01869ca4d2 Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
kre a64e63ed28 Do a better job of detecting the error in pkgsrc/devel/libbson-1.6.3's
configure script, ie: $(( which is intended to be a sub-shell in a
command substitution, but is an arith subst instead, it needs to be
written $( ( to do as intended.   Instead of just blindly carrying on to
find the missing )) somewhere, anywhere, give up as soon as we have seen
an unbalanced ')' that isn't immediately followed by another ')' which
in a valid arith subst it always would be.

While here, there has been a comment in the code for quite a while noting a
difference in the standard between the text descr & grammar when it comes to
the syntax of case statements.   Add more comments to explain why parsing it
as we do is in fact definitely the correct way (ie: the grammar wins arguments
like this...).
2017-07-03 20:16:44 +00:00
joerg da656e3d1c Kill enough K&R cruft to build with clang again. 2017-07-01 23:12:08 +00:00
kre 2ff69d1b74 Make $- list flags in the same order they appear in sh(1) 2017-07-01 06:14:51 +00:00
wiz ea9a6a6434 Sort options (our default is 0..9AaBbZz).
Fix markup problems and a typo.
2017-07-01 05:11:57 +00:00
kre 8d40ff9951 Correct a markup typo (why did I not see this before the prev commit??) 2017-06-30 23:48:50 +00:00
kre 3b0318c107 Omnibus manual update for prompt expansions and new variables. Throw in
some random cleanups as a bonus.
2017-06-30 23:07:29 +00:00
kre dc83385122 Implement a bunch of new shell environment variables. many mostly useful
in prompts when expanded at prompt time, but all available for general use.
Many of the new ones are not available in SMALL shells (they work as normal
if assigned, but the shell does not set or use them - and there is no magic
in a SMALL shell (usually for install media.))
2017-06-30 23:05:45 +00:00
kre 1fca9bbf62 Implement PS1, PS2 and PS4 expansions (variable expansions, arithmetic
expansions, and if enabled by the promptcmds option, command substitutions.)
2017-06-30 23:02:56 +00:00
kre 3b297678bf Include redirections in trace output from "set -x" 2017-06-30 23:01:21 +00:00
kre 19986c5f4a NFC: DEBUG only change - provide an externally visible (to the DEBUG sh
internals) interface to one of the internal (private to trace code) functions
2017-06-30 23:00:40 +00:00
kamil 6327936549 ksh: Eliminate dead function x_complete_word() 2017-06-30 05:18:36 +00:00
kamil dda96fab20 ksh: Eliminate dead code from expand.h 2017-06-30 05:14:12 +00:00
kamil 00cd1c66a2 ksh: Drop old hack for FreeBSD 1.1.5 and CLK_TCK 2017-06-30 04:44:46 +00:00
kamil dd8a75d57f ksh: Upgrade to C99 <stdbool.h>
This shell already used C99 functions.
2017-06-30 04:41:19 +00:00
kamil c2a517fe40 ksh: Eliminate dead MEM_DEBUG sections, there is missing code for it
MEM_DEBUG used to contain malloc(3) debugging facilities.
2017-06-30 04:30:26 +00:00
kamil a5a27bbf6f ksh: Drop support for OSes without POSIX sigaction(2) 2017-06-30 04:22:22 +00:00
kamil 2537c199ea ksh: Drop support for OSes that don't map /dev/fd 2017-06-30 04:11:57 +00:00
kamil 91e15fa768 ksh: Drop old hack fo SunOS 4.1.x (1990-1994) 2017-06-30 04:01:48 +00:00
kamil fac4b39487 ksh: Drop support for systems without <sys/stat.h>
In future the order of includes will be normalized with KNF.

No functional change intended.
2017-06-30 03:56:12 +00:00
kamil 1dacfa0dd2 ksh: Drop support for systems with broken <sys/time.h> / <time.h> 2017-06-30 03:43:57 +00:00
kamil e6ed5dea98 ksh: Drop support for systems without POSIX lstat(2) 2017-06-30 03:35:16 +00:00
kamil a396fc9936 ksh: Drop support for systems without POSIX <sys/wait.h> 2017-06-30 03:32:28 +00:00
kamil 3e5f067b68 ksh: Drop support for systems with broken times(3)
This fallback code wouldn't work anyway.

times(3) is an obsolete interface by getrusage(2) and gettimeofday(2).
In future it will be swiched to more modern interfaces.

No functional change intended.
2017-06-30 03:23:18 +00:00
kamil 2c22621e8f ksh: Assume ANSI C prototypes 2017-06-30 02:51:14 +00:00
kamil 81c962c859 ksh: Drop support for systems without functional waitpid(2) 2017-06-30 02:38:09 +00:00
kamil 8ea5ae4cd1 ksh: Drop support for systems without POSIX signal routines 2017-06-30 02:20:47 +00:00
kamil 306d025987 ksh: Drop support for systems without implementation of EINTR
These systems weren't handled anyway.
2017-06-30 02:13:29 +00:00
kamil 51ebc97c9d ksh: Drop support for systems without handling shebang 2017-06-30 02:06:59 +00:00
kamil 5c93126131 ksh: Drop support for OSes without POSIX types
Assume available: mode_t, off_t, pid_t, uid_t, rlim_t, sigset_t.
2017-06-30 02:02:41 +00:00
kamil 9d5663e055 ksh: Drop support for systems without <sys/wait.h> 2017-06-30 01:56:34 +00:00
kamil 3e63fce1f9 ksh: Drop ksh_wait.h that reinvents <sys/wait.h> (POSIX header)
Switch jobs.c to <sys/wait.h>.

No functional change intended.
2017-06-30 01:52:34 +00:00
kamil d0aa393796 ksh: Drop support for systems without gid_t 2017-06-30 01:36:30 +00:00
kre 4754b1e8f4 Now libedit supports embedded mode switch sequence, improve sh
support for them (adds PSlit variable to set the magic character).
2017-06-28 13:46:06 +00:00
christos 650f73e320 Add literal prompt support this allows one to do:
CA="$(printf '\1')"
PS1="${CA}$(tput bold)${CA}\$${CA}$(tput sgr0)${CA} "
2017-06-27 23:27:03 +00:00
kre 8ca5565bc1 Make one example more like a real world possibility (it still isn't, but
is closer) - though the actual content is irrelevant to the point being made.
2017-06-27 12:43:44 +00:00
wiz 30b9dfc881 Get rid of workarounds for ancient groff html backend.
Simplify macro usage.
2017-06-27 08:30:40 +00:00
kre 3c2922e71c Properly support EDITRC - use it as (naming) the file when setting
up libedit, and re-do the config whenever EDITRC is set.
2017-06-27 02:22:08 +00:00
kre a3be5e86c2 Make arg parsing in kill POSIX compatible with POSIX (XBD 2.12) by
parsing the way getopt(3) would, if only it could handle the (required)
-signumber and -signame options.  This adds two "features" to kill,
-ssigname and -lstatus now work (ie: one word with all of the '-', the
option letter, and its value) and "--" also now works (kill -- -pid1 pid2
will not attempt to send the pid1 signal to pid2, but rather SIGTERM
to the pid1 process group and pid2).  It is still the case that (apart
from --) at most 1 option is permitted (-l, -s, -signame, or -signumber.)

Note that we now have an ambiguity, -sname might mean "-s name" or
send the signal "sname" - if one of those turns out to be valid, that
will be accepted, otherwise the error message will indicate that "sname"
is not a valid signal name, not that "name" is not.   Keeping the "-s"
and signal name as separate words avoids this issue.

Also caution: should someone be weird enough to define a new signal
name (as in the part after SIG) which is almost the same name as an
existing name that starts with 'S' by adding an extra 'S' prepended
(eg: adding a SIGSSYS) then the ambiguity problem becomes much worse.
In that case "kill -ssys" will be resolved in favour of the "-s"
flag being used (the more modern syntax) and would send a SIGSYS, rather
that a SIGSSYS.    So don't do that.

While here, switch to using signalname(3) (bye bye NSIG, et. al.), add
some constipation, and show a little pride in formatting the signal names
for "kill -l" (and in the usage when appropriate -- same routine.)   Respect
COLUMNS (POSIX XBD 8.3) as primary specification of the width (terminal width,
not number of columns to print) for kill -l, a very small value for COLUMNS
will cause kill -l output to list signals one per line, a very large
value will cause them all to be listed on one line.) (eg: "COLUMNS=1 kill -l")

TODO: the signal printing for "trap -l" and that for "kill -l"
should be switched to use a common routine (for the sh builtin versions.)

All changes of relevance here are to bin/kill - the (minor) changes to bin/sh
are only to properly expose the builtin version of getenv(3) so the builtin
version of kill can use it (ie: make its prototype available.)
2017-06-26 22:09:16 +00:00
christos 57d721417b source .editrc after we initialize so that commands persist! 2017-06-26 20:28:01 +00:00
kre 7f75cc46b5 Another ancient (highly improbable) bug bites the dust. This one
caused by incorrect macro usage (ie: using the wrong one) which has
been in the sources since version 1.1 (ie: forever).

Like the previous (STACKSTRNUL) bug, the probability of this one
actually occurring has been infinitesimal but the LINENO code increases
that to infinitesimal and a smidgen... (or a few, depending upon usage).

Still, apparently that was enough, Kamil Rytarowski discovered that the
zsh configure script (damn competition!) managed to trigger this problem.
2017-06-24 11:23:35 +00:00
kamil c6c3f8f1f5 ksh: Drop support for systems without clock_t type 2017-06-23 00:35:20 +00:00
kamil b831372d44 ksh: Replace homegrown int_least32_t with the C99 version 2017-06-23 00:29:42 +00:00
kamil 730f723665 ksh: Drop support for systems that return void for closedir(2) 2017-06-23 00:20:22 +00:00
kamil acc2fa794c ksh: Use ANSI C varargs, drop support for older version <varargs.h> 2017-06-23 00:18:01 +00:00
kamil cb1c866326 ksh: Remove remnant hack for SCO UNIX in tty code 2017-06-23 00:11:01 +00:00
kamil a761aa7e3f ksh: Remove support for NeXT Operating System 2017-06-23 00:09:36 +00:00
kamil 0e8072bdff ksh: Drop the latest ifdef for BSD4.1 and eliminate dead code around it 2017-06-23 00:07:15 +00:00
kamil c65b0df2e9 ksh: Drop BSD4.3 temporary hack in tty code 2017-06-23 00:04:20 +00:00
kamil 14ae4d8526 ksh: Drop support for UNIX V7-style signal routines 2017-06-23 00:00:58 +00:00
kamil 0a9965d29a ksh: Drop fallback for BSD4.2 signal routines 2017-06-22 23:59:28 +00:00
kamil 53e78cf286 ksh: Remove fallback to BSD4.1 signal routines 2017-06-22 23:56:24 +00:00
kamil 3b7ff6c991 ksh: Drop support for systems without mmap(2) 2017-06-22 23:54:13 +00:00
kamil 52b3355e26 ksh: Drop support for systems without dup2(2) 2017-06-22 23:50:24 +00:00
kamil 237b342911 ksh: Drop support for ISC UNIX 2017-06-22 23:47:29 +00:00
kamil eed5a31e9b ksh: Drop support for systems without offsetof(3) 2017-06-22 23:42:35 +00:00
kamil bdcebfe8f5 ksh: Drop support for systems without <limits.h> 2017-06-22 23:38:49 +00:00
kamil accac1300c ksh: Drop support for systems without <fcntl.h> 2017-06-22 23:37:00 +00:00
kamil fb30a30908 ksh: Drop support for systems without memmove(3) and stop using bcopy(3) 2017-06-22 23:33:36 +00:00
kamil 99f9f7cfb5 ksh: Drop support for systems without memset(3) 2017-06-22 23:30:42 +00:00
kamil 98fef8f2dd ksh: Drop usage of SVID header <memory.h>, it's legacy standard 2017-06-22 23:29:35 +00:00
kamil 00f99741e1 ksh: Drop support for systems without strcasecmp(3) and strncasecmp(3) 2017-06-22 23:27:53 +00:00
kamil 05a5edb66a ksh: Drop support for systems without strstr(3) 2017-06-22 23:26:17 +00:00
kamil 8f43bfe473 ksh: Drop support for systems without <string.h> 2017-06-22 23:23:27 +00:00
kamil ba6c50ffa7 ksh: Drop support for systems without <stddef.h>
No functional change.
2017-06-22 23:19:53 +00:00
kamil 6f9fbdf520 ksh: Drop support for systems without <stdlib.h>
No functional change.
2017-06-22 23:17:50 +00:00
kamil 17e1427bb7 ksh: Drop support for systems without <unistd.h>
This code wouldn't work for them anyway.

No functional change.
2017-06-22 23:15:05 +00:00
kamil b42d86bc68 ksh: Kill switch for CLOSEDIR_VOID (closedir(2) returns void)
No users in the code. No functional change.
2017-06-22 23:11:48 +00:00
kamil 9d04c96c0d ksh: Assume that $CC handles const (ANSI C89)
No functional change.
2017-06-22 23:09:32 +00:00
kamil af6175f2e1 Drop support for $CC incapable to use void* / volatile* (pre ANSI C89) 2017-06-22 19:46:54 +00:00
kamil d6fe16556c Drop Ultrix support from ksh(1), a DEC UNIX for VAX 2017-06-22 19:41:07 +00:00
kamil eb13ce8ce3 Reapply removal of code from 90ties for OS/2 Cygwin AIX HPUX SCOUnix
Added missing #endif terminator in emacs.c
2017-06-22 14:20:46 +00:00
kamil 266bea007e Temporarily revert previous.
emacs.* gets wrong code in generation
2017-06-22 14:11:27 +00:00
kamil ffa8eeb219 Remove code for AIX, including hack for 3.2.5 (from 1997) - from ksh(1)
OK by <kre>
2017-06-22 13:37:16 +00:00
kamil 2f8869f916 Drop HP-UX support from ksh(1)
OK by <kre>
2017-06-22 13:35:47 +00:00
kamil 4ae20c97a6 Remove sco unix 3.2v4.1 support (from 1992) from ksh(1)
OK by <kre>
2017-06-22 13:34:48 +00:00
kamil e5604d4f02 Remove os2 support in ksh(1)
OK by <kre>
2017-06-22 13:33:39 +00:00
kamil fc74b4892d Remove ancient cygwin support in ksh(1)
OK by <kre>
2017-06-22 13:32:04 +00:00
kre 467f8e2cd3 It is amazing what nonsense appears to work sometimes... (all my nonsense too!)
Two bugs here, one benign because of the way the script is used.
The other hidden by NetBSD's sort being stable, and the data not really
requiring sorting at all...

So as it happens these fixes change nothing, but they are needed anyway.

(The contents of the generated file are only used in DEBUG shells, so
this is really even less important than it seems.)
2017-06-19 11:55:07 +00:00