X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fcommand%2Frpn.qc;h=1ca075bbbdf1f614652985039cf575182f13a149;hp=374d07df17ac8e3ec0b28e5177332ccb3763ef66;hb=86c9dc7c3696c329496b06375c1e79fb407401ce;hpb=1532af143411264782fd7646d151df486e2b16aa diff --git a/qcsrc/common/command/rpn.qc b/qcsrc/common/command/rpn.qc index 374d07df17..1ca075bbbd 100644 --- a/qcsrc/common/command/rpn.qc +++ b/qcsrc/common/command/rpn.qc @@ -1,46 +1,50 @@ +#include "command.qh" +#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; + LOG_INFO("rpn: stack underflow\n"); + 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; + LOG_INFO("rpn: stack overflow\n"); + 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; + LOG_INFO("rpn: empty stack\n"); + 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; + LOG_INFO("rpn: empty stack\n"); + rpn_error = true; } } @@ -58,18 +62,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); @@ -103,8 +107,8 @@ void GenericCommand_rpn(float request, float argc, string command) } else { - print("rpn: empty cvar name for 'def'\n"); - rpn_error = TRUE; + LOG_INFO("rpn: empty cvar name for 'def'\n"); + rpn_error = true; } } else if(rpncmd == "defs" || rpncmd == "@") { s = ""; @@ -128,8 +132,8 @@ void GenericCommand_rpn(float request, float argc, string command) } else { - print("rpn: empty cvar name for 'defs'\n"); - rpn_error = TRUE; + LOG_INFO("rpn: empty cvar name for 'defs'\n"); + rpn_error = true; } } else if(rpncmd == "load") { rpn_set(cvar_string(rpn_get())); @@ -249,7 +253,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) @@ -284,17 +288,17 @@ void GenericCommand_rpn(float request, float argc, string command) db_put(rpn_db, "stack.pos", ftos(i-2)); } else { rpn_error = 1; - print("rpn: database underflow\n"); + LOG_INFO("rpn: database underflow\n"); } } else if(rpncmd == "dbget") { - + i = stof(db_get(rpn_db, "stack.pointer")); if(i) { rpn_push(db_get(rpn_db, strcat("stack.", ftos(i-1)))); } else { rpn_error = 1; - print("rpn: database empty\n"); + LOG_INFO("rpn: database empty\n"); } } else if(rpncmd == "dblen") { rpn_push(db_get(rpn_db, "stack.pointer")); @@ -321,13 +325,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,8 +346,8 @@ void GenericCommand_rpn(float request, float argc, string command) i = stof(db_get(rpn_db, "stack.pos")); if(!j) { - rpn_error = TRUE; - print("rpn: empty database\n"); + rpn_error = true; + LOG_INFO("rpn: empty database\n"); } else { --j; rpn_push(db_get(rpn_db, strcat("stack.", ftos(i)))); @@ -368,7 +372,7 @@ void GenericCommand_rpn(float request, float argc, string command) rpn_push(db_get(rpn_db, strcat("stack.", s))); } else { rpn_error = 1; - print("rpn: empty database\n"); + LOG_INFO("rpn: empty database\n"); } } else if(rpncmd == "dbat") { rpn_push(db_get(rpn_db, "stack.pos")); @@ -380,8 +384,8 @@ 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; + LOG_INFO("rpn: database cursor out of bounds\n"); + rpn_error = true; } if(!rpn_error) { @@ -393,8 +397,8 @@ void GenericCommand_rpn(float request, float argc, string command) j = stof(db_get(rpn_db, "stack.pointer")); if(!j) { - rpn_error = TRUE; - print("rpn: empty database, cannot move cursor\n"); + rpn_error = true; + LOG_INFO("rpn: empty database, cannot move cursor\n"); } if(!rpn_error) { @@ -404,12 +408,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; + LOG_INFO("rpn: database cursor destination out of bounds\n"); + rpn_error = true; } if(!rpn_error) { @@ -426,7 +430,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) @@ -510,8 +514,8 @@ void GenericCommand_rpn(float request, float argc, string command) { if (!fexists(s)) { - print("rpn: ERROR: ", s, " does not exist!\n"); - rpn_error = TRUE; + LOG_INFO("rpn: ERROR: ", s, " does not exist!\n"); + rpn_error = true; } } } else if(rpncmd == "fexists") { @@ -524,9 +528,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") { @@ -549,52 +553,52 @@ void GenericCommand_rpn(float request, float argc, string command) while(rpn_sp > 0) { s = rpn_pop(); - print("rpn: still on stack: ", s, "\n"); + LOG_INFO("rpn: still on stack: ", s, "\n"); } } return; } - + default: case CMD_REQUEST_USAGE: { - print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " rpn EXPRESSION...\n")); - print(" Operator description (x: string, s: set, f: float):\n"); - print(" x pop -----------------------------> : removes the top\n"); - print(" x dup -----------------------------> x x : duplicates the top\n"); - print(" x x exch --------------------------> x x : swap the top two\n"); - print(" /cvarname load --------------------> x : loads a cvar\n"); - print(" /cvarname x def -------------------> : writes to a cvar\n"); - print(" f f add|sub|mul|div|mod|pow -------> f : adds/... two numbers\n"); - print(" f f and|or|xor|bitand|bitor|bitxor > f : logical and bitwise operations\n"); - print(" f f eq|ne|gt|ge|lt|le|max|min -----> f : compares two numbers\n"); - print(" f neg|abs|sgn|rand|floor|ceil------> f : negates/... a number\n"); - print(" f not|bitnot ----------------------> f : logical and bitwise negation\n"); - print(" f exp|log|sin|cos -----------------> f : exponential function & Co.\n"); - print(" f f f bound -----------------------> f : bounds the middle number\n"); - print(" f1 f2 b when ----------------------> f : f1 if b, f2 otherwise\n"); - print(" s s union|intersection|difference -> s : set operations\n"); - print(" s shuffle -------------------------> s : randomly arrange elements\n"); - print(" /key /value put -------------------> : set a database key\n"); - print(" /key get --------------------------> s : get a database value\n"); - print(" x dbpush --------------------------> : pushes the top onto the database\n"); - print(" dbpop|dbget -----------------------> x : removes/reads DB's top\n"); - print(" dblen|dbat ------------------------> f : gets the DB's size/cursor pos\n"); - print(" dbclr -----------------------------> : clear the DB\n"); - print(" s dbsave|dbload--------------------> : save/load the DB to/from a file\n"); - print(" x dbins ---------------------------> : moves the top into the DB\n"); - print(" dbext|dbread ----------------------> x : extract/get from the DB's cursor\n"); - print(" f dbmov|dbgoto --------------------> : move or set the DB's cursor\n"); - print(" s localtime -----------------------> s : formats the current local time\n"); - print(" s gmtime --------------------------> s : formats the current UTC time\n"); - print(" time ------------------------------> f : seconds since VM start\n"); - print(" s /MD4 digest ---------------------> s : MD4 digest\n"); - print(" s /SHA256 digest ------------------> s : SHA256 digest\n"); - print(" s /formatstring sprintf1s ---------> s : sprintf with 1 string (pad, cut)\n"); - print(" s eval ----------------------------> : does something eval\n"); - print(" Set operations operate on 'such''strings'.\n"); - print(" Unknown tokens insert their cvar value.\n"); + LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " rpn EXPRESSION...\n")); + LOG_INFO(" Operator description (x: string, s: set, f: float):\n"); + LOG_INFO(" x pop -----------------------------> : removes the top\n"); + LOG_INFO(" x dup -----------------------------> x x : duplicates the top\n"); + LOG_INFO(" x x exch --------------------------> x x : swap the top two\n"); + LOG_INFO(" /cvarname load --------------------> x : loads a cvar\n"); + LOG_INFO(" /cvarname x def -------------------> : writes to a cvar\n"); + LOG_INFO(" f f add|sub|mul|div|mod|pow -------> f : adds/... two numbers\n"); + LOG_INFO(" f f and|or|xor|bitand|bitor|bitxor > f : logical and bitwise operations\n"); + LOG_INFO(" f f eq|ne|gt|ge|lt|le|max|min -----> f : compares two numbers\n"); + LOG_INFO(" f neg|abs|sgn|rand|floor|ceil------> f : negates/... a number\n"); + LOG_INFO(" f not|bitnot ----------------------> f : logical and bitwise negation\n"); + LOG_INFO(" f exp|log|sin|cos -----------------> f : exponential function & Co.\n"); + LOG_INFO(" f f f bound -----------------------> f : bounds the middle number\n"); + LOG_INFO(" f1 f2 b when ----------------------> f : f1 if b, f2 otherwise\n"); + LOG_INFO(" s s union|intersection|difference -> s : set operations\n"); + LOG_INFO(" s shuffle -------------------------> s : randomly arrange elements\n"); + LOG_INFO(" /key /value put -------------------> : set a database key\n"); + LOG_INFO(" /key get --------------------------> s : get a database value\n"); + LOG_INFO(" x dbpush --------------------------> : pushes the top onto the database\n"); + LOG_INFO(" dbpop|dbget -----------------------> x : removes/reads DB's top\n"); + LOG_INFO(" dblen|dbat ------------------------> f : gets the DB's size/cursor pos\n"); + LOG_INFO(" dbclr -----------------------------> : clear the DB\n"); + LOG_INFO(" s dbsave|dbload--------------------> : save/load the DB to/from a file\n"); + LOG_INFO(" x dbins ---------------------------> : moves the top into the DB\n"); + LOG_INFO(" dbext|dbread ----------------------> x : extract/get from the DB's cursor\n"); + LOG_INFO(" f dbmov|dbgoto --------------------> : move or set the DB's cursor\n"); + LOG_INFO(" s localtime -----------------------> s : formats the current local time\n"); + LOG_INFO(" s gmtime --------------------------> s : formats the current UTC time\n"); + LOG_INFO(" time ------------------------------> f : seconds since VM start\n"); + LOG_INFO(" s /MD4 digest ---------------------> s : MD4 digest\n"); + LOG_INFO(" s /SHA256 digest ------------------> s : SHA256 digest\n"); + LOG_INFO(" s /formatstring sprintf1s ---------> s : sprintf with 1 string (pad, cut)\n"); + LOG_INFO(" s eval ----------------------------> : does something eval\n"); + LOG_INFO(" Set operations operate on 'such''strings'.\n"); + LOG_INFO(" Unknown tokens insert their cvar value.\n"); return; } }