/** This function determines the caracteristics of a given line (code line, comment line etc...). * It is called by the "CountLines" function. * @see CountLines */ void CodeStatExecDlg::AnalyseLine(LanguageDef &language, wxString line, bool &comment, bool &code, bool &multi_line_comment) { int first_single_line_comment, first_multi_line_comment_begin, first_multi_line_comment_end; // Delete first and trailing spaces line = line.Trim(true); line = line.Trim(false); if (line.IsEmpty()) return; // Searching for single and multi-lines comment signs if (language.single_line_comment.Length() > 0) first_single_line_comment = line.Find(language.single_line_comment); else first_single_line_comment = -1; if (language.multiple_line_comment[0].Length() > 0) first_multi_line_comment_begin = line.Find(language.multiple_line_comment[0]); else first_multi_line_comment_begin = -1; if (language.multiple_line_comment[1].Length() > 0) first_multi_line_comment_end = line.Find(language.multiple_line_comment[1]); else first_multi_line_comment_end = -1; // We are in a multiple line comment => finding the "end of multiple line comment" sign if (multi_line_comment) { comment = true; if (first_multi_line_comment_end > -1) { multi_line_comment = false; if (first_multi_line_comment_end+language.multiple_line_comment[1].Length() < line.Length()) AnalyseLine(language, line.Mid(first_multi_line_comment_end+language.multiple_line_comment[1].Length()), comment, code, multi_line_comment); } } // We are not in a multiple line comment else if (!multi_line_comment) { // First comment sign found is a single line comment sign if ( (first_single_line_comment>-1) &&((first_multi_line_comment_begin==-1)||((first_multi_line_comment_begin>-1)&&(first_single_line_comment<first_multi_line_comment_begin))) ) { comment = true; if (first_single_line_comment > 0) code = true; } // First comment sign found is a multi-line comment begin sign else if (first_multi_line_comment_begin>-1) { multi_line_comment = true; comment = true; if (first_multi_line_comment_begin > 0) code = true; if (first_multi_line_comment_begin+language.multiple_line_comment[0].Length() < line.Length()) AnalyseLine(language, line.Mid(first_multi_line_comment_begin+language.multiple_line_comment[0].Length()), comment, code, multi_line_comment); } else { code = true; } } }
// analyse some lines of the buffer trying to guess it's type. // if it fails, it assumes the native type for our platform. wxTextFileType wxTextBuffer::GuessType() const { wxASSERT( IsOpened() ); // scan the buffer lines size_t nUnix = 0, // number of '\n's alone nDos = 0, // number of '\r\n' nMac = 0; // number of '\r's // we take MAX_LINES_SCAN in the beginning, middle and the end of buffer #define MAX_LINES_SCAN (10) size_t nCount = m_aLines.Count() / 3, nScan = nCount > 3*MAX_LINES_SCAN ? MAX_LINES_SCAN : nCount / 3; #define AnalyseLine(n) \ switch ( m_aTypes[n] ) { \ case wxTextFileType_Unix: nUnix++; break; \ case wxTextFileType_Dos: nDos++; break; \ case wxTextFileType_Mac: nMac++; break; \ default: wxFAIL_MSG(_("unknown line terminator")); \ } size_t n; for ( n = 0; n < nScan; n++ ) // the beginning AnalyseLine(n); for ( n = (nCount - nScan)/2; n < (nCount + nScan)/2; n++ ) AnalyseLine(n); for ( n = nCount - nScan; n < nCount; n++ ) AnalyseLine(n); #undef AnalyseLine // interpret the results (FIXME far from being even 50% fool proof) if ( nScan > 0 && nDos + nUnix + nMac == 0 ) { // no newlines at all wxLogWarning(_("'%s' is probably a binary buffer."), m_strBufferName.c_str()); } else { #define GREATER_OF(t1, t2) n##t1 == n##t2 ? typeDefault \ : n##t1 > n##t2 \ ? wxTextFileType_##t1 \ : wxTextFileType_##t2 #if !defined(__WATCOMC__) || wxCHECK_WATCOM_VERSION(1,4) if ( nDos > nUnix ) return GREATER_OF(Dos, Mac); else if ( nDos < nUnix ) return GREATER_OF(Unix, Mac); else { // nDos == nUnix return nMac > nDos ? wxTextFileType_Mac : typeDefault; } #endif // __WATCOMC__ #undef GREATER_OF } return typeDefault; }
/** This function analyses a given source file and count the lines of code, comments etc... */ void CountLines(ProjectCodeStats& stat, const wxFileName &filename, const LanguageDef &language) { wxTextFile file; if (file.Open(filename.GetFullPath(), wxConvFile)) { bool multiLineComment = false; stat.totalLines += file.GetLineCount(); for (unsigned int i=0; i<file.GetLineCount(); ++i) { wxString line(file[i]); line = line.Trim(true); line = line.Trim(false); bool comment = false; bool code = false; if (line.IsEmpty()) ++stat.emptyLines; else { AnalyseLine(comment, code, multiLineComment, language, line); if (comment&&code) ++stat.codeAndCommentLines; else if (comment) ++stat.commentLines; else if (code) ++stat.codeLines; } } } }
/** This function analyses a given source file and count the lines of code, comments etc... */ void CodeStatExecDlg::CountLines(wxFileName filename, LanguageDef &language, long int &code_lines, long int &codecomments_lines, long int &comment_lines, long int &empty_lines, long int &total_lines) { wxTextFile file; if (file.Open(filename.GetFullPath(),wxConvFile)) { bool multi_line_comment = false; total_lines += file.GetLineCount(); for (unsigned int i=0; i<file.GetLineCount(); ++i) { wxString line(file[i]); line = line.Trim(true); line = line.Trim(false); bool comment = false; bool code = false; if (line.IsEmpty()) ++empty_lines; else { AnalyseLine(language, line, comment, code, multi_line_comment); if (comment&&code) ++codecomments_lines; else if (comment) ++comment_lines; else if (code) ++code_lines; } } } }
bool global::readConfig(char * filename) { ifstream infile((const char *)filename); if(!infile) { fprintf(stderr,"there is no this filename!"); return false; } map<string,string> m; m.clear(); string line,key,value; while( getline(infile,line) ) { if( AnalyseLine(line,key,value) ) m[key] = value; } infile.close(); httpport = atoi(m["httpPort"].c_str()); starturl = m["startUrl"]; return true; }
bool ResourceBuffer::NextRow(int32 nLines) { for (int32 i = 0; i < nLines; ++i) { m_nCol = 0; m_strLine.clear(); m_vecCol.clear(); if (std::getline(m_cFileStream, m_strLine)) { if (m_strLine.empty()) { return false; }else { //printf("Read row comment:%s\n",m_strLine.c_str()); } } else { return false; } } if(strlen(m_strLine.c_str()) == 0 || strcmp(m_strLine.c_str(),"\n") == 0 || strcmp(m_strLine.c_str(),"\t") == 0 || strcmp(m_strLine.c_str(),"\r") == 0) { return false; } AnalyseLine(m_strLine, m_vecCol); if(m_vecCol.size() < 1) { return false; } return true; }
void CFlashPlayerDlg::LoadConfig() { CAtlStdioFile playercfg; CString inifile = m_program_dir + _T("mplayer.ini"); if(SUCCEEDED(playercfg.OpenFile(inifile.GetBuffer(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING))) { CStringA lineA; CString line; while(playercfg.ReadLineA(lineA)) { line = local2unicode(lineA.GetBuffer()).c_str(); lineA.ReleaseBuffer(); line.TrimLeft(_T(" ")); line.TrimRight(_T(" ")); line.MakeLower(); if(line.Find(_T("#")) == 0) continue; if(line.Find(_T("fs=yes")) == 0) { m_fs_init = true; continue; } if(line.Find(_T("fs=1")) == 0) { m_fs_init = true; continue; } if(line.Find(_T("ontop=2")) == 0) { m_ontop = true; continue; } if(line.Find(_T("ontop=1")) == 0) { m_ontop = true; continue; } } playercfg.Close(); } inifile.ReleaseBuffer(); CAtlStdioFile inputcfg; inifile = m_program_dir + _T("input.ini"); if(SUCCEEDED(inputcfg.OpenFile(inifile.GetBuffer(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING))) { CString line,command,value,key; CStringA lineA; while(inputcfg.ReadLineA(lineA)) { line = local2unicode(lineA.GetBuffer()).c_str(); lineA.ReleaseBuffer(); if(AnalyseLine(line,key,command,value)) m_inputs.Add(key,command,value); } inputcfg.Close(); } else { m_inputs.Add(_T("F"),_T("vo_fullscreen"),_T("")); m_inputs.Add(_T("f"),_T("vo_fullscreen"),_T("")); m_inputs.Add(_T("T"),_T("vo_ontop"),_T("")); m_inputs.Add(_T("t"),_T("vo_ontop"),_T("")); m_inputs.Add(_T("RIGHT"),_T("seek"),_T("30")); m_inputs.Add(_T("LEFT"),_T("seek"),_T("-30")); m_inputs.Add(_T("DOWN"),_T("seek"),_T("10")); m_inputs.Add(_T("UP"),_T("seek"),_T("-10")); m_inputs.Add(_T("SPACE"),_T("pause"),_T("")); m_inputs.Add(_T("ESC"),_T("quit"),_T("")); m_inputs.Add(_T("K"),_T("keep_aspect"),_T("")); m_inputs.Add(_T("k"),_T("keep_aspect"),_T("")); m_inputs.Add(_T(">"),_T("pt_step"),_T("1")); m_inputs.Add(_T("."),_T("pt_step"),_T("1")); m_inputs.Add(_T("<"),_T("pt_step"),_T("-1")); m_inputs.Add(_T(","),_T("pt_step"),_T("-1")); } }