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