static int generalStreamAux(HRSstream_t s, char *dataOUT) { generalStream_s *gs = s->gs; int v; assert(gs->translate != NULL); if ((gs->fp == NULL) || (advFile(gs) == 0)) return HRS_STREAM_STOP; do { if (gs->filter != NULL) v = gs->filter(s->paramSet, s->paramTable, gs->fp, dataOUT); else v = gs->translate(s->paramSet, s->paramTable, gs->fp, dataOUT); if (v == HRS_STREAM_STOP) return HRS_STREAM_STOP; else if (v < 0) { HRSerrorExit1("%s: translation function failed.\n", s->streamName); } else if (v == HRS_STREAM_KEEP_REC) { return v; } else if (advFile(gs)) continue; else /* out of files */ return HRS_STREAM_STOP; } while (1); /* should never get here */ }
void MainWindow::buttonEvent(int button) { switch (button) { case 0: { QFile advFile("advice.dat"); if (!advFile.open(QIODevice::ReadOnly)) qDebug() << "Error: Unable to open file"; QStringList fileLines = getLinesWithBreaks(advFile); int numLines = fileLines.length(); int randLine = rand() % numLines; QString myMessage = "Advice: " + fileLines.at(randLine); myTextEdit->append(myMessage); break; } case 1: { QFile wthrFile("weather.dat"); if (!wthrFile.open(QIODevice::ReadOnly)) qDebug() << "Error: Unable to open file"; QStringList fileLines = getLinesWithBreaks(wthrFile); int numLines = fileLines.length(); int randLine = rand() % numLines; QString myMessage = "Weather: " + fileLines.at(randLine); myTextEdit->append(myMessage); break; } case 2: { QFile rmndFile("reminder.dat"); if (!rmndFile.open(QIODevice::ReadOnly)) qDebug() << "Error: Unable to open file"; QStringList fileLines = getLinesWithBreaks(rmndFile); int numLines = fileLines.length(); int randLine = rand() % numLines; QString message = fileLines.at(randLine); QMessageBox *myReminderBox = new QMessageBox(this); prompt->blockSignals(true); myReminderBox->addButton(prompt, QMessageBox::ActionRole); myReminderBox->addButton("OK", QMessageBox::RejectRole); myReminderBox->setIcon(QMessageBox::Information); myReminderBox->setModal(true); while (alreadyDisplayed.contains(message) && alreadyDisplayed.length() != numLines) { numLines = fileLines.length(); randLine = rand() % numLines; message = fileLines.at(randLine); } if (alreadyDisplayed.length() != numLines) { prompt->setChecked(true); myReminderBox->setText(message); myReminderBox->exec(); if (prompt->checkState() == Qt::Unchecked) { alreadyDisplayed.append(message); } } else myTextEdit->append("There are no more reminders."); break; } case 3: { QMessageBox *closeBox = new QMessageBox(this); closeBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No); closeBox->setText("Are you sure you want to quit?"); closeBox->setIcon(QMessageBox::Question); closeBox->setModal(true); int clicked = closeBox->exec(); if (clicked == 16384) QApplication::quit(); } } }