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