void MusicWindow::folderSelected() { //QList<ModelIndex>::Iterator it = indexes.begin(); int s = ui.folderList->currentRow(); QString folder = ui.folderList->currentItem()->text(); initFileList(folder); }
static float getProductTotalCost(int line_number) { int i = 0; FILENAME_AND_LINE_NO file_datas[NUM_OF_FILES] = {0}; initFileList(file_datas); product_total_cost = 0; for(i = 0; i < NUM_OF_FILES; i++) { file_datas[i].line_number = line_number; if(pthread_create(&(Thread_Ids[i]), NULL, &readCostAndUpdateTotal, (void *)&(file_datas[i])) != 0) { write(STDERR_FILENO, PTHREAD_CREATE_ERROR, sizeof(PTHREAD_CREATE_ERROR)); exit(EXIT_ERROR_CODE); } } for(i = 0; i < NUM_OF_FILES; i++) { if(pthread_join(Thread_Ids[i], NULL) != 0) { write(STDERR_FILENO, PTHREAD_JOIN_FAILED, sizeof(PTHREAD_JOIN_FAILED)); exit(EXIT_ERROR_CODE); } } return product_total_cost; }
void PrintHelpFiles( HelpSrchPathItem *srch ) { FileList *list; list = initFileList(); fillFileList( srch, list ); sortFileList( list ); printFileList( list ); freeFileList( list ); }
void AlarmToneModel::setTonesPath(const QString &path) { if (m_tonesPath != path) { m_tonesPath = path; emit tonesPathChanged(); beginResetModel(); initFileList(); endResetModel(); } }
void callInit(){ /* file1=fopen("gg.txt","r"); char line[150]; char *buf; while(fgets(line,150,file1)!=NULL){ buf = strtok (line,"\""); buf = strtok (NULL,"\""); printf("\n%s",buf); } fclose(file1); */ file1=fopen("gg.txt","w+"); initFileList("./Galu",0,file1); fclose(file1); }
/*Assumes file is either in the character or guilds schema*/ BOOLEAN externalMergeSort(FILE ** sorted, int pagesize, int buffers, char * path, int * passes, int * runs, Schema * schema){ FileList initialFileList; int totalRecordCount = 0; initFileList(&initialFileList); printf("Commencing sort merge on file '%s'\n",path); if(initialRun(path, (pagesize * buffers), schema, &initialFileList, &totalRecordCount) == FALSE) return TRUE; *passes = 1; *runs += initialFileList.fileCount; printf("Pass %i resulted in %i runs\n",*passes,*runs); /*printFileContents(&initialFileList, *schema);*/ mergeRuns(sorted, pagesize, buffers, initialFileList, passes, runs, totalRecordCount); rewind(*sorted); return TRUE; }
void main() { int i; do{ printf("1 to initialize txt file\n2 to compare\n3 to exit\n:"); scanf("%d",&i); if(i==1){ file1=fopen("gg.txt","w+"); initFileList("./Galu",0,file1); fclose(file1); }else if(i==2){ file1=fopen("gg.txt","r"); file2=fopen("out.txt","w+"); compareFiles("./Galu",0,file1); fclose(file1); fclose(file2); callInit(); }else if(i==3){ break; } }while(1); }
void callInit(char *str){ file1=fopen("initFiles.txt","w+"); initFileList(str,0,file1); fclose(file1); }
void initFileList(const char *name, int level,FILE *f){ DIR *dir; struct dirent *ent; char path[1024]=""; char t[ 512 ] = ""; int len; struct stat b; if (!(dir = opendir(name))) return; if (!(ent = readdir(dir))) return; int i=0; do{ // if folder if (ent->d_type == DT_DIR){ if(strcmp(ent->d_name,"chunkstempofolder")==0)continue; if(strcmp(ent->d_name,"..")==0) len = snprintf(path, sizeof(path)-1, "%s", name); else len = snprintf(path, sizeof(path)-1, "%s/%s", name, ent->d_name); path[len] = 0; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; initFileList(path, level + 1,f); } //if file else{ //printf("\n===%s-%s",path,name); //printf("\n===%s",path); len = snprintf(path, sizeof(path)-1, "%s", name); //printf("\nscanning: %s",ent->d_name); //if(strcmp(ent->d_name,"a.c")!=0 && strcmp(ent->d_name,"a.out")!=0 && strcmp(ent->d_name,"sha1.c")!=0 && strcmp(ent->d_name,"sha1.h")!=0 && strcmp(ent->d_name,"out.txt")!=0 && strcmp(ent->d_name,"initFiles.txt")!=0) { char file[strlen(path)+strlen(ent->d_name)+1]; strcpy(file,path); strcat(file,"/"); strcat(file,ent->d_name); stat(file, &b); // for jpeg exceptions char *sha; /*if(strstr(strrchr(ent->d_name, '.') , ".jpg")!=NULL || strstr(strrchr(ent->d_name, '.') , ".pdf")!=NULL || strstr(strrchr(ent->d_name, '.') , ".mkv")!=NULL || strstr(strrchr(ent->d_name, '.') , ".zip") || strstr(strrchr(ent->d_name, '.') , ".flv") || strstr(strrchr(ent->d_name, '.') , ".ppt") || strstr(strrchr(ent->d_name, '.') , ".mp3")){ FILE *tempF, *jpgF; char tempStr[strlen(path)+strlen(ent->d_name)+1]; char tempStr2[strlen(ent->d_name)+4]; strcpy(tempStr,path); strcat(tempStr,"/"); strcat(tempStr,ent->d_name); //printf("\n%s",tempStr); jpgF=fopen(tempStr,"r"); strcat(tempStr,".txt"); tempF=fopen(tempStr,"w"); if(strstr(strrchr(ent->d_name, '.') , ".jpg")!=NULL) convertUTF8ToUnicode(jpgF, tempF,0); while(!feof(jpgF)) convertUTF8ToUnicode(jpgF, tempF,1); strcpy(tempStr2,ent->d_name); strcat(tempStr2,".txt"); sha=getSha(path,ent->d_name); //sha="WFEWFFDTJRERTYJHTREWFEGHTRWFERT2345yge"; fprintf(f, "%s|", sha); if(remove(tempStr)==0) printf("\nDeleted:%s",tempStr); }else*/{ sha=getSha(path,ent->d_name); fprintf(f, "%s|", sha); } //printf("%lu|",getSize(file)); fprintf(f, "%lu|", getSize(file)); strftime(t, 100, "%m%d%Y-%H:%M:%S", localtime(&b.st_ctime)); //printf("%s|",t); fprintf(f, "%s|",t); strftime(t, 100, "%m%d%Y-%H:%M:%S", localtime(&b.st_mtime)); //printf("%s|",t); fprintf(f, "%s|",t); strftime(t, 100, "%m%d%Y-%H:%M:%S|", localtime(&b.st_atime)); //printf("%s",t); fprintf(f, "%s",t); //printf("%s\n",file); strcpy(file,path); strcat(file,"/\""); strcat(file,ent->d_name); strcat(file,"\""); fprintf(f, "%s\n",file); // file path strcpy(file,path); strcat(file,"/"); //strcat(file,"\""); strcat(file,ent->d_name); //strcat(file,"\""); strcpy(t, file); strcat(t,"|"); // file hash strcat(t,sha); strcat(t,"|"); // file size char buffer[18]; //printf("\n%s is changed\n",file); sprintf(buffer, "%lu", getSize(file)); strcat(t,buffer); strcat(t,"|"); stat(file, &b); strftime(buffer, 100, "%m%d%Y-%H:%M:%S|", localtime(&b.st_ctime)); //printf("\n%s\n",buffer); strcat(t,buffer); strftime(buffer, 100, "%m%d%Y-%H:%M:%S|", localtime(&b.st_mtime)); strcat(t,buffer); strftime(buffer, 100, "%m%d%Y-%H:%M:%S", localtime(&b.st_atime)); strcat(t,buffer); fprintf(file2, "%s\n",t); //printf("\n===="); //} } } while (ent = readdir(dir)); closedir(dir); }
void initFileList(const char *name, int level,FILE *f){ DIR *dir; struct dirent *ent; char path[1024]=""; char t[ 512 ] = ""; int len; struct stat b; if (!(dir = opendir(name))) return; if (!(ent = readdir(dir))) return; int i=0; do{ // if folder if (ent->d_type == DT_DIR){ if(strcmp(ent->d_name,"..")==0) len = snprintf(path, sizeof(path)-1, "%s", name); else len = snprintf(path, sizeof(path)-1, "%s/%s", name, ent->d_name); path[len] = 0; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; initFileList(path, level + 1,f); } //if file else{ len = snprintf(path, sizeof(path)-1, "%s", name); if(strcmp(ent->d_name,"a.c")!=0 && strcmp(ent->d_name,"a.out")!=0 && strcmp(ent->d_name,"sha1.c")!=0 && strcmp(ent->d_name,"sha1.h")!=0 && strcmp(ent->d_name,"out.txt")!=0 && strcmp(ent->d_name,"gg.txt")!=0) { char file[strlen(path)+strlen(ent->d_name)+1]; strcpy(file,path); strcat(file,"/"); strcat(file,ent->d_name); stat(file, &b); //printf("%s|",getSha(path,ent->d_name)); fprintf(f, "%s|", getSha(path,ent->d_name)); //printf("%lu|",getSize(file)); fprintf(f, "%lu|", getSize(file)); strftime(t, 100, "%m%d%Y-%H:%M:%S", localtime(&b.st_ctime)); //printf("%s|",t); fprintf(f, "%s|",t); strftime(t, 100, "%m%d%Y-%H:%M:%S", localtime(&b.st_mtime)); //printf("%s|",t); fprintf(f, "%s|",t); strftime(t, 100, "%m%d%Y-%H:%M:%S|", localtime(&b.st_atime)); //printf("%s",t); fprintf(f, "%s",t); //printf("%s\n",file); strcpy(file,path); strcat(file,"/\""); strcat(file,ent->d_name); strcat(file,"\""); fprintf(f, "%s\n",file); } } } while (ent = readdir(dir)); closedir(dir); }
AlarmToneModel::AlarmToneModel(QObject *parent) : QAbstractListModel(parent) , m_tonesPath(DefaultAlarmToneDir) { initFileList(); }
BOOLEAN mergeRuns(FILE ** sorted, int pagesize, int availableBuffers, FileList currentFiles, int * passes, int * runs, int totalRecordCount){ RecordHeap rHeap; Buffer * bufferNodes; int bufferIndex; /*Determine max files that can be merged in a run*/ /*That is available buffers -1 for the output buffer*/ /*This is also the output buffer indes*/ int outputBuffIndex = availableBuffers -1; /*Buffer array (of buffer nodes) where size of which is the number of buffers available to store in memory*/ bufferNodes = calloc(availableBuffers, sizeof(Buffer)); if(!bufferNodes){ fprintf(stderr, "Error: Failed to allocate buffer array\n"); return FALSE; } /*Allocate memory for record arrays for each buffer*/ for(bufferIndex = 0; bufferIndex < availableBuffers; bufferIndex++){ initBuffer(&bufferNodes[bufferIndex], pagesize); } /*Initialise priority queue It's size is the amount of files that can be merged in a run*/ /*outputBuffIndex is the last index in the buffer array*/ if(initHeap(&rHeap, outputBuffIndex * pagesize) == FALSE){ return FALSE; } /*while more merging required, (more than 1 temporary file)*/ /*go through a pass*/ while(currentFiles.fileCount > 1){ int runCount = 0; /*Define first file to be the start of the file linked list*/ FileNode * firstFileForRun = currentFiles.fileHeadNode; /*Run file list, is the files to be merged in the next pass*/ FileList runFileList;/*= calloc(1, sizeof(FileList));*/ float runsInPassFloat = ((float)currentFiles.fileCount/(float)(availableBuffers-1)); int runsInPass = ceil(runsInPassFloat); initFileList(&runFileList); /*while still merging required for pass*/ /*go through a run*/ while(runCount < runsInPass){ int buffersInUse = 0; int bufferIndex = 0; int init = 0; FileNode * currentRunFile = firstFileForRun; FILE * outputFile; /*create new temp file for merge run, written to when output buffer is full*/ if((outputFile = tmpfile()) == NULL){ fprintf(stderr, "Error: Failed to create output temporary file for run\n"); return FALSE; } /*add file pointer to the file list for the next pass*/ addFile(&runFileList,outputFile); /*Read in pages from current files to buffers*/ for(bufferIndex = 0; bufferIndex < outputBuffIndex; bufferIndex++){ int recordPageIndex; /*fill buffer with records from file*/ if(currentRunFile->fp != NULL){ for(recordPageIndex = 0; recordPageIndex < pagesize; recordPageIndex++){ /*read in record*/ Record record; if(fread(&record, sizeof(Record), 1, currentRunFile->fp) == 1){ /*add record to page (records array)*/ init++; if(addRecord(&bufferNodes[bufferIndex], record, pagesize, recordPageIndex) == FALSE) return FALSE; /*add record index to heap*/ if(addToHeap(&rHeap, &bufferNodes[bufferIndex], recordPageIndex) == FALSE) return FALSE; } /*else reached file end*/ else{ /*temp file will be automatically deleted by the system*/ fclose(currentRunFile->fp); currentRunFile->fp = NULL; /*removeFile(currentFiles, currentRunFile);*/ /*add blank records*/ /*int blankRecordCount; for(blankRecordCount = recordCount; blankRecordCount < pagesize; blankRecordCount++){ int recordPageIndex = addBlankRecord(&bufferNodes[bufferIndex], pagesize); if(recordPageIndex < 0) return FALSE; }*/ break; } } bufferNodes[bufferIndex].fileNode = currentRunFile; buffersInUse++; currentRunFile = currentRunFile->nextFileNode; if (currentRunFile == NULL) break; } else break; } /*set firstFileForRun for next run*/ firstFileForRun = currentRunFile; /*while all buffers are not empty (there is still records in pages in some buffer not including the output buffer)*/ while(buffersInUse > 0 && rHeap.count > 0){ /*keep getting min record and writing to output buffer*/ /*get smallest record*/ RecordIndex minIndex = removeMinHeap(&rHeap); if(minIndex.guildID == 0) return FALSE; /*move smallest record from main buffer memory to output buffer*/ /*add record to output buffer*/ addRecord(&bufferNodes[outputBuffIndex], minIndex.buff->pageRecords[minIndex.pgIndex], pagesize, bufferNodes[outputBuffIndex].recordCount); /*remove the same record from original buffer*/ removeRecord(minIndex.buff, minIndex.pgIndex); /*if output buffer is full, write page to file*/ if(bufferNodes[outputBuffIndex].recordCount == pagesize){ /*write page to file*/ int written; written = fwrite(bufferNodes[outputBuffIndex].pageRecords, sizeof(Record), pagesize, outputFile); if(written !=pagesize){ fprintf(stderr, "Error: Failed to write to output file, wrote %i records\n",written); return FALSE; } /*clear page in output buffer*/ clearPage(&bufferNodes[outputBuffIndex], pagesize); } /*if original buffer is empty, read in another page*/ if(minIndex.buff->recordCount == 0){ int recordPageIndex; /*fill buffer with records from file*/ for(recordPageIndex = 0; recordPageIndex < pagesize; recordPageIndex++){ Record record; if(minIndex.buff->fileNode->fp != NULL){ if(fread(&record, sizeof(Record), 1, minIndex.buff->fileNode->fp) == 1){ /*add record to page (records array)*/ if(addRecord(minIndex.buff, record, pagesize, recordPageIndex) == FALSE) return FALSE; /*add record index to heap*/ if(addToHeap(&rHeap, minIndex.buff, recordPageIndex) == FALSE) return FALSE; } /*else reached file end*/ else{ /*temp file will be automatically deleted by the system*/ fclose(minIndex.buff->fileNode->fp); minIndex.buff->fileNode->fp = NULL; /*removeFile(currentFiles, minIndex.buff->fileNode);*/ break; } } } } /*if buffer is still empty, then 0 records were read in, therefore file is empty and the buffer is now free*/ if(minIndex.buff->recordCount == 0) /*decrement buffers in use counter*/ buffersInUse--; } /*All files for run have been fully read*/ /*Write out records still in output buffer*/ if(bufferNodes[outputBuffIndex].recordCount > 0){ /*Output buffer page was not full*/ int i = 0; for(i = 0; i < pagesize; i++){ if(bufferNodes[outputBuffIndex].pageRecords[i].GuildID != 0){ fwrite(&bufferNodes[outputBuffIndex].pageRecords[i], sizeof(Record), 1, outputFile); removeRecord(&bufferNodes[outputBuffIndex], i); } } } /*Rewind outfile for future merge*/ rewind(outputFile); runCount++; } /*set runFileListas new current file list*/ freeFileNode(¤tFiles); currentFiles = runFileList; *passes = *passes+1; *runs = *runs + runCount; printf("Pass %i resulted in %i runs\n",*passes,runCount); } /*FileList will contain link to only 1 temporary binary file*/ if(currentFiles.fileCount != 1){ fprintf(stderr, "Error: Number of files:%i is invalid\n",currentFiles.fileCount); return FALSE; } *sorted = currentFiles.fileHeadNode->fp; /*free allocated memory*/ for(bufferIndex = 0; bufferIndex < availableBuffers; bufferIndex++){ freeBuffer(&bufferNodes[bufferIndex]); } free(bufferNodes); freeHeap(&rHeap); freeFileNode(¤tFiles); /*free(currentFiles);*/ return TRUE; }
UINT_PTR CALLBACK AddSrcDlgProc95( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { WORD cmd; int item; LRESULT rc; HWND ctl; HWND dlg; GetFilesInfo *info; lparam = lparam; switch( msg ) { case WM_INITDIALOG: { OPENFILENAME *of; of = (OPENFILENAME *)lparam; ctl = GetDlgItem( hwnd, FOD_REMOVE ); EnableWindow( ctl, FALSE ); dlg = GetParent( hwnd ); SendMessage( dlg, CDM_SETCONTROLTEXT, IDOK, (LPARAM)"&Add" ); SET_DLGDATA( hwnd, of->lCustData ); info = (GetFilesInfo *)of->lCustData; info->filter_index = of->nFilterIndex; info->filter = of->lpstrFilter; initFileList( hwnd ); } break; case WM_COMMAND: cmd = LOWORD( wparam ); switch( cmd ) { case FOD_ADD: addCurrentFile95( hwnd ); return( TRUE ); case FOD_ADDALL: addAllFiles95( hwnd ); break; case FOD_REMOVE: ctl = GetDlgItem( hwnd, FOD_FILELIST ); item = (int)SendMessage( ctl, LB_GETCURSEL, 0, 0 ); if( item != LB_ERR ) { rc = SendMessage( ctl, LB_DELETESTRING, item, 0 ); if( item != 0 ) { SendMessage( ctl, LB_SETCURSEL, item - 1, 0 ); } else { SendMessage( ctl, LB_SETCURSEL, item, 0 ); } } checkRemoveButton( hwnd ); break; case FOD_FILELIST: if( GET_WM_COMMAND_CMD( wparam, lparam ) == LBN_SELCHANGE || GET_WM_COMMAND_CMD( wparam, lparam ) == LBN_SELCANCEL ) { checkRemoveButton( hwnd ); } break; case FOD_CLOSE: GetResults( hwnd ); info = (GetFilesInfo *)GET_DLGDATA( hwnd ); info->ret_code = IDOK; PostMessage( GetParent( hwnd ), WM_COMMAND, IDCANCEL, 0L ); return( TRUE ); case IDCANCEL: info = (GetFilesInfo *)GET_DLGDATA( hwnd ); info->ret_code = IDCANCEL; PostMessage( GetParent( hwnd ), WM_COMMAND, IDCANCEL, 0L ); return( TRUE ); default: return( FALSE ); } break; case WM_NOTIFY: switch( ((NMHDR *)lparam)->code ) { case CDN_FILEOK: PostMessage( hwnd, WM_COMMAND, FOD_ADD, 0L ); SET_DLGRESULT( hwnd, 1L ); return( TRUE ); case CDN_TYPECHANGE: info = (GetFilesInfo *)GET_DLGDATA( hwnd ); info->filter_index = ((OFNOTIFY *)lparam)->lpOFN->nFilterIndex; break; } break; default: return( FALSE ); } return( TRUE ); }
UINT_PTR CALLBACK AddSrcDlgProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { WORD cmd; int item; LRESULT rc; HWND ctl; lparam = lparam; switch( msg ) { case WM_INITDIALOG: { OPENFILENAME *of; ctl = GetDlgItem( hwnd, FOD_REMOVE ); EnableWindow( ctl, FALSE ); ctl = GetDlgItem( hwnd, IDOK ); EnableWindow( ctl, FALSE ); of = (OPENFILENAME *)lparam; SET_DLGDATA( hwnd, of->lCustData ); initFileList( hwnd ); } break; case WM_COMMAND: cmd = LOWORD( wparam ); switch( cmd ) { case FOD_FILES: if( GET_WM_COMMAND_CMD( wparam, lparam ) == LBN_DBLCLK ) { addCurrentFile( hwnd ); return( TRUE ); } else { return( FALSE ); } case IDOK: return( FALSE ); case FOD_ADD: addCurrentFile( hwnd ); PostMessage( hwnd, WM_COMMAND, IDOK, 0 ); return( TRUE ); case FOD_ADDALL: addAllFiles( hwnd ); break; case FOD_REMOVE: ctl = GetDlgItem( hwnd, FOD_FILELIST ); item = (int)SendMessage( ctl, LB_GETCURSEL, 0, 0 ); if( item != LB_ERR ) { rc = SendMessage( ctl, LB_DELETESTRING, item, 0 ); if( item != 0 ) { SendMessage( ctl, LB_SETCURSEL, item - 1, 0 ); } else { SendMessage( ctl, LB_SETCURSEL, item, 0 ); } } checkRemoveButton( hwnd ); break; case FOD_FILELIST: if( GET_WM_COMMAND_CMD( wparam, lparam ) == LBN_SELCHANGE || GET_WM_COMMAND_CMD( wparam, lparam ) == LBN_SELCANCEL ) { checkRemoveButton( hwnd ); } break; case FOD_CLOSE: GetResults( hwnd ); doClose( hwnd ); PostMessage( hwnd, WM_COMMAND, IDOK, 0 ); return( TRUE ); default: return( FALSE ); } break; default: return( FALSE ); } return( TRUE ); }