⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cparser.cpp

📁 Conferencing code using Dialogic hardware
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**********@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********************************
* DIALOGIC CONFIDENTIAL
*
* Copyright (C) 2006-2007 Dialogic Corporation. All Rights Reserved.
* The source code contained or described herein and all documents related
* to the source code ("Material") are owned by Dialogic Corporation or its
* suppliers or licensors. Title to the Material remains with Dialogic Corporation
* or its suppliers and licensors. The Material contains trade secrets and
* proprietary and confidential information of Dialogic or its suppliers and
* licensors. The Material is protected by worldwide copyright and trade secret
* laws and treaty provisions. No part of the Material may be used, copied,
* reproduced, modified, published, uploaded, posted, transmitted, distributed,
* or disclosed in any way without Dialogic's prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Dialogic in writing.
*
***********************************@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********/
//***********************************************************************
//***********************************************************************
// ConfigFile.cpp: implementation of the ConfigFile class.
//
//////////////////////////////////////////////////////////////////////
#include <ctype.h> 
#include "utils.h"
#include "CParser.h"

static const char * CFG_MODULE_NAME = "CParser";

// These are tokens as well as delimiters
// ( space, tab and new line are also delimiters, but are not tokens)
static const char *atomic_tokens="%^&()=|,;'[]{}?<>";
static const char *comment_line = "#*!";       // a line comment

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//*****************************************************************************
// Purpose	: 
//    Constructor
// Parameters:	
//    none
// Returns:	none
//*****************************************************************************
CParser::CParser(CGenLog *pLog):
                 CanLog(pLog) {
  m_section_name = 0;
  m_is_correct = true;
  ClearBuffer();
}  //	End of constructor()



//*****************************************************************************
// Purpose	: 
//    release all buffers and init internal variables
// Parameters:	
//    none
// Returns:	void
//*****************************************************************************
void CParser::ClearBuffer(){
    m_buffer = 0;
    m_current_pos = 0;
    m_current_line = 0;
    str_deletestoredstring(&m_section_name);
    m_section_id = -1;
    m_back = false;
    m_last_line = 0;
    m_last_pos = 0;
}  //	End of DeleteBuffer()

//*****************************************************************************
// Purpose	: 
//    Advance m_current_pos to the first token in buffer
// Parameters:	
//    none
// Returns:	bool 
//      false = no more data
//*****************************************************************************
bool CParser::Rewind(){
    m_current_line = 1;
    m_current_pos  = m_buffer;
    str_deletestoredstring(&m_section_name);
    m_section_id = -1;
    m_back = false;
    m_last_line = 1;
    m_last_pos = 0;

    return GotoNextToken();
}  //	End of Rewind()


//*****************************************************************************
// Purpose	: 
//    advance m_current_pos to the first non-space character
// Parameters:	
//    None
// Returns:	
//    bool (false = no more data)
//*****************************************************************************
bool CParser::SkipSpace() {
    if ( 0 == m_current_pos ){
        // null buffer
        return false;
    }

    while ( *m_current_pos ) {
        if (!isspace(*m_current_pos) ){
            return true;
        }

        if (CHAR_NEWLINE == *m_current_pos){
            ++ m_current_line;
        }

        ++m_current_pos;
    }  // while
	return false;
}  //	End of SkipSpace()

//*****************************************************************************
// Purpose	: 
//    advance m_current_pos at the beginning of the next line
//    ( skip comments )
// Parameters:	
//    none
// Returns:	
//    bool (false = no more data)
//*****************************************************************************
bool  CParser::GotoNextLine() {
    if (!m_current_pos){
        // null buffer
        return false;
    }

	m_current_pos = strchr(m_current_pos, CHAR_NEWLINE);

    if ( m_current_pos == 0) {
         return false;
    }

    ++ m_current_pos;
    ++ m_current_line;

    if ( *m_current_pos == 0) {
        return false;
    }

    return true;
}  //	End of GotoNextLine()

//*****************************************************************************
// Purpose	: 
//    advance m_current_pos at the beginning of the next token
// Parameters:	
//    None
// Returns:	
//    bool (false = no more data)
//*****************************************************************************
bool CParser::GotoNextToken() {

    if (!m_current_pos){
        // null buffer
        return false;
    }

    while ( SkipSpace( ) ) { 
        if (    (*m_current_pos   == '*') 
             && (m_current_pos[1] == '/')  
           ) {
            m_current_pos+=2;
            m_is_correct = false;
            LOG( LOG_ERR2, CFG_MODULE_NAME,
                 "Line %d: Extra closing '*/'",
                 GetCurrentLineNumber() );
        }else if(    strchr(comment_line, *m_current_pos)
            || (    (*m_current_pos   == '/') 
                 && (m_current_pos[1] == '/')  
               ) 
          ) {
            // skip this line
            if (! GotoNextLine()){
                return false;
            } 
        } else if (    (*m_current_pos   == '/') 
                    && (m_current_pos[1] == '*')  
                  ) {
            // Start of multi-line comment
            m_current_pos +=2;
            list<int> * bgn_lines = new list<int>;
            bgn_lines->push_back(GetCurrentLineNumber());
            bool brc = SkipMultiLineComment(bgn_lines);
            if ( bgn_lines->size() ){
                // Then we have unmatched openning comments
                m_is_correct = false;
                list <int>::iterator pos;
                for ( pos = bgn_lines->begin(); pos != bgn_lines->end(); ++pos ) {
                      LOG( LOG_ERR2, CFG_MODULE_NAME,
                           "Line %d: Unmatched  '/*'",*pos);
                } 
            } 
            delete bgn_lines;
            if (!brc) {
                // done, no more data
                return false;
            }
        } else {
            return true;
        }
	}
  return false;
}  //	End of GotoNextToken()

//*****************************************************************************
// Purpose	: 
//    read section name (enclosed in [] ) and section ID
// Parameters:	
//    None
// Returns:	
//    bool (false = no more data)
//*****************************************************************************
bool CParser::TrySection() {

    if (!m_current_pos){
        // null buffer
        return false;
    }

    if (*m_current_pos != '['){
        return true;
    }

    // skip "["
    ++m_current_pos;

    char token[MAXTOKEN];
    char section[MAXTOKEN];
    *section = 0;
    while ( GetNextToken(token,sizeof(token) ) ) {
        // skip anything enclosed in []
        // load m_cnf_section and m_section_id 
        // [Board Configuration] is section 'BoardConfiguration' id=0
        // [Board 12] is section 'Boars' id = 12
        if (COMPARE_EQUAL != str_compare(token,"]") ){ 
            if (   (*section == 0 ) 
                || !str_getnumber(token, &m_section_id) ){
                str_safecat(section, sizeof(section), token);
            }
        } else {
            break;
        }
    }
    str_storestring(&m_section_name,section);
    return GotoNextToken();
}  //	End of TrySection()

//*****************************************************************************
// Purpose	: 
//    store rest of the line in client's buffer and advance m_current_pos
// Parameters:	
//    [out] buffer - holder for token
//     [in] buffer size
// Returns:	
//    bool (false = no more data)
//    also returns token in token_buf.
//           Guaranteed not to overflow, but may trim long tokens
//*****************************************************************************
bool CParser::GetLine(char *token_buf, size_t token_len) {

    if (token_len == 0){
        return false ; // no buffer
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -