sh: Improve comments in expand.c.
This commit is contained in:
parent
049640c1f0
commit
2ca3d70fc6
@ -138,12 +138,18 @@ expandhere(union node *arg, int fd)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform variable substitution and command substitution on an argument,
|
* Perform expansions on an argument, placing the resulting list of arguments
|
||||||
* placing the resulting list of arguments in arglist. If EXP_FULL is true,
|
* in arglist. Parameter expansion, command substitution and arithmetic
|
||||||
* perform splitting and file name expansion. When arglist is NULL, perform
|
* expansion are always performed; additional expansions can be requested
|
||||||
* here document expansion.
|
* 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
|
void
|
||||||
expandarg(union node *arg, struct arglist *arglist, int flag)
|
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
|
* Perform parameter expansion, command substitution and arithmetic
|
||||||
* characters to allow for further processing. Otherwise treat
|
* expansion, and tilde expansion if requested via EXP_TILDE/EXP_VARTILDE.
|
||||||
* $@ like $* since no splitting will be performed.
|
* 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
|
STATIC void
|
||||||
argstr(char *p, int flag)
|
argstr(char *p, int flag)
|
||||||
{
|
{
|
||||||
@ -212,7 +221,7 @@ argstr(char *p, int flag)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
switch (c = *p++) {
|
switch (c = *p++) {
|
||||||
case '\0':
|
case '\0':
|
||||||
case CTLENDVAR: /* ??? */
|
case CTLENDVAR:
|
||||||
goto breakloop;
|
goto breakloop;
|
||||||
case CTLQUOTEMARK:
|
case CTLQUOTEMARK:
|
||||||
/* "$@" syntax adherence hack */
|
/* "$@" syntax adherence hack */
|
||||||
@ -262,6 +271,10 @@ argstr(char *p, int flag)
|
|||||||
breakloop:;
|
breakloop:;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform tilde expansion, placing the result in the stack string and
|
||||||
|
* returning the next position in the input string to process.
|
||||||
|
*/
|
||||||
STATIC char *
|
STATIC char *
|
||||||
exptilde(char *p, int flag)
|
exptilde(char *p, int flag)
|
||||||
{
|
{
|
||||||
@ -367,12 +380,11 @@ expari(int flag)
|
|||||||
int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
|
int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
|
||||||
int quoted;
|
int quoted;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine is slightly over-complicated for
|
* This routine is slightly over-complicated for
|
||||||
* efficiency. First we make sure there is
|
* efficiency. First we make sure there is
|
||||||
* enough space for the result, which may be bigger
|
* 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
|
* scan backwards looking for the start of arithmetic. If the
|
||||||
* next previous character is a CTLESC character, then we
|
* next previous character is a CTLESC character, then we
|
||||||
* have to rescan starting from the beginning since CTLESC
|
* 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
|
STATIC void
|
||||||
expbackq(union node *cmd, int quoted, int flag)
|
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
|
* Break the argument string into pieces based upon IFS and add the
|
||||||
* strings to the argument list. The regions of the string to be
|
* strings to the argument list. The regions of the string to be
|
||||||
* searched for IFS characters have been stored by recordregion.
|
* 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
|
STATIC void
|
||||||
ifsbreakup(char *string, struct arglist *arglist)
|
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];
|
STATIC char expdir[PATH_MAX];
|
||||||
#define expdir_end (expdir + sizeof(expdir))
|
#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
|
STATIC void
|
||||||
expandmeta(struct strlist *str, int flag __unused)
|
expandmeta(struct strlist *str, int flag __unused)
|
||||||
{
|
{
|
||||||
@ -1469,7 +1485,7 @@ breakloop:
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove any CTLESC characters from a string.
|
* Remove any CTLESC and CTLQUOTEMARK characters from a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user