X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fsplines%2Fq_parse.cpp;h=324cd29f81fa502c6a11892d351c9d727d6ecdb5;hb=830125fad042fad35dc029b6eb57c8156ad7e176;hp=17fd12ed39825b438ca7cbe26f3f065fa1e7889c;hpb=33efc9089296fc4e5f54d43581a0db81576ba848;p=xonotic%2Fnetradiant.git diff --git a/libs/splines/q_parse.cpp b/libs/splines/q_parse.cpp index 17fd12ed..324cd29f 100644 --- a/libs/splines/q_parse.cpp +++ b/libs/splines/q_parse.cpp @@ -1,60 +1,60 @@ /* -Copyright (C) 1999-2007 id Software, Inc. and contributors. -For a list of contributors, see the accompanying CONTRIBUTORS file. + Copyright (C) 1999-2007 id Software, Inc. and contributors. + For a list of contributors, see the accompanying CONTRIBUTORS file. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ // q_parse.c -- support for parsing text files #include "q_shared.h" /* -============================================================================ + ============================================================================ -PARSING + PARSING -============================================================================ -*/ + ============================================================================ + */ // multiple character punctuation tokens static const char *punctuation[] = { "+=", "-=", "*=", "/=", "&=", "|=", "++", "--", - "&&", "||", "<=", ">=", "==", "!=", + "&&", "||", "<=", ">=", "==", "!=", NULL }; typedef struct { - char token[MAX_TOKEN_CHARS]; - int lines; - qboolean ungetToken; - char parseFile[MAX_QPATH]; + char token[MAX_TOKEN_CHARS]; + int lines; + qboolean ungetToken; + char parseFile[MAX_QPATH]; } parseInfo_t; -#define MAX_PARSE_INFO 16 -static parseInfo_t parseInfo[MAX_PARSE_INFO]; -static int parseInfoNum; -static parseInfo_t *pi = &parseInfo[0]; +#define MAX_PARSE_INFO 16 +static parseInfo_t parseInfo[MAX_PARSE_INFO]; +static int parseInfoNum; +static parseInfo_t *pi = &parseInfo[0]; /* -=================== -Com_BeginParseSession -=================== -*/ + =================== + Com_BeginParseSession + =================== + */ void Com_BeginParseSession( const char *filename ) { if ( parseInfoNum == MAX_PARSE_INFO - 1 ) { Com_Error( ERR_FATAL, "Com_BeginParseSession: session overflow" ); @@ -67,10 +67,10 @@ void Com_BeginParseSession( const char *filename ) { } /* -=================== -Com_EndParseSession -=================== -*/ + =================== + Com_EndParseSession + =================== + */ void Com_EndParseSession( void ) { if ( parseInfoNum == 0 ) { Com_Error( ERR_FATAL, "Com_EndParseSession: session underflow" ); @@ -80,24 +80,24 @@ void Com_EndParseSession( void ) { } /* -=================== -Com_GetCurrentParseLine -=================== -*/ + =================== + Com_GetCurrentParseLine + =================== + */ int Com_GetCurrentParseLine( void ) { return pi->lines; } /* -=================== -Com_ScriptError + =================== + Com_ScriptError -Prints the script name and line number in the message -=================== -*/ + Prints the script name and line number in the message + =================== + */ void Com_ScriptError( const char *msg, ... ) { - va_list argptr; - char string[32000]; + va_list argptr; + char string[32000]; va_start( argptr, msg ); vsprintf( string, msg,argptr ); @@ -107,8 +107,8 @@ void Com_ScriptError( const char *msg, ... ) { } void Com_ScriptWarning( const char *msg, ... ) { - va_list argptr; - char string[32000]; + va_list argptr; + char string[32000]; va_start( argptr, msg ); vsprintf( string, msg,argptr ); @@ -119,13 +119,13 @@ void Com_ScriptWarning( const char *msg, ... ) { /* -=================== -Com_UngetToken + =================== + Com_UngetToken -Calling this will make the next Com_Parse return -the current token instead of advancing the pointer -=================== -*/ + Calling this will make the next Com_Parse return + the current token instead of advancing the pointer + =================== + */ void Com_UngetToken( void ) { if ( pi->ungetToken ) { Com_ScriptError( "UngetToken called twice" ); @@ -137,11 +137,11 @@ void Com_UngetToken( void ) { static const char *SkipWhitespace( const char (*data), qboolean *hasNewLines ) { int c; - while( (c = *data) <= ' ') { - if( !c ) { + while ( ( c = *data ) <= ' ' ) { + if ( !c ) { return NULL; } - if( c == '\n' ) { + if ( c == '\n' ) { pi->lines++; *hasNewLines = qtrue; } @@ -152,19 +152,19 @@ static const char *SkipWhitespace( const char (*data), qboolean *hasNewLines ) { } /* -============== -Com_ParseExt - -Parse a token out of a string -Will never return NULL, just empty strings. -An empty string will only be returned at end of file. - -If "allowLineBreaks" is qtrue then an empty -string will be returned if the next token is -a newline. -============== -*/ -static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { + ============== + Com_ParseExt + + Parse a token out of a string + Will never return NULL, just empty strings. + An empty string will only be returned at end of file. + + If "allowLineBreaks" is qtrue then an empty + string will be returned if the next token is + a newline. + ============== + */ +static char *Com_ParseExt( const char *( *data_p ), qboolean allowLineBreaks ) { int c = 0, len; qboolean hasNewLines = qfalse; const char *data; @@ -201,16 +201,16 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { // skip double slash comments if ( c == '/' && data[1] == '/' ) { - while (*data && *data != '\n') { + while ( *data && *data != '\n' ) { data++; } continue; } // skip /* */ comments - if ( c=='/' && data[1] == '*' ) { + if ( c == '/' && data[1] == '*' ) { while ( *data && ( *data != '*' || data[1] != '/' ) ) { - if( *data == '\n' ) { + if ( *data == '\n' ) { pi->lines++; } data++; @@ -228,16 +228,18 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { // handle quoted strings if ( c == '\"' ) { data++; - while( 1 ) { + while ( 1 ) { c = *data++; - if ( ( c=='\\' ) && ( *data == '\"' ) ) { + if ( ( c == '\\' ) && ( *data == '\"' ) ) { // allow quoted strings to use \" to indicate the " character data++; - } else if ( c=='\"' || !c ) { + } + else if ( c == '\"' || !c ) { pi->token[len] = 0; *data_p = ( char * ) data; return pi->token; - } else if( *data == '\n' ) { + } + else if ( *data == '\n' ) { pi->lines++; } if ( len < MAX_TOKEN_CHARS - 1 ) { @@ -249,11 +251,11 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { // check for a number // is this parsing of negative numbers going to cause expression problems - if ( ( c >= '0' && c <= '9' ) || ( c == '-' && data[ 1 ] >= '0' && data[ 1 ] <= '9' ) || - ( c == '.' && data[ 1 ] >= '0' && data[ 1 ] <= '9' ) ) { + if ( ( c >= '0' && c <= '9' ) || ( c == '-' && data[ 1 ] >= '0' && data[ 1 ] <= '9' ) || + ( c == '.' && data[ 1 ] >= '0' && data[ 1 ] <= '9' ) ) { do { - if (len < MAX_TOKEN_CHARS - 1) { + if ( len < MAX_TOKEN_CHARS - 1 ) { pi->token[len] = c; len++; } @@ -264,7 +266,7 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { // parse the exponent if ( c == 'e' || c == 'E' ) { - if (len < MAX_TOKEN_CHARS - 1) { + if ( len < MAX_TOKEN_CHARS - 1 ) { pi->token[len] = c; len++; } @@ -272,7 +274,7 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { c = *data; if ( c == '-' || c == '+' ) { - if (len < MAX_TOKEN_CHARS - 1) { + if ( len < MAX_TOKEN_CHARS - 1 ) { pi->token[len] = c; len++; } @@ -281,7 +283,7 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { } do { - if (len < MAX_TOKEN_CHARS - 1) { + if ( len < MAX_TOKEN_CHARS - 1 ) { pi->token[len] = c; len++; } @@ -291,31 +293,31 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { } while ( c >= '0' && c <= '9' ); } - if (len == MAX_TOKEN_CHARS) { + if ( len == MAX_TOKEN_CHARS ) { len = 0; } pi->token[len] = 0; *data_p = ( char * ) data; return pi->token; - } + } // check for a regular word // we still allow forward and back slashes in name tokens for pathnames // and also colons for drive letters if ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || c == '_' || c == '/' || c == '\\' ) { do { - if (len < MAX_TOKEN_CHARS - 1) { + if ( len < MAX_TOKEN_CHARS - 1 ) { pi->token[len] = c; len++; } data++; c = *data; - } while ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || c == '_' - || ( c >= '0' && c <= '9' ) || c == '/' || c == '\\' || c == ':' || c == '.' ); + } while ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || c == '_' + || ( c >= '0' && c <= '9' ) || c == '/' || c == '\\' || c == ':' || c == '.' ); - if (len == MAX_TOKEN_CHARS) { + if ( len == MAX_TOKEN_CHARS ) { len = 0; } pi->token[len] = 0; @@ -326,12 +328,12 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { // check for multi-character punctuation token for ( punc = punctuation ; *punc ; punc++ ) { - int l; - int j; + int l; + int j; l = strlen( *punc ); for ( j = 0 ; j < l ; j++ ) { - if ( data[j] != (*punc)[j] ) { + if ( data[j] != ( *punc )[j] ) { break; } } @@ -355,11 +357,11 @@ static char *Com_ParseExt( const char *(*data_p), qboolean allowLineBreaks ) { } /* -=================== -Com_Parse -=================== -*/ -const char *Com_Parse( const char *(*data_p) ) { + =================== + Com_Parse + =================== + */ +const char *Com_Parse( const char *( *data_p ) ) { if ( pi->ungetToken ) { pi->ungetToken = qfalse; return pi->token; @@ -368,11 +370,11 @@ const char *Com_Parse( const char *(*data_p) ) { } /* -=================== -Com_ParseOnLine -=================== -*/ -const char *Com_ParseOnLine( const char *(*data_p) ) { + =================== + Com_ParseOnLine + =================== + */ +const char *Com_ParseOnLine( const char *( *data_p ) ) { if ( pi->ungetToken ) { pi->ungetToken = qfalse; return pi->token; @@ -383,18 +385,19 @@ const char *Com_ParseOnLine( const char *(*data_p) ) { /* -================== -Com_MatchToken -================== -*/ -void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning ) { - const char *token; + ================== + Com_MatchToken + ================== + */ +void Com_MatchToken( const char *( *buf_p ), const char *match, qboolean warning ) { + const char *token; token = Com_Parse( buf_p ); if ( strcmp( token, match ) ) { - if (warning) { + if ( warning ) { Com_ScriptWarning( "MatchToken: %s != %s", token, match ); - } else { + } + else { Com_ScriptError( "MatchToken: %s != %s", token, match ); } } @@ -402,43 +405,43 @@ void Com_MatchToken( const char *(*buf_p), const char *match, qboolean warning ) /* -================= -Com_SkipBracedSection - -The next token should be an open brace. -Skips until a matching close brace is found. -Internal brace depths are properly skipped. -================= -*/ -void Com_SkipBracedSection( const char *(*program) ) { - const char *token; - int depth; + ================= + Com_SkipBracedSection + + The next token should be an open brace. + Skips until a matching close brace is found. + Internal brace depths are properly skipped. + ================= + */ +void Com_SkipBracedSection( const char *( *program ) ) { + const char *token; + int depth; depth = 0; do { token = Com_Parse( program ); - if( token[1] == 0 ) { - if( token[0] == '{' ) { + if ( token[1] == 0 ) { + if ( token[0] == '{' ) { depth++; } - else if( token[0] == '}' ) { + else if ( token[0] == '}' ) { depth--; } } - } while( depth && *program ); + } while ( depth && *program ); } /* -================= -Com_SkipRestOfLine -================= -*/ -void Com_SkipRestOfLine ( const char *(*data) ) { - const char *p; - int c; + ================= + Com_SkipRestOfLine + ================= + */ +void Com_SkipRestOfLine( const char *( *data ) ) { + const char *p; + int c; p = *data; - while ( (c = *p++) != 0 ) { + while ( ( c = *p++ ) != 0 ) { if ( c == '\n' ) { pi->lines++; break; @@ -449,32 +452,32 @@ void Com_SkipRestOfLine ( const char *(*data) ) { } /* -==================== -Com_ParseRestOfLine -==================== -*/ -const char *Com_ParseRestOfLine( const char *(*data_p) ) { - static char line[MAX_TOKEN_CHARS]; + ==================== + Com_ParseRestOfLine + ==================== + */ +const char *Com_ParseRestOfLine( const char *( *data_p ) ) { + static char line[MAX_TOKEN_CHARS]; const char *token; line[0] = 0; - while( 1 ) { + while ( 1 ) { token = Com_ParseOnLine( data_p ); if ( !token[0] ) { break; } if ( line[0] ) { - Q_strcat( line, sizeof(line), " " ); + Q_strcat( line, sizeof( line ), " " ); } - Q_strcat( line, sizeof(line), token ); + Q_strcat( line, sizeof( line ), token ); } return line; } -float Com_ParseFloat( const char *(*buf_p) ) { - const char *token; +float Com_ParseFloat( const char *( *buf_p ) ) { + const char *token; token = Com_Parse( buf_p ); if ( !token[0] ) { @@ -483,8 +486,8 @@ float Com_ParseFloat( const char *(*buf_p) ) { return atof( token ); } -int Com_ParseInt( const char *(*buf_p) ) { - const char *token; +int Com_ParseInt( const char *( *buf_p ) ) { + const char *token; token = Com_Parse( buf_p ); if ( !token[0] ) { @@ -495,41 +498,40 @@ int Com_ParseInt( const char *(*buf_p) ) { -void Com_Parse1DMatrix( const char *(*buf_p), int x, float *m ) { - const char *token; - int i; +void Com_Parse1DMatrix( const char *( *buf_p ), int x, float *m ) { + const char *token; + int i; Com_MatchToken( buf_p, "(" ); - for (i = 0 ; i < x ; i++) { - token = Com_Parse(buf_p); - m[i] = atof(token); + for ( i = 0 ; i < x ; i++ ) { + token = Com_Parse( buf_p ); + m[i] = atof( token ); } Com_MatchToken( buf_p, ")" ); } -void Com_Parse2DMatrix( const char *(*buf_p), int y, int x, float *m ) { - int i; +void Com_Parse2DMatrix( const char *( *buf_p ), int y, int x, float *m ) { + int i; Com_MatchToken( buf_p, "(" ); - for (i = 0 ; i < y ; i++) { - Com_Parse1DMatrix (buf_p, x, m + i * x); + for ( i = 0 ; i < y ; i++ ) { + Com_Parse1DMatrix( buf_p, x, m + i * x ); } Com_MatchToken( buf_p, ")" ); } -void Com_Parse3DMatrix( const char *(*buf_p), int z, int y, int x, float *m ) { - int i; +void Com_Parse3DMatrix( const char *( *buf_p ), int z, int y, int x, float *m ) { + int i; Com_MatchToken( buf_p, "(" ); - for (i = 0 ; i < z ; i++) { - Com_Parse2DMatrix (buf_p, y, x, m + i * x*y); + for ( i = 0 ; i < z ; i++ ) { + Com_Parse2DMatrix( buf_p, y, x, m + i * x * y ); } Com_MatchToken( buf_p, ")" ); } -