/* =========================================================================== maya2q3 - export .md3 files from maya Copyright (C) 2005 HermitWorks Entertainment Corporation This program 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. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. =========================================================================== */ #include "common.h" void fail( const char *msg ) { MGlobal::displayError( msg ); #ifdef _DEBUG __debugbreak(); #endif throw std::exception( msg ); } void demand( bool cond, const char *msg ) { if( !cond ) fail( msg ); } void warn( const char *msg ) { MGlobal::displayWarning( msg ); } void trace( const char *msg ) { MGlobal::displayInfo( msg ); } const char* va( const char *s, ... ) { const uint numStr = 4; const uint strMax = 4096; static char buf[numStr][strMax]; static int idx = 0; va_list argptr; va_start( argptr, s ); char *ret = buf[idx]; vsnprintf( ret, strMax, s, argptr ); idx = (idx + 1) % numStr; va_end( argptr ); return ret; } //port of Com_ParseExt static const char* SkipWhitespace( const char *data, bool &hasNewLines ) { int c; while( (c = *data) <= ' ') { if( !c ) return null; if( c == '\n' ) { //com_lines++; hasNewLines = true; } data++; } return data; } void ParseExt( const char *&data_p, bool allowLineBreaks, parse_token &tok ) { char c = 0; int len = 0; bool hasNewLines = false; const char *data = data_p; tok = ""; // make sure incoming data is valid if( !data ) { data_p = null; return; } for( ; ; ) { // skip whitespace data = SkipWhitespace( data, hasNewLines ); if( !data ) { data_p = null; return; } if( hasNewLines && !allowLineBreaks ) { data_p = data; return; } c = *data; if( c == '/' && data[1] == '/' ) { // skip double slash comments data += 2; while( *data && *data != '\n' ) data++; } else if( c == '/' && data[1] == '*' ) { // skip /* */ comments data += 2; while( *data && (*data != '*' || data[1] != '/') ) data++; if( *data ) data += 2; } else break; } if(c == '\"') { // handle quoted strings data++; for( ; ; ) { c = *data++; if( c == '\"' || !c ) { tok[len] = 0; data_p = data; return; } if( len < parse_token::MaxLength ) { tok[len] = c; len++; } } } // parse a regular word do { if( len < parse_token::MaxLength ) { tok[len] = c; len++; } data++; c = *data; //if( c == '\n' ) // com_lines++; } while( c > 32 ); if( len == parse_token::MaxLength ) len = 0; tok[len] = 0; data_p = data; } void SkipRestOfLine( const char *&data ) { const char *p = data; char c; while( c = *p++ ) { if( c == '\n' ) { //com_lines++; break; } } data = p; } void ParseVector( float *v, int count, const char *&text, bool parseBrackets ) { parse_token tok; if( parseBrackets ) { ParseExt( text, false, tok ); demand( tok == "(", "missing (" ); } for( int i = 0; i < count ; i++ ) { ParseExt( text, false, tok ); demand( tok != "", "missing vector element" ); if( v ) v[i] = (float)atof( tok ); } if( parseBrackets ) { ParseExt( text, false, tok ); demand( tok == ")", "missing )" ); } }