命令行解析函数
1 #define MAX_ARGS 80 2 #define ARGSIZE 256 3 4 static int cmd_argc; 5 static char cmd_argv[ MAX_ARGS ][ ARGSIZE ]; 6 7 void Cmd_Init( const char *text ) 8 { 9 char *p; 10 11 cmd_argc = 0; 12 13 while ( cmd_argc < MAX_ARGS ) 14 { 15 while ( *text && isspace( *text ) ) 16 { 17 text++; 18 } 19 20 if ( !*text || *text == '\n' ) 21 break; 22 23 if ( *text == '"' ) 24 { 25 text++; 26 p = ( char * )&cmd_argv[ cmd_argc++ ]; 27 28 while ( *text && *text != '"' ) 29 { 30 *p++ = *text++; 31 } 32 33 *p = '\0'; 34 35 if ( *text == '"' ) 36 text++; 37 } 38 else 39 { 40 p = ( char * )&cmd_argv[ cmd_argc++ ]; 41 42 while ( *text && !isspace( *text ) ) 43 { 44 *p++ = *text++; 45 } 46 47 *p = '\0'; 48 } 49 } 50 } 51 52 int Cmd_Argc( void ) 53 { 54 return cmd_argc; 55 } 56 57 char *Cmd_Argv( int i ) 58 { 59 if ( i < cmd_argc ) 60 return cmd_argv[ i ]; 61 62 return ""; 63 }