]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/common/gamecommand.qc
add 'addtolist' to 'qc_cmd help'
[divverent/nexuiz.git] / data / qcsrc / common / gamecommand.qc
1 #define MAX_RPN_STACK 16
2 float rpn_db;
3 float rpn_error;
4 float rpn_sp;
5 string rpn_stack[MAX_RPN_STACK];
6 string rpn_pop() {
7         if(rpn_sp > 0) {
8                 --rpn_sp;
9                 return rpn_stack[rpn_sp];
10         } else {
11                 print("rpn: stack underflow\n");
12                 rpn_error = TRUE;
13                 return "";
14         }
15 }
16 void rpn_push(string s) {
17         if(rpn_sp < MAX_RPN_STACK) {
18                 rpn_stack[rpn_sp] = s;
19                 ++rpn_sp;
20         } else {
21                 print("rpn: stack overflow\n");
22                 rpn_error = TRUE;
23         }
24 }
25 string rpn_get() {
26         if(rpn_sp > 0) {
27                 return rpn_stack[rpn_sp - 1];
28         } else {
29                 print("rpn: empty stack\n");
30                 rpn_error = TRUE;
31                 return "";
32         }
33 }
34 void rpn_set(string s) {
35         if(rpn_sp > 0) {
36                 rpn_stack[rpn_sp - 1] = s;
37         } else {
38                 print("rpn: empty stack\n");
39                 rpn_error = TRUE;
40         }
41 }
42 float rpn_getf() { return stof(rpn_get()); }
43 float rpn_popf() { return stof(rpn_pop()); }
44 void rpn_pushf(float f) { return rpn_push(ftos(f)); }
45 void rpn_setf(float f) { return rpn_set(ftos(f)); }
46
47 float GameCommand_Generic(string command)
48 {
49         float argc;
50         float i, j, f, n;
51         vector rgb;
52         string s, s2, c;
53         argc = tokenize_sane(command);
54         if(argv(0) == "help")
55         {
56                 print("  rpn EXPRESSION... - a RPN calculator.\n");
57                 print("    Operator description (x: string, s: set, f: float):\n");
58                 print("    x pop ----------------------------->     : removes the top\n");
59                 print("    x dup -----------------------------> x x : duplicates the top\n");
60                 print("    x x exch --------------------------> x x : swap the top two\n");
61                 print("    /cvarname load --------------------> x   : loads a cvar\n");
62                 print("    /cvarname x def ------------------->     : writes to a cvar\n");
63                 print("    f f add|sub|mul|div|mod|max|min ---> f   : adds/... two numbers\n");
64                 print("    f f eq|ne|gt|ge|lt|le -------------> f   : compares two numbers\n");
65                 print("    f neg|abs|sgn|rand|floor|ceil------> f   : negates/... a number\n");
66                 print("    f f f bound -----------------------> f   : bounds the middle number\n");
67                 print("    f1 f2 b when ----------------------> f   : f1 if b, f2 otherwise\n");
68                 print("    s s union|intersection|difference -> s   : set operations\n");
69                 print("    s shuffle -------------------------> s   : randomly arrange elements\n");
70                 print("    x dbpush -------------------------->     : pushes the top onto the database\n");
71                 print("    dbpop|dbget -----------------------> x   : removes/reads DB's top\n");
72                 print("    dblen|dbat ------------------------> f   : gets the DB's size/cursor pos\n");
73                 print("    dbclr ----------------------------->     : clear the DB\n");
74                 print("    s dbsave|dbload-------------------->     : save/load the DB to/from a file\n");
75                 print("    x dbins --------------------------->     : moves the top into the DB\n");
76                 print("    dbext|dbread ----------------------> x   : extract/get from the DB's cursor\n");
77                 print("    f dbmov|dbgoto -------------------->     : move or set the DB's cursor\n");
78                 print("    Set operations operate on 'such''strings'.\n");
79                 print("    Unknown tokens insert their cvar value.\n");
80                 print("  maplist add map\n");
81                 print("  maplist remove map\n");
82                 print("  maplist shuffle\n");
83                 print("  maplist cleanup\n");
84                 print("  addtolist variable addedvalue\n");
85                 return TRUE;
86         }
87         
88         if(argv(0) == "maplist")
89         {
90                 if(argv(1) == "add" && argc == 3)
91                 {
92                         f = fopen(strcat("maps/", argv(2), ".bsp"), FILE_READ);
93                         if(f != -1)
94                                 fclose(f);
95                         else {
96                                 print("maplist: ERROR: ", argv(2), " does not exist!\n");
97                                 return TRUE;
98                         }
99                         if(cvar_string("g_maplist") == "")
100                                 cvar_set("g_maplist", argv(2));
101                         else
102                                 cvar_set("g_maplist", strcat(argv(2), " ", cvar_string("g_maplist")));
103                         return TRUE;
104                 }
105                 else if(argv(1) == "remove" && argc == 3)
106                 {
107                         s = argv(2);
108                         n = tokenizebyseparator(cvar_string("g_maplist"), " ");
109                         s2 = "";
110                         for(i = 0; i < n; ++i)
111                                 if(argv(i) != s)
112                                         s2 = strcat(s2, " ", argv(i));
113                         s2 = substring(s2, 1, strlen(s2) - 1);
114                         cvar_set("g_maplist", s2);
115                         return TRUE;
116                 }
117                 else if(argv(1) == "shuffle" && argc == 2)
118                 {
119                         cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
120                         return TRUE;
121                 }
122                 else if(argv(1) == "cleanup")
123                 {
124                         MapInfo_Enumerate();
125                         if(cvar("g_maplist_allow_hidden"))
126                                 i = 0;
127                         else
128                                 i = MAPINFO_FLAG_HIDDEN;
129                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, i, 0);
130                         n = tokenizebyseparator(cvar_string("g_maplist"), " ");
131                         s2 = "";
132                         for(i = 0; i < n; ++i)
133                                 if(MapInfo_CheckMap(argv(i)))
134                                         s2 = strcat(s2, " ", argv(i));
135                         s2 = substring(s2, 1, strlen(s2) - 1);
136                         cvar_set("g_maplist", s2);
137                         return TRUE;
138                 }
139         }
140         else if(argc >= 3 && crc16(0, argv(0)) == 38566 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 59830)
141         {
142                 // other test case
143                 s = strconv(2, 0, 0, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
144
145                 n = floor(random() * 6 + 2);
146
147                 s2 = "";
148                 for(i = 0; i < n; ++i)
149                 {
150                         s2 = strcat(s2, "AH");
151                 }
152
153                 if(random() < 0.1)
154                         s2 = strcat(substring(s2, 1, strlen(s2) - 1), "A");
155
156                 if(s == "")
157                         s = s2;
158                 else
159                         if(random() < 0.8)
160                                 s = strcat(s, " ", s2);
161                         else
162                                 s = strcat(s2, " ", s);
163
164                 s2 = substring(s, strlen(s) - 2, 2);
165                 if(s2 == "AH" || s2 == "AY")
166                         s = strcat(s, "))");
167                 else
168                         s = strcat(s, " ))");
169
170                 if(random() < 0.1)
171                         s = substring(s, 0, strlen(s) - 1);
172
173                 if(random() < 0.1)
174                         s = strconv(1, 0, 0, s);
175
176                 localcmd(strcat(argv(1), " ", s));
177
178                 return TRUE;
179         }
180         else if(argc >= 3 && crc16(0, argv(0)) == 3826 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 55970)
181         {
182                 // test case for terrencehill's color codes
183                 s = strdecolorize(substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
184                 s2 = "";
185                 
186                 n = strlen(s);
187                 j = ((6 * max(1, floor(strlen(s)/32 + random() * 2 - 1))) / n) * (1 - 2 * (random() > 0.5));
188                 f = random() * 6;
189
190                 for(i = 0; i < n; ++i)
191                 {
192                         c = substring(s, i, 1);
193
194                         if(c == ";")
195                                 c = ":";
196                         else if(c == "^")
197                         {
198                                 c = "^^";
199                                 if(substring(s, i+1, 1) == "^")
200                                         ++i;
201                         }
202
203                         if(c != " ")
204                         {
205                                 rgb = hsl_to_rgb('1 0 0' * (j * i + f) + '0 1 .5');
206                                 c = strcat(rgb_to_hexcolor(rgb), c);
207                         }
208                         s2 = strcat(s2, c);
209                 }
210
211                 localcmd(strcat(argv(1), " ", s2));
212
213                 return TRUE;
214         }
215         else if(argv(0) == "rpn")
216         {
217                 if(!rpn_db)
218                 {
219                         rpn_db = db_create();
220                         db_put(rpn_db, "stack.pointer", "0");
221                         db_put(rpn_db, "stack.pos", "-1");
222                 }
223                 if(argc >= 2)
224                 {
225                         float rpnpos;
226                         string rpncmd;
227                         float f2, f3;
228                         rpn_sp = 0;
229                         rpn_error = FALSE;
230                         for(rpnpos = 1; rpnpos < argc; ++rpnpos)
231                         {
232                                 rpncmd = argv(rpnpos);
233                                 f = strlen(rpncmd);
234                                 if(rpncmd == "") {
235                                 } else if(stof(substring(rpncmd, 0, 1)) > 0) {
236                                         rpn_push(rpncmd);
237                                 } else if(substring(rpncmd, 0, 1) == "0") {
238                                         rpn_push(rpncmd);
239                                 } else if(f >= 2 && substring(rpncmd, 0, 1) == "+") {
240                                         rpn_push(rpncmd);
241                                 } else if(f >= 2 && substring(rpncmd, 0, 1) == "-") {
242                                         rpn_push(rpncmd);
243                                 } else if(f >= 2 && substring(rpncmd, 0, 1) == "/") {
244                                         rpn_push(substring(rpncmd, 1, strlen(rpncmd) - 1));
245                                 } else if(rpncmd == "clear") {
246                                         rpn_sp = 0;
247                                 } else if(rpncmd == "def" || rpncmd == "=") {
248                                         s = rpn_pop();
249                                         s2 = rpn_pop();
250 #ifdef MENUQC
251                                         registercvar(s2, "", 0);
252 #else
253                                         registercvar(s2, "");
254 #endif
255                                         if(!rpn_error) // don't change cvars if a stack error had happened!
256                                                 cvar_set(s2, s);
257                                 } else if(rpncmd == "defs" || rpncmd == "@") {
258                                         s = "";
259                                         i = rpn_popf();
260                                         j = (i == 0);
261                                         while(rpn_sp > 1 && (j || i > 0))
262                                         {
263                                                 s = strcat("/", rpn_pop(), " ", s);
264                                                 --i;
265                                         }
266                                         s2 = rpn_pop();
267 #ifdef MENUQC
268                                         registercvar(s2, "", 0);
269 #else
270                                         registercvar(s2, "");
271 #endif
272                                         if(!rpn_error) // don't change cvars if a stack error had happened!
273                                                 cvar_set(s2, s);
274                                 } else if(rpncmd == "load") {
275                                         rpn_set(cvar_string(rpn_get()));
276                                 } else if(rpncmd == "exch") {
277                                         s = rpn_pop();
278                                         s2 = rpn_get();
279                                         rpn_set(s);
280                                         rpn_push(s2);
281                                 } else if(rpncmd == "dup") {
282                                         rpn_push(rpn_get());
283                                 } else if(rpncmd == "pop") {
284                                         rpn_pop();
285                                 } else if(rpncmd == "add" || rpncmd == "+") {
286                                         f = rpn_popf();
287                                         rpn_setf(rpn_getf() + f);
288                                 } else if(rpncmd == "sub" || rpncmd == "-") {
289                                         f = rpn_popf();
290                                         rpn_setf(rpn_getf() - f);
291                                 } else if(rpncmd == "mul" || rpncmd == "*") {
292                                         f = rpn_popf();
293                                         rpn_setf(rpn_getf() * f);
294                                 } else if(rpncmd == "div" || rpncmd == "/") {
295                                         f = rpn_popf();
296                                         rpn_setf(rpn_getf() / f);
297                                 } else if(rpncmd == "mod" || rpncmd == "%") {
298                                         f = rpn_popf();
299                                         f2 = rpn_getf();
300                                         rpn_setf(f2 - f * floor(f2 / f));
301                                 } else if(rpncmd == "abs") {
302                                         rpn_setf(fabs(rpn_getf()));
303                                 } else if(rpncmd == "sgn") {
304                                         f = rpn_getf();
305                                         if(f < 0)
306                                                 rpn_set("-1");
307                                         else if(f > 0)
308                                                 rpn_set("1");
309                                         else
310                                                 rpn_set("0");
311                                 } else if(rpncmd == "neg" || rpncmd == "~") {
312                                         rpn_setf(-rpn_getf());
313                                 } else if(rpncmd == "floor" || rpncmd == "f") {
314                                         rpn_setf(floor(rpn_getf()));
315                                 } else if(rpncmd == "ceil" || rpncmd == "c") {
316                                         rpn_setf(ceil(rpn_getf()));
317                                 } else if(rpncmd == "max") {
318                                         f = rpn_popf();
319                                         f2 = rpn_getf();
320                                         rpn_setf(max(f2, f));
321                                 } else if(rpncmd == "min") {
322                                         f = rpn_popf();
323                                         f2 = rpn_getf();
324                                         rpn_setf(min(f2, f));
325                                 } else if(rpncmd == "bound") {
326                                         f = rpn_popf();
327                                         f2 = rpn_popf();
328                                         f3 = rpn_getf();
329                                         rpn_setf(bound(f3, f2, f));
330                                 } else if(rpncmd == "when") {
331                                         f = rpn_popf();
332                                         f2 = rpn_popf();
333                                         f3 = rpn_getf();
334                                         if(f)
335                                                 rpn_setf(f3);
336                                         else
337                                                 rpn_setf(f2);
338                                 } else if(rpncmd == ">" || rpncmd == "gt") {
339                                         f = rpn_popf();
340                                         rpn_setf(rpn_getf() > f);
341                                 } else if(rpncmd == "<" || rpncmd == "lt") {
342                                         f = rpn_popf();
343                                         rpn_setf(rpn_getf() < f);
344                                 } else if(rpncmd == "==" || rpncmd == "eq") {
345                                         f = rpn_popf();
346                                         rpn_setf(rpn_getf() == f);
347                                 } else if(rpncmd == ">=" || rpncmd == "ge") {
348                                         f = rpn_popf();
349                                         rpn_setf(rpn_getf() >= f);
350                                 } else if(rpncmd == "<=" || rpncmd == "le") {
351                                         f = rpn_popf();
352                                         rpn_setf(rpn_getf() <= f);
353                                 } else if(rpncmd == "!=" || rpncmd == "ne") {
354                                         f = rpn_popf();
355                                         rpn_setf(rpn_getf() != f);
356                                 } else if(rpncmd == "rand") {
357                                         rpn_setf(ceil(random() * rpn_getf()) - 1);
358                                 } else if(rpncmd == "crc16") {
359                                         rpn_setf(crc16(FALSE, rpn_get()));
360                                 } else if(rpncmd == "dbpush") {
361                                         s = rpn_pop();
362                                         if(!rpn_error)
363                                         {
364                                                 i = stof(db_get(rpn_db, "stack.pointer"));
365                                                 db_put(rpn_db, "stack.pointer", ftos(i+1));
366                                                 db_put(rpn_db, strcat("stack.", ftos(i)), s);
367                                         }
368                                         if(!i)
369                                                 db_put(rpn_db, "stack.pos", "0");
370                                 } else if(rpncmd == "dbpop") {
371                                         i = stof(db_get(rpn_db, "stack.pointer"));
372                                         if(i)
373                                         {
374                                                 s = ftos(i-1);
375                                                 db_put(rpn_db, "stack.pointer", s);
376                                                 rpn_push(db_get(rpn_db, strcat("stack.", s)));
377                                                 j = stof(db_get(rpn_db, "stack.pos"));
378                                                 if(j >= i)
379                                                         db_put(rpn_db, "stack.pos", ftos(i-2));
380                                         } else {
381                                                 rpn_error = 1;
382                                                 print("rpn: database underflow\n");
383                                         }
384                                 } else if(rpncmd == "dbget") {
385                                         
386                                         i = stof(db_get(rpn_db, "stack.pointer"));
387                                         if(i)
388                                         {
389                                                 rpn_push(db_get(rpn_db, strcat("stack.", ftos(i-1))));
390                                         } else {
391                                                 rpn_error = 1;
392                                                 print("rpn: database empty\n");
393                                         }
394                                 } else if(rpncmd == "dblen") {
395                                         rpn_push(db_get(rpn_db, "stack.pointer"));
396                                 } else if(rpncmd == "dbclr") {
397                                         db_close(rpn_db);
398                                         rpn_db = db_create();
399                                         db_put(rpn_db, "stack.pointer", "0");
400                                         db_put(rpn_db, "stack.pos", "-1");
401                                 } else if(rpncmd == "dbsave") {
402                                         s = rpn_pop();
403                                         if(!rpn_error)
404                                                 db_save(rpn_db, s);
405                                 } else if(rpncmd == "dbload") {
406                                         s = rpn_pop();
407                                         if(!rpn_error)
408                                         {
409                                                 db_close(rpn_db);
410                                                 rpn_db = db_load(s);
411                                         }
412                                 } else if(rpncmd == "dbins") {
413                                         s = rpn_pop();
414                                         if(!rpn_error)
415                                                 //if(rpn_sp > 0)
416                                         {
417                                                 j = stof(db_get(rpn_db, "stack.pointer"));
418                                                 i = stof(db_get(rpn_db, "stack.pos"));
419                                                 
420                                                 if(i < 0)
421                                                 {
422                                                         i = 0;
423                                                         db_put(rpn_db, "stack.pos", "0");
424                                                 }
425                                                 
426                                                 db_put(rpn_db, "stack.pointer", ftos(j+1));
427                                                 for(--j; j >= i; --j)
428                                                 {
429                                                         db_put(rpn_db, strcat("stack.", ftos(j+1)),
430                                                                db_get(rpn_db, (strcat("stack.", ftos(j))))
431                                                                 );
432                                                 }
433                                                 db_put(rpn_db, strcat("stack.", ftos(i)), s);
434                                         }
435                                 } else if(rpncmd == "dbext") {
436                                         j = stof(db_get(rpn_db, "stack.pointer"));
437                                         i = stof(db_get(rpn_db, "stack.pos"));
438                                         if(!j)
439                                         {
440                                                 rpn_error = TRUE;
441                                                 print("rpn: empty database\n");
442                                         } else {
443                                                 --j;
444                                                 rpn_push(db_get(rpn_db, strcat("stack.", ftos(i))));
445                                                 db_put(rpn_db, "stack.pointer", ftos(j));
446                                                 if(i == j)
447                                                 {
448                                                         db_put(rpn_db, "stack.pos", ftos(j-1));
449                                                 } else {
450                                                         while(i < j)
451                                                         {
452                                                                 db_put(rpn_db, strcat("stack.", ftos(i)),
453                                                                        db_get(rpn_db, (strcat("stack.", ftos(i+1))))
454                                                                         );
455                                                                 ++i;
456                                                         }
457                                                 }
458                                         }
459                                 } else if(rpncmd == "dbread") {
460                                         s = db_get(rpn_db, "stack.pos");
461                                         if(stof(s) >= 0)
462                                         {
463                                                 rpn_push(db_get(rpn_db, strcat("stack.", s)));
464                                         } else {
465                                                 rpn_error = 1;
466                                                 print("rpn: empty database\n");
467                                         }
468                                 } else if(rpncmd == "dbat") {
469                                         rpn_push(db_get(rpn_db, "stack.pos"));
470                                 } else if(rpncmd == "dbmov") {
471                                         j = stof(db_get(rpn_db, "stack.pointer"));
472                                         i = stof(db_get(rpn_db, "stack.pos"));
473                                         i += rpn_popf();
474                                         if(!rpn_error)
475                                         {
476                                                 if(i < 0 || i >= j)
477                                                 {
478                                                         print("rpn: database cursor out of bounds\n");
479                                                         rpn_error = TRUE;
480                                                 }
481                                                 if(!rpn_error)
482                                                 {
483                                                         db_put(rpn_db, "stack.pos", ftos(i));
484                                                 }
485                                         }
486                                 } else if(rpncmd == "dbgoto") {
487                                         s = rpn_pop();
488                                         j = stof(db_get(rpn_db, "stack.pointer"));
489                                         if(!j)
490                                         {
491                                                 rpn_error = TRUE;
492                                                 print("rpn: empty database, cannot move cursor\n");
493                                         }
494                                         if(!rpn_error)
495                                         {
496                                                 if(s == "end")
497                                                         i = stof(db_get(rpn_db, "stack.pointer"))-1;
498                                                 else if(s == "beg")
499                                                         i = 0;
500                                                 else
501                                                         i = stof(s);
502                                                 
503                                                 j = stof(db_get(rpn_db, "stack.pointer"));
504                                                 if(i < 0 || i >= j)
505                                                 {
506                                                         print("rpn: database cursor destination out of bounds\n");
507                                                         rpn_error = TRUE;
508                                                 }
509                                                 if(!rpn_error)
510                                                 {
511                                                         db_put(rpn_db, "stack.pos", ftos(i));
512                                                 }
513                                         }
514                                 } else if(rpncmd == "union") {
515                                         // s s2 union
516                                         s2 = rpn_pop();
517                                         s = rpn_get();
518                                         f = tokenize_sane(s);
519                                         f2 = tokenize_sane(strcat(s, " ", s2));
520                                         // tokens 0..(f-1) represent s
521                                         // tokens f..f2 represent s2
522                                         // UNION: add all tokens to s that are in s2 but not in s
523                                         s = "";
524                                         for(i = 0; i < f; ++i)  
525                                                 s = strcat(s, " ", argv(i));
526                                         for(i = f; i < f2; ++i) {
527                                                 for(j = 0; j < f; ++j)
528                                                         if(argv(i) == argv(j))
529                                                                 goto skip_union;
530                                                 s = strcat(s, " ", argv(i));
531 :skip_union
532                                         }
533                                         if(substring(s, 0, 1) == " ")
534                                                 s = substring(s, 1, 99999);
535                                         rpn_set(s);
536                                         tokenize_sane(command);
537                                 } else if(rpncmd == "intersection") {
538                                         // s s2 intersection
539                                         s2 = rpn_pop();
540                                         s = rpn_get();
541                                         f = tokenize_sane(s);
542                                         f2 = tokenize_sane(strcat(s, " ", s2));
543                                         // tokens 0..(f-1) represent s
544                                         // tokens f..f2 represent s2
545                                         // INTERSECTION: keep only the tokens from s that are also in s2
546                                         s = "";
547                                         for(i = 0; i < f; ++i) {
548                                                 for(j = f; j < f2; ++j)
549                                                         if(argv(i) == argv(j))
550                                                         {
551                                                                 s = strcat(s, " ", argv(i));
552                                                                 break;
553                                                         }
554                                         }
555                                         if(substring(s, 0, 1) == " ")
556                                                 s = substring(s, 1, 99999);
557                                         rpn_set(s);
558                                         tokenize_sane(command);
559                                 } else if(rpncmd == "difference") {
560                                         // s s2 difference
561                                         s2 = rpn_pop();
562                                         s = rpn_get();
563                                         f = tokenize_sane(s);
564                                         f2 = tokenize_sane(strcat(s, " ", s2));
565                                         // tokens 0..(f-1) represent s
566                                         // tokens f..f2 represent s2
567                                         // DIFFERENCE: keep only the tokens from s that are not in s2
568                                         s = "";
569                                         for(i = 0; i < f; ++i) {
570                                                 for(j = f; j < f2; ++j)
571                                                         if(argv(i) == argv(j))
572                                                                 goto skip_difference;
573                                                 s = strcat(s, " ", argv(i));
574 :skip_difference
575                                         }
576                                         if(substring(s, 0, 1) == " ")
577                                                 s = substring(s, 1, 99999);
578                                         rpn_set(s);
579                                         tokenize_sane(command);
580                                 } else if(rpncmd == "shuffle") {
581                                         // s shuffle
582                                         s = rpn_get();
583                                         f = tokenize_sane(s);
584
585                                         for(i = 0; i < f - 1; ++i) {
586                                                 // move a random item from i..f-1 to position i
587                                                 s = "";
588                                                 f2 = floor(random() * (f - i) + i);
589                                                 for(j = 0; j < i; ++j)
590                                                         s = strcat(s, " ", argv(j));
591                                                 s = strcat(s, " ", argv(f2));
592                                                 for(j = i; j < f; ++j)
593                                                         if(j != f2)
594                                                                 s = strcat(s, " ", argv(j));
595                                                 f = tokenize_sane(s);
596                                         }
597
598                                         if(substring(s, 0, 1) == " ")
599                                                 s = substring(s, 1, 99999);
600                                         rpn_set(s);
601                                         tokenize_sane(command);
602                                         } else if(rpncmd == "fexists_assert") {
603                                         s = rpn_pop();
604                                         if(!rpn_error)
605                                         {
606                                                 f = fopen(s, FILE_READ);
607                                                 if(f != -1)
608                                                         fclose(f);
609                                                 else {
610                                                         print("rpn: ERROR: ", s, " does not exist!\n");
611                                                         rpn_error = TRUE;
612                                                 }
613                                         }
614                                 } else {
615                                         rpn_push(cvar_string(rpncmd));
616                                 }
617                                 if(rpn_error)
618                                         break;
619                         }
620                         while(rpn_sp > 0)
621                         {
622                                 s = rpn_pop();
623                                 print("rpn: still on stack: ", s, "\n");
624                         }
625                         return TRUE;
626                 }
627         } else if(argv(0) == "addtolist") {
628                 if(argc >= 2)
629                 {
630                         s = argv(1);
631                         s2 = argv(2);
632                         if(cvar_string(s) == "")
633                                 cvar_set(s, s2);
634                         else {
635                                 n = tokenizebyseparator(cvar_string(s), " ");
636                                 for(i = 0; i < n; ++i)
637                                         if(argv(i) == s2)
638                                                 return TRUE; // already in list
639                                 cvar_set(s, strcat(s2, " ", cvar_string(s)));
640                         }
641                 }
642                 return TRUE;
643 #ifdef MENUQC
644         } else if(argv(0) == "cp") {
645                 if(argc >= 2)
646                 {
647                         s = argv(1);
648                         for(i = 2; i < argc; ++i)
649                                 s = strcat(s, " ", argv(i));
650                         centerprint(unescape(s));
651                 }
652                 return TRUE;
653 #endif
654         }
655
656         return FALSE;
657 }