]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/ScriptParser.cpp
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / contrib / bobtoolz / ScriptParser.cpp
index 012e531a822be3683715e6b695f60ef39473b277..21f9f14f5791fd06215af42dd6ea47921e9c061b 100644 (file)
@@ -1,54 +1,54 @@
 #include "StdAfx.h"
 #include "ScriptParser.h"
 
-CScriptParser::CScriptParser(void): 
-       m_pScript(NULL),
-       m_pScriptSection(NULL),
-       m_pLastScriptSection(NULL),
-       m_pToken(NULL) {
+CScriptParser::CScriptParser( void ) :
+       m_pScript( NULL ),
+       m_pScriptSection( NULL ),
+       m_pLastScriptSection( NULL ),
+       m_pToken( NULL ) {
        ClearBuffer();
 }
 
-CScriptParser::~CScriptParser(void) {
+CScriptParser::~CScriptParser( void ) {
        ClearBuffer();
 }
 
-void CScriptParser::ClearBuffer(void) {
-       if(m_pScript) {
+void CScriptParser::ClearBuffer( void ) {
+       if ( m_pScript ) {
                delete[] m_pScript;
                m_pScript = NULL;
        }
-       if(m_pToken) {
+       if ( m_pToken ) {
                delete[] m_pToken;
                m_pToken = NULL;
        }
        m_pScriptSection = NULL;
        m_pLastScriptSection = NULL;
-       memset(m_breakChars, 0, sizeof(m_breakChars));
+       memset( m_breakChars, 0, sizeof( m_breakChars ) );
 }
 
-const char* CScriptParser::MakeToken(const char* pToken) {
-       if(m_pToken) {
+const char* CScriptParser::MakeToken( const char* pToken ) {
+       if ( m_pToken ) {
                delete[] m_pToken;
                m_pToken = NULL;
        }
 
-       if(!pToken) {
+       if ( !pToken ) {
                pToken = "";
        }
 
-       int len = static_cast<int>(strlen(pToken));
+       int len = static_cast<int>( strlen( pToken ) );
 
        m_pToken = new char[len + 1];
        m_pToken[len] = '\0';
-       strcpy(m_pToken, pToken);
+       strcpy( m_pToken, pToken );
 
        return m_pToken;
 }
 
 #define MAX_TOKEN_STRING 1024
 // Should NEVER return NULL
-const char* CScriptParser::GetToken(bool bAllowLinebreaks) {
+const char* CScriptParser::GetToken( bool bAllowLinebreaks ) {
        int c = 0, len;
        char token[MAX_TOKEN_STRING];
        bool bNewLines = false;
@@ -58,27 +58,28 @@ const char* CScriptParser::GetToken(bool bAllowLinebreaks) {
        len = 0;
        *token = '\0';
 
-       if(!m_pScript || !m_pScriptSection) {
-               return MakeToken(token);
+       if ( !m_pScript || !m_pScriptSection ) {
+               return MakeToken( token );
        }
 
        while ( true ) {
                SkipWhitespace( &bNewLines );
                if ( !*m_pScriptSection ) {
-                       return MakeToken(token);
+                       return MakeToken( token );
                }
                if ( bNewLines && !bAllowLinebreaks ) {
-                       return MakeToken(token);
+                       return MakeToken( token );
                }
 
                c = *m_pScriptSection;
-               
+
                if ( c == '/' && m_pScriptSection[1] == '/' ) { // C style comments
                        m_pScriptSection += 2;
-                       while (*m_pScriptSection && *m_pScriptSection != '\n') {
+                       while ( *m_pScriptSection && *m_pScriptSection != '\n' ) {
                                m_pScriptSection++;
                        }
-               } else if ( c=='/' && m_pScriptSection[1] == '*' ) { // C++ style comments
+               }
+               else if ( c == '/' && m_pScriptSection[1] == '*' ) { // C++ style comments
                        m_pScriptSection += 2;
                        while ( *m_pScriptSection && ( *m_pScriptSection != '*' || m_pScriptSection[1] != '/' ) ) {
                                m_pScriptSection++;
@@ -86,20 +87,21 @@ const char* CScriptParser::GetToken(bool bAllowLinebreaks) {
                        if ( *m_pScriptSection ) {
                                m_pScriptSection += 2;
                        }
-               } else {
+               }
+               else {
                        break;
                }
        }
 
-       if (c == '\"') {
+       if ( c == '\"' ) {
                m_pScriptSection++;
                while ( true ) {
                        c = *m_pScriptSection++;
-                       if (c=='\"' || !c) {
+                       if ( c == '\"' || !c ) {
                                token[len] = 0;
-                               return MakeToken(token);
+                               return MakeToken( token );
                        }
-                       if (len < MAX_TOKEN_STRING) {
+                       if ( len < MAX_TOKEN_STRING ) {
                                token[len] = c;
                                len++;
                        }
@@ -107,72 +109,73 @@ const char* CScriptParser::GetToken(bool bAllowLinebreaks) {
        }
 
        do {
-               if(len > 0 && IsBreakChar(*m_pScriptSection)) {
+               if ( len > 0 && IsBreakChar( *m_pScriptSection ) ) {
                        break;
                }
 
-               if (len < MAX_TOKEN_STRING) {
+               if ( len < MAX_TOKEN_STRING ) {
                        token[len] = c;
                        len++;
                }
                m_pScriptSection++;
 
-               if(IsBreakChar(c)) {
+               if ( IsBreakChar( c ) ) {
                        break;
                }
 
                c = *m_pScriptSection;
-       } while (c > 32);
+       } while ( c > 32 );
 
-       if (len == MAX_TOKEN_STRING) {
+       if ( len == MAX_TOKEN_STRING ) {
                len = 0;
        }
        token[len] = 0;
 
-       return MakeToken(token);
+       return MakeToken( token );
 }
 
-void CScriptParser::SkipWhitespace(bool* pbNewLines) {
+void CScriptParser::SkipWhitespace( bool* pbNewLines ) {
        int c;
 
-       if(!m_pScript || !m_pScriptSection) {
+       if ( !m_pScript || !m_pScriptSection ) {
                return;
        }
 
-       while( (c = *m_pScriptSection) <= ' ') {
-               if( !c ) {
+       while ( ( c = *m_pScriptSection ) <= ' ' ) {
+               if ( !c ) {
                        return;
                }
-               if( c == '\n' ) {
+               if ( c == '\n' ) {
                        *pbNewLines = true;
                }
                m_pScriptSection++;
        }
 }
 
-void CScriptParser::SkipBracedSection(void) {
-       const char              *token;
-       int                             depth;
+void CScriptParser::SkipBracedSection( void ) {
+       const char      *token;
+       int depth;
 
        depth = 0;
        do {
                token = GetToken( true );
-               if( token[1] == 0 ) {
-                       if( *token == '{' ) {
+               if ( token[1] == 0 ) {
+                       if ( *token == '{' ) {
                                depth++;
-                       } else if( *token == '}' ) {
+                       }
+                       else if ( *token == '}' ) {
                                depth--;
                        }
                }
-       } while( depth && *m_pScriptSection );
+       } while ( depth && *m_pScriptSection );
 }
 
-void CScriptParser::SkipRestOfLine(void) {
-       char    *p;
-       int             c;
+void CScriptParser::SkipRestOfLine( void ) {
+       char    *p;
+       int c;
 
        p = m_pScriptSection;
-       while ( (c = *p++) != 0 ) {
+       while ( ( c = *p++ ) != 0 ) {
                if ( c == '\n' ) {
                        break;
                }
@@ -180,16 +183,16 @@ void CScriptParser::SkipRestOfLine(void) {
        m_pScriptSection = p;
 }
 
-void CScriptParser::UndoGetToken(void) {
-       if(!m_pLastScriptSection) {
+void CScriptParser::UndoGetToken( void ) {
+       if ( !m_pLastScriptSection ) {
                return;
        }
        m_pScriptSection = m_pLastScriptSection;
        m_pLastScriptSection = NULL;
 }
 
-void CScriptParser::ResetParseSession(void) {
-       if(!m_pScript) {
+void CScriptParser::ResetParseSession( void ) {
+       if ( !m_pScript ) {
                return;
        }
 
@@ -197,43 +200,43 @@ void CScriptParser::ResetParseSession(void) {
        m_pLastScriptSection = NULL;
 }
 
-char* CScriptParser::GetBufferCopy(void) {
-       if(!m_pScript) {
+char* CScriptParser::GetBufferCopy( void ) {
+       if ( !m_pScript ) {
                return NULL;
        }
 
-       int len = static_cast<int>(strlen(m_pScript));
+       int len = static_cast<int>( strlen( m_pScript ) );
        char* pBuffer = new char[len + 1];
-       strcpy(pBuffer, m_pScript);
+       strcpy( pBuffer, m_pScript );
        return pBuffer;
 }
 
-int CScriptParser::GetTokenOffset(void) {
-       if(!m_pScript || !m_pScriptSection) {
+int CScriptParser::GetTokenOffset( void ) {
+       if ( !m_pScript || !m_pScriptSection ) {
                return 0;
        }
 
-       return static_cast<int>(m_pScriptSection - m_pScript);
+       return static_cast<int>( m_pScriptSection - m_pScript );
 }
 
-void CScriptParser::LoadScript(const char* pScript) {
+void CScriptParser::LoadScript( const char* pScript ) {
        ClearBuffer();
 
-       int len = static_cast<int>(strlen(pScript));
-       if(len <= 0) {
+       int len = static_cast<int>( strlen( pScript ) );
+       if ( len <= 0 ) {
                return;
        }
 
        m_pScript = new char[len + 1];
        m_pScript[len] = '\0';
 
-       strcpy(m_pScript, pScript);
+       strcpy( m_pScript, pScript );
        m_pScriptSection = m_pScript;
 }
 
-void CScriptParser::AddBreakChar(char c) {
-       for(int i = 0; i < SP_MAX_BREAKCHARS; i++) {
-               if(!m_breakChars[i]) {
+void CScriptParser::AddBreakChar( char c ) {
+       for ( int i = 0; i < SP_MAX_BREAKCHARS; i++ ) {
+               if ( !m_breakChars[i] ) {
                        m_breakChars[i] = c;
                        return;
                }
@@ -242,23 +245,23 @@ void CScriptParser::AddBreakChar(char c) {
        // TODO: Error: max break chars hit
 }
 
-bool CScriptParser::IsBreakChar(char c) {
-       for(int i = 0; i < SP_MAX_BREAKCHARS; i++) {
-               if(!m_breakChars[i]) {
+bool CScriptParser::IsBreakChar( char c ) {
+       for ( int i = 0; i < SP_MAX_BREAKCHARS; i++ ) {
+               if ( !m_breakChars[i] ) {
                        return false;
                }
-               if(m_breakChars[i] == c) {
+               if ( m_breakChars[i] == c ) {
                        return true;
                }
        }
        return false;
 }
 
-void CScriptParser::SetScript(char* pScript) {
+void CScriptParser::SetScript( char* pScript ) {
        ClearBuffer();
 
-       int len = static_cast<int>(strlen(pScript));
-       if(len <= 0) {
+       int len = static_cast<int>( strlen( pScript ) );
+       if ( len <= 0 ) {
                return;
        }