]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/command/rpn.qc
Merge branch 'master' into Mario/ctf_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / command / rpn.qc
index 374d07df17ac8e3ec0b28e5177332ccb3763ef66..bb920d697e91ce9e2dfc10b1bc4f4fd2e1a2c4a5 100644 (file)
@@ -1,46 +1,48 @@
+#include "rpn.qh"
+
 // ========================================
 //  RPN command code, written by divVerent
 //  Last updated: December 28th, 2011
 // ========================================
 
-string rpn_pop() 
+string rpn_pop()
 {
        if(rpn_sp > 0) {
                --rpn_sp;
                return rpn_stack[rpn_sp];
        } else {
                print("rpn: stack underflow\n");
-               rpn_error = TRUE;
+               rpn_error = true;
                return "";
        }
 }
-void rpn_push(string s) 
+void rpn_push(string s)
 {
        if(rpn_sp < MAX_RPN_STACK) {
                rpn_stack[rpn_sp] = s;
                ++rpn_sp;
        } else {
                print("rpn: stack overflow\n");
-               rpn_error = TRUE;
+               rpn_error = true;
        }
 }
-string rpn_get() 
+string rpn_get()
 {
        if(rpn_sp > 0) {
                return rpn_stack[rpn_sp - 1];
        } else {
                print("rpn: empty stack\n");
-               rpn_error = TRUE;
+               rpn_error = true;
                return "";
        }
 }
-void rpn_set(string s) 
+void rpn_set(string s)
 {
        if(rpn_sp > 0) {
                rpn_stack[rpn_sp - 1] = s;
        } else {
                print("rpn: empty stack\n");
-               rpn_error = TRUE;
+               rpn_error = true;
        }
 }
 
@@ -58,18 +60,18 @@ void GenericCommand_rpn(float request, float argc, string command)
                        float i, j, f, f2, f3, rpnpos;
                        //vector rgb;
                        string s, s2, rpncmd;
-                       
+
                        if(!rpn_db)
                        {
                                rpn_db = db_create();
                                db_put(rpn_db, "stack.pointer", "0");
                                db_put(rpn_db, "stack.pos", "-1");
                        }
-                       
+
                        if(argc >= 2)
                        {
                                rpn_sp = 0;
-                               rpn_error = FALSE;
+                               rpn_error = false;
                                for(rpnpos = 1; rpnpos < argc; ++rpnpos)
                                {
                                        rpncmd = argv(rpnpos);
@@ -104,7 +106,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                else
                                                {
                                                        print("rpn: empty cvar name for 'def'\n");
-                                                       rpn_error = TRUE;
+                                                       rpn_error = true;
                                                }
                                        } else if(rpncmd == "defs" || rpncmd == "@") {
                                                s = "";
@@ -129,7 +131,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                else
                                                {
                                                        print("rpn: empty cvar name for 'defs'\n");
-                                                       rpn_error = TRUE;
+                                                       rpn_error = true;
                                                }
                                        } else if(rpncmd == "load") {
                                                rpn_set(cvar_string(rpn_get()));
@@ -249,7 +251,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                        } else if(rpncmd == "rand") {
                                                rpn_setf(ceil(random() * rpn_getf()) - 1);
                                        } else if(rpncmd == "crc16") {
-                                               rpn_setf(crc16(FALSE, rpn_get()));
+                                               rpn_setf(crc16(false, rpn_get()));
                                        } else if(rpncmd == "put") {
                                                s2 = rpn_pop();
                                                if (!rpn_error)
@@ -287,7 +289,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                        print("rpn: database underflow\n");
                                                }
                                        } else if(rpncmd == "dbget") {
-                                               
+
                                                i = stof(db_get(rpn_db, "stack.pointer"));
                                                if(i)
                                                {
@@ -321,13 +323,13 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                {
                                                        j = stof(db_get(rpn_db, "stack.pointer"));
                                                        i = stof(db_get(rpn_db, "stack.pos"));
-                                                       
+
                                                        if(i < 0)
                                                        {
                                                                i = 0;
                                                                db_put(rpn_db, "stack.pos", "0");
                                                        }
-                                                       
+
                                                        db_put(rpn_db, "stack.pointer", ftos(j+1));
                                                        for(--j; j >= i; --j)
                                                        {
@@ -342,7 +344,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                i = stof(db_get(rpn_db, "stack.pos"));
                                                if(!j)
                                                {
-                                                       rpn_error = TRUE;
+                                                       rpn_error = true;
                                                        print("rpn: empty database\n");
                                                } else {
                                                        --j;
@@ -381,7 +383,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                        if(i < 0 || i >= j)
                                                        {
                                                                print("rpn: database cursor out of bounds\n");
-                                                               rpn_error = TRUE;
+                                                               rpn_error = true;
                                                        }
                                                        if(!rpn_error)
                                                        {
@@ -393,7 +395,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                j = stof(db_get(rpn_db, "stack.pointer"));
                                                if(!j)
                                                {
-                                                       rpn_error = TRUE;
+                                                       rpn_error = true;
                                                        print("rpn: empty database, cannot move cursor\n");
                                                }
                                                if(!rpn_error)
@@ -404,12 +406,12 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                                i = 0;
                                                        else
                                                                i = stof(s);
-                                                       
+
                                                        j = stof(db_get(rpn_db, "stack.pointer"));
                                                        if(i < 0 || i >= j)
                                                        {
                                                                print("rpn: database cursor destination out of bounds\n");
-                                                               rpn_error = TRUE;
+                                                               rpn_error = true;
                                                        }
                                                        if(!rpn_error)
                                                        {
@@ -426,7 +428,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                // tokens f..f2 represent s2
                                                // UNION: add all tokens to s that are in s2 but not in s
                                                s = "";
-                                               for(i = 0; i < f; ++i)  
+                                               for(i = 0; i < f; ++i)
                                                        s = strcat(s, " ", argv(i));
                                                for(i = f; i < f2; ++i) {
                                                        for(j = 0; j < f; ++j)
@@ -511,7 +513,7 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                        if (!fexists(s))
                                                        {
                                                                print("rpn: ERROR: ", s, " does not exist!\n");
-                                                               rpn_error = TRUE;
+                                                               rpn_error = true;
                                                        }
                                                }
                                        } else if(rpncmd == "fexists") {
@@ -524,9 +526,9 @@ void GenericCommand_rpn(float request, float argc, string command)
                                                                rpn_setf(0);
                                                }
                                        } else if(rpncmd == "localtime") {
-                                               rpn_set(strftime(TRUE, rpn_get()));
+                                               rpn_set(strftime(true, rpn_get()));
                                        } else if(rpncmd == "gmtime") {
-                                               rpn_set(strftime(FALSE, rpn_get()));
+                                               rpn_set(strftime(false, rpn_get()));
                                        } else if(rpncmd == "time") {
                                                rpn_pushf(time);
                                        } else if(rpncmd == "digest") {
@@ -555,7 +557,7 @@ void GenericCommand_rpn(float request, float argc, string command)
 
                        return;
                }
-                       
+
                default:
                case CMD_REQUEST_USAGE:
                {