void ExerciseWindow::checkExercise() { openFromNewLine = ui->checkBox_newLine->isChecked(); generateSourceCode(); toCode(); QString etalon = ui->textBrowser->toPlainText(); QString userAnswer = ui->textBrowser_2->toPlainText(); if (etalon == userAnswer) { ui->label->setStyleSheet("QLabel { background-color : green; color : white; }"); ui->label->setText("Верно!"); } else { ui->label->setStyleSheet("QLabel { background-color : red; color : white; }"); ui->label->setText("Неверно!"); } }
/** * @brief main function * @param argc argument count * @param argv arguments * @return 0 (success) or -1 (failure) */ int main (int argc, char **argv) { ifstream rcfile; ifstream hfile; filebuf *rcbuf; filebuf *hbuf; int rcBitmapCount = 0; int rcSoundCount = 0; int hBitmapCount = 0; int hSoundCount = 0; int bitmapNo; int soundNo; bool error = false; // check command line parameters if (argc > 1) { if (strncmp(argv[1], "--sprite", 8) == 0) { cout << NAME_OF_BOMBERMAN_DLL << endl; return 0; } else if (strncmp(argv[1], "--bin", 5) == 0) { cout << RESDIR << endl; return 0; } } // assume we're in the RESGEN directory, there are ../RES and ../RES32 // open resource.rc and resource.h rcfile.open(RESDIR RCFILE, ios_base::in); if (!rcfile.is_open()) { fprintf(stderr, "Could not open resource file " RESDIR RCFILE "\n"); return -1; } hfile.open(RESDIR HFILE, ios_base::in); if (!hfile.is_open()) { fprintf(stderr, "Could not open resource header file " RESDIR HFILE "\n"); return -1; } rcbuf = rcfile.rdbuf(); hbuf = hfile.rdbuf(); determineResourceCount(rcfile, hfile, rcBitmapCount, rcSoundCount, hBitmapCount, hSoundCount); // compare results if (hBitmapCount != rcBitmapCount) { fprintf(stderr, "WARNING: the number of bitmap resources (%d) in the " "resource file (" RCFILE ") differs from the number of bitmap " "resources (%d) in the header file (" HFILE "). Note that resource " "macros have to begin with BMP_ in the header file.\n", rcBitmapCount, hBitmapCount); fprintf(stderr, "Incomplete resources (i.e. its ID in the header or " "its filename in the rc file is missing) will not be included\n"); } if (hSoundCount != rcSoundCount) { fprintf(stderr, "WARNING: the number of sound resources (%d) in the " "resource file (" RCFILE ") differs from the number of sound " "resources (%d) in the header file (" HFILE "). Note that resource " "macros have to begin with SND_ in the header file.\n", rcSoundCount, hSoundCount); fprintf(stderr, "Incomplete resources (i.e. its ID in the header or " "its filename in the rc file is missing) will not be included\n"); } // now we will use hBitmapCount / hSoundCount as the valid count error = !buildResourceArrayWithHeader(hBitmapCount, hSoundCount, hfile, hbuf, bitmapNo, soundNo); // compare results if (hBitmapCount != bitmapNo) { fprintf(stderr, "WARNING: only %d out of %d bitmap resources were " "correctly parsed from the resource header (" HFILE ").\n", bitmapNo, hBitmapCount); } if (hSoundCount != soundNo) { fprintf(stderr, "WARNING: only %d out of %d sound resources were " "correctly parsed from the resource header (" HFILE ").\n", soundNo, hSoundCount); } if (error) { for (int i = 0; i < bitmapNo; i++) if (resources[TYPE_BITMAP][i].r_name != NULL) delete[] resources[TYPE_BITMAP][i].r_name; for (int i = 0; i < soundNo; i++) if (resources[TYPE_SOUND][i].r_name != NULL) delete[] resources[TYPE_SOUND][i].r_name; delete[] resources[TYPE_BITMAP]; delete[] resources[TYPE_SOUND]; hfile.close(); rcfile.close(); return -1; } error = !completeResourceArrayWithRC(hBitmapCount, hSoundCount, rcfile, rcbuf, bitmapNo, soundNo); // compare results if (hBitmapCount != bitmapNo) { fprintf(stderr, "WARNING: only %d out of %d bitmap resources were " "correctly parsed from the resource file (" RCFILE ").\n", bitmapNo, hBitmapCount); } if (hSoundCount != soundNo) { fprintf(stderr, "WARNING: only %d out of %d sound resources were " "correctly parsed from the resource file (" RCFILE ").\n", soundNo, hSoundCount); } if (error) { for (int i = 0; i < hBitmapCount; i++) { if (resources[TYPE_BITMAP][i].r_name != NULL) delete[] resources[TYPE_BITMAP][i].r_name; if (resources[TYPE_BITMAP][i].r_path != NULL) delete[] resources[TYPE_BITMAP][i].r_path; } for (int i = 0; i < hSoundCount; i++) { if (resources[TYPE_SOUND][i].r_name != NULL) delete[] resources[TYPE_SOUND][i].r_name; if (resources[TYPE_SOUND][i].r_path != NULL) delete[] resources[TYPE_SOUND][i].r_path; } delete[] resources[TYPE_BITMAP]; delete[] resources[TYPE_SOUND]; hfile.close(); rcfile.close(); return -1; } // we may close the files now hfile.close(); rcfile.close(); // now we will generate the source code, opening each resource and convert // its contents into a character array error = !generateSourceCode(hBitmapCount, hSoundCount, bitmapNo, soundNo); if (error) { cerr << "error creating source code.\n"; unlink(RESDATAC); } // clean up for (int i = 0; i < hBitmapCount; i++) { delete[] resources[TYPE_BITMAP][i].r_name; delete[] resources[TYPE_BITMAP][i].r_path; } for (int i = 0; i < hSoundCount; i++) { delete[] resources[TYPE_SOUND][i].r_name; delete[] resources[TYPE_SOUND][i].r_path; } delete[] resources[TYPE_BITMAP]; delete[] resources[TYPE_SOUND]; if (!error) { cout << "Source code was successfully generated." << endl; return 0; } else return -1; }