void scanFiles() { freeFiles(); // Read the directory/device TOC if(curDirEntries){ free(curDirEntries); curDirEntries = NULL; } print_gecko("Reading directory: %s\r\n",curFile.name); curDirEntryCount = devices[DEVICE_CUR]->readDir(&curFile, &curDirEntries, -1); memcpy(&curDir, &curFile, sizeof(file_handle)); sortFiles(curDirEntries, curDirEntryCount); print_gecko("Found %i entries\r\n",curDirEntryCount); }
void sortFiles(trieNodePointer root) { // trieNodePointer root = ROOT; for (int i=0; i < 36; i++) { if (root->children[i] != NULL) { if (root->children[i]->token != NULL) { sortFileHelper(root->children[i]->files); } sortFiles(root->children[i]); } } }
int main(int argv, char** argc) { File* hw; Marker* markers; Marker* it; const char* markersPath; const char* hwPath; FILE* outFile; if (argv != 3) { printf("Usage: %s markers homeworks\n", argc[0]); printf("markers: Markers file path.\n"); printf("files: HW files path.\n"); exit(EXIT_FAILURE); } markersPath = argc[1]; hwPath = argc[2]; markers = readMarkers(markersPath); srand(time(NULL)); rand(); rand(); hw = makeFileList(hwPath); markers = distribute(hw, markers); markers = sortMarkers(markers, numMarkers(markers)); for (it = markers; it; it = it->next) { it->files = sortFiles(it->files, numFiles(it->files)); } printMarkers(markers); for (it = markers; it; it = it->next) { free((void*)it->name); } freeMarkers(markers); freeFiles(hw); return 0; }
void main_loop() { while(PAD_ButtonsHeld(0) & PAD_BUTTON_A) { VIDEO_WaitVSync (); } // We don't care if a subsequent device is "default" if(needsDeviceChange) { free_files(); if(deviceHandler_deinit) { deviceHandler_deinit(deviceHandler_initial); } if (forceSlot) { deviceHandler_FAT_deinit(&initial_SD1); } curDevice = -1; needsDeviceChange = 0; deviceHandler_initial = NULL; needsRefresh = 1; curMenuLocation = ON_FILLIST; select_device(0); if (curDevice == WKF) { trySlotB(); } curMenuLocation = ON_OPTIONS; } if(deviceHandler_initial) { // If the user selected a device, make sure it's ready before we browse the filesystem deviceHandler_deinit( deviceHandler_initial ); sdgecko_setSpeed(EXI_SPEED32MHZ); if(!deviceHandler_init( deviceHandler_initial )) { if(((deviceHandler_initial->name[0] == 's')&&(deviceHandler_initial->name[1] == 'd'))||(deviceHandler_initial->name[0] == 'i')) { print_gecko("SD/IDE-EXI Device Failed to initialize @ 32MHz!\r\nTrying again once @ 16MHz...\r\n"); sdgecko_setSpeed(EXI_SPEED16MHZ); if(!deviceHandler_init(deviceHandler_initial)) { // Try the alternate slot for SDGecko or IDE-EXI if(deviceHandler_initial->name[0] == 's') deviceHandler_initial = (deviceHandler_initial == &initial_SD0) ? &initial_SD1:&initial_SD0; else deviceHandler_initial = (deviceHandler_initial == &initial_IDE0) ? &initial_IDE1:&initial_IDE0; memcpy(&curFile, deviceHandler_initial, sizeof(file_handle)); } print_gecko("Trying alternate slot @ 32MHz...\r\n"); sdgecko_setSpeed(EXI_SPEED32MHZ); if(!deviceHandler_init( deviceHandler_initial )) { print_gecko("Alternate slot failed once @ 16MHz... \r\n"); sdgecko_setSpeed(EXI_SPEED16MHZ); if(!deviceHandler_init( deviceHandler_initial )) { print_gecko("Both slots failed twice\r\n"); needsDeviceChange = 1; return; } } } } if(curDevice==SD_CARD || curDevice==WKF || curDevice==IDEEXI) { load_config(forceSlot); } } else { curMenuLocation=ON_OPTIONS; } // If a previously undetected device has been successfully init'd, mark it as available from now on if(!deviceHandler_getDeviceAvailable(curDevice)) { deviceHandler_setDeviceAvailable(curDevice, 1); } while(1) { if(deviceHandler_initial && needsRefresh) { curMenuLocation=ON_OPTIONS; free_files(); curSelection=0; files=0; curMenuSelection=0; // Read the directory/device TOC if(allFiles){ free(allFiles); allFiles = NULL; } print_gecko("Reading directory: %s\r\n",curFile.name); files = deviceHandler_readDir(&curFile, &allFiles, -1); memcpy(&curDir, &curFile, sizeof(file_handle)); sortFiles(allFiles, files); print_gecko("Found %i entries\r\n",files); if(files<1) { deviceHandler_deinit(deviceHandler_initial); needsDeviceChange=1; break;} needsRefresh = 0; curMenuLocation=ON_FILLIST; } while(PAD_ButtonsHeld(0) & PAD_BUTTON_A) { VIDEO_WaitVSync (); } drawFiles(&allFiles, files); u16 btns = PAD_ButtonsHeld(0); if(curMenuLocation==ON_OPTIONS) { if(btns & PAD_BUTTON_LEFT){ curMenuSelection = (--curMenuSelection < 0) ? (MENU_MAX-1) : curMenuSelection;} else if(btns & PAD_BUTTON_RIGHT){curMenuSelection = (curMenuSelection + 1) % MENU_MAX; } } if(deviceHandler_initial && ((btns & PAD_BUTTON_B)||(curMenuLocation==ON_FILLIST))) { while(PAD_ButtonsHeld(0) & PAD_BUTTON_B){ VIDEO_WaitVSync (); } curMenuLocation=ON_FILLIST; renderFileBrowser(&allFiles, files); } else if(btns & PAD_BUTTON_A) { //handle menu event switch(curMenuSelection) { case 0: // Device change needsDeviceChange = 1; //Change from SD->DVD or vice versa break; case 1: // Settings show_settings(NULL, NULL); break; case 2: // Credits show_info(); break; case 3: if(deviceHandler_initial) { memcpy(&curFile, deviceHandler_initial, sizeof(file_handle)); if(curDevice == WKF) { wkfReinit(); deviceHandler_deinit(deviceHandler_initial); } } needsRefresh=1; break; case 4: __libogc_exit(0); break; } } while (!(!(PAD_ButtonsHeld(0) & PAD_BUTTON_B) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_A) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT))) { VIDEO_WaitVSync(); } if(needsDeviceChange) { break; } } }
void OpticalFlowThread::run() { qDebug() << "Optflow thread started."; if (m_inputDir.isEmpty() || m_outputDir.isEmpty()) { qDebug() << "Dirs incorrect."; return; } QDir dirin(m_inputDir); if (!dirin.exists()) { qDebug() << "Input dir does not exist."; return; } QFileInfoList images = dirin.entryInfoList(getSupportedImagesFilter() , QDir::Files , QDir::Name); sortFiles(images); QImage* img1; QImage* img2; QImage* flow; img1 = NULL; img2 = NULL; QString filename1; m_running = true; int counter(0); while (m_alive) { foreach (QFileInfo file, images) { if (m_pause) { m_mutexSleep.lock(); m_condition.wait(&m_mutexSleep); m_mutexSleep.unlock(); } if (!m_alive) { break; } QString filename2 = QString("%1%2").arg(m_inputDir, file.fileName()); //compute optical flow if (img1 == NULL) { img1 = new QImage(filename2); filename1 = filename2; continue; } qDebug() << "image1 : " << filename1 << " image2 : " << filename2; img2 = new QImage(filename2); flow = m_optflowtools->computeFlow(img1, img2 , filename1 , filename2); //emit result float perc = (float)(counter + 1) / (float)images.size() * 100.f; emit flowComputed(img1, img2, flow, ceil(perc)); counter++; //manage images img1 = img2; filename1 = filename2; } emit flowComputed(NULL, NULL, NULL, 100); m_alive = false; } qDebug() << "Optflow thread ended."; m_running = false; }
/* * Thread - Compose ArchReqs in the queue. */ void * Compose( void *arg) { QueueInit(&composeQ); ThreadsInitWait(wakeup, wakeup); while (AdState->AdExec < ES_term) { struct QueueEntry *qe; struct ArchReq *ar; struct ArchSet *as; /* * Wait for entries in the queue. */ ThreadsReconfigSync(RC_allow); PthreadMutexLock(&composeWaitMutex); while (AdState->AdExec < ES_term && composeQ.QuHead.QeFwd == &composeQ.QuHead) { PthreadCondWait(&composeWait, &composeWaitMutex); } if (AdState->AdExec >= ES_term) { PthreadMutexUnlock(&composeWaitMutex); break; } ThreadsReconfigSync(RC_wait); /* * Remove and process next compose queue entry. */ qe = composeQ.QuHead.QeFwd; ar = qe->QeAr; arname = qe->QeArname; QueueRemove(qe); PthreadMutexUnlock(&composeWaitMutex); arFiList = NULL; if ((ar->ArStatus & (ARF_changed | ARF_merge | ARF_rmreq)) || (ar->ArFlags & AR_unqueue)) { ar->ArFlags &= AR_unqueue; MessageReturnQueueEntry(qe); continue; } if (!(ar->ArFlags & AR_first)) { /* * Remove processed files. */ pruneArchReq(ar); if (ar->ArFiles == 0) { MessageReturnQueueEntry(qe); continue; } ar->ArState = ARS_schedule; } ar->ArFlags &= AR_offline | AR_segment; as = FindArchSet(ar->ArAsname); if (as == NULL) { Trace(TR_MISC, "Invalid ArchReq %s", arname); MessageReturnQueueEntry(qe); continue; } if (as->AsFlags & AS_disk_archive) { ar->ArFlags |= AR_disk; } else if (as->AsFlags & AS_honeycomb) { ar->ArFlags |= AR_honeycomb; } ar->ArDrivesUsed = 0; ar->ArDivides = DM_none; ar->ArSelFiles = ar->ArFiles; ar->ArSelSpace = ar->ArSpace; /* * Process the compositions as required. */ if (ar->ArFlags & AR_offline) { /* * Check offline files for available stage volumes. */ checkOffline(ar); ar->ArDivides = DM_offline; } if (ar->ArFlags & AR_segment) { ar->ArDivides = DM_segment; sortSegments(ar); } if (as->AsJoin != JM_none) { ar = joinFiles(ar, as); qe->QeAr = ar; } if (as->AsSort != SM_none) { sortFiles(ar, as); } if (as->AsReserve & RM_owner) { ar->ArDivides = (as->AsReserve & RM_dir) ? DM_ownerDir : DM_ownerUidGid; } prepareArchReq(ar); ScheduleEnqueue(qe); } ThreadsExit(); /*NOTREACHED*/ return (arg); }