MDL-20700 coding style cleanup - cvs keywords removed, closign php tag removed, trailing whitespace cleanup

This commit is contained in:
Petr Skoda
2009-11-01 16:48:45 +00:00
parent 795b694516
commit 6f5e085205
51 changed files with 270 additions and 270 deletions
+33 -33
View File
@@ -10,7 +10,7 @@ Copyright (C) 2005 Miles Kaufmann <http://www.twmagic.com/>
NAME
EvalMath - safely evaluate math expressions
SYNOPSIS
<?
include('evalmath.class.php');
@@ -26,9 +26,9 @@ SYNOPSIS
// and then use them
$result = $m->evaluate('3*f(42,a)');
?>
DESCRIPTION
Use the EvalMath class when you want to evaluate mathematical expressions
Use the EvalMath class when you want to evaluate mathematical expressions
from untrusted sources. You can define your own variables and functions,
which are stored in the object. Try it, it's fun!
@@ -37,13 +37,13 @@ METHODS
Evaluates the expression and returns the result. If an error occurs,
prints a warning and returns false. If $expr is a function assignment,
returns true on success.
$m->e($expr)
A synonym for $m->evaluate().
$m->vars()
Returns an associative array of all user-defined variables and values.
$m->funcs()
Returns an array of all user-defined functions.
@@ -62,7 +62,7 @@ LICENSE
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1 Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@@ -71,7 +71,7 @@ LICENSE
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -89,14 +89,14 @@ LICENSE
/**
* This class was heavily modified in order to get usefull spreadsheet emulation ;-)
* skodak
*
*
*/
class EvalMath {
var $suppress_errors = false;
var $last_error = null;
var $v = array(); // variables (and constants)
var $f = array(); // user-defined functions
var $vb = array(); // constants
@@ -110,14 +110,14 @@ class EvalMath {
'average'=>array(-1), 'max'=>array(-1), 'min'=>array(-1),
'mod'=>array(2), 'pi'=>array(0), 'power'=>array(2),
'round'=>array(1, 2), 'sum'=>array(-1));
function EvalMath() {
}
function e($expr) {
return $this->evaluate($expr);
}
function evaluate($expr) {
$this->last_error = null;
$expr = trim($expr);
@@ -157,11 +157,11 @@ class EvalMath {
return $this->pfx($this->nfx($expr)); // straight up evaluation, woo
}
}
function vars() {
return $this->v;
}
function funcs() {
$output = array();
foreach ($this->f as $fnn=>$dat)
@@ -173,23 +173,23 @@ class EvalMath {
// Convert infix to postfix notation
function nfx($expr) {
$index = 0;
$stack = new EvalMathStack;
$output = array(); // postfix form of expression, to be passed to pfx()
$expr = trim(strtolower($expr));
$ops = array('+', '-', '*', '/', '^', '_');
$ops_r = array('+'=>0,'-'=>0,'*'=>0,'/'=>0,'^'=>1); // right-associative operator?
$ops_r = array('+'=>0,'-'=>0,'*'=>0,'/'=>0,'^'=>1); // right-associative operator?
$ops_p = array('+'=>0,'-'=>0,'*'=>1,'/'=>1,'_'=>1,'^'=>2); // operator precedence
$expecting_op = false; // we use this in syntax-checking the expression
// and determining when a - is a negation
if (preg_match("/[^\w\s+*^\/()\.,-]/", $expr, $matches)) { // make sure the characters are all good
return $this->trigger("illegal character '{$matches[0]}'");
}
while(1) { // 1 Infinite Loop ;)
$op = substr($expr, $index, 1); // get the first character at the current index
// find out if we're currently at the beginning of a number/variable/function/parenthesis/operand
@@ -198,7 +198,7 @@ class EvalMath {
if ($op == '-' and !$expecting_op) { // is it a negation instead of a minus?
$stack->push('_'); // put a negation on the stack
$index++;
} elseif ($op == '_') { // we have to explicitly deny this, because it's legal on the stack
} elseif ($op == '_') { // we have to explicitly deny this, because it's legal on the stack
return $this->trigger("illegal character '_'"); // but not in the input expression
//===============
} elseif ((in_array($op, $ops) or $ex) and $expecting_op) { // are we putting an operator on the stack?
@@ -243,7 +243,7 @@ class EvalMath {
$index++;
//===============
} elseif ($op == ',' and $expecting_op) { // did we just finish a function argument?
while (($o2 = $stack->pop()) != '(') {
while (($o2 = $stack->pop()) != '(') {
if (is_null($o2)) return $this->trigger("unexpected ','"); // oops, never had a (
else $output[] = $o2; // pop the argument expression stuff and push onto the output
}
@@ -307,11 +307,11 @@ class EvalMath {
break;
}
}
while (substr($expr, $index, 1) == ' ') { // step the index past whitespace (pretty much turns whitespace
while (substr($expr, $index, 1) == ' ') { // step the index past whitespace (pretty much turns whitespace
$index++; // into implicit multiplication if no operator is there)
}
}
}
while (!is_null($op = $stack->pop())) { // pop everything off the stack and push onto output
if ($op == '(') return $this->trigger("expecting ')'"); // if there are (s on the stack, ()s were unbalanced
$output[] = $op;
@@ -321,11 +321,11 @@ class EvalMath {
// evaluate postfix notation
function pfx($tokens, $vars = array()) {
if ($tokens == false) return false;
$stack = new EvalMathStack;
foreach ($tokens as $token) { // nice and easy
// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
@@ -393,7 +393,7 @@ class EvalMath {
if ($stack->count != 1) return $this->trigger("internal error");
return $stack->pop();
}
// trigger an error, but nicely, if need be
function trigger($msg) {
$this->last_error = $msg;
@@ -407,12 +407,12 @@ class EvalMathStack {
var $stack = array();
var $count = 0;
function push($val) {
$this->stack[$this->count] = $val;
$this->count++;
}
function pop() {
if ($this->count > 0) {
$this->count--;
@@ -420,7 +420,7 @@ class EvalMathStack {
}
return null;
}
function last($n=1) {
if ($this->count - $n >= 0) {
return $this->stack[$this->count-$n];