Esempio n. 1
0
bool text_helper::firstColumnIsIncrimental(QTextStream &stream, const QString &delimiter)
{
    qint64 streamStartingPosition = stream.pos();
    double firstColumnValue, prevFirstColumnValue = 0;
    bool firstColumnIsIncrimental = true;
    QString line = QString();
    QStringList strings;
    bool ok;

    //Read out the first line (possibly header)
    line = QString(stream.readLine());

    while (!stream.atEnd()) {
        line = QString(stream.readLine());
        QStringList strings = line.split(delimiter);

        //Lets determine if we can use the first column as an X-axis
        firstColumnValue = strings.value(0).toDouble(&ok);

        if (!ok || (firstColumnValue < prevFirstColumnValue)) {
            firstColumnIsIncrimental = false;
            break;
        }

        prevFirstColumnValue = firstColumnValue;
    }

    //Reposition the stream
    stream.seek(streamStartingPosition);

    return firstColumnIsIncrimental;
}
Esempio n. 2
0
bool Csv::readFile()
{
    QFile file(fullPath);

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    QString str;
    QTextStream in;

    QTextStream in1(&file);
    str = in1.readAll();
    file.close();
    in.setString(&str);

    //set progressBar max value
    maxValueProgbar = str.length();

    //Parser
    QStringList outList;
    LexerCsv mylex;
    connect(&mylex, SIGNAL(returnedToken(int)), this, SLOT(checkProgressStream(int)),
            Qt::DirectConnection);
    QString header = in.readLine();
    if (header.startsWith("CALIBRATION VALUES V"))
    {
        char ch;

        //parse "Description Header" for "unit delimiter, string delimiter, comment
        in.seek(20);
        mylex.getNextToken(in);
        if (mylex.getToken() == Float)
        {
            mylex.getNextToken(in);
            if (mylex.getToken() == ValueSeparator && (mylex.getLexem() == "," || mylex.getLexem() == ";" || mylex.getLexem() == "\t"))
            {
                mylex.valueSeparator = mylex.getLexem().at(0);
                mylex.getNextToken(in);
                if (mylex.getToken() == Text && (mylex.getLexem() == "," || mylex.getLexem() == "."))
                {
                    mylex.decimalPointSeparator = mylex.getLexem().at(0);
                    in >> ch;
                    if (ch == mylex.valueSeparator)
                    {
                        in >> mylex.commentIndicator;
                        in >> ch;
                        if (ch == mylex.valueSeparator)
                        {
                            char c1, c2;
                            in >> c1;
                            in >> c2;
                            if (c1 == c2)
                                mylex.stringDelimiter = c1;
                            else
                            {
                                showError("CSV description Header : parser error at line " + QString::number(mylex.getLine())
                                           + " with lexem " + QString(mylex.getLexem().c_str()));
                                return false;
                            }
                        }
Esempio n. 3
0
bool loadTPL(Translator &translator, QIODevice &dev, ConversionData &cd)
{
    // Hack: Check if the template is utf8
    QTextStream testStream;
    testStream.setDevice( &dev );
    QString testContent = testStream.readAll();
    if ( ( testContent.startsWith( QLatin1String("{*?template charset="), Qt::CaseInsensitive ) &&
           ( testContent.startsWith( QLatin1String("{*?template charset=utf8?*}"), Qt::CaseInsensitive ) ||
             testContent.startsWith( QLatin1String("{*?template charset=utf-8?*}"), Qt::CaseInsensitive ) ) ) ||
         cd.m_assumeUtf8 )
    {
        stream.setCodec( QTextCodec::codecForName("UTF-8") );
        stream.setAutoDetectUnicode( true );
    }
    else
    {
        stream.setCodec( QTextCodec::codecForLocale() );
        stream.setAutoDetectUnicode( false );
    }
    stream.setDevice( &dev );
    stream.seek( 0 ); // we need to rewind it because the testStream has read all data on the QIODevice

    parse( &translator, cd.m_sourceDir.path() + QDir::separator() + cd.m_sourceFileName );

    return true;
}
Esempio n. 4
0
void Entity::handleTag( const Comment* openingTag, const Comment* closingTag, QTextStream& file, QIODevice& output) {

    file.seek(openingTag->getCommentEnd()+1);

    while (!file.atEnd()) {
        qint64 pos=file.pos();
        if (pos>=closingTag->getCommentStart()){
            file.seek(closingTag->getCommentEnd()+1);
            break;
        }
        QChar c1;
        file >> c1;
        const Comment* p= isSpecial(pos);

        if (p!=nullptr){
            if (p->isAutoClosing()){
                //     output.write(p->comment);
                //    output.write("<!--REMOVESTART-->");
                p->output(this,output);
                //    output.write("<!--REMOVEEND-->");
            } else {
                const Comment* closingTag=findClosingTag(p,file);
                if (closingTag != nullptr){
                    QBuffer buf;
                    buf.open(QBuffer::WriteOnly|QBuffer::Text);
                    handleTag(p,closingTag,file,buf);
                    buf.close();

                    if (false /*p->getTag()==STYLE_START*/){
                        //embedded_styles.append(buf.buffer());
                    } else {
                        output.write(buf.buffer());
                    }
                }
            }
        } else if (isInOuput(pos)){

            if (openingTag->isHTML() && c1=='\n'){
                output.write(QString("<BR/>").toUtf8());
            } else {
                if (!c1.isNonCharacter()) output.write(QString(c1).toUtf8());
            }
        }
    }

    return ;
}
Esempio n. 5
0
int MathTest::openDefaults(QpFile& inFile, QTextStream& stream, bool builtin)
{
    // Default Test Parameters
    // =====================================================
    //
    //  Test Selection, number of problems, and time allowed
    //
    //                      Number of   Time in
    //              Test    Problems    Seconds
    //  Add           2         10          10
    //  Subtract      2         10          15
    //  Multiply      2         10          25
    //  Divide        2         10          30
    //
    //  Grade Level   1 (2nd grade level)
    //
    //  userName "" (NULL)
    //
    QString defStr = QString(
                "2 10 10 \n"
                "2 10 15 \n"
                "2 10 25 \n"
                "2 10 30 \n"
                "1 \n "
                );

    QString defaultFileName;
    int status;

    if(userNameEdit->text() != "")
        defaultFileName = "mt-" % userNameEdit->text() % ".txt";
    else
        defaultFileName = "mt-default.txt";

    QFlags<QIODevice::OpenModeFlag>
        flags = QIODevice::ReadWrite | QIODevice::Text;

    inFile.setQuietOnSuccess(true);
    if((status = inFile.get(defaultFileName, flags)) != qpfile::fFailed)
        stream.setDevice(&inFile);
    else {
        stream.setString(&defStr);
        pMsg->sendInfo("Using built-in default test parameters.");
    }

    if((status == qpfile::fCreated) && builtin)
        stream << defStr;

    stream.seek(0);
    return status;
}
void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
        QmlJS::Document::Ptr doc, int requestId, const QmlDebug::QmlEventLocation &location)
{
    PropertyVisitor propertyVisitor;
    QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line, location.column);

    if (!node)
        return;

    qint64 startPos = node->firstSourceLocation().begin();
    qint64 len = node->lastSourceLocation().end() - startPos;

    textDoc.seek(startPos);
    QString details = textDoc.read(len).replace(QLatin1Char('\n'), QLatin1Char(' ')).simplified();

    emit rewriteDetailsString(requestId, details);
}
Esempio n. 7
0
void loadConfig(const QString &fileName)
{
    QFile file(configDir + fileName);
    file.open(QIODevice::ReadOnly);
    QString line, property;
    QTextStream stream;
    stream.setString(&line, QIODevice::ReadOnly);

    while (!file.atEnd()) {
        line = file.readLine();
        if (line.isEmpty() || line[0] == '#' || line[0] == '\n' || (line[0] == '\r' && line[1] == '\n')) continue;
        if (line[0] == '[') {
            property = line.mid(1, line.indexOf(']') - 1);
        } else {
            stream.seek(0);
            loadProperty(property, stream);
        }
    }

    file.close();
}
Esempio n. 8
0
void text_helper::checkAndProcessColumnHeaders( QTextStream &stream, const QString &delimiter,
                                                QList<QVariantMap> &metaData, int firstDataColumn  )
{
    qint64 streamStartingPosition = stream.pos();

    QString line = QString(stream.readLine());
    QStringList strings = line.split(delimiter);
    bool headerFound = true;
    int column;

    QVariantMap variantMap;

    //Check if the first line is not a header (only contains spaces, numbers, decimal points)
    QRegExp re("^[ .0-9]*$");
    if (re.exactMatch(line)) {
        //reset stream and return
        stream.seek(streamStartingPosition);
        headerFound = false;
    }

    for (column = firstDataColumn; column < strings.size(); column++) {
        variantMap.clear();
        if (headerFound) {
            if (strings.value(column).size() != 0) {
                variantMap["Key Field"] = strings.value(column);
                variantMap["Data Source"] = column;
            }
        } else {
            //Use column number as the header
            variantMap["Key Field"] = QString(tr("Column ")) + QString::number(column);
            variantMap["Data Source"] = column;
        }

        if (!variantMap.isEmpty())
            metaData.append(variantMap);
    }
}
Esempio n. 9
0
QString text_helper::autoDetectDelimiter(QTextStream &stream)
{
    const QString delimiters[] = {"\t", ",", " "};
    qint64 streamStartingPosition = stream.pos();
    QVector<QString> possibleDelimiters;
    QString line = QString();
    QStringList strings;
    int i;

    while (!stream.atEnd() && (possibleDelimiters.size() != 1)) {
        line = QString(stream.readLine());
        possibleDelimiters.clear();

        if (line.isEmpty())
            continue;

        for (i = 0; i < 3; i++) {
            strings.clear();
            strings = line.split(delimiters[i]);
            if ( strings.size() != 1 ) {
                possibleDelimiters.append(delimiters[i]);
            }
        }
    }
    //qDebug() << "Best guess from auto delim format->" << possibleDelimiters.first() << possibleDelimiters.size();

    //Reposition the stream
    stream.seek(streamStartingPosition);

    if (!possibleDelimiters.empty()) {
        return possibleDelimiters.first();
    }

    //Something went wrong, lets pick whatever is first and run with it. Maybe there is only 1 column
    return delimiters[0];
}
Esempio n. 10
0
///
/// \brief SpecMap::SpecMap
/// Main function for processing data from text files to create SpecMap objects.
/// Currently written to accept files in "wide" format, will be expanded to deal
/// with different ASCII formats later with conditionals.
/// \param inputstream a text stream derived from the input file
/// \param main_window the main window of the app
/// \param directory the working directory
///
SpecMap::SpecMap(QTextStream &inputstream, QMainWindow *main_window, QString *directory)
{
    //Set up variables unrelated to hyperspectral data:
    map_list_widget_ = main_window->findChild<QListWidget *>("mapsListWidget");
    map_loading_count_ = 0;
    principal_components_calculated_ = false;
    partial_least_squares_calculated_ = false;
    z_scores_calculated_ = false;
    directory_ = directory;

    int i, j;
    wall_clock timer;

    /*Read the first line to get the wavelength*/
    inputstream.seek(0);
    cout << "Loading wavelength vector..." << endl;
    timer.tic();
    QString wavelength_string = inputstream.readLine();

    QStringList wavelength_string_list =
            wavelength_string.split("\t",  QString::SkipEmptyParts);

    int columns = wavelength_string_list.size();
    wavelength_.set_size(columns);

    for(i=0; i<columns; ++i){
        wavelength_(i) = wavelength_string_list.at(i).toDouble();
    }
    double seconds = timer.toc();
    cout << "Reading wavelength took " << seconds <<" s." << endl;
    i=0;
    j=0;


    QString spectra_string;

    QStringList spectra_string_list;
    QProgressDialog progress("Counting rows...", "Cancel", 0, 100, NULL);
    progress.setWindowTitle("Loading Dataset");
    progress.setWindowModality(Qt::WindowModal);

    int rows = 0;
    cout << "Counting rows..." << endl;
    timer.tic();
    while(inputstream.readLine()!=NULL){
        ++rows;
    }
    progress.setValue(1);
    progress.setRange(0,rows+1);

    spectra_.set_size(rows, columns);
    x_.set_size(rows);
    y_.set_size(rows);
    seconds = timer.toc();
    cout << "Counting rows and resizing took " << seconds << " s." << endl;
    cout << "Reading spectra, x, and y..." << endl;

    progress.setLabelText("Parsing spectra...");

    timer.tic();
    inputstream.seek(0);
    inputstream.readLine(); //discard it to advance to next line

    for(i=0; i<rows; ++i){
        spectra_string=inputstream.readLine();
        spectra_string_list =
                spectra_string.split("\t", QString::SkipEmptyParts);
        x_(i) = spectra_string_list.at(0).toDouble();
        spectra_string_list.removeAt(0);

        y_(i) = spectra_string_list.at(0).toDouble();
        spectra_string_list.removeAt(0);
        for (j=0; j<columns; ++j){
            spectra_(i,j) = spectra_string_list.at(j).toDouble();
        }
        if (progress.wasCanceled()){
            constructor_canceled_ = true;
            return;
        }
        progress.setValue(i);
    }
    seconds = timer.toc();
    constructor_canceled_ = false;
    cout << "Reading x, y, and spectra took " << seconds << " s." << endl;
}
Esempio n. 11
0
/*!
	\brief Load opt file
	\param	in	QTextStream which holds the opt.txt file
	NOTICE(panqing): Before loading opt data, dat and prn data are already loaded. mainEdgeAttrList is filled.
	TODO(panqing): showNameList and attrNameList are needed to be set
*/
int DataIO::loadOptData(QTextStream &in)
{
	QString line;	//	One line of the file
	QStringList lineList;	// Items in one line, seperated by some delimiters
	const int lengthThreshold = 10;	// Recognize one line as a recording by its length
	quint16 xPos, yPos, halfSceneWidth, halfSceneHeight, maxX=0, maxY=0, minX=50000, minY=50000;
	quint32 subSegPartID = 0, lastSubSegPartID = 0;

	while (!(line = in.readLine()).contains("SegmentId"))
		;

  qint64 filePos=in.pos();  // 当前文件位置
  while ((line = in.readLine()).length() >= lengthThreshold)
  {
    lineList = line.split(",", QString::SkipEmptyParts);

    // 先遍历所有血管段一遍,得到最大/最小坐标
    xPos = lineList.at(5).toInt();
    yPos = lineList.at(6).toInt();
    if (xPos>maxX)
      maxX=xPos;
    if (yPos>maxY)
      maxY=yPos;
    if (xPos<minX)
      minX=xPos;
    if (yPos<minY)
      minY=yPos;
    xPos = lineList.at(9).toInt();
    yPos = lineList.at(10).toInt();
    if (xPos>maxX)
      maxX=xPos;
    if (yPos>maxY)
      maxY=yPos;
    if (xPos<minX)
      minX=xPos;
    if (yPos<minY)
      minY=yPos;
  }
  halfSceneWidth=(maxX-minX)/2;
  halfSceneHeight=(maxY-minY)/2;
  ResManager::getSceneRect().setRect(0,0,halfSceneWidth*2*1.1,halfSceneHeight*2*1.1);

  in.seek(filePos);
	while ((line = in.readLine()).length() >= lengthThreshold)
	{
		EdgeAttr *edgeAttr = NULL;
		lineList = line.split(",", QString::SkipEmptyParts);
		quint16 segName = lineList.at(0).toInt();
		for (int i=0;i<edgeAttrList.size();++i)
		{
			if (segName==edgeAttrList[i]->getIntAttr(EdgeAttr::SEGNAME))
			{
        edgeAttr=edgeAttrList[i];
				break;
			}
		}

		lastSubSegPartID = subSegPartID;	// Store the last sub segment part id
		subSegPartID = lineList.at(1).toInt();	// Acquire the sub segment part id of the new line
		// The last sub segment part id is 99
		// Change the last sub segment part id to its previous id plus 1
		// For example, 0, 1, 2, 99 --> 0, 1, 2, 3
		if (subSegPartID == 99)
			subSegPartID = lastSubSegPartID + 1;

		quint32 startNodeIndex, endNodeIndex;
		// StartNode
		// if the node is an subNodeItem, the index of the node is set as coeff*subIndex+nodeIndex
		if (lineList.at(4).toInt() >= 0)
			startNodeIndex = lineList.at(4).toInt();
		else
			startNodeIndex = lineList.at(0).toInt() + coeff*subSegPartID;

		if (!nodeHash.contains(startNodeIndex))
		{
			xPos = lineList.at(5).toInt();
			yPos = lineList.at(6).toInt();

			if (startNodeIndex < coeff)
			{
				MainNodeItem *mainNodeItem = new MainNodeItem(NULL, startNodeIndex);
				mainNodeItem->setPos(xPos-halfSceneWidth-minX, yPos-halfSceneHeight-minY);
				nodeHash.insert(startNodeIndex, mainNodeItem);
			}
			else
			{
				SubNodeItem *subNodeItem = new SubNodeItem(NULL, startNodeIndex);
				subNodeItem->setPos(xPos-halfSceneWidth-minX, yPos-halfSceneHeight-minY);
				nodeHash.insert(startNodeIndex, subNodeItem);
			}
		}

		// EndNode
		if (lineList.at(8).toInt() >= 0)
			endNodeIndex = lineList.at(8).toInt();
		else
			endNodeIndex = lineList.at(0).toInt() + coeff*(1+subSegPartID);

		if (!nodeHash.contains(endNodeIndex))
		{
			xPos = lineList.at(9).toInt();
			yPos = lineList.at(10).toInt();
			if (endNodeIndex < coeff)
			{
				MainNodeItem *mainNodeItem = new MainNodeItem(NULL, endNodeIndex);
				mainNodeItem->setPos(xPos-halfSceneWidth-minX, yPos-halfSceneHeight-minY);
				nodeHash.insert(endNodeIndex, mainNodeItem);
			}
			else
			{
				SubNodeItem *subNodeItem = new SubNodeItem(NULL, endNodeIndex);
				subNodeItem->setPos(xPos-halfSceneWidth-minX, yPos-halfSceneHeight-minY);
				nodeHash.insert(endNodeIndex, subNodeItem);
			}
		}
    SubEdgeItem *subEdgeItem = new SubEdgeItem(nodeHash[startNodeIndex], nodeHash[endNodeIndex], edgeAttr);
    edgeItemList.append(subEdgeItem);
    subEdgeItem->setEdgeAttr(edgeAttr);
	}
	return 0;
}
Esempio n. 12
0
void MibEditor::ExtractMIBfromRFC(void)
{
    QRegExp module_regexp("^[ \t]*([A-Za-z0-9-]*) *(PIB-)?DEFINITIONS *(::=)? *(BEGIN)? *$");
    QRegExp page_regexp("\\[[pP]age [iv0-9]*\\] *");
    QRegExp macro_regexp("^[ \t]*[A-Za-z0-9-]* *MACRO *::=");
    QRegExp end_regexp("^[ \t]*END[ \t]*$");
    QRegExp blankline_regexp("^[ \t]*$");
    QRegExp blank_regexp("[^ \t]");
    QRegExp leadingspaces_regexp("^([ ]*)");
    QRegExp draft_regexp("^[ ]*Internet[ \\-]Draft");

    QFile file_in("empty");
    QFile file_tmpout("empty");
    QFile file_out("empty");
    QTextStream in(&file_in);
    QTextStream tmpout; 
    QTextStream out; 

    QString line;
    QString module;
    QStringList modules;

    QString dir = NULL, filename = NULL;
    int skipmibfile = 0, skip = 0, skipped = 0, macro = 0, n = 0;

    // Open RFC file
    filename = QFileDialog::getOpenFileName(s->MainUI()->MIBFile,
                                        tr("Open RFC file"), "", 
                                        "RFC files (*.txt);;All Files (*.*)");

    if (!filename.isEmpty())
    {
        file_in.setFileName(filename);
        if (!file_in.open(QFile::ReadOnly | QFile::Text))
        {
            QMessageBox::warning(NULL, tr("SnmpB: Extract MIB from RFC"),
                                 tr("Cannot read file %1: %2\n")
                                 .arg(file_in.fileName())
                                 .arg(file_in.errorString()));
            return;
        }
    }
    else
        return;

    // Ask for directory where to save MIB files 
    dir = QFileDialog::getExistingDirectory(s->MainUI()->MIBFile,
                           tr("Select destination folder for MIB files"), "");

    if (dir.isEmpty())
    {
        QMessageBox::warning(NULL, tr("SnmpB: Extract MIB from RFC"),
                             tr("No directory selected. Aborting.\n"));
        file_in.close();
        return;
    }

    if (!QFileInfo(dir).isWritable())
    {
        QMessageBox::warning(NULL, tr("SnmpB: Extract MIB from RFC"),
                tr("Directory not writable by this user. Aborting.\n"));
        file_in.close();
        return;
    }

    // Extract & save each modules ...

    // Process each line
    while (in.atEnd() != true)
    {
        line = in.readLine();

        if (draft_regexp.indexIn(line) != -1)
            continue;

        // Start of module
        if (module_regexp.indexIn(line) != -1)
        {
            module = module_regexp.cap(1); 
            skip = 9;
            skipped = -1;
            macro = 0;
            n = 0;

            // Create temporary output file
            file_tmpout.setFileName(QDir::tempPath()+"/"+module+".tmp");
            file_tmpout.remove();
            if (!file_tmpout.open(QFile::ReadWrite | QFile::Text))
            {
                QMessageBox::warning(NULL, tr("SnmpB: Extract MIB from RFC"),
                                     tr("Cannot create file %1: %2. Abort.\n")
                                     .arg(file_tmpout.fileName())
                                     .arg(file_tmpout.errorString()));
                file_in.close();
                return;
            }

            tmpout.setDevice(&file_tmpout); 

            // Create output file
            file_out.setFileName(dir+"/"+module);
            if (file_out.exists())
            {
                QMessageBox mb(QMessageBox::Question, 
                               tr("SnmpB: Extract MIB from RFC"), 
                               tr("The file %1 already exist.\n")
                               .arg(file_out.fileName()));
                QPushButton *ob = mb.addButton(tr("Overwrite"), 
                                               QMessageBox::YesRole);
                QPushButton *sb = mb.addButton(tr("Skip"), 
                                               QMessageBox::NoRole);
                mb.exec();

                if (mb.clickedButton() == ob)
                {
                    // overwrite 
                    skipmibfile = 0;
                }
                else if (mb.clickedButton() == sb)
                {
                    // skip 
                    skipmibfile = 1;
                }
            }
            else
                skipmibfile = 0;

            if (!skipmibfile)
            {
                file_out.remove();
                if (!file_out.open(QFile::ReadWrite | QFile::Text))
                {
                    QMessageBox::warning(NULL, tr("SnmpB: Extract MIB from RFC"),
                                         tr("Cannot create file %1: %2. Skipping.\n")
                                         .arg(file_out.fileName())
                                         .arg(file_out.errorString()));
                    skipmibfile = 1;
                }
                else
                    out.setDevice(&file_out);
            }
        }

        // At the end of a page we start the counter skipped to skip the
        // next few lines.
        if (page_regexp.indexIn(line) != -1)
            skipped = 0;

        // If we are skipping...
        if (skipped >= 0)
        {
            skipped++;

            // If we have skipped enough lines to the top of the next page...
            if (skipped >= skip)
            {
                skipped = -1;
            }
            else
            {
                // Finish skipping, if we find a non-empty line, but not before
                // we have skipped four lines. remember the miminum of lines
                // we have ever skipped to keep empty lines in a modules that
                // appear near the top of a page.
                if ((skipped >= 4) && (blank_regexp.indexIn(line) != -1))
                {
                    if (skipped < skip)
                        skip = skipped;

                    skipped = -1;
                }   
            }
        }

        // So, if we are not skipping and inside a module, remember the line.
        if ((skipped == -1) && (module.length() > 0))
        {
            n++;
            tmpout << line << endl;
        }

        // Remember when we enter a macro definition
        if (macro_regexp.indexIn(line) != -1)
            macro = 1;

        // End of module
        if (end_regexp.indexIn(line) != -1)
        {
            if (macro == 0)
            {
                tmpout.flush(); 
                tmpout.seek(0);

                int strip = 99, p = 0;

                while (tmpout.atEnd() != true)
                {
                    line = tmpout.readLine();

                    // Find the minimum column that contains non-blank
                    // characters in order to cut a blank prefix off.
                    // Ignore lines that only contain white spaces.
                    if (blankline_regexp.indexIn(line) == -1)
                    {
                        if (leadingspaces_regexp.indexIn(line) != -1)
                        {
                            p = leadingspaces_regexp.cap(1).length(); 
                            if ((p < strip) && (line.length() > p))
                                strip = p;
                        }
                    }
                }

                tmpout.seek(0);

                if (!skipmibfile)
                {
                    int num_bl = 0;

                    while (tmpout.atEnd() != true)
                    {
                        line = tmpout.readLine();
                        // For each block of consecutive blank lines,
                        // remove all lines but one.
                        if (blankline_regexp.indexIn(line) != -1)
                        {
                            num_bl++;
                            continue;
                        }
                        else
                        {
                            if (num_bl > 0)
                                out << endl;
                            num_bl = 0;
                        }

                        out << line.remove(0, strip) << endl;
                    }

                    out.flush(); 
                    file_out.close();

                    modules << module;
                }

                file_tmpout.remove();

                module = "";
            }
            else
            {
                macro = 0;
            }
        }
    }

    file_in.close();
 
    if(modules.size() > 0)
    {
        QString module_list;
        for (int i = 0; i < modules.size(); i++)
        {
            module_list += "\n\t";
            module_list +=  modules[i];
        }

        QMessageBox::information(NULL, tr("SnmpB: Extract MIB from RFC"),
                                 tr("%1 MIB module(s) have been extracted. \
The following MIB file(s) were created: %2")
                                 .arg(modules.size())
                                 .arg(module_list));
    }
Esempio n. 13
0
void MathTest::getMaxops()
{
    // The following are the default maxima for left and right operands
    // for the respective arithmetic operations and grade levels.
    //
    //  Max Operand Values for the given grade levels
    //
    //  Grade Level 1       2       3       4
    //
    //  Add Lop    10      50     100    1000
    //      Rop    10      10     100     500
    //  Sub Lop    10      20     100    1000
    //      Rop    10      10     100     500
    //  Mul Lop     3      10      13      20
    //      Rop     3      10      13      20
    //  Div Lop     3      10      13      20
    //      Rop     3      10      13      20
    //
    QString qsMaxops = QString(
                "10 10 50 10 100 100 1000 500 \n"
                "10 10 50 10 100 100 1000 500 \n"
                "10  3 10 10  15  15   20  20 \n"
                "10  3 10 10  15  15   20  20 \n"
                );

    int status;
    QString buff;
    QTextStream stream;
    QpFile maxopsFile(pMsg);
    QString maxopsFileName = "mt-maxops.txt";

    QFlags<QIODevice::OpenModeFlag>
        flags = QIODevice::ReadWrite | QIODevice::Text;

    if((status = maxopsFile.get(maxopsFileName, flags, true)) != qpfile::fFailed)
        stream.setDevice(&maxopsFile);
    else {
        stream.setString(&qsMaxops);
        //pMsg->sendInfo("Using built-in default test parameters.");
    }

    if(status == qpfile::fCreated)
        stream << qsMaxops;

    stream.seek(0);

    // Get the Operand Maxima
    //
    int j, k;
    for(j = 0; j < op_boundary; ++j) {
        for(k = 0; k < gl_boundary; ++k) {
            TESTPARM *pt = &testMatrix[j];
            stream >> buff;
            pt->maxops.iaLop[k] = QString(buff).toInt();
            stream >> buff;
            pt->maxops.iaRop[k] = QString(buff).toInt();
        }
    }
    if(maxopsFile.exists())
        maxopsFile.close();
}