sh: Improve comments in expand.c.
This commit is contained in:
parent
049640c1f0
commit
2ca3d70fc6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=212243
@ -138,12 +138,18 @@ expandhere(union node *arg, int fd)
|
||||
|
||||
|
||||
/*
|
||||
* Perform variable substitution and command substitution on an argument,
|
||||
* placing the resulting list of arguments in arglist. If EXP_FULL is true,
|
||||
* perform splitting and file name expansion. When arglist is NULL, perform
|
||||
* here document expansion.
|
||||
* Perform expansions on an argument, placing the resulting list of arguments
|
||||
* in arglist. Parameter expansion, command substitution and arithmetic
|
||||
* expansion are always performed; additional expansions can be requested
|
||||
* via flag (EXP_*).
|
||||
* The result is left in the stack string.
|
||||
* When arglist is NULL, perform here document expansion. A partial result
|
||||
* may be written to herefd, which is then not included in the stack string.
|
||||
*
|
||||
* Caution: this function uses global state and is not reentrant.
|
||||
* However, a new invocation after an interrupted invocation is safe
|
||||
* and will reset the global state for the new call.
|
||||
*/
|
||||
|
||||
void
|
||||
expandarg(union node *arg, struct arglist *arglist, int flag)
|
||||
{
|
||||
@ -195,11 +201,14 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
|
||||
|
||||
|
||||
/*
|
||||
* Perform variable and command substitution. If EXP_FULL is set, output CTLESC
|
||||
* characters to allow for further processing. Otherwise treat
|
||||
* $@ like $* since no splitting will be performed.
|
||||
* Perform parameter expansion, command substitution and arithmetic
|
||||
* expansion, and tilde expansion if requested via EXP_TILDE/EXP_VARTILDE.
|
||||
* Processing ends at a CTLENDVAR character as well as '\0'.
|
||||
* This is used to expand word in ${var+word} etc.
|
||||
* If EXP_FULL, EXP_CASE or EXP_REDIR are set, keep and/or generate CTLESC
|
||||
* characters to allow for further processing.
|
||||
* If EXP_FULL is set, also preserve CTLQUOTEMARK characters.
|
||||
*/
|
||||
|
||||
STATIC void
|
||||
argstr(char *p, int flag)
|
||||
{
|
||||
@ -212,7 +221,7 @@ argstr(char *p, int flag)
|
||||
for (;;) {
|
||||
switch (c = *p++) {
|
||||
case '\0':
|
||||
case CTLENDVAR: /* ??? */
|
||||
case CTLENDVAR:
|
||||
goto breakloop;
|
||||
case CTLQUOTEMARK:
|
||||
/* "$@" syntax adherence hack */
|
||||
@ -262,6 +271,10 @@ argstr(char *p, int flag)
|
||||
breakloop:;
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform tilde expansion, placing the result in the stack string and
|
||||
* returning the next position in the input string to process.
|
||||
*/
|
||||
STATIC char *
|
||||
exptilde(char *p, int flag)
|
||||
{
|
||||
@ -367,12 +380,11 @@ expari(int flag)
|
||||
int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
|
||||
int quoted;
|
||||
|
||||
|
||||
/*
|
||||
* This routine is slightly over-complicated for
|
||||
* efficiency. First we make sure there is
|
||||
* enough space for the result, which may be bigger
|
||||
* than the expression if we add exponentiation. Next we
|
||||
* than the expression. Next we
|
||||
* scan backwards looking for the start of arithmetic. If the
|
||||
* next previous character is a CTLESC character, then we
|
||||
* have to rescan starting from the beginning since CTLESC
|
||||
@ -413,9 +425,8 @@ expari(int flag)
|
||||
|
||||
|
||||
/*
|
||||
* Expand stuff in backwards quotes.
|
||||
* Perform command substitution.
|
||||
*/
|
||||
|
||||
STATIC void
|
||||
expbackq(union node *cmd, int quoted, int flag)
|
||||
{
|
||||
@ -974,6 +985,12 @@ recordregion(int start, int end, int inquotes)
|
||||
* Break the argument string into pieces based upon IFS and add the
|
||||
* strings to the argument list. The regions of the string to be
|
||||
* searched for IFS characters have been stored by recordregion.
|
||||
* CTLESC characters are preserved but have little effect in this pass
|
||||
* other than escaping CTL* characters. In particular, they do not escape
|
||||
* IFS characters: that should be done with the ifsregion mechanism.
|
||||
* CTLQUOTEMARK characters are used to preserve empty quoted strings.
|
||||
* This pass treats them as a regular character, making the string non-empty.
|
||||
* Later, they are removed along with the other CTL* characters.
|
||||
*/
|
||||
STATIC void
|
||||
ifsbreakup(char *string, struct arglist *arglist)
|
||||
@ -1075,15 +1092,14 @@ ifsbreakup(char *string, struct arglist *arglist)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Expand shell metacharacters. At this point, the only control characters
|
||||
* should be escapes. The results are stored in the list exparg.
|
||||
*/
|
||||
|
||||
STATIC char expdir[PATH_MAX];
|
||||
#define expdir_end (expdir + sizeof(expdir))
|
||||
|
||||
/*
|
||||
* Perform pathname generation and remove control characters.
|
||||
* At this point, the only control characters should be CTLESC and CTLQUOTEMARK.
|
||||
* The results are stored in the list exparg.
|
||||
*/
|
||||
STATIC void
|
||||
expandmeta(struct strlist *str, int flag __unused)
|
||||
{
|
||||
@ -1469,7 +1485,7 @@ dft: default:
|
||||
|
||||
|
||||
/*
|
||||
* Remove any CTLESC characters from a string.
|
||||
* Remove any CTLESC and CTLQUOTEMARK characters from a string.
|
||||
*/
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user