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