void PgnImporter::run() { QFile file(m_fileName); QFileInfo fileInfo(m_fileName); const QTime startTime = QTime::currentTime(); static const int updateInterval = 1024; int numReadGames = 0; if (!fileInfo.exists()) { emit error(PgnImporter::FileDoesNotExist); return; } if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { emit error(PgnImporter::IoError); return; } PgnStream pgnStream(&file); QList<const PgnGameEntry*> games; forever { PgnGameEntry* game = new PgnGameEntry; if (m_abort || !game->read(pgnStream)) { delete game; break; } games << game; numReadGames++; if (numReadGames % updateInterval == 0) emit databaseReadStatus(startTime, numReadGames); } PgnDatabase* db = new PgnDatabase(m_fileName); db->setEntries(games); db->setLastModified(fileInfo.lastModified()); emit databaseRead(db); }
int main (void) { srand(time(0)); struct StringDatabase* D = databaseInit(); FILE* databaseFile = fopen ("base.txt", "r"); databaseRead(D, databaseFile); //BTreePrintTree(D->root, 0, stdout); fclose (databaseFile); //return; // databasePrint(D, stdout); // printf ("%d\n", databaseFindPrefix(D, "")); char array[SIZE * SIZE] = {}; array[0] = 'b'; array[1] = 'a'; array[2] = 's'; array[3] = 'i'; array[4] = 's'; //array[9] = 's'; //array[7] = 'd'; char result[SIZE * SIZE] = {}; databaseRemove(D, "basis"); #define PRINT_FIELD(field) \ {\ int i, j;\ for (i = 0; i < SIZE; i++)\ { \ for ( j = 0; j < SIZE; j++) \ printf("%c ", array[SIZE * i + j] ? array[SIZE * i + j] : '-');\ printf ("\n");\ }\ } PRINT_FIELD(array); int k; for (k = 0; k < SIZE * SIZE; k++) { int location = 0; char inserted = 0; computerNext (array, SIZE, SIZE, D, result, &location, &inserted); printf ("result = %s, location = (%d, %d), inserted = %c\n", result, location / SIZE + 1, location % SIZE + 1, inserted); if (inserted == 0) break; databaseRemove(D, result); memset(result, 0, SIZE * SIZE); array[location] = inserted; PRINT_FIELD(array); } //*/ databaseDestroy(D); }