main() { char in[MAXSTR + 1], out[MAXSTR + 1]; int err; while (TRUE) { if (fgets(in, sizeof in, stdin) == NULL) { break; } /* Cheap way to be insensitive to EOL conventions. */ snprintf(out, MAXSTR, "%s",ParseMacro(in,&err)); if (err) { V printf("=> %s\n", in); V printf("---"); while (--err > 0) { V printf("-"); } V printf("^\n"); } V printf("%s", out); } return 0; }
wxString TemplateParser::ParseTemplate() { try { while (!m_in.Eof()) { Token token = GetNextToken(); switch (token) { case TOK_MACRO: ParseMacro(); break; case TOK_PROPERTY: ParseProperty(); break; case TOK_TEXT: ParseText(); break; default: return wxT(""); } } } catch ( wxFBException& ex ) { wxLogError( ex.what() ); } return m_out; }
void LoadAssemblyFile(const std::wstring& fileName, TextFile::Encoding encoding) { tTextData Text; int num = 0; AddFileName((char*)convertWStringToUtf8(fileName).c_str()); Global.IncludeNestingLevel++; if (Global.IncludeNestingLevel == ASSEMBLER_INCLUDE_NESTING_LEVEL) { Logger::printError(Logger::Error,L"Maximum include nesting level reached"); return; } TextFile input; if (input.open(fileName,TextFile::Read,encoding) == false) { Logger::printError(Logger::Error,L"Could not open file"); return; } while (!input.atEnd()) { Global.FileInfo.LineNumber++; Global.FileInfo.TotalLineCount++; if (GetLine(input,Text.buffer) == false) continue; if (Text.buffer.size() == 0) continue; Text.buffer = Global.symbolTable.insertEquations(Text.buffer,Global.FileInfo.FileNum,Global.Section); if (CheckEquLabel(Text.buffer) == false) { Text.buffer = checkLabel(Text.buffer,false); splitLine(Text.buffer,Text.name,Text.params); if (Text.name.empty()) continue; if (ParseMacro(input,Text.name,Text.params) == true) continue; if (Arch->AssembleDirective(Text.name,Text.params) == false) { Arch->AssembleOpcode(Text.name,Text.params); } } if (Logger::hasFatalError()) return; } Logger::printQueue(); Global.IncludeNestingLevel--; input.close(); }
/** 打开脚本 @param @param @return */ bool CCsvReader::_Open(Stream *pStream) { if(pStream == NULL) { return false; } DWORD dwValidLineCount = 0; char szBuffer[2048] = { 0 }; uint dwLength = sizeof(szBuffer); bool bRet = pStream->readString(szBuffer, dwLength); while(bRet) { // 检查注释行或者空行 DWORD dwLen = strlen(szBuffer); if(dwLen > 0) { if(szBuffer[dwLen - 1] == '\r' || szBuffer[dwLen - 1] == '\n') { szBuffer[dwLen - 1] = 0; dwLen--; } if(dwLen > 1 && (szBuffer[dwLen - 2] == '\r' || szBuffer[dwLen - 2] == '\n')) { szBuffer[dwLen - 2] = 0; dwLen--; } } bool bMustContinue = false; if(dwLen > 0) { // 忽略空行 int __nPos = 0; bool __bFlag = false; while(__nPos < dwLen) { if(szBuffer[__nPos] != m_szSeparator) { __bFlag = true; } __nPos++; } if(!__bFlag) { bMustContinue = true; } else { // 空格或制表符跳过 int nPos = 0; while(szBuffer[nPos] && (szBuffer[nPos] == ' ' || szBuffer[nPos] == '\t')) { nPos++; } if(nPos >= (int)dwLen) { bMustContinue = true; } else if(szBuffer[nPos] == '#') { // #macro if(nPos + 5 < (int)dwLen && memcmp(&szBuffer[nPos + 1], "macro", 5) == 0) { ParseMacro(&szBuffer[nPos + 6]); } bMustContinue = true; } } } else { bMustContinue = true; } if(!bMustContinue) { // 添加有意义的行 if(dwValidLineCount == 0) // 添加字段描述行 { ParseFieldDesc(szBuffer); dwValidLineCount++; } else if(dwValidLineCount == 1) // 添加字段类型行 { ParseFieldType(szBuffer); dwValidLineCount++; } else // 添加实际的数据记录 { // add by zjp // 中英文的标点符号可能会导致配置表读取失败,添加读配置表的时的一个报错机制 // 判断机制:每一个数据行解析出来的字段数目与类型行的字段数目相同 int nSize = m_vectorFieldType.size(); size_t start_pos = std::string::npos; const std::string stringLine = szBuffer; size_t end_pos = stringLine.find_first_of(m_szSeparator); int nCount = 0; while(end_pos != std::string::npos) // find { nCount++; start_pos = end_pos; end_pos = stringLine.find_first_of(m_szSeparator, start_pos + 1); if(end_pos == std::string::npos && start_pos < stringLine.length()) { end_pos = stringLine.length(); } } if (nSize!=nCount) { ErrorLn("配置表可能中英文逗号有问题,文件名:"<<m_curStrName.c_str()<<"出问题的有效行的行号为:"<<m_vectorLines.size()+3); } m_vectorLines.push_back(szBuffer); } } // 读下一行 dwLength = sizeof(szBuffer); bRet = pStream->readString(szBuffer, dwLength); } return true; }