]> icculus.org git repositories - divverent/darkplaces.git/blob - cmd.c
-Changed the SDL window icon back to DP's icon.
[divverent/darkplaces.git] / cmd.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // cmd.c -- Quake script command processing module
21
22 #include "quakedef.h"
23
24 #define MAX_ALIAS_NAME  32
25
26 typedef struct cmdalias_s
27 {
28         struct cmdalias_s *next;
29         char name[MAX_ALIAS_NAME];
30         char *value;
31 } cmdalias_t;
32
33 static cmdalias_t *cmd_alias;
34
35 static qboolean cmd_wait;
36
37 static mempool_t *cmd_mempool;
38
39 #define CMD_TOKENIZELENGTH 4096
40 static char cmd_tokenizebuffer[CMD_TOKENIZELENGTH];
41 static int cmd_tokenizebufferpos = 0;
42
43 //=============================================================================
44
45 /*
46 ============
47 Cmd_Wait_f
48
49 Causes execution of the remainder of the command buffer to be delayed until
50 next frame.  This allows commands like:
51 bind g "impulse 5 ; +attack ; wait ; -attack ; impulse 2"
52 ============
53 */
54 static void Cmd_Wait_f (void)
55 {
56         cmd_wait = true;
57 }
58
59 /*
60 =============================================================================
61
62                                                 COMMAND BUFFER
63
64 =============================================================================
65 */
66
67         // LordHavoc: inreased this from 8192 to 32768
68 static sizebuf_t        cmd_text;
69 static qbyte            cmd_text_buf[32768];
70
71 /*
72 ============
73 Cbuf_Init
74 ============
75 */
76 void Cbuf_Init (void)
77 {
78         // space for commands and script files
79         cmd_text.data = cmd_text_buf;
80         cmd_text.maxsize = sizeof(cmd_text_buf);
81         cmd_text.cursize = 0;
82 }
83
84 /*
85 ============
86 Cbuf_Shutdown
87 ============
88 */
89 void Cbuf_Shutdown (void)
90 {
91 }
92
93 /*
94 ============
95 Cbuf_AddText
96
97 Adds command text at the end of the buffer
98 ============
99 */
100 void Cbuf_AddText (const char *text)
101 {
102         int             l;
103
104         l = strlen (text);
105
106         if (cmd_text.cursize + l >= cmd_text.maxsize)
107         {
108                 Con_Print("Cbuf_AddText: overflow\n");
109                 return;
110         }
111
112         SZ_Write (&cmd_text, text, strlen (text));
113 }
114
115
116 /*
117 ============
118 Cbuf_InsertText
119
120 Adds command text immediately after the current command
121 Adds a \n to the text
122 FIXME: actually change the command buffer to do less copying
123 ============
124 */
125 void Cbuf_InsertText (const char *text)
126 {
127         char    *temp;
128         int             templen;
129
130         // copy off any commands still remaining in the exec buffer
131         templen = cmd_text.cursize;
132         if (templen)
133         {
134                 temp = Mem_Alloc (tempmempool, templen);
135                 memcpy (temp, cmd_text.data, templen);
136                 SZ_Clear (&cmd_text);
137         }
138         else
139                 temp = NULL;
140
141         // add the entire text of the file
142         Cbuf_AddText (text);
143
144         // add the copied off data
145         if (temp != NULL)
146         {
147                 SZ_Write (&cmd_text, temp, templen);
148                 Mem_Free (temp);
149         }
150 }
151
152 /*
153 ============
154 Cbuf_Execute
155 ============
156 */
157 void Cbuf_Execute (void)
158 {
159         int i;
160         char *text;
161         char line[1024];
162         int quotes;
163
164         // LordHavoc: making sure the tokenizebuffer doesn't get filled up by repeated crashes
165         cmd_tokenizebufferpos = 0;
166
167         while (cmd_text.cursize)
168         {
169 // find a \n or ; line break
170                 text = (char *)cmd_text.data;
171
172                 quotes = 0;
173                 for (i=0 ; i< cmd_text.cursize ; i++)
174                 {
175                         if (text[i] == '"')
176                                 quotes++;
177                         if ( !(quotes&1) &&  text[i] == ';')
178                                 break;  // don't break if inside a quoted string
179                         if (text[i] == '\r' || text[i] == '\n')
180                                 break;
181                 }
182
183                 memcpy (line, text, i);
184                 line[i] = 0;
185
186 // delete the text from the command buffer and move remaining commands down
187 // this is necessary because commands (exec, alias) can insert data at the
188 // beginning of the text buffer
189
190                 if (i == cmd_text.cursize)
191                         cmd_text.cursize = 0;
192                 else
193                 {
194                         i++;
195                         cmd_text.cursize -= i;
196                         memcpy (cmd_text.data, text+i, cmd_text.cursize);
197                 }
198
199 // execute the command line
200                 Cmd_ExecuteString (line, src_command);
201
202                 if (cmd_wait)
203                 {       // skip out while text still remains in buffer, leaving it
204                         // for next frame
205                         cmd_wait = false;
206                         break;
207                 }
208         }
209 }
210
211 /*
212 ==============================================================================
213
214                                                 SCRIPT COMMANDS
215
216 ==============================================================================
217 */
218
219 /*
220 ===============
221 Cmd_StuffCmds_f
222
223 Adds command line parameters as script statements
224 Commands lead with a +, and continue until a - or another +
225 quake +prog jctest.qp +cmd amlev1
226 quake -nosound +cmd amlev1
227 ===============
228 */
229 void Cmd_StuffCmds_f (void)
230 {
231         int             i, j, l;
232         // this is per command, and bounds checked (no buffer overflows)
233         char    build[2048];
234
235         if (Cmd_Argc () != 1)
236         {
237                 Con_Print("stuffcmds : execute command line parameters\n");
238                 return;
239         }
240
241         for (i = 0;i < com_argc;i++)
242         {
243                 if (com_argv[i] && com_argv[i][0] == '+' && (com_argv[i][1] < '0' || com_argv[i][1] > '9'))
244                 {
245                         l = 0;
246                         j = 1;
247                         while (com_argv[i][j])
248                                 build[l++] = com_argv[i][j++];
249                         i++;
250                         for (;i < com_argc;i++)
251                         {
252                                 if (!com_argv[i])
253                                         continue;
254                                 if ((com_argv[i][0] == '+' || com_argv[i][0] == '-') && (com_argv[i][1] < '0' || com_argv[i][1] > '9'))
255                                         break;
256                                 if (l + strlen(com_argv[i]) + 5 > sizeof(build))
257                                         break;
258                                 build[l++] = ' ';
259                                 build[l++] = '\"';
260                                 for (j = 0;com_argv[i][j];j++)
261                                         build[l++] = com_argv[i][j];
262                                 build[l++] = '\"';
263                         }
264                         build[l++] = '\n';
265                         build[l++] = 0;
266                         Cbuf_InsertText (build);
267                         i--;
268                 }
269         }
270 }
271
272
273 /*
274 ===============
275 Cmd_Exec_f
276 ===============
277 */
278 static void Cmd_Exec_f (void)
279 {
280         char *f;
281
282         if (Cmd_Argc () != 2)
283         {
284                 Con_Print("exec <filename> : execute a script file\n");
285                 return;
286         }
287
288         f = (char *)FS_LoadFile (Cmd_Argv(1), tempmempool, false);
289         if (!f)
290         {
291                 Con_Printf("couldn't exec %s\n",Cmd_Argv(1));
292                 return;
293         }
294         Con_DPrintf("execing %s\n",Cmd_Argv(1));
295
296         Cbuf_InsertText (f);
297         Mem_Free(f);
298 }
299
300
301 /*
302 ===============
303 Cmd_Echo_f
304
305 Just prints the rest of the line to the console
306 ===============
307 */
308 static void Cmd_Echo_f (void)
309 {
310         int             i;
311
312         for (i=1 ; i<Cmd_Argc() ; i++)
313                 Con_Printf("%s ",Cmd_Argv(i));
314         Con_Print("\n");
315 }
316
317 /*
318 ===============
319 Cmd_Alias_f
320
321 Creates a new command that executes a command string (possibly ; seperated)
322 ===============
323 */
324 static void Cmd_Alias_f (void)
325 {
326         cmdalias_t      *a;
327         char            cmd[1024];
328         int                     i, c;
329         const char              *s;
330
331         if (Cmd_Argc() == 1)
332         {
333                 Con_Print("Current alias commands:\n");
334                 for (a = cmd_alias ; a ; a=a->next)
335                         Con_Printf("%s : %s\n", a->name, a->value);
336                 return;
337         }
338
339         s = Cmd_Argv(1);
340         if (strlen(s) >= MAX_ALIAS_NAME)
341         {
342                 Con_Print("Alias name is too long\n");
343                 return;
344         }
345
346         // if the alias already exists, reuse it
347         for (a = cmd_alias ; a ; a=a->next)
348         {
349                 if (!strcmp(s, a->name))
350                 {
351                         Z_Free (a->value);
352                         break;
353                 }
354         }
355
356         if (!a)
357         {
358                 cmdalias_t *prev, *current;
359
360                 a = Z_Malloc (sizeof(cmdalias_t));
361                 strlcpy (a->name, s, sizeof (a->name));
362                 // insert it at the right alphanumeric position
363                 for( prev = NULL, current = cmd_alias ; current && strcmp( current->name, a->name ) < 0 ; prev = current, current = current->next )
364                         ;
365                 if( prev ) {
366                         prev->next = a;
367                 } else {
368                         cmd_alias = a;
369                 }
370                 a->next = current;
371         }
372         
373
374 // copy the rest of the command line
375         cmd[0] = 0;             // start out with a null string
376         c = Cmd_Argc();
377         for (i=2 ; i< c ; i++)
378         {
379                 strlcat (cmd, Cmd_Argv(i), sizeof (cmd));
380                 if (i != c)
381                         strlcat (cmd, " ", sizeof (cmd));
382         }
383         strlcat (cmd, "\n", sizeof (cmd));
384
385         a->value = Z_Malloc (strlen (cmd) + 1);
386         strcpy (a->value, cmd);
387 }
388
389 /*
390 =============================================================================
391
392                                         COMMAND EXECUTION
393
394 =============================================================================
395 */
396
397 typedef struct cmd_function_s
398 {
399         struct cmd_function_s *next;
400         const char *name;
401         xcommand_t function;
402 } cmd_function_t;
403
404
405 #define MAX_ARGS                80
406
407 static int cmd_argc;
408 static const char *cmd_argv[MAX_ARGS];
409 static const char *cmd_null_string = "";
410 static const char *cmd_args = NULL;
411
412 cmd_source_t cmd_source;
413
414
415 static cmd_function_t *cmd_functions;           // possible commands to execute
416
417 /*
418 ========
419 Cmd_List
420
421         CmdList Added by EvilTypeGuy eviltypeguy@qeradiant.com
422         Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
423
424 ========
425 */
426 static void Cmd_List_f (void)
427 {
428         cmd_function_t *cmd;
429         const char *partial;
430         int len, count;
431
432         if (Cmd_Argc() > 1)
433         {
434                 partial = Cmd_Argv (1);
435                 len = strlen(partial);
436         }
437         else
438         {
439                 partial = NULL;
440                 len = 0;
441         }
442
443         count = 0;
444         for (cmd = cmd_functions; cmd; cmd = cmd->next)
445         {
446                 if (partial && strncmp(partial, cmd->name, len))
447                         continue;
448                 Con_Printf("%s\n", cmd->name);
449                 count++;
450         }
451
452         Con_Printf("%i Command%s", count, (count > 1) ? "s" : "");
453         if (partial)
454                 Con_Printf(" beginning with \"%s\"", partial);
455
456         Con_Print("\n\n");
457 }
458
459 /*
460 ============
461 Cmd_Init
462 ============
463 */
464 void Cmd_Init (void)
465 {
466         cmd_mempool = Mem_AllocPool("commands", 0, NULL);
467
468 //
469 // register our commands
470 //
471         Cmd_AddCommand ("stuffcmds",Cmd_StuffCmds_f);
472         Cmd_AddCommand ("exec",Cmd_Exec_f);
473         Cmd_AddCommand ("echo",Cmd_Echo_f);
474         Cmd_AddCommand ("alias",Cmd_Alias_f);
475         Cmd_AddCommand ("cmd", Cmd_ForwardToServer);
476         Cmd_AddCommand ("wait", Cmd_Wait_f);
477         Cmd_AddCommand ("cmdlist", Cmd_List_f);         // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
478         Cmd_AddCommand ("cvarlist", Cvar_List_f);       // 2000-01-09 CmdList, CvarList commands
479                                                                                                 // By Matthias "Maddes" Buecher
480         Cmd_AddCommand ("set", Cvar_Set_f);
481         Cmd_AddCommand ("seta", Cvar_SetA_f);
482 }
483
484 /*
485 ============
486 Cmd_Shutdown
487 ============
488 */
489 void Cmd_Shutdown(void)
490 {
491         Mem_FreePool(&cmd_mempool);
492 }
493
494 /*
495 ============
496 Cmd_Argc
497 ============
498 */
499 int             Cmd_Argc (void)
500 {
501         return cmd_argc;
502 }
503
504 /*
505 ============
506 Cmd_Argv
507 ============
508 */
509 const char *Cmd_Argv (int arg)
510 {
511         if (arg >= cmd_argc )
512                 return cmd_null_string;
513         return cmd_argv[arg];
514 }
515
516 /*
517 ============
518 Cmd_Args
519 ============
520 */
521 const char *Cmd_Args (void)
522 {
523         return cmd_args;
524 }
525
526
527 /*
528 ============
529 Cmd_TokenizeString
530
531 Parses the given string into command line tokens.
532 ============
533 */
534 static void Cmd_TokenizeString (const char *text)
535 {
536         int l;
537
538         cmd_argc = 0;
539         cmd_args = NULL;
540
541         while (1)
542         {
543                 // skip whitespace up to a /n
544                 while (*text && *text <= ' ' && *text != '\r' && *text != '\n')
545                         text++;
546
547                 // line endings:
548                 // UNIX: \n
549                 // Mac: \r
550                 // Windows: \r\n
551                 if (*text == '\n' || *text == '\r')
552                 {
553                         // a newline seperates commands in the buffer
554                         if (*text == '\r' && text[1] == '\n')
555                                 text++;
556                         text++;
557                         break;
558                 }
559
560                 if (!*text)
561                         return;
562
563                 if (cmd_argc == 1)
564                          cmd_args = text;
565
566                 if (!COM_ParseTokenConsole(&text))
567                         return;
568
569                 if (cmd_argc < MAX_ARGS)
570                 {
571                         l = strlen(com_token) + 1;
572                         if (cmd_tokenizebufferpos + l > CMD_TOKENIZELENGTH)
573                                 Sys_Error("Cmd_TokenizeString: ran out of %i character buffer space for command arguements\n", CMD_TOKENIZELENGTH);
574                         strcpy (cmd_tokenizebuffer + cmd_tokenizebufferpos, com_token);
575                         cmd_argv[cmd_argc] = cmd_tokenizebuffer + cmd_tokenizebufferpos;
576                         cmd_tokenizebufferpos += l;
577                         cmd_argc++;
578                 }
579         }
580
581 }
582
583
584 /*
585 ============
586 Cmd_AddCommand
587 ============
588 */
589 void Cmd_AddCommand (const char *cmd_name, xcommand_t function)
590 {
591         cmd_function_t *cmd;
592         cmd_function_t *prev, *current;
593
594 // fail if the command is a variable name
595         if (Cvar_VariableString(cmd_name)[0])
596         {
597                 Con_Printf("Cmd_AddCommand: %s already defined as a var\n", cmd_name);
598                 return;
599         }
600
601 // fail if the command already exists
602         for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
603         {
604                 if (!strcmp (cmd_name, cmd->name))
605                 {
606                         Con_Printf("Cmd_AddCommand: %s already defined\n", cmd_name);
607                         return;
608                 }
609         }
610
611         cmd = Mem_Alloc(cmd_mempool, sizeof(cmd_function_t));
612         cmd->name = cmd_name;
613         cmd->function = function;
614         cmd->next = cmd_functions;
615
616 // insert it at the right alphanumeric position
617         for( prev = NULL, current = cmd_functions ; current && strcmp( current->name, cmd->name ) < 0 ; prev = current, current = current->next )
618                 ;
619         if( prev ) {
620                 prev->next = cmd;
621         } else {
622                 cmd_functions = cmd;
623         }
624         cmd->next = current;
625 }
626
627 /*
628 ============
629 Cmd_Exists
630 ============
631 */
632 qboolean Cmd_Exists (const char *cmd_name)
633 {
634         cmd_function_t  *cmd;
635
636         for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
637                 if (!strcmp (cmd_name,cmd->name))
638                         return true;
639
640         return false;
641 }
642
643
644 /*
645 ============
646 Cmd_CompleteCommand
647 ============
648 */
649 const char *Cmd_CompleteCommand (const char *partial)
650 {
651         cmd_function_t *cmd;
652         int len;
653
654         len = strlen(partial);
655
656         if (!len)
657                 return NULL;
658
659 // check functions
660         for (cmd = cmd_functions; cmd; cmd = cmd->next)
661                 if (!strncmp(partial, cmd->name, len))
662                         return cmd->name;
663
664         return NULL;
665 }
666
667 /*
668         Cmd_CompleteCountPossible
669
670         New function for tab-completion system
671         Added by EvilTypeGuy
672         Thanks to Fett erich@heintz.com
673         Thanks to taniwha
674
675 */
676 int Cmd_CompleteCountPossible (const char *partial)
677 {
678         cmd_function_t *cmd;
679         int len, h;
680
681         h = 0;
682         len = strlen(partial);
683
684         if (!len)
685                 return 0;
686
687         // Loop through the command list and count all partial matches
688         for (cmd = cmd_functions; cmd; cmd = cmd->next)
689                 if (!strncasecmp(partial, cmd->name, len))
690                         h++;
691
692         return h;
693 }
694
695 /*
696         Cmd_CompleteBuildList
697
698         New function for tab-completion system
699         Added by EvilTypeGuy
700         Thanks to Fett erich@heintz.com
701         Thanks to taniwha
702
703 */
704 const char **Cmd_CompleteBuildList (const char *partial)
705 {
706         cmd_function_t *cmd;
707         int len = 0;
708         int bpos = 0;
709         int sizeofbuf = (Cmd_CompleteCountPossible (partial) + 1) * sizeof (const char *);
710         const char **buf;
711
712         len = strlen(partial);
713         buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *));
714         // Loop through the alias list and print all matches
715         for (cmd = cmd_functions; cmd; cmd = cmd->next)
716                 if (!strncasecmp(partial, cmd->name, len))
717                         buf[bpos++] = cmd->name;
718
719         buf[bpos] = NULL;
720         return buf;
721 }
722
723 /*
724         Cmd_CompleteAlias
725
726         New function for tab-completion system
727         Added by EvilTypeGuy
728         Thanks to Fett erich@heintz.com
729         Thanks to taniwha
730
731 */
732 const char *Cmd_CompleteAlias (const char *partial)
733 {
734         cmdalias_t *alias;
735         int len;
736
737         len = strlen(partial);
738
739         if (!len)
740                 return NULL;
741
742         // Check functions
743         for (alias = cmd_alias; alias; alias = alias->next)
744                 if (!strncasecmp(partial, alias->name, len))
745                         return alias->name;
746
747         return NULL;
748 }
749
750 /*
751         Cmd_CompleteAliasCountPossible
752
753         New function for tab-completion system
754         Added by EvilTypeGuy
755         Thanks to Fett erich@heintz.com
756         Thanks to taniwha
757
758 */
759 int Cmd_CompleteAliasCountPossible (const char *partial)
760 {
761         cmdalias_t      *alias;
762         int                     len;
763         int                     h;
764
765         h = 0;
766
767         len = strlen(partial);
768
769         if (!len)
770                 return 0;
771
772         // Loop through the command list and count all partial matches
773         for (alias = cmd_alias; alias; alias = alias->next)
774                 if (!strncasecmp(partial, alias->name, len))
775                         h++;
776
777         return h;
778 }
779
780 /*
781         Cmd_CompleteAliasBuildList
782
783         New function for tab-completion system
784         Added by EvilTypeGuy
785         Thanks to Fett erich@heintz.com
786         Thanks to taniwha
787
788 */
789 const char **Cmd_CompleteAliasBuildList (const char *partial)
790 {
791         cmdalias_t *alias;
792         int len = 0;
793         int bpos = 0;
794         int sizeofbuf = (Cmd_CompleteAliasCountPossible (partial) + 1) * sizeof (const char *);
795         const char **buf;
796
797         len = strlen(partial);
798         buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *));
799         // Loop through the alias list and print all matches
800         for (alias = cmd_alias; alias; alias = alias->next)
801                 if (!strncasecmp(partial, alias->name, len))
802                         buf[bpos++] = alias->name;
803
804         buf[bpos] = NULL;
805         return buf;
806 }
807
808 /*
809 ============
810 Cmd_ExecuteString
811
812 A complete command line has been parsed, so try to execute it
813 FIXME: lookupnoadd the token to speed search?
814 ============
815 */
816 void Cmd_ExecuteString (const char *text, cmd_source_t src)
817 {
818         int oldpos;
819         cmd_function_t *cmd;
820         cmdalias_t *a;
821
822         oldpos = cmd_tokenizebufferpos;
823         cmd_source = src;
824         Cmd_TokenizeString (text);
825
826 // execute the command line
827         if (!Cmd_Argc())
828         {
829                 cmd_tokenizebufferpos = oldpos;
830                 return;         // no tokens
831         }
832
833 // check functions (only after host_initialized)
834         if (host_initialized || !strcasecmp(cmd_argv[0], "exec") || !strcasecmp(cmd_argv[0], "set") || !strcasecmp(cmd_argv[0], "seta"))
835         {
836                 for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
837                 {
838                         if (!strcasecmp (cmd_argv[0],cmd->name))
839                         {
840                                 cmd->function ();
841                                 cmd_tokenizebufferpos = oldpos;
842                                 return;
843                         }
844                 }
845         }
846
847 // check alias (only after host_initialized)
848         if (host_initialized)
849         {
850                 for (a=cmd_alias ; a ; a=a->next)
851                 {
852                         if (!strcasecmp (cmd_argv[0], a->name))
853                         {
854                                 Cbuf_InsertText (a->value);
855                                 cmd_tokenizebufferpos = oldpos;
856                                 return;
857                         }
858                 }
859         }
860
861 // check cvars (always)
862         if (!Cvar_Command () && host_initialized)
863                 Con_Printf("Unknown command \"%s\"\n", Cmd_Argv(0));
864
865         cmd_tokenizebufferpos = oldpos;
866 }
867
868
869 /*
870 ===================
871 Cmd_ForwardStringToServer
872
873 Sends an entire command string over to the server, unprocessed
874 ===================
875 */
876 void Cmd_ForwardStringToServer (const char *s)
877 {
878         if (cls.state != ca_connected)
879         {
880                 Con_Printf("Can't \"%s\", not connected\n", s);
881                 return;
882         }
883
884         if (cls.demoplayback)
885                 return;         // not really connected
886
887         // LordHavoc: thanks to Fuh for bringing the pure evil of SZ_Print to my
888         // attention, it has been eradicated from here, its only (former) use in
889         // all of darkplaces.
890         MSG_WriteByte(&cls.message, clc_stringcmd);
891         SZ_Write(&cls.message, s, strlen(s) + 1);
892 }
893
894 /*
895 ===================
896 Cmd_ForwardToServer
897
898 Sends the entire command line over to the server
899 ===================
900 */
901 void Cmd_ForwardToServer (void)
902 {
903         const char *s;
904         if (strcasecmp(Cmd_Argv(0), "cmd"))
905                 s = va("%s %s", Cmd_Argv(0), Cmd_Argc() > 1 ? Cmd_Args() : "");
906         else
907                 s = Cmd_Argc() > 1 ? Cmd_Args() : "";
908         Cmd_ForwardStringToServer(s);
909 }
910
911
912 /*
913 ================
914 Cmd_CheckParm
915
916 Returns the position (1 to argc-1) in the command's argument list
917 where the given parameter apears, or 0 if not present
918 ================
919 */
920
921 int Cmd_CheckParm (const char *parm)
922 {
923         int i;
924
925         if (!parm)
926                 Sys_Error ("Cmd_CheckParm: NULL");
927
928         for (i = 1; i < Cmd_Argc (); i++)
929                 if (!strcasecmp (parm, Cmd_Argv (i)))
930                         return i;
931
932         return 0;
933 }
934