diff options
author | harti <harti@FreeBSD.org> | 2005-02-17 12:31:53 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-02-17 12:31:53 +0000 |
commit | fd36b19bc9f43b22887cc9d4e0269042b12de04b (patch) | |
tree | 5cb32de4f705eba9865a584f8a53fa801ab3f157 /usr.bin | |
parent | a2901d4c5ea82dad608e8c9c6697df1273cad00f (diff) | |
download | FreeBSD-src-fd36b19bc9f43b22887cc9d4e0269042b12de04b.zip FreeBSD-src-fd36b19bc9f43b22887cc9d4e0269042b12de04b.tar.gz |
Move error case to begin of if-else chain. Do not needless initialize
startc, but only at the place where the initialisation is needed. Remove
a needless else.
Submitted by: Max Okumoto <okumoto@ucsd.edu> (partly)
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/var.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 1e15c67..a570427 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -874,7 +874,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, Boolean haveModifier;/* TRUE if have modifiers for the variable */ char endc; /* Ending character when variable in parens * or braces */ - char startc=0; /* Starting character when variable in parens + char startc; /* Starting character when variable in parens * or braces */ int cnt; /* Used to count brace pairs when variable in * in parens or braces */ @@ -891,7 +891,19 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, dynamic = FALSE; start = str; + if (str[1] == '\0') { + /* + * Error - there is only a dollar sign! + */ + *lengthPtr = 1; + return (err ? var_Error : varNoError); + } + if (str[1] == OPEN_PAREN || str[1] == OPEN_BRACE) { + /* + * Check if brackets contain a variable name. + */ + /* build up expanded variable name in this buffer */ Buffer *buf = Buf_Init(MAKE_BSIZE); @@ -901,8 +913,8 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, */ startc = str[1]; endc = (startc == OPEN_PAREN) ? CLOSE_PAREN : CLOSE_BRACE; - tstr = str + 2; + while (*tstr != '\0' && *tstr != endc && *tstr != ':') { if (*tstr == '$') { size_t rlen; @@ -939,7 +951,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, *tstr = '\0'; /* modify input string */ Buf_AddByte(buf, (Byte)'\0'); - str = Buf_GetAll(buf, (size_t *)NULL); + str = Buf_GetAll(buf, (size_t *)NULL); /* REPLACE str */ vlen = strlen(str); v = VarFind(str, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); @@ -1066,13 +1078,6 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, } Buf_Destroy(buf, TRUE); - } else if (str[1] == '\0') { - /* - * Error - there is only a dollar sign! - */ - *lengthPtr = 1; - return (err ? var_Error : varNoError); - } else { /* * If it's not bounded by braces of some sort, life is much simpler. @@ -1116,11 +1121,11 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr, * Error */ return (err ? var_Error : varNoError); - } else { - haveModifier = FALSE; - tstr = &str[1]; - endc = str[1]; } + haveModifier = FALSE; + startc = 0; + endc = str[1]; + tstr = &str[1]; } if (v->flags & VAR_IN_USE) { |