diff options
author | harti <harti@FreeBSD.org> | 2005-05-12 15:35:33 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-05-12 15:35:33 +0000 |
commit | c5cd0cafaa49e714fa85c05bacf0d4180c3b45d8 (patch) | |
tree | 7d047c200c32a947df4b12c1aad6f9f03a1fc4ad /usr.bin/make | |
parent | de9fcf7a3ab80e5df414f5cf453ea18415913cc8 (diff) | |
download | FreeBSD-src-c5cd0cafaa49e714fa85c05bacf0d4180c3b45d8.zip FreeBSD-src-c5cd0cafaa49e714fa85c05bacf0d4180c3b45d8.tar.gz |
Remove a useless else and un-indent the following code.
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/cond.c | 755 |
1 files changed, 378 insertions, 377 deletions
diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index fb2978a..0a76913 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -435,438 +435,439 @@ CondToken(Boolean doEval) { Token t; - if (condPushBack == None) { - while (*condExpr == ' ' || *condExpr == '\t') { + if (condPushBack != None) { + t = condPushBack; + condPushBack = None; + return (t); + } + + while (*condExpr == ' ' || *condExpr == '\t') { + condExpr++; + } + switch (*condExpr) { + case '(': + t = LParen; + condExpr++; + break; + case ')': + t = RParen; + condExpr++; + break; + case '|': + if (condExpr[1] == '|') { condExpr++; } - switch (*condExpr) { - case '(': - t = LParen; - condExpr++; - break; - case ')': - t = RParen; - condExpr++; - break; - case '|': - if (condExpr[1] == '|') { - condExpr++; - } - condExpr++; - t = Or; - break; - case '&': - if (condExpr[1] == '&') { - condExpr++; - } - condExpr++; - t = And; - break; - case '!': - t = Not; + condExpr++; + t = Or; + break; + case '&': + if (condExpr[1] == '&') { condExpr++; - break; - case '\n': - case '\0': - t = EndOfFile; - break; - case '$': { - char *lhs; - char *rhs; - const char *op; - size_t varSpecLen = 0; - Boolean doFree; + } + condExpr++; + t = And; + break; + case '!': + t = Not; + condExpr++; + break; + case '\n': + case '\0': + t = EndOfFile; + break; + case '$': { + char *lhs; + char *rhs; + const char *op; + size_t varSpecLen = 0; + Boolean doFree; + /* + * Parse the variable spec and skip over it, saving its + * value in lhs. + */ + t = Err; + lhs = Var_Parse(condExpr, VAR_CMD, doEval, + &varSpecLen, &doFree); + if (lhs == var_Error) { /* - * Parse the variable spec and skip over it, saving its - * value in lhs. + * Even if !doEval, we still report syntax + * errors, which is what getting var_Error + * back with !doEval means. */ - t = Err; - lhs = Var_Parse(condExpr, VAR_CMD, doEval, - &varSpecLen, &doFree); - if (lhs == var_Error) { - /* - * Even if !doEval, we still report syntax - * errors, which is what getting var_Error - * back with !doEval means. - */ - return (Err); - } - condExpr += varSpecLen; + return (Err); + } + condExpr += varSpecLen; - if (!isspace((unsigned char)*condExpr) && - strchr("!=><", *condExpr) == NULL) { - Buffer *buf; + if (!isspace((unsigned char)*condExpr) && + strchr("!=><", *condExpr) == NULL) { + Buffer *buf; - buf = Buf_Init(0); + buf = Buf_Init(0); - Buf_Append(buf, lhs); + Buf_Append(buf, lhs); - if (doFree) - free(lhs); + if (doFree) + free(lhs); - for (;*condExpr && - !isspace((unsigned char)*condExpr); - condExpr++) - Buf_AddByte(buf, (Byte)*condExpr); + for (;*condExpr && + !isspace((unsigned char)*condExpr); + condExpr++) + Buf_AddByte(buf, (Byte)*condExpr); - Buf_AddByte(buf, (Byte)'\0'); - lhs = (char *)Buf_GetAll(buf, &varSpecLen); - Buf_Destroy(buf, FALSE); + Buf_AddByte(buf, (Byte)'\0'); + lhs = (char *)Buf_GetAll(buf, &varSpecLen); + Buf_Destroy(buf, FALSE); - doFree = TRUE; - } + doFree = TRUE; + } - /* - * Skip whitespace to get to the operator - */ - while (isspace((unsigned char)*condExpr)) - condExpr++; + /* + * Skip whitespace to get to the operator + */ + while (isspace((unsigned char)*condExpr)) + condExpr++; + /* + * Make sure the operator is a valid one. If it isn't a + * known relational operator, pretend we got a + * != 0 comparison. + */ + op = condExpr; + switch (*condExpr) { + case '!': + case '=': + case '<': + case '>': + if (condExpr[1] == '=') { + condExpr += 2; + } else { + condExpr += 1; + } + break; + default: + op = "!="; + rhs = "0"; + + goto do_compare; + } + while (isspace((unsigned char)*condExpr)) { + condExpr++; + } + if (*condExpr == '\0') { + Parse_Error(PARSE_WARNING, + "Missing right-hand-side of operator"); + goto error; + } + rhs = condExpr; + do_compare: + if (*rhs == '"') { /* - * Make sure the operator is a valid one. If it isn't a - * known relational operator, pretend we got a - * != 0 comparison. + * Doing a string comparison. Only allow == and + * != for * operators. */ - op = condExpr; - switch (*condExpr) { - case '!': - case '=': - case '<': - case '>': - if (condExpr[1] == '=') { - condExpr += 2; - } else { - condExpr += 1; - } - break; - default: - op = "!="; - rhs = "0"; - - goto do_compare; - } - while (isspace((unsigned char)*condExpr)) { - condExpr++; - } - if (*condExpr == '\0') { + char *string; + char *cp, *cp2; + int qt; + Buffer *buf; + + do_string_compare: + if (((*op != '!') && (*op != '=')) || + (op[1] != '=')) { Parse_Error(PARSE_WARNING, - "Missing right-hand-side of operator"); + "String comparison operator should " + "be either == or !="); goto error; } - rhs = condExpr; - do_compare: - if (*rhs == '"') { - /* - * Doing a string comparison. Only allow == and - * != for * operators. - */ - char *string; - char *cp, *cp2; - int qt; - Buffer *buf; - - do_string_compare: - if (((*op != '!') && (*op != '=')) || - (op[1] != '=')) { - Parse_Error(PARSE_WARNING, - "String comparison operator should " - "be either == or !="); - goto error; - } - buf = Buf_Init(0); - qt = *rhs == '"' ? 1 : 0; - - for (cp = &rhs[qt]; - ((qt && (*cp != '"')) || - (!qt && strchr(" \t)", *cp) == NULL)) && - (*cp != '\0'); cp++) { - if ((*cp == '\\') && (cp[1] != '\0')) { - /* - * Backslash escapes things -- - * skip over next character, * if it exists. - */ - cp++; - Buf_AddByte(buf, (Byte)*cp); - - } else if (*cp == '$') { - size_t len = 0; - Boolean freeIt; - - cp2 = Var_Parse(cp, VAR_CMD, - doEval, &len, &freeIt); - if (cp2 != var_Error) { - Buf_Append(buf, cp2); - if (freeIt) { - free(cp2); - } - cp += len - 1; - } else { - Buf_AddByte(buf, - (Byte)*cp); + buf = Buf_Init(0); + qt = *rhs == '"' ? 1 : 0; + + for (cp = &rhs[qt]; + ((qt && (*cp != '"')) || + (!qt && strchr(" \t)", *cp) == NULL)) && + (*cp != '\0'); cp++) { + if ((*cp == '\\') && (cp[1] != '\0')) { + /* + * Backslash escapes things -- + * skip over next character, * if it exists. + */ + cp++; + Buf_AddByte(buf, (Byte)*cp); + + } else if (*cp == '$') { + size_t len = 0; + Boolean freeIt; + + cp2 = Var_Parse(cp, VAR_CMD, + doEval, &len, &freeIt); + if (cp2 != var_Error) { + Buf_Append(buf, cp2); + if (freeIt) { + free(cp2); } + cp += len - 1; } else { - Buf_AddByte(buf, (Byte)*cp); + Buf_AddByte(buf, + (Byte)*cp); } + } else { + Buf_AddByte(buf, (Byte)*cp); } + } - string = Buf_Peel(buf); + string = Buf_Peel(buf); - DEBUGF(COND, ("lhs = \"%s\", rhs = \"%s\", " - "op = %.2s\n", lhs, string, op)); - /* - * Null-terminate rhs and perform the - * comparison. t is set to the result. - */ - if (*op == '=') { - t = strcmp(lhs, string) ? False : True; + DEBUGF(COND, ("lhs = \"%s\", rhs = \"%s\", " + "op = %.2s\n", lhs, string, op)); + /* + * Null-terminate rhs and perform the + * comparison. t is set to the result. + */ + if (*op == '=') { + t = strcmp(lhs, string) ? False : True; + } else { + t = strcmp(lhs, string) ? True : False; + } + free(string); + if (rhs == condExpr) { + if (!qt && *cp == ')') + condExpr = cp; + else + condExpr = cp + 1; + } + } else { + /* + * rhs is either a float or an integer. + * Convert both the lhs and the rhs to a + * double and compare the two. + */ + double left, right; + char *string; + + if (*CondCvtArg(lhs, &left) != '\0') + goto do_string_compare; + if (*rhs == '$') { + size_t len = 0; + Boolean freeIt; + + string = Var_Parse(rhs, VAR_CMD, doEval, + &len, &freeIt); + if (string == var_Error) { + right = 0.0; } else { - t = strcmp(lhs, string) ? True : False; - } - free(string); - if (rhs == condExpr) { - if (!qt && *cp == ')') - condExpr = cp; - else - condExpr = cp + 1; + if (*CondCvtArg(string, + &right) != '\0') { + if (freeIt) + free(string); + goto do_string_compare; + } + if (freeIt) + free(string); + if (rhs == condExpr) + condExpr += len; } } else { - /* - * rhs is either a float or an integer. - * Convert both the lhs and the rhs to a - * double and compare the two. - */ - double left, right; - char *string; + char *c = CondCvtArg(rhs, &right); - if (*CondCvtArg(lhs, &left) != '\0') + if (c == rhs) goto do_string_compare; - if (*rhs == '$') { - size_t len = 0; - Boolean freeIt; + if (rhs == condExpr) { + /* + * Skip over the right-hand side + */ + condExpr = c; + } + } - string = Var_Parse(rhs, VAR_CMD, doEval, - &len, &freeIt); - if (string == var_Error) { - right = 0.0; - } else { - if (*CondCvtArg(string, - &right) != '\0') { - if (freeIt) - free(string); - goto do_string_compare; - } - if (freeIt) - free(string); - if (rhs == condExpr) - condExpr += len; - } + DEBUGF(COND, ("left = %f, right = %f, " + "op = %.2s\n", left, right, op)); + switch (op[0]) { + case '!': + if (op[1] != '=') { + Parse_Error(PARSE_WARNING, + "Unknown operator"); + goto error; + } + t = (left != right ? True : False); + break; + case '=': + if (op[1] != '=') { + Parse_Error(PARSE_WARNING, + "Unknown operator"); + goto error; + } + t = (left == right ? True : False); + break; + case '<': + if (op[1] == '=') { + t = (left <= right?True:False); } else { - char *c = CondCvtArg(rhs, &right); - - if (c == rhs) - goto do_string_compare; - if (rhs == condExpr) { - /* - * Skip over the right-hand side - */ - condExpr = c; - } + t = (left < right?True:False); } - - DEBUGF(COND, ("left = %f, right = %f, " - "op = %.2s\n", left, right, op)); - switch (op[0]) { - case '!': - if (op[1] != '=') { - Parse_Error(PARSE_WARNING, - "Unknown operator"); - goto error; - } - t = (left != right ? True : False); - break; - case '=': - if (op[1] != '=') { - Parse_Error(PARSE_WARNING, - "Unknown operator"); - goto error; - } - t = (left == right ? True : False); - break; - case '<': - if (op[1] == '=') { - t = (left <= right?True:False); - } else { - t = (left < right?True:False); - } - break; - case '>': - if (op[1] == '=') { - t = (left >= right?True:False); - } else { - t = (left > right?True:False); - } - break; - default: - break; + break; + case '>': + if (op[1] == '=') { + t = (left >= right?True:False); + } else { + t = (left > right?True:False); } + break; + default: + break; } - error: - if (doFree) - free(lhs); - break; + } + error: + if (doFree) + free(lhs); + break; + } + + default: { + CondProc *evalProc; + Boolean invert = FALSE; + char *arg; + int arglen; + + if (strncmp(condExpr, "defined", 7) == 0) { + /* + * Use CondDoDefined to evaluate the argument + * and CondGetArg to extract the argument from + * the 'function call'. + */ + evalProc = CondDoDefined; + condExpr += 7; + arglen = CondGetArg(&condExpr, &arg, + "defined", TRUE); + if (arglen == 0) { + condExpr -= 7; + goto use_default; } - default: { - CondProc *evalProc; - Boolean invert = FALSE; - char *arg; - int arglen; + } else if (strncmp(condExpr, "make", 4) == 0) { + /* + * Use CondDoMake to evaluate the argument and + * CondGetArg to extract the argument from the + * 'function call'. + */ + evalProc = CondDoMake; + condExpr += 4; + arglen = CondGetArg(&condExpr, &arg, + "make", TRUE); + if (arglen == 0) { + condExpr -= 4; + goto use_default; + } - if (strncmp(condExpr, "defined", 7) == 0) { - /* - * Use CondDoDefined to evaluate the argument - * and CondGetArg to extract the argument from - * the 'function call'. - */ - evalProc = CondDoDefined; - condExpr += 7; - arglen = CondGetArg(&condExpr, &arg, - "defined", TRUE); - if (arglen == 0) { - condExpr -= 7; - goto use_default; - } + } else if (strncmp(condExpr, "exists", 6) == 0) { + /* + * Use CondDoExists to evaluate the argument and + * CondGetArg to extract the argument from the + * 'function call'. + */ + evalProc = CondDoExists; + condExpr += 6; + arglen = CondGetArg(&condExpr, &arg, + "exists", TRUE); + if (arglen == 0) { + condExpr -= 6; + goto use_default; + } - } else if (strncmp(condExpr, "make", 4) == 0) { - /* - * Use CondDoMake to evaluate the argument and - * CondGetArg to extract the argument from the - * 'function call'. - */ - evalProc = CondDoMake; - condExpr += 4; - arglen = CondGetArg(&condExpr, &arg, - "make", TRUE); - if (arglen == 0) { - condExpr -= 4; - goto use_default; - } + } else if (strncmp(condExpr, "empty", 5) == 0) { + /* + * Use Var_Parse to parse the spec in parens and + * return True if the resulting string is empty. + */ + size_t length; + Boolean doFree; + char *val; - } else if (strncmp(condExpr, "exists", 6) == 0) { - /* - * Use CondDoExists to evaluate the argument and - * CondGetArg to extract the argument from the - * 'function call'. - */ - evalProc = CondDoExists; - condExpr += 6; - arglen = CondGetArg(&condExpr, &arg, - "exists", TRUE); - if (arglen == 0) { - condExpr -= 6; - goto use_default; - } + condExpr += 5; - } else if (strncmp(condExpr, "empty", 5) == 0) { - /* - * Use Var_Parse to parse the spec in parens and - * return True if the resulting string is empty. - */ - size_t length; - Boolean doFree; - char *val; - - condExpr += 5; - - for (arglen = 0; - condExpr[arglen] != '(' && - condExpr[arglen] != '\0'; arglen += 1) - continue; - - if (condExpr[arglen] != '\0') { - length = 0; - val = Var_Parse(&condExpr[arglen - 1], - VAR_CMD, FALSE, &length, &doFree); - if (val == var_Error) { - t = Err; - } else { - /* - * A variable is empty when it - * just contains spaces... - * 4/15/92, christos - */ - char *p; - - for (p = val; - *p && - isspace((unsigned char)*p); - p++) - continue; - t = (*p == '\0') ? True : False; - } - if (doFree) { - free(val); - } + for (arglen = 0; + condExpr[arglen] != '(' && + condExpr[arglen] != '\0'; arglen += 1) + continue; + + if (condExpr[arglen] != '\0') { + length = 0; + val = Var_Parse(&condExpr[arglen - 1], + VAR_CMD, FALSE, &length, &doFree); + if (val == var_Error) { + t = Err; + } else { /* - * Advance condExpr to beyond the - * closing ). Note that we subtract - * one from arglen + length b/c length - * is calculated from - * condExpr[arglen - 1]. + * A variable is empty when it + * just contains spaces... + * 4/15/92, christos */ - condExpr += arglen + length - 1; - } else { - condExpr -= 5; - goto use_default; + char *p; + + for (p = val; + *p && + isspace((unsigned char)*p); + p++) + continue; + t = (*p == '\0') ? True : False; } - break; - - } else if (strncmp(condExpr, "target", 6) == 0) { - /* - * Use CondDoTarget to evaluate the argument and - * CondGetArg to extract the argument from the - * 'function call'. - */ - evalProc = CondDoTarget; - condExpr += 6; - arglen = CondGetArg(&condExpr, &arg, - "target", TRUE); - if (arglen == 0) { - condExpr -= 6; - goto use_default; + if (doFree) { + free(val); } - - } else { /* - * The symbol is itself the argument to the - * default function. We advance condExpr to - * the end of the symbol by hand (the next - * whitespace, closing paren or binary operator) - * and set to invert the evaluation - * function if condInvert is TRUE. + * Advance condExpr to beyond the + * closing ). Note that we subtract + * one from arglen + length b/c length + * is calculated from + * condExpr[arglen - 1]. */ - use_default: - invert = condInvert; - evalProc = condDefProc; - arglen = CondGetArg(&condExpr, &arg, "", FALSE); + condExpr += arglen + length - 1; + } else { + condExpr -= 5; + goto use_default; } + break; + } else if (strncmp(condExpr, "target", 6) == 0) { /* - * Evaluate the argument using the set function. If - * invert is TRUE, we invert the sense of the function. + * Use CondDoTarget to evaluate the argument and + * CondGetArg to extract the argument from the + * 'function call'. */ - t = (!doEval || (* evalProc) (arglen, arg) ? - (invert ? False : True) : - (invert ? True : False)); - free(arg); - break; + evalProc = CondDoTarget; + condExpr += 6; + arglen = CondGetArg(&condExpr, &arg, + "target", TRUE); + if (arglen == 0) { + condExpr -= 6; + goto use_default; } + + } else { + /* + * The symbol is itself the argument to the + * default function. We advance condExpr to + * the end of the symbol by hand (the next + * whitespace, closing paren or binary operator) + * and set to invert the evaluation + * function if condInvert is TRUE. + */ + use_default: + invert = condInvert; + evalProc = condDefProc; + arglen = CondGetArg(&condExpr, &arg, "", FALSE); + } + + /* + * Evaluate the argument using the set function. If + * invert is TRUE, we invert the sense of the function. + */ + t = (!doEval || (* evalProc) (arglen, arg) ? + (invert ? False : True) : + (invert ? True : False)); + free(arg); + break; } - } else { - t = condPushBack; - condPushBack = None; } return (t); } |