home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / CmdArgs.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  2KB  |  47 lines

  1.  
  2. #ifndef __CMDARGS_H__
  3. #define __CMDARGS_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     Command arguments.
  9.  
  10. ===============================================================================
  11. */
  12.  
  13. class idCmdArgs {
  14. public:
  15.                             idCmdArgs( void ) { argc = 0; }
  16.                             idCmdArgs( const char *text, bool keepAsStrings ) { TokenizeString( text, keepAsStrings ); }
  17.  
  18.     void                    operator=( const idCmdArgs &args );
  19.  
  20.                             // The functions that execute commands get their parameters with these functions.
  21.     int                        Argc( void ) const { return argc; }
  22.                             // Argv() will return an empty string, not NULL if arg >= argc.
  23.     const char *            Argv( int arg ) const { return ( arg >= 0 && arg < argc ) ? argv[arg] : ""; }
  24.                             // Returns a single string containing argv(start) to argv(end)
  25.                             // escapeArgs is a fugly way to put the string back into a state ready to tokenize again
  26.     const char *            Args( int start = 1, int end = -1, bool escapeArgs = false ) const;
  27.  
  28.                             // Takes a null terminated string and breaks the string up into arg tokens.
  29.                             // Does not need to be /n terminated.
  30.                             // Set keepAsStrings to true to only seperate tokens from whitespace and comments, ignoring punctuation
  31.     void                    TokenizeString( const char *text, bool keepAsStrings );
  32.  
  33.     void                    AppendArg( const char *text );
  34.     void                    Clear( void ) { argc = 0; }
  35.     const char **            GetArgs( int *argc );
  36.  
  37. private:
  38.     static const int        MAX_COMMAND_ARGS = 64;
  39.     static const int        MAX_COMMAND_STRING = 2 * MAX_STRING_CHARS;
  40.  
  41.     int                        argc;                                // number of arguments
  42.     char *                    argv[MAX_COMMAND_ARGS];                // points into tokenized
  43.     char                    tokenized[MAX_COMMAND_STRING];        // will have 0 bytes inserted
  44. };
  45.  
  46. #endif /* !__CMDARGS_H__ */
  47.