summaryrefslogtreecommitdiffstats
path: root/bin/sh/expand.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix expanding of quoted positional parameters in case patterns.stefanf2006-11-071-6/+6
| | | | | | Obtained from: NetBSD (expand.c 1.58 and 1.59) Submitted by: Paul Jarc PR: 56147
* When parsing an invalid parameter expansion (eg. ${} or ${foo@bar}) do notstefanf2006-11-051-0/+5
| | | | | | | | | | | 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
* Remove some white space at EOL.schweikh2006-02-041-8/+8
|
* Various small code cleanups resulting from a code reviewingrse2005-09-061-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and linting procedure: 1. Remove useless sub-expression: - if (*start || (!ifsspc && start > string && (nulonly || 1))) { + if (*start || (!ifsspc && start > string)) { The sub-expression "(nulonly || 1)" always evaluates to true and according to CVS logs seems to be just a left-over from some debugging and introduced by accident. Removing the sub-expression doesn't change semantics and a code inspection showed that the variable "nulonly" is also not necessary here in any way (and the expression would require fixing instead of removing). 2. Remove dead code: - if (backslash && c == '\\') { - if (read(STDIN_FILENO, &c, 1) != 1) { - status = 1; - break; - } - STPUTC(c, p); - } else if (ap[1] != NULL && strchr(ifs, c) != NULL) { + if (ap[1] != NULL && strchr(ifs, c) != NULL) { Inspection of the control and data flow showed that variable "backslash" is always false (0) when the "if"-expression is evaluated, hence the whole block is effectively dead code. Additionally, the skipping of characters after a backslash is already performed correctly a few lines above, so this code is also not needed at all. According to the CVS logs and the ASH 0.2 sources, this code existed in this way already since its early days. 3. Cleanup Style: - ! trap[signo][0] == '\0' && + ! (trap[signo][0] == '\0') && The expression wants to ensure the trap is not assigned the empty string. But the "!" operator has higher precedence than "==", so the comparison should be put into parenthesis to form the intended way of expression. Nevertheless the code was effectively not really broken as both particular NUL comparisons are semantically equal, of course. But the parenthesized version is a lot more intuitive. 4. Remove shadowing variable declaration: - char *q; The declaration of symbol "q" hides another identical declaration of "q" in the same context. As the other "q" is already reused multiple times and also can be reused again without negative side-effects, just remove the shadowing declaration. 5. Just small cosmetics: - if (ifsset() != 0) + if (ifsset()) The ifsset() macro is already coded by returning the boolean result of a comparison operator, so no need to compare this boolean result again against a numerical value. This also aligns the macros usage to the remaining existing code. Reviewed by: stefanf@
* Fix a bug when shell expansion is done against dangling symlinks, bydelphij2005-07-071-1/+1
| | | | | | | | | | | | converting the stat() call to a lstat() call, which will cover the situation. One can exercise this bug by referring a dangling link with something like */the-link. Approved by: re (scottl) Submitted by: Simon 'corecode' Schubert [corecode fs ei tum de] Obtained from: NetBSD via DragonFlyBSD (NetBSD rev. 1.51 and DragonFly rev. 1.6) MFC After: 3 days
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* Remove collate_range_cmp() stabilization, it conflicts with rangesache2003-08-031-9/+2
|
* Changes following CScout analysis:dds2003-07-051-6/+6
| | | | | | | | | | | - 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
* Instead of eating trailing newlines after inserting them into thefenner2003-05-311-5/+12
| | | | | | | | | | | | | output buffer, don't insert them at all. This prevents a buffer *underrun* when the substitution consists completely of newlines (e.g. `echo`) and the byte before the source buffer to which p points is a '\n', in which case more characters would be removed from the output buffer than were inserted. This fixes certain port builds on sparc64. Approved by: re (scottl) Reviewed by: des, tjr
* Fixed (soon might be fatal) -Wformat warnings.ru2003-03-151-2/+3
|
* Do not strip CTL* escapes from redirection filenames in exptilde(),tjr2003-01-081-4/+4
| | | | | | | | expari(), expbackq() and evalvar(). Similar to revision 1.39. Patch from Tor Egge. PR: 45349 MFC after: 2 weeks
* Add the "wordexp" shell built-in command which will be used to implementtjr2002-12-261-0/+22
| | | | the POSIX wordexp() function.
* Do not strip CTL* escapes from redirection filenames in argstr(); theytjr2002-10-081-1/+1
| | | | | | | | are later stripped with rmescapes() in expandarg(). If the filename has already been unescaped, doing it again in rmescapes() can walk off the end of the string, leading to memory corruption and eventually SIGSEGV. Noticed by: kris
* Replace various spellings with FALLTHROUGH which is lint()ablecharnier2002-08-251-1/+1
|
* Consistently use FBSDIDobrien2002-06-301-2/+2
|
* Implement the -u (-o nounset) option, which gives an error message iftjr2002-05-191-0/+11
| | | | | | an unset variable is expanded. Obtained from: NetBSD (bjh21, christos)
* o __P has been reovedimp2002-02-021-104/+56
| | | | | | | | | | | | | | | | | | 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) { ...
* Don't check uninitialized memory for having the shell control charactertegge2001-09-191-4/+4
| | | | | | | | | | | value CTLARI since this might break expansion of arithmetic expressions. Don't access memory below start of stackblock. Problem analyzed by hunt@iprg.nokia.com, slightly different patch applied. PR: 24443 Submitted by: hunt@iprg.nokia.com
* BASESYNTAX, DQSYNTAX, SQSYNTAX and ARISYNTAX handles negative indexes.tegge2001-09-191-4/+4
| | | | | Allow those to be used to properly quote characters in the shell control character range.
* Fix environment passung to eval'ed commands.cracauer2000-05-151-1/+1
| | | | | | PR: bin/6577 Submitted by: Anatoly Vorobey <mellon@pobox.com> Approved by: silence amoung other sh experts
* First round of 8-bit fixes.cracauer1999-12-151-4/+4
|
* Fix "subscript has type `char'" warnings by casting to int, ascracauer1999-12-041-4/+5
| | | | discussed on -arch.
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Various spelling/formatting changes.kris1999-05-081-3/+3
| | | | Submitted by: Philippe Charnier <charnier@xp11.frmug.org>
* Next approach to make loops in interactive interruptable.cracauer1999-04-211-2/+2
| | | | PR: bin/9173
* During variable expansion, the internal representation of the expressiontegge1999-04-131-5/+5
| | | | | might be relocated. Handle this case. PR: 7059
* When a variable expansion is enclosed in double quotes, the internaltegge1999-04-091-14/+54
| | | | | | | | | | | representation of the expression is quoted. Take care of this when doing pattern matching in conjunction with trimming. #!/bin/sh c=d:e; echo "${c%:e}" PR: NetBSD PR#7231 Noticed by: Havard Eidnes <Havard.Eidnes@runit.sintef.no>
* Be more consistent with handling of quote mark control character.tegge1998-09-131-58/+6
| | | | | | | 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.
* Better handling of word splitting. Don't record the same regiontegge1998-09-061-42/+210
| | | | | | multiple times when performing nested variable expansion, and preserve some quoting information in order to avoid removing apparently empty expansion result.
* Add rcsid. Spelling.charnier1998-05-181-3/+5
|
* Back out previous fix - this bug's got diplomatic immunity as a registeredjkh1997-06-191-3/+1
| | | | political issue.
* >Number: 3780jkh1997-06-191-1/+3
| | | | | | | | >Category: bin >Synopsis: WEXITSTATUS() may return nagative value, which causes sh to generate bad $? PR: 3780 Submitted by: sanewo@ba2.so-net.or.jp
* Now [^abc] means the same as [!abc] like bash and *csh already doesache1997-06-061-4/+4
|
* Use the __unused attribute where warranted.steve1997-05-191-2/+2
|
* Sync with NetBSD's revision 1.29 of this file.steve1997-04-281-27/+55
| | | | Obtained from: NetBSD
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Fix a expansion bug that caused the result of `echo $((1 << 30))`steve1997-02-161-2/+5
| | | | | | to get truncated. Submitted by: bde
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-01-141-1/+1
| | | | | | | | 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.
* This doesn't change any behavior, but may be a slightsteve1996-12-211-2/+2
| | | | | | optimization. (num-- > 0) --> (--num >= 0). Obtained from: NetBSD
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-18/+28
| | | | Obtained from: NetBSD, me
* 1) define STATIC as static and not emptyache1996-10-311-2/+20
| | | | 2) replace collate_range_cmp call with its code
* Ok, lets try this again, shall we? It was definatly my mistake, notpeter1996-09-101-16/+20
| | | | Steve's.. :-]
* ack! back these out so I can see what I did wrong. It looks like apeter1996-09-101-19/+15
| | | | patch-by-hand botch, but it sig-11's during make world.
* Fix for PR#1248, sh doesn't expand past ${9}peter1996-09-101-16/+20
| | | | Submitted by: Steve Price <sprice@hiwaay.net>
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-108/+280
| | | | | | | | | | | | | | merge of parallel duplicate work by Steve Price and myself. :-] There are some changes to the build that are my fault... mkinit.c was trying (poorly) to duplicate some of the work that make(1) is designed to do. The Makefile hackery is my fault too, the depend list was incomplete because of some explicit OBJS+= entries, so mkdep wasn't picking up their source file #includes. This closes a pile of /bin/sh PR's, but not all of them.. Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter
* Convert to newly added collate compare functionache1996-08-121-40/+4
|
* Localize itache1996-08-111-2/+40
|
* Remove trailing whitespace.rgrimes1995-05-301-8/+8
| | | | Reviewed by: phk
* Fix the deletion of trailing newlines with backquote expansion.guido1995-03-011-2/+4
| | | | | | Reviewed by: Submitted by: Obtained from:
* Added $Id$dg1994-09-241-0/+2
|
OpenPOWER on IntegriCloud