Commit Graph

3513 Commits

Author SHA1 Message Date
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
kre
87d90665d5 Another fix from FreeBSD (this one from April 2009).
When processing a string (as in eval, trap, or sh -c) don't allow
trailing \n's to destroy the exit status of the last command executed.

That is:
	sh -c 'false

	'
	echo $?
should produce 1, not 0.
2017-06-19 03:21:31 +00:00
kre
3892a5b005 Fix from FreeBSD (applied there in July 2008...)
Don't dump core with input like sh -c 'x=; echo >&$x' - that is where
the word after a >& or <& redirect expands to nothing at all.
2017-06-19 02:51:51 +00:00
kre
d8ae0af5de Correct the initial line number used for processing -c arg strings.
(It was inheriting the value from end of profile file processing) - I didn't
notice before as I usually test with empty or no profile files to avoid
complications.   Trivial change which should have very limited impact.
2017-06-19 02:49:33 +00:00
kre
701ac13230 Now that excessive use of STACKSTRNUL has served its purpose (well, accidental
purpose) in exposing the bug in its implementation, go back to not using
it when not needed for DEBUG TRACE purposes.   This change should have no
practical effect on either a DEBUG shell (where the STACKSTRNUL() calls
remain) or a non DEBUG shell where they are not needed.
2017-06-19 02:46:50 +00:00
kre
bbd0083b9e "b" more forgiving when sorting options to allow reasonable (and intended)
flexibility in option.list format.   Changes nothing for current option.list.
2017-06-19 02:43:55 +00:00
kre
f72bc19e74 NFC: DEBUG mode only change. Fix botched cleanup of one TRACE(). 2017-06-18 07:50:46 +00:00
kre
765053c5be NFC: DEBUG related comment change - catch up with reality. 2017-06-17 12:41:20 +00:00
kre
0ed8885aea NFC - DEBUG mode only change - complete a change made earlier (marking
the line number when included in the trace line tag to show whether it
comes from the parser, or the elsewhere as they tend to be quite different).
Initially only one case was changed, while I pondered whether I liked it
or not.  Now it is all done...   Also when there is a line tag at all,
always include the root/sub-shell indicator character, not only when the
pid is included.
2017-06-17 12:16:16 +00:00
kre
16bbc7c6f2 NFC - DEBUG mode only change - convert this to the new TRACE() format. 2017-06-17 12:12:50 +00:00
kre
200131770d NFC - DEBUG changes, update this to new TRACE method.
KNF - white space and comment formatting.
2017-06-17 11:53:24 +00:00
kre
ad0b72d9e9 Cosmetic changes to variable flags - make their values more suited
to my delicate sensibilities...  (NFC).

Arrange not to barf (ever) if some turkey makes _ readonly.  Do this
by adding a VNOERROR flag that causes errors in var setting to be
ignored (intended use is only for internal shell var setting, like of "_").
(nb: invalid var name errors ignore this flag, but those should never
occur on a var set by the shell itself.)

From FreeBSD: don't simply discard memory if a variable is not set for
any reason (including because it is readonly) if the var's value had
been malloc'd.  Free it instead...
2017-06-17 10:46:34 +00:00
kre
cf8ba701af Changed the long name for the -L option from lineno_fn_relative
to local_lineno as the latter seemed to be marginally more popular,
and perhaps more importantly, is the same length as the peviously
existing quietprofile option, which means the man page indentation
for the list of options can return to (about) what it was before...
(That is, less indented, which means more data/line, which means less
lines of man page - a good thing!)
2017-06-17 07:50:35 +00:00
kre
ee3b307fc5 Many internal memory management type fixes.
PR bin/52302   (core dump with interactive shell, here doc and error
on same line) is fixed.   (An old bug.)

echo "$( echo x; for a in $( seq 1000 ); do printf '%s\n'; done; echo y )"
consistently prints 1002 lines (x, 1000 empty ones, then y) as it should
(And you don't want to know what it did before, or why.) (Another old one.)

(Recently added) Problems with ~ expansion fixed (mem management related).

Proper fix for the cwrappers configure problem (which includes the quick
fix that was done earlier, but extends upon that to be correct). (This was
another newly added problem.)

And the really devious (and rare) old bug - if STACKSTRNUL() needs to
allocate a new buffer in which to store the \0, calculate the size of
the string space remaining correctly, unlike when SPUTC() grows the
buffer, there is no actual data being stored in the STACKSTRNUL()
case - the string space remaining was calculated as one byte too few.
That would be harmless, unless the next buffer also filled, in which
case it was assumed that it was really full, not one byte less, meaning
one junk char (a nul, or anything) was being copied into the next (even
bigger buffer) corrupting the data.

Consistent use of stalloc() to allocate a new block of (stack) memory,
and grabstackstr() to claim a block of (stack) memory that had already
been occupied but not claimed as in use.  Since grabstackstr is implemented
as just a call to stalloc() this is a no-op change in practice, but makes
it much easier to comprehend what is really happening.  Previous code
sometimes used stalloc() when the use case was really for grabstackstr().
Change grabstackstr() to actually use the arg passed to it, instead of
(not much better than) guessing how much space to claim,

More care when using unstalloc()/ungrabstackstr() to return space, and in
particular when the stack must be returned to its previous state, rather than
just returning no-longer needed space, neither of those work.  They also don't
work properly if there have been (really, even might have been) any stack mem
allocations since the last stalloc()/grabstackstr().   (If we know there
cannot have been then the alloc/release sequence is kind of pointless.)
To work correctly in general we must use setstackmark()/popstackmark() so
do that when needed.  Have those also save/restore the top of stack string
space remaining.

	[Aside: for those reading this, the "stack" mentioned is not
	in any way related to the thing used for maintaining the C
	function call state, ie: the "stack segment" of the program,
	but the shell's internal memory management strategy.]

More comments to better explain what is happening in some cases.
Also cleaned up some hopelessly broken DEBUG mode data that were
recently added (no effect on anyone but the poor semi-human attempting
to make sense of it...).

User visible changes:

Proper counting of line numbers when a here document is delimited
by a multi-line end-delimiter, as in

	cat << 'REALLY
	END'
	here doc line 1
	here doc line 2
	REALLY
	END

(which is an obscure case, but nothing says should not work.)  The \n
in the end-delimiter of the here doc (the last one) was not incrementing
the line number, which from that point on in the script would be 1 too
low (or more, for end-delimiters with more than one \n in them.)

With tilde expansion:
	unset HOME; echo ~
changed to return getpwuid(getuid())->pw_home instead of failing (returning ~)

POSIX says this is unspecified, which makes it difficult for a script to
compensate for being run without HOME set (as in env -i sh script), so
while not able to be used portably, this seems like a useful extension
(and is implemented the same way by some other shells).

Further, with
	HOME=; printf %s ~
we now write nothing (which is required by POSIX - which requires ~ to
expand to the value of $HOME if it is set) previously if $HOME (in this
case) or a user's directory in the passwd file (for ~user) were a null
STRING, We failed the ~ expansion and left behind '~' or '~user'.
2017-06-17 07:22:12 +00:00
kre
9038bdca03 Free stack memory in a couple of obscure cases where it wasn't
being done (one in probably dead code that is never compiled, the other
in a very rare error case.)   Since it is stack memory it wasn't lost
in any case, just held longer than needed.
2017-06-17 04:19:12 +00:00
kre
6f4f36666c NFC (normal use) - DEBUG only change, when showing empty arg list don't
omit terminating \n.
2017-06-17 04:16:33 +00:00
kre
354d46cb96 s/volatile/const/ -- wonderful how opposites attract like this. 2017-06-17 04:12:06 +00:00
kre
e4db6fa481 (Perhaps) temporary fix to pkgtools (cwrappers) build (configure).
Expanding  `` containing \ \n sequences looks to have been giving
problems.   I don't think this is the correct fix, but it will do
no worse harm than (perhaps) incorrectly calculating LINENO in this
kind of (rare) circumstance.   I'll look and see if there should be
a better fix later.
2017-06-08 22:10:39 +00:00
kre
d13b59261c Correct spelling in comments of DEBUG only code... 2017-06-08 13:17:00 +00:00
kre
15de6ce7d7 Remove some left over baggage from the LINENO v1 implementation that
didn't get removed with v2, and should have.   This would have had
(I think, without having tested it) one very minor effect on the way
LINENO worked in the v2 implementation, but my guess is it would have
taken a long time before anyone noticed...
2017-06-08 13:12:17 +00:00
kre
09cdcbe36d I am an idiot... revert the previous unintended commit. 2017-06-08 02:25:43 +00:00
kre
205db3db95 Improve the (new) LINENO section, markup changes (with thanks to wiz@ for
assistace) and some better wording in a few placed.
2017-06-08 02:23:51 +00:00
wiz
c090f1523c New sentence, new line. Whitespace. 2017-06-07 13:49:48 +00:00
kre
51791eabef PR bin/52280
removescapes_nl in expari() even when not quoted,
CRTNONL's appear regardless of quoting (unlike CTLESC).
2017-06-07 09:31:30 +00:00
kre
f7d07fc011 Undo some over agressive fixes for a (pre-commit) bug that did not
need these changes to be fixed - and these cause problems in another
absurd use case.   Either of these issues is unlikely to be seen by
anyone who isn't an idiot masochist...
2017-06-07 08:10:31 +00:00
kre
69c48e3253 Set the line number before expanding args, not after. As the line_number
would have usually been set earlier, this change is mostly an effective
no-op, but it is better this way (just in case) - not observed to have
caused any problems.
2017-06-07 08:07:50 +00:00
kre
ce6f66ce50 Unbreak (at least) i386 build .... I have no idea why this built for me on
amd64 (problem was missing prototype for snprintf witout <stdio.h>)

While here, add some (DEBUG mode only) tracing that proved useful in
solving another problem.
2017-06-07 08:06:22 +00:00