char * GetStatusString (statusfile_t *sf, char *section, char *variable) { hash_item_t *p_hi; char *ret = NULL; if (sf->filename == NULL) return (NULL); if (!pthread_mutex_lock(&(sf->mutex_lock))) { if ((p_hi = LookupVar(sf, section, variable)) != NULL) { ret = p_hi->value; } pthread_mutex_unlock(&(sf->mutex_lock)); } return (ret); }
int SetStatusString (statusfile_t *sf, char *section, char *variable, char *value) { hash_item_t *p_hi; int ret = 0; if (sf->filename == NULL) return (0); if (!pthread_mutex_lock(&(sf->mutex_lock))) { /* Do we delete the value? */ if (value == NULL) { DeleteVar(sf, section, variable); ret = 1; } /* See if its already in there. If it is, then replace the current val */ else if ((p_hi = LookupVar(sf, section, variable)) != NULL) { if ((p_hi->value != NULL) && strcmp(p_hi->value, value)) { free(p_hi->value); p_hi->value = strdup(value); } ret = 1; } /* If its not, add a new value */ else { p_hi = irrd_malloc(sizeof(hash_item_t)); p_hi->key = strdup(variable); p_hi->value = strdup(value); if (InsertVar(sf, section, p_hi)) ret = 1; } ret = WriteStatusFile(sf, NULL); pthread_mutex_unlock(&(sf->mutex_lock)); } return (ret); }
//------------------------------------------------------------------------------ float Evaluator::Evaluate(const vector<Token>& expression, const Environment* env) { // Now perform the actual shunting :) for (size_t i = 0; i < expression.size(); ++i) { const Token& t = expression[i]; if (t.type == Token::Type::Constant) { operandStack.push_back(t); } else if (t.type == Token::Type::BinOp) { // Apply any higher priority operators int prio = BINOP_PRIO[t.binOp]; while (!operatorStack.empty()) { const Token& op = operatorStack.back(); if (op.type == Token::Type::BinOp && BINOP_PRIO[op.binOp] >= prio) { ApplyBinOp(op.binOp); operatorStack.pop_back(); } else break; } operatorStack.push_back(t); } else if (t.type == Token::Type::FuncCall) { operatorStack.push_back(t); } else if (t.type == Token::Type::LeftParen) { operatorStack.push_back(t); } else if (t.type == Token::Type::Comma) { // apply all the operators until the left paren ApplyUntilLeftParen(false); } else if (t.type == Token::Type::RightParen) { ApplyUntilLeftParen(true); if (!operatorStack.empty()) { // if the token at the top of the operator stack is a function call, // then invoke it Token t = operatorStack.back(); if (t.type == Token::Type::FuncCall) { InvokeFunction(t, env); operatorStack.pop_back(); } } } else if (t.type == Token::Type::Var) { LookupVar(t, env); } } // apply all the remaining operators while (!operatorStack.empty()) { ApplyBinOp(PopOperator().binOp); } return PopValue(); }