Example #1
0
QString echoBlock(int tabs, const QString &in)
{
	QStringList pars = in.split('\n', QString::KeepEmptyParts);
	if(!pars.isEmpty() && pars.last().isEmpty())
		pars.removeLast();
	QStringList lines;
	int n;
	for(n = 0; n < pars.count(); ++n) {
		QStringList list = wrapString(pars[n], CONF_WRAP);
		for(int n2 = 0; n2 < list.count(); ++n2)
			lines.append(list[n2]);
	}

	QString str;
	for(n = 0; n < lines.count(); ++n) {
		QString out;
		out.fill(9, tabs); // 9 == tab character
		if(lines[n].isEmpty())
			out += QString("printf \"\\n\"\n");
		else
			out += QString("printf \"%1\\n\"\n").arg(c_escape(lines[n]));
		str += out;
	}
	return str;
}
Example #2
0
 void ReactionStoichMgr::
 writeNetProductionRates(ostream& f) {
   f << "    void getNetProductionRates(const doublereal* r, doublereal* w) {" << endl;
   map<int, string> out;
   m_revproducts->writeIncrementSpecies("r",out);
   m_irrevproducts->writeIncrementSpecies("r",out);
   m_reactants->writeDecrementSpecies("r",out);
   map<int, string>::iterator b;
   for (b = out.begin(); b != out.end(); ++b) {
     string rhs = wrapString(b->second);
     rhs[1] = '=';
     f << "     w[" << b->first << "] " << rhs << ";" << endl;
   }
   f << "    }" << endl << endl << endl;
 }
void ReactionStoichMgr::writeDestructionRates(ostream& f)
{
    f << "    void getDestructionRates(const doublereal* rf, const doublereal* rb," << endl;
    f << "          doublereal* d) {" << endl;
    map<size_t, string> out;
    m_revproducts.writeIncrementSpecies("rb",out);
    m_reactants.writeIncrementSpecies("rf",out);
    map<size_t, string>::iterator b;
    for (b = out.begin(); b != out.end(); ++b) {
        string rhs = wrapString(b->second);
        rhs[1] = '=';
        f << "     d[" << b->first << "] " << rhs << ";" << endl;
    }
    f << "    }" << endl << endl << endl;
}
Example #4
0
QString formatBlock(const QString &in)
{
	QStringList pars = in.split('\n', QString::KeepEmptyParts);
	if(!pars.isEmpty() && pars.last().isEmpty())
		pars.removeLast();
	QStringList lines;
	int n;
	for(n = 0; n < pars.count(); ++n) {
		QStringList list = wrapString(pars[n], CONF_WRAP);
		for(int n2 = 0; n2 < list.count(); ++n2)
			lines.append(list[n2]);
	}

	QString str;
	for(n = 0; n < lines.count(); ++n)
		str += lines[n] + '\n';
	return str;
}
Example #5
0
SWError renderStaticText( StaticTextPtr st )
{
	SWError err = kNoError;
	TTF_Font *font = NULL;
	FramePtr frameP;
	char wrappedString[ kMaxStringLength ];

	if( err == kNoError )
	{
			// load the font we will be using
		font = TTF_OpenFont( st->fontPath, st->fontSize );
		if( ! font ) err = kSTCouldntOpenFontError;
	}

	if( err == kNoError )
	{
		TTF_SetFontStyle( font, st->fontStyle );
		
		strcpy( wrappedString, st->string );
		
		if( st->wrap )
			err = wrapString( wrappedString, font, st->bounds.right - st->bounds.left );
	}

	if( err == kNoError )
	{
		frameP = st->sprite.curFrameP;
				
		err = blitStringToFrame(
			wrappedString,
			font,
			st->align,
			st->rendering,
			&st->textColor,
			&st->backColor,
			frameP );
		
		st->sprite.needsToBeDrawn = true;
	}

	if( font != NULL ) TTF_CloseFont( font );
	
	return err;
}
Example #6
0
void logCritical(const char* message, ...) {
  va_list arguments;
  CharString formattedMessage = newCharString();
  CharString wrappedMessage;

  va_start(arguments, message);
  // Instead of going through the common logging method, we always dump critical
  // messages to stderr
  vsnprintf(formattedMessage->data, formattedMessage->length, message, arguments);
  wrappedMessage = wrapString(formattedMessage, 0);
  fprintf(stderr, "ERROR: %s\n", wrappedMessage->data);
  if(eventLoggerInstance != NULL && eventLoggerInstance->logFile != NULL) {
    fprintf(eventLoggerInstance->logFile, "ERROR: %s\n", wrappedMessage->data);
  }

  freeCharString(formattedMessage);
  freeCharString(wrappedMessage);
  va_end(arguments);
}
Example #7
0
void runTest(Test func()) {
    Test result = func();
    result.run();
    std::cout << result.getName() << "()";
    if (result.hasPassed()) {
        std::cout << " -- PASS";
    } else {
        std::cout << " -- FAIL" << std::endl;
        std::stringstream inputs;
        size_t maxLength = 0;
        for (auto iter = result.getFailedStart(); iter != result.getFailedEnd(); iter++) {
            std::string tmp = "| Input: '" + *iter + "'";
            if (tmp.length() > maxLength) maxLength = tmp.length();
            inputs << tmp << std::endl;
        }
        if (maxLength % 2) maxLength++;
        std::cout << wrapString(" Failed ", '-', maxLength) << std::endl << inputs.str() << std::string(maxLength, '-');
    }
    std::cout << std::endl;
}
Example #8
0
void CliParser::printHelpText(int maxWidth) const
{
    int longOptLength = 0;
    for (const CliOption &o : _options)
        longOptLength = max(longOptLength, int(o.longOpt.size()));
    longOptLength += 4;

    std::cout << "Usage: " << _programName << " " << _usage << "\nOptions:\n";
    for (const CliOption &o : _options) {
        if (o.shortOpt == '\0')
            std::cout << "     ";
        else
            std::cout << " -" << o.shortOpt << "  ";
        std::cout.width(longOptLength);
        std::cout << std::left;
        if (o.longOpt.empty())
            std::cout << "";
        else
            std::cout << ("--" + o.longOpt);
        std::cout << "  ";
        wrapString(maxWidth, 5 + longOptLength + 2, o.description);
    }
    std::cout.flush();
}
Example #9
0
}

void logFileError(const char* filename, const char* message) {
  logCritical("Could not parse file '%s'", filename);
  logCritical("Got error message message: %s", message);
  logPossibleBug("This file is either corrupt or was parsed incorrectly");
}

void logPossibleBug(const char* cause) {
  CharString extraText = newCharStringWithCString("If you believe this to be a \
bug in MrsWatson, please re-run the program with the --error-report option to \
generate a diagnostic report to send to support.");
  CharString wrappedCause;
  CharString wrappedExtraText;

  wrappedCause = wrapString(newCharStringWithCString(cause), 0);
  wrappedExtraText = wrapString(extraText, 0);
  fprintf(stderr, "%s\n", wrappedCause->data);
  fprintf(stderr, "%s\n", wrappedExtraText->data);

  freeCharString(wrappedCause);
  freeCharString(wrappedExtraText);
}

void flushErrorLog(void) {
  if(eventLoggerInstance != NULL && eventLoggerInstance->logFile != NULL) {
    fflush(eventLoggerInstance->logFile);
  }
}

void freeEventLogger(void) {
Example #10
0
void HistoryDlg::exportHistory(const QString &fname)
{
	QFile f(fname);
	if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
		QMessageBox::information(this, tr("Error"), tr("Error writing to file."));
		return;
	}
	QTextStream stream(&f);

	QString us = d->pa->nick();
	UserListItem *u = d->pa->findFirstRelevant(d->jid);
	QString them = JIDUtil::nickOrJid(u->name(), u->jid().full());

	d->exp = new EDBHandle(d->pa->edb());
	QString id;
	while(1) {
		if(id.isEmpty()) {
			d->exp->getOldest(d->jid, 1000);
		} else {
			d->exp->get(d->jid, id, EDB::Forward, 1000);
		}
		while(d->exp->busy()) {
			qApp->processEvents();
		}

		const EDBResult *r = d->exp->result();
		if(!r) {
			break;
		}
		if(r->count() <= 0) {
			break;
		}

		// events are in forward order
		for(int i = 0; i < r->count(); ++i) {
			EDBItem* item = r->value(i);
			id = item->nextId();
			PsiEvent *e = item->event();
			QString txt;

			QDateTime dt = e->timeStamp();
			QString ts;
			//ts.sprintf("%04d/%02d/%02d %02d:%02d:%02d", dt.date().year(), dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second());
			ts = dt.toString(Qt::LocalDate);

			QString nick;
			if(e->originLocal()) {
				nick = us;
			} else {
				nick = them;
			}

			QString heading = QString("(%1) ").arg(ts) + nick + ": ";
			if(e->type() == PsiEvent::Message) {
				MessageEvent *me = (MessageEvent *)e;
				stream << heading << endl;

				QStringList lines = me->message().body().split('\n', QString::KeepEmptyParts);
				foreach(const QString& str, lines) {
					QStringList sub = wrapString(str, 72);
					foreach(const QString& str2, sub) {
						txt += QString("    ") + str2 + '\n';
					}
				}
			}