summaryrefslogtreecommitdiffstats
path: root/bin/sh/parser.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Simplify list() in the parser.jilles2013-08-301-21/+22
| | | | | | The erflag argument was only used by old-style (``) command substitutions. We can remove it and handle the special case in the command substitution code.
* sh: Separate out nbinary allocation into a function.jilles2013-08-301-21/+22
|
* sh: Use makename() where possible.jilles2013-08-301-22/+5
|
* sh: Add a function for the case where one token is required in the parse.jilles2013-08-301-31/+23
|
* sh: Cast -1 to pointer rather than pointer to variable of wrong type.jilles2013-08-301-1/+1
| | | | | | | | | | NEOF needs to be a non-null pointer distinct from valid union node pointers. It is not dereferenced. The new NEOF is much like SIG_ERR except that it is an object pointer instead of a function pointer. The variable tokpushback can now be static.
* sh: Disallow empty simple commands.jilles2013-08-251-8/+4
| | | | | | | | | | As per POSIX, a simple command must have at least one redirection, assignment word or command word. These occured in rare cases such as eval "f()" . The extension of allowing no commands inside { }, if, while, for, etc. remains.
* sh: Remove unnecessary reset functions.jilles2013-08-161-8/+1
| | | | These are already handled by exception handlers.
* sh: Allow a lone redirection before '|', ';;' or ';&'.jilles2013-08-141-0/+3
| | | | | | | Example: </dev/null | : PR: 181240 MFC after: 1 week
* sh: Remove an incorrect comment.jilles2013-07-251-1/+1
|
* sh: Remove #define MKINIT.jilles2013-07-251-2/+2
| | | | MKINIT only served for the removed mkinit. Many variables can be static now.
* sh: Remove mkinit.jilles2013-07-251-4/+4
| | | | | | | | | | | | | | Replace the RESET blocks with regular functions and a reset() function that calls them all. This code generation tool is unusual and does not appear to provide much benefit. I do not think isolating the knowledge about which modules need to be reset is worth an almost 500-line build tool and wider scope for variables used by the reset functions. Also, relying on reset functions is often wrong: the cleanup should be done in exception handlers so that no stale state remains after 'command eval' and the like.
* sh: Fix various compiler warnings.jilles2013-04-011-5/+6
| | | | | | | It now passes WARNS=7 with clang on i386. GCC 4.2.1 does not understand setjmp() properly so will always trigger -Wuninitialized. I will not add the volatile keywords to suppress this.
* sh: Fix crash when parsing '{ } &'.jilles2013-01-131-2/+2
| | | | MFC after: 1 week
* sh: Don't lose $? when backquoted command ends with semicolon or newline.jilles2013-01-131-1/+2
| | | | | | | | | An empty simple command was added and overwrote the exit status with 0. This affects `...` but not $(...). Example: v=`false;`; echo $?
* sh: Remove special support for background simple commands.jilles2011-06-181-3/+2
| | | | It expands the arguments in the parent shell process, which is incorrect.
* sh: Add case statement fallthrough (with ';&' instead of ';;').jilles2011-06-171-4/+10
| | | | | | | | | | | | Replacing ;; with the new control operator ;& will cause the next list to be executed as well without checking its pattern, continuing until a list ends with ;; or until the end of the case statement. This is like omitting "break" in a C "switch" statement. The sequence ;& was formerly invalid. This feature is proposed for the next POSIX issue in Austin Group issue #449.
* sh: Do parameter expansion before printing PS4 (set -x).jilles2011-06-091-0/+44
| | | | | | | | | | | | | | | | The function name expandstr() and the general idea of doing this kind of expansion by treating the text as a here document without end marker is from dash. All variants of parameter expansion and arithmetic expansion also work (the latter is not required by POSIX but it does not take extra code and many other shells also allow it). Command substitution is prevented because I think it causes too much code to be re-entered (for example creating an unbounded recursion of trace lines). Unfortunately, our LINENO is somewhat crude, otherwise PS4='$LINENO+ ' would be quite useful.
* sh: Expand aliases after assignments and redirections.jilles2011-05-211-0/+22
|
* sh: Allow terminating a heredoc with a terminator at EOF without a newline.jilles2011-05-201-3/+5
| | | | | | | | | | | | | | | | | | | | | | This is sometimes used with eval or old-style command substitution, and most shells other than ash derivatives allow it. It can also be used with scripts that violate POSIX's requirement on the application that they end in a newline (scripts must be text files except that line length is unlimited). Example: v=`cat <<EOF foo EOF` echo $v This commit does not add support for the similar construct with new-style command substitution, like v=$(cat <<EOF foo EOF) This continues to require a newline after the terminator.
* sh: Add \u/\U support (in $'...') for UTF-8.jilles2011-05-081-0/+23
| | | | | | | | | | Because we have no iconv in base, support for other charsets is not possible. Note that \u/\U are processed using the locale that was active when the shell started. This is necessary to avoid behaviour that depends on the parse/execute split (for example when placing braces around an entire script). Therefore, UTF-8 encoding is implemented manually.
* sh: Add $'quoting' (C-style escape sequences).jilles2011-05-051-6/+139
| | | | | | | | | | | | | | | | | | | | | | | | A string between $' and ' may contain backslash escape sequences similar to the ones in a C string constant (except that a single-quote must be escaped and a double-quote need not be). Details are in the sh(1) man page. This construct is useful to include unprintable characters, tabs and newlines in strings; while this can be done with a command substitution containing a printf command, that needs ugly workarounds if the result is to end with a newline as command substitution removes all trailing newlines. The construct may also be useful in future to describe unprintable characters without needing to write those characters themselves in 'set -x', 'export -p' and the like. The implementation attempts to comply to the proposal for the next issue of the POSIX specification. Because this construct is not in POSIX.1-2008, using it in scripts intended to be portable is unwise. Matching the minimal locale support in the rest of sh, the \u and \U sequences are currently not useful. Exp-run done by: pav (with some other sh(1) changes)
* sh: Detect an error for ${#var<GARBAGE>}.jilles2011-05-041-0/+2
| | | | | | | | | In particular, this makes things like ${#foo[0]} and ${#foo[@]} errors rather than silent equivalents of ${#foo}. PR: bin/151720 Submitted by: Mark Johnston Exp-run done by: pav (with some other sh(1) changes)
* sh: Do not word split "${#parameter}".jilles2011-04-201-2/+2
| | | | | | | | | | | | | This is only a problem if IFS contains digits, which is unusual but valid. Because of an incorrect fix for PR bin/12137, "${#parameter}" was treated as ${#parameter}. The underlying problem was that "${#parameter}" erroneously added CTLESC bytes before determining the length. This was properly fixed for PR bin/56147 but the incorrect fix was not backed out. Reported by: Seeker on forums.freebsd.org MFC after: 2 weeks
* sh: Fix some parameter expansion variants ${#...}.jilles2011-03-131-19/+30
| | | | | | | | | These already worked: $# ${#} ${##} ${#-} ${#?} These now work as well: ${#+word} ${#-word} ${##word} ${#%word} There is an ambiguity in the standard with ${#?}: it could be the length of $? or it could be $# giving an error in the (impossible) case that it is not set. We continue to use the former interpretation as it seems more useful.
* sh: Fix two things about {(...)} <redir:jilles2011-02-051-1/+4
| | | | | | | | * In {(...) <redir1;} <redir2, do not drop redir1. * Maintain the difference between (...) <redir and {(...)} <redir: In (...) <redir, the redirection is performed in the child, while in {(...)} <redir it should be performed in the parent (like {(...); :;} <redir)
* sh: Allow arbitrary large numbers in CHECKSTRSPACE.jilles2010-12-261-2/+1
| | | | | | Reduce "stack string" API somewhat and simplify code. Add a check for integer overflow of the "stack string" length (probably incomplete).
* Remove duplicate check, turning dead code into live code.uqs2010-12-131-2/+0
| | | | | Coverity CID: 5114 Reviewed by: jilles
* sh: Code size optimizations to "stack string" memory allocation:jilles2010-11-231-7/+6
| | | | | | | | * Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC. * Add STPUTS macro (based on function) and use it instead of loops that add nul-terminated strings to the stack string. No functional change is intended, but code size is about 1K less on i386.
* sh: Fix some issues with aliases and case, by importing dash checkkwd code.jilles2010-11-021-50/+49
| | | | | | | | | | | This moves the function of the noaliases variable into the checkkwd variable. This way it is properly reset on errors and aliases can be used normally in the commands for each case (the case labels recognize the keyword esac but no aliases). The new code is clearer as well. Obtained from: dash
* sh: Use iteration instead of recursion to evaluate semicolon lists.jilles2010-10-311-10/+17
| | | | | This reduces CPU and memory usage when executing long lists (such as long functions).
* sh: Tweak some string constants to reduce code size.jilles2010-10-291-1/+1
| | | | | * Reduce some needless differences. * Shorten some error messages that should not happen.
* sh: Reject function names ending in one of !%*+-=?@}~jilles2010-10-291-1/+5
| | | | | | | | | These do something else in ksh: name=(...) is an array or compound variable assignment and the others are extended patterns. This is the last patch of the ones tested in the exp run. Exp-run done by: pav (with some other sh(1) changes)
* sh: Detect various additional errors in the parser.jilles2010-10-291-3/+3
| | | | | | | | | | | | | Apart from detecting breakage earlier or at all, this also fixes a segfault in the testsuite. The "handling" of the breakage left an invalid internal representation in some cases. Examples: echo a; do echo b echo `) echo a` echo `date; do do do` Exp-run done by: pav (with some other sh(1) changes)
* sh: Error out on various specials/keywords in the wrong place in backticks.jilles2010-10-291-16/+16
| | | | | | | | Example: echo `date)` Exp-run done by: pav (with some other sh(1) changes) Obtained from: NetBSD (Christos Zoulas, NetBSD PR 11317)
* sh: Do IFS splitting on word in ${v+word} and ${v-word}.jilles2010-10-291-4/+12
| | | | | | | | | | | | | | | | | The code is inspired by NetBSD sh somewhat, but different because we preserve the old Almquist/Bourne/Korn ability to have an unquoted part in a quoted ${v+word}. For example, "${v-"*"}" expands to $v as a single field if v is set, but generates filenames otherwise. Note that this is the only place where we split text literally from the script (the similar ${v=word} assigns to v and then expands $v). The parser must now add additional markers to allow the expansion code to know whether arbitrary characters in substitutions are quoted. Example: for i in ${$+a b c}; do echo $i; done Exp-run done by: pav (with some other sh(1) changes)
* sh: Only accept a '}' inside ${v+-=?...} if double-quote state matches.jilles2010-10-281-4/+4
| | | | | | | | | | | | | If double-quote state does not match, treat the '}' literally. This ensures double-quote state remains the same before and after a ${v+-=?...} which helps with expand.c. It makes things like ${foo+"\${bar}"} which I have seen in the wild work as expected. Exp-run done by: pav (with some other sh(1) changes)
* sh: Make double-quotes quote a '}' inside ${v#...} and ${v%...}.jilles2010-10-281-1/+2
| | | | | Exp-run done by: pav (with some other sh(1) changes) PR: bin/57554
* sh: Ignore double-quotes in arithmetic rather than treating them as quotes.jilles2010-10-241-4/+3
| | | | | | | | This provides similar behaviour, but allows a simpler parser. This changes r206473. Exp-run done by: pav (with some other sh(1) changes)
* sh: Do not allow overriding a special builtin with a function.jilles2010-10-241-0/+5
| | | | | | | | | | | | | | | | | This is a syntax error. POSIX does not say explicitly whether defining a function with the same name as a special builtin is allowed, but it does say that it is impossible to call such a function. A special builtin can still be overridden with an alias. This commit is part of a set of changes that will ensure that when something looks like a special builtin to the parser, it is one. (Not the other way around, as it remains possible to call a special builtin named by a variable or other substitution.) Exp-run done by: pav (with some other sh(1) changes)
* sh: Make sure defined functions can actually be called.jilles2010-10-241-3/+7
| | | | | | | | | | | | | | | | | Add some conservative checks on function names: - Disallow expansions or quoting characters; these can only be called via strange control characters - Disallow '/'; these functions cannot be called anyway, as exec.c assumes they are pathnames - Make the CTL* bytes work properly in function names. These are syntax errors. POSIX does not require us to support more than names (letters, digits and underscores, not starting with a digit), but I do not want to restrict it that much at this time. Exp-run done by: pav (with some other sh(1) changes)
* sh: Change ! within a pipeline to start a new pipeline instead.jilles2010-10-241-19/+11
| | | | | | | | | | | | | | This is how ksh93 treats ! within a pipeline and makes the ! in a | ! b | c negate the exit status of the pipeline, as if it were a | { ! b | c; } Side effect: something like f() ! a is now a syntax error, because a function definition takes a command, not a pipeline. Exp-run done by: pav (with some other sh(1) changes)
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroobrien2010-10-131-44/+44
| | | | and its usage.
* Consistently use "STATIC" for all functions in order to be able to setobrien2010-10-131-13/+14
| | | | | | breakpoints with in a debugger. And use naked "static" for variables. Noticed by: bde
* sh: Add __dead2 to two functions that do not return.jilles2010-09-121-2/+2
| | | | | Apart from helping static analyzers, this also appears to reduce the size of the binary slightly.
* sh: Fix crash due to uninitialized here-document.jilles2010-07-251-0/+3
| | | | | | | | | | | | | | | If an ; or & token was followed by an EOF token, pending here-documents were left uninitialized. Execution would crash, either in the main shell process for literal here-documents or in a child process for expanded here-documents. In the latter case the problem is hard to detect apart from the core dumps and log messages. Side effect: slightly different retries on inputs where EOF is not persistent. Note that tools/regression/bin/sh/parser/heredoc6.0 still causes a similar crash in a child process. The text passed to eval is malformed and should be rejected.
* sh: Allow a background command consisting solely of redirections.jilles2010-07-181-0/+1
| | | | | | | Example: </dev/null & MFC after: 2 weeks
* sh: There cannot be a TNOT in simplecmd(), remove checks.jilles2010-07-141-19/+3
| | | | | | simplecmd() only handles simple commands and function definitions, neither of which involves the ! keyword. The initial token on entry to simplecmd() is one of the following: TSEMI, TAND, TOR, TNL, TEOF, TWORD, TRP.
* sh: Use $PWD instead of getcwd() for the \w and \W prompt expansions.jilles2010-07-021-12/+11
| | | | | | This ensures that the logical working directory (which may include symlinks) is shown and is similar to the default behaviour of the pwd builtin.
* sh: Fix compilation with -DNO_HISTORY.jilles2010-06-191-0/+1
| | | | | | | | | | | The LINENO code uses snprintf() and relied on "myhistedit.h" to pull in the necessary <stdio.h>. Compiling with -DNO_HISTORY disables all editing and history support and allows linking without -ledit -ltermcap. This may be useful for embedded systems. MFC after: 2 weeks
* sh: Fix a crash if a heredoc was not properly ended and parsing continued.jilles2010-05-301-0/+1
| | | | | | | | | Example (in interactive mode): cat <<EOF && ) The next command typed caused sh to segfault, because the state for the here document was not reset. Like parser_temp, this uses the fact that the parser is not re-entered.
OpenPOWER on IntegriCloud