Commit graph

67 commits

Author SHA1 Message Date
Jilles Tjoelker c6204d4a81 sh: Some changes to stderr flushing:
* increase buffer size from 100 to 256 bytes
* remove implied flush from out2str(), in particular this avoids unnecessary
  flushing in the middle of a -x tracing line
* rename dprintf() to out2fmt_flush(), make it flush out2 and use this
  function in various places where flushing is desired after an error
  message
2009-11-21 14:28:32 +00:00
Jilles Tjoelker 7ab07e8ada sh: Allow a newline before "in" in a for command, as required by POSIX. 2009-11-14 22:08:32 +00:00
Jilles Tjoelker f6196ed2d4 sh: Show more information about syntax errors in command substitution:
the line number where the command substitution started.
This applies to both the $() and `` forms but is most useful for ``
because the other line number is relative to the enclosed text there.
(For older versions, -v can be used as a workaround.)
2009-10-16 16:17:57 +00:00
Jilles Tjoelker 47e5ae08a1 sh: Disallow mismatched quotes in backticks (...).
Due to the amount of code removed by this, it seems that allowing unmatched
quotes was a deliberate imitation of System V sh and real ksh. Most other
shells do not allow unmatched quotes (e.g. bash, zsh, pdksh, NetBSD /bin/sh,
dash).

PR:		bin/137657
2009-10-01 21:40:08 +00:00
Jilles Tjoelker 224fbf9fd6 sh: Improve handling of setjmp/longjmp volatile:
- remove ineffective and unnecessary (void) &var; [1]
- remove some unnecessary volatile keywords
- add a necessary volatile keyword
- save the old handler before doing something that could use the saved
  value

Submitted by:	Christoph Mallon [1]
Approved by:	ed (mentor)
2009-06-23 20:45:12 +00:00
Ralf S. Engelschall 26286b8acf correctly test for __GNUC__ macro (non-GCC compilers do not have it defined at all) 2009-06-01 11:02:09 +00:00
Stefan Farfeleder 515c60105d Parse 'cmd1 && ! cmd2 | cmd3' correctly, the bang should apply to the entire
pipeline cmd2 | cmd3 and not just cmd2.

PR:		130298
Submitted by:	Jilles Tjoelker
2009-04-13 19:10:56 +00:00
Stefan Farfeleder 4f30f2993f Fix checking if a variable name is LINENO. As STPUTC changes the pointer if it
needs to enlarge the buffer, we must not keep a pointer to the beginning.

PR:	ports/123879
2008-05-28 21:44:32 +00:00
Stefan Farfeleder b71085aacf Expand $LINENO to the current line number. This is required by SUSv3's "User
Portability Utilities" option.

Often configure scripts generated by the autotools test if $LINENO works and
refuse to use /bin/sh if not.

Package test run by:	pav
2008-05-15 19:55:27 +00:00
Stefan Farfeleder 62addaefc9 When parsing an invalid parameter expansion (eg. ${} or ${foo@bar}) do not
issue a syntax error immediately but save the information that it is erroneous
for later when the parameter expansion is actually done.  This means eg. "false
&& ${}" will not generate an error which seems to be required by POSIX.
Include the invalid parameter expansion in the error message (sometimes
abbreviated with ... because recovering it would require a lot of code).

PR:		105078
Submitted by:	emaste
2006-11-05 18:36:05 +00:00
Yaroslav Tykhiy 62f9f95382 Do not forget to increment the input line counter
when reading a word spanning multiple lines.

PR:		bin/101094
MFC after:	5 days
2006-07-31 11:32:12 +00:00
Stefan Farfeleder 811beb4b88 Remove a hack for an ancient gdb. 2005-08-15 17:49:38 +00:00
Stefan Farfeleder 716b138b4b Put the comparison with PEOF into a new macro is_eof(). Don't use it if the
character comes from a string.
2005-08-13 15:47:13 +00:00
Stefan Farfeleder 8d99957008 Use assignment rather than comparison. 2005-08-13 15:00:54 +00:00
Stefan Farfeleder 955e9f68da Include missing headers. 2005-08-13 08:26:58 +00:00
David E. O'Brien f0c73601c1 Support \H, \h, \w, \W, \$ string expansion in the prompt.
Submitted by:	mini
2005-03-01 03:35:58 +00:00
Mark Murray 6195fb4102 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
Dag-Erling Smørgrav 7e1c72660f Replace home-grown dup2() implementation with actual dup2() calls. This
should slightly reduce the number of system calls in critical portions of
the shell, and select a more efficient path through the fdalloc code.

Reviewed by:	bde
2004-01-21 12:50:01 +00:00
Diomidis Spinellis 2ba1b30bf5 Changes following CScout analysis:
- Removed dead declarations
- Made objects that should have been declared as static, static.

The changes use STATIC instead of static, following the existing
convention in the rest of the code.

Approved by:	schweikh (mentor)
MFC after:	2 weeks
2003-07-05 15:18:44 +00:00
Tim J. Robbins 427748f7df Disallow empty condition parts of "if", "while" and "until" compound
commands. Commands like "if then ... fi" and "while do ... done" are no
longer accepted. Bodies of compound commands are still allowed to be
empty, because even though POSIX does not allow them, most shells do.
2002-10-06 06:35:51 +00:00
Tim J. Robbins b1a667509b Remove bits and pieces of support for atty, which was made obsolete by
adding history and vi/emacs-style line editing to the shell itself.
Atty was a user-mode terminal emulator (like screen and window) that did
line editing and history.
2002-10-01 00:54:14 +00:00
Tim J. Robbins f7a9b7fe3a Allow a left parenthesis before patterns in case blocks. POSIX requires
us to accept this, but I've never seen a script that uses it.
2002-09-30 13:25:00 +00:00
Tim J. Robbins e00e16ad7f Allow empty case/esac statements; POSIX requires this, and recent versions
of autoconf are generating scripts that use this feature.

PR:		43275 35879
Submitted by:	Dan Nelson <dnelson@allantgroup.com>
2002-09-30 10:57:44 +00:00
Philippe Charnier 0d9f1a69d8 Replace various spellings with FALLTHROUGH which is lint()able 2002-08-25 13:01:47 +00:00
Tim J. Robbins d8d737d751 Allow redirections by themselves between "&&" and "||" operators.
For example, >/dev/null && echo foo

Pointed out by:	FUJISHIMA Satsuki
MFC after:	1 week
2002-08-11 03:04:23 +00:00
Tim J. Robbins 776600e6de Don't allow "||" or "&&" to be the first tokens of a command.
PR:		40386
MFC after:	2 weeks
2002-07-22 05:50:12 +00:00
David E. O'Brien 2749b14129 Consistently use FBSDID 2002-06-30 05:15:05 +00:00
Juli Mallett 8b7808bc49 Minor const cleanup.
Don't discard qualifiers we don't need to discard.
2002-06-20 05:20:50 +00:00
Tim J. Robbins 1a958c6653 Implement the -C (-o noclobber) option, which prevents existing regular
files from being overwritten by shell redirection.
2002-05-19 06:03:05 +00:00
Warner Losh 5134c3f799 o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
  they already are.
o Change
	int
	foo() {
	...
  to
	int
	foo(void)
	{
	...
2002-02-02 06:50:57 +00:00
Tor Egge 0c4eedda7b BASESYNTAX, DQSYNTAX, SQSYNTAX and ARISYNTAX handles negative indexes.
Allow those to be used to properly quote characters in the shell
control character range.
2001-09-19 20:07:47 +00:00
Brian Somers b785bd7d3b `|'' should be more binding than `!'' so that this isn't broken:
if ! echo bla | wc -c ; then
		echo broken
	fi

Obtained from: NetBSD
2001-04-09 12:46:19 +00:00
Brian Somers 6c0bde79a8 A much better (more correct) fix for handling ``!'' characters
Obtained from: NetBSD
2001-04-04 10:11:43 +00:00
Brian Somers 51a9b1c281 Handle ``!'' characters when they appear as second and subsequent
parts of an && or || expression.

This makes this expression work as expected:

	if true && ! false; then echo yes; fi
2001-04-04 09:30:50 +00:00
Brian Somers 4682f420f2 Implement the <> redirection operator. 2000-10-03 23:13:14 +00:00
Martin Cracauer b5803eae6a Disable part of my 8-bits fixes from December 1999.
Serious fix still needed, see discussion on -current
(Subject: /bin/sh dumps core with here-document of 8bit text)

Problem in this code originally spotted by
Jun Kuriyama <kuriyama@FreeBSD.org>
2000-08-16 12:23:57 +00:00
Martin Cracauer 98e05fd3ef Fix parsing of string for eval command.
PR:		18447
Submitted by:	Koji Mori <mori@tri.asanuma.co.jp>
2000-05-15 13:02:07 +00:00
Martin Cracauer f01e3d0cfe Fix warnings, some of them serious because sh violated name
spaces reserved by the header files it includes.

mkinit.c still produces C code with redundant declarations, although
they are more harmless since they automatically derived from the right
places.
2000-04-20 09:49:16 +00:00
Martin Cracauer c11e75cfcf Fix ${#varname} (getting length of string) when in double-quotes.
Approved-by:	jkh

PR:		bin/12137
Submitted by:	"Danny J. Zerkel" <dzerkel@columbus.rr.com>
2000-02-15 08:00:11 +00:00
Martin Cracauer 2dde9ce37a Second part of 8-bit fixes. 1999-12-16 12:03:46 +00:00
Martin Cracauer 73f612b50d First round of 8-bit fixes. 1999-12-15 11:46:32 +00:00
Martin Cracauer e92feeebb1 Fix "subscript has type `char'" warnings by casting to int, as
discussed on -arch.
1999-12-04 17:12:47 +00:00
Peter Wemm 2a4562393f $Id$ -> $FreeBSD$ 1999-08-27 23:15:48 +00:00
Tor Egge 5557a02a60 Be more consistent with handling of quote mark control character.
Don't output double-quotes inside variable expansion/arithmetic
expansion region in here-documents.  When leaving the arithmetic
expansion syntax mode, adjust the dblquote flag according to
previous syntax, in order to avoid splitting of quoted variables.
1998-09-13 19:24:57 +00:00
Tor Egge 6f47734fd7 Better handling of word splitting. Don't record the same region
multiple times when performing nested variable expansion, and
preserve some quoting information in order to avoid removing
apparently empty expansion result.
1998-09-06 21:13:09 +00:00
Philippe Charnier 3d7b5b9302 Add rcsid. Spelling. 1998-05-18 06:44:24 +00:00
Steve Price e7a0b0244d Use the __unused attribute where warranted. 1997-05-19 00:18:52 +00:00
Steve Price 7920a31db6 Revert changes from rev 1.16 to 1.17 for now. Closes PR 2879. 1997-04-28 03:22:09 +00:00
Peter Wemm b97fa2ef50 Revert $FreeBSD$ to $Id$ 1997-02-22 14:13:04 +00:00
Jordan K. Hubbard 1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00