/** This function analyses a given source file and count the lines of bCode, comments etc... */ void Counter::countLines(wxTextFile& file, CounterRule* pRule, int &total_lines, int &code_lines, int &comment_lines, int &codecomments_lines, int &empty_lines) { bool bDelimitedCommentMode = false; total_lines += file.GetLineCount(); for (unsigned int i=0; i<file.GetLineCount(); ++i) { // Trim space wxString strLine(file[i]); strLine = strLine.Trim(true); strLine = strLine.Trim(false); bool bComment = false; bool bCode = false; if (strLine.IsEmpty()) ++empty_lines; else { analyseLine(pRule, strLine, bComment, bCode, bDelimitedCommentMode); if (bComment&&bCode) ++codecomments_lines; else if (bComment) ++comment_lines; else if (bCode) ++code_lines; } }// End for }
void Line::Evaluate() { if (line.size() < 5) return; analyseLine(); for (auto &partialLine : partialLines) partialLine->Evaluate(); }
/*! * \brief Loads the symbol for the component from the symbol field * \param SymbolString * \param Lib_ * \param Comp_ * \return the number of painting elements or a negative nuber if error */ int SymbolWidget::setSymbol( QString& SymbolString, const QString& Lib_, const QString& Comp_) { Arcs.clear(); Lines.clear(); Rects.clear(); Ellips.clear(); Texts.clear(); LibraryName = Lib_; ComponentName = Comp_; QString Line; ///QString foo = SymbolString; QTextStream stream(&SymbolString, QIODevice::ReadOnly); x1 = y1 = INT_MAX; x2 = y2 = INT_MIN; int z=0, Result; while(!stream.atEnd()) { Line = stream.readLine(); Line = Line.trimmed(); if(Line.isEmpty()) continue; if(Line.at(0) != '<') return -1; // check for start char if(Line.at(Line.length()-1) != '>') return -1; // check for end char Line = Line.mid(1, Line.length()-2); // cut off start and end character Result = analyseLine(Line); if(Result < 0) return -6; // line format error z += Result; } x1 -= 4; // enlarge component boundings a little x2 += 4; y1 -= 4; y2 += 4; cx = -x1 + TextWidth; cy = -y1; int dx = x2-x1 + TextWidth; if((x2-x1) < DragNDropWidth) dx = (x2-x1 + DragNDropWidth)/2 + TextWidth; if(dx < DragNDropWidth) dx = DragNDropWidth; setMinimumSize(dx, y2-y1 + TextHeight+4); if(width() > dx) dx = width(); resize(dx, y2-y1 + TextHeight+4); update(); return z; // return number of ports }
/** * @brief parseFile * @param fileName Filename */ void FileReport::parseFile(string& fileName){ const char* constName = fileName.c_str(); string line; fstream file; if(!fileExists(fileName)){ cout << "File does not exist!"; } file.open(constName); name = fileName; while (getline(file, line)){ analyseLine(line); } computeCommentDensity(); toCSVFile(fileName); }
// --------------------------------------------------------------------- // Loads the symbol for the subcircuit from the schematic file and // returns the number of painting elements. int LibComp::loadSymbol() { int z, Result; QString FileString, Line; z = loadSection("Symbol", FileString); if(z < 0) { if(z != -7) return z; // If library component not defined as subcircuit, then load // new component and transfer data to this component. z = loadSection("Model", Line); if(z < 0) return z; Component *pc = getComponentFromName(Line); if(pc == 0) return -20; copyComponent(pc); pc->Props.setAutoDelete(false); delete pc; return 1; } z = 0; x1 = y1 = INT_MAX; x2 = y2 = INT_MIN; QTextStream stream(&FileString, QIODevice::ReadOnly); while(!stream.atEnd()) { Line = stream.readLine(); Line = Line.trimmed(); if(Line.isEmpty()) continue; if(Line.at(0) != '<') return -11; if(Line.at(Line.length()-1) != '>') return -12; Line = Line.mid(1, Line.length()-2); // cut off start and end character Result = analyseLine(Line, 2); if(Result < 0) return -13; // line format error z += Result; } x1 -= 4; x2 += 4; // enlarge component boundings a little y1 -= 4; y2 += 4; return z; // return number of ports }
/** * @brief Main function to parse the file * */ void MeshFileParser::parseFileProcess() { QString _path = this->getFilePath(); QFile _file(_path); bool _fileCreated = false; if (_file.exists()) { _fileCreated = _file.open(QIODevice::ReadOnly); if (_fileCreated ) { QTextStream _reader(&_file); QString _line = _reader.readLine(); while(!_line.isNull()) { analyseLine(_line); _line = _reader.readLine(); } setParsedValues(_currentParsedValues); } _file.close(); } }
// --------------------------------------------------------------------- // Loads the symbol for the subcircuit from the schematic file and // returns the number of painting elements. int Subcircuit::loadSymbol(const QString& DocName) { QFile file(DocName); if(!file.open(IO_ReadOnly)) return -1; QString Line; // ***************************************************************** // To strongly speed up the file read operation the whole file is // read into the memory in one piece. QTextStream ReadWhole(&file); QString FileString = ReadWhole.read(); file.close(); QTextStream stream(&FileString, IO_ReadOnly); // read header ************************** do { if(stream.atEnd()) return -2; Line = stream.readLine(); Line = Line.stripWhiteSpace(); } while(Line.isEmpty()); if(Line.left(16) != "<Qucs Schematic ") // wrong file type ? return -3; Line = Line.mid(16, Line.length()-17); if(!checkVersion(Line)) // wrong version number ? return -4; // read content ************************* while(!stream.atEnd()) { Line = stream.readLine(); if(Line == "<Symbol>") break; } x1 = y1 = INT_MAX; x2 = y2 = INT_MIN; int z=0, Result; while(!stream.atEnd()) { Line = stream.readLine(); if(Line == "</Symbol>") { x1 -= 4; // enlarge component boundings a little x2 += 4; y1 -= 4; y2 += 4; return z; // return number of ports } Line = Line.stripWhiteSpace(); if(Line.at(0) != '<') return -5; if(Line.at(Line.length()-1) != '>') return -6; Line = Line.mid(1, Line.length()-2); // cut off start and end character Result = analyseLine(Line, 1); if(Result < 0) return -7; // line format error z += Result; } return -8; // field not closed }
/** This function determines the caracteristics of a given strLine (bCode strLine, bComment strLine etc...). * It is called by the "CountLines" function. * @see CountLines */ void Counter::analyseLine(CounterRule* pRule, wxString strLine, bool &bComment, bool &bCode, bool &bDelimitedCommentMode) { int nIdxFirstSglLnComm, nIdxFirstMltLnCommBegin, nIdxFirstMltLnCommEnd; // Delete first and trailing spaces strLine = strLine.Trim(true); strLine = strLine.Trim(false); if (strLine.IsEmpty()) return; // Searching for single and multi-lines bComment signs if (pRule->m_strSglLnComm.Len() > 0) nIdxFirstSglLnComm = strLine.Find(pRule->m_strSglLnComm); else nIdxFirstSglLnComm = -1; if (pRule->m_strMltLnCommBegin.Len() > 0) nIdxFirstMltLnCommBegin = strLine.Find(pRule->m_strMltLnCommBegin); else nIdxFirstMltLnCommBegin = -1; if (pRule->m_strMltLnCommEnd.Len() > 0) nIdxFirstMltLnCommEnd = strLine.Find(pRule->m_strMltLnCommEnd); else nIdxFirstMltLnCommEnd = -1; // We are in a multiple strLine bComment => finding the "end of multiple strLine bComment" sign if (bDelimitedCommentMode) { bComment = true; if (nIdxFirstMltLnCommEnd > -1) { bDelimitedCommentMode = false; if (nIdxFirstMltLnCommEnd+pRule->m_strMltLnCommEnd.Len() < strLine.Length()) analyseLine(pRule, strLine.Mid(nIdxFirstMltLnCommEnd+pRule->m_strMltLnCommEnd.Length()), bComment, bCode, bDelimitedCommentMode); } } // We are not in a multiple strLine bComment else if (!bDelimitedCommentMode) { // First bComment sign found is a single strLine bComment sign if ( (nIdxFirstSglLnComm>-1) &&((nIdxFirstMltLnCommBegin==-1) ||((nIdxFirstMltLnCommBegin>-1)&&(nIdxFirstSglLnComm<nIdxFirstMltLnCommBegin))) ) { bComment = true; if (nIdxFirstSglLnComm > 0) bCode = true; } // First bComment sign found is a multi-strLine bComment begin sign else if (nIdxFirstMltLnCommBegin>-1) { bDelimitedCommentMode = true; bComment = true; if (nIdxFirstMltLnCommBegin > 0) bCode = true; if (nIdxFirstMltLnCommBegin+pRule->m_strMltLnCommBegin.Len() < strLine.Length()) analyseLine(pRule, strLine.Mid(nIdxFirstMltLnCommBegin+pRule->m_strMltLnCommBegin.Length()), bComment, bCode, bDelimitedCommentMode); } else { bCode = true; } } }