Exemplo n.º 1
0
SortedFile::SortedFile(const string & fileName, 
		       int offset, int len, Datatype type,
		       int maxItems, Status& status)
      : fileName(fileName), type(type), offset(offset), 
	length(len), maxItems(maxItems)
{
  // Check incoming parameters.

  status = OK;

  if (offset < 0 || len < 1)
    status = BADSORTPARM;
  else if (type != STRING && type != INTEGER && type != DOUBLE)
    status = BADSORTPARM;
  else if (type == INTEGER && len != sizeof(int)
	   || type == DOUBLE && len != sizeof(double))
    status = BADSORTPARM;

  if (status != OK)
    return;

  // Must have space for at least 2 items (records) because otherwise
  // items cannot be swapped and sorted!

  if (maxItems < 2 || !(buffer = new SORTREC [maxItems])) {
    status = INSUFMEM;
    return;
  }
    
  status = sortFile();
}
Exemplo n.º 2
0
void sortMp3Files(char* path){
    DIR *folder;
    struct dirent *file;

    if((folder = opendir(path)) != NULL){
        while((file = readdir(folder)) != NULL){
            if(strstr(file->d_name, ".mp3\0")){
                sortFile(path, file->d_name);
            }
        }
    }else{
        perror("Could not open folder");
	exit(1);
    }
}
Exemplo n.º 3
0
void FilesGrouper::addFilesToSort(istream &ifs, bool l_entered) {
	if (l_entered)
		cout << "Enter all files to be merged into one file, when finished, enter 'q':\n"; 

	string filename; 
	ofstream ofs(new_file); 
	ofstream ofsEnteredFiles(listed_files); 
	while (getline(ifs, filename)) {
		if (l_entered && filename == "q")
			break; 

		if (filename != "") {
			ofs << filename << "\n"; 

			ofsEnteredFiles << (filename + "_copy") << "\n"; 
		}
	}
	ofs.close(); 
	ofsEnteredFiles.close(); 

	// Iterate through the file and parse
	ifstream ifs2(new_file); 
	ofs.open(current_file);		// purpose is not to overwrite main file containing list of files to merge
	while (getline(ifs2, filename)) {
		if (sortFile(filename)) {
			ofs << filename; 	

			if (duplicate_original_file) 
				ofs << "_copy"; 
			ofs << "\n"; 
		}
	}

	// Update all the subfiles generated presorted files thus no need to sort file 
	for (int i = 0; i < subfile_count; ++i) {
		ofs << ("sub_file_" + to_string(i)) << "\n"; 	
	}

	ofs.close(); 
}
Exemplo n.º 4
0
void MainWindow::createActions()    /*菜单选项*/
{
    /*文件菜单*/
    openAction = new QAction(tr("打开"),this);
    openAction->setStatusTip(tr("打开新文件"));
    connect(openAction,SIGNAL(triggered()),this,SLOT(openFile()));

    importAction = new QAction(tr("导入"),this);
    importAction->setStatusTip(tr("导入数据"));
    connect(importAction,SIGNAL(triggered()),this,SLOT(importFile()));
    importAction->setDisabled(true);

    sortAction = new QAction(tr("分类数据"),this);
    sortAction->setStatusTip(tr("处理分类数据"));
    connect(sortAction,SIGNAL(triggered()),this,SLOT(sortFile()));
    sortAction->setDisabled(true);

    exitAction = new QAction(tr("退出"),this);
    exitAction->setStatusTip(tr("退出程序"));
    connect(exitAction,SIGNAL(triggered()),this,SLOT(close()));

    /*导入菜单*/
    ebdicAction = new QAction(tr("显示EBDIC码"),this);
    ebdicAction->setStatusTip(tr("显示EBDIC码"));
    connect(ebdicAction,SIGNAL(triggered()),this,SLOT(loadEBDIC()));
    ebdicAction->setDisabled(true);

    reelAction = new QAction(tr("显示卷头"),this);
    reelAction->setStatusTip(tr("显示卷头信息"));
    connect(reelAction,SIGNAL(triggered()),this,SLOT(loadReel()));
    reelAction->setDisabled(true);

    traceAction = new QAction(tr("显示道头"),this);
    traceAction->setStatusTip(tr("显示选定位置道头信息"));
    connect(traceAction,SIGNAL(triggered()),this,SLOT(loadTrace()));
    traceAction->setDisabled(true);

    dataAction = new QAction(tr("地震数据"),this);
    dataAction->setStatusTip(tr("显示选定位置的地震记录"));
    connect(dataAction,SIGNAL(triggered()),this,SLOT(loadData()));
    dataAction->setDisabled(true);

    /*画图菜单*/
    waveAction = new QAction(tr("波形显示"),this);
    waveAction->setStatusTip(tr("波形显示剖面"));
    connect(waveAction,SIGNAL(triggered()),this,SLOT(drawWave()));
    waveAction->setDisabled(true);


    grayAction = new QAction(tr("灰度显示"),this);
    grayAction->setStatusTip(tr("显示灰度图像"));
    connect(grayAction,SIGNAL(triggered()),this,SLOT(drawGray()));
    grayAction->setDisabled(true);

    colorAction = new QAction(tr("彩色显示"),this);
    colorAction->setStatusTip(tr("显示彩色图像"));
    connect(colorAction,SIGNAL(triggered()),this,SLOT(drawColor()));
    colorAction->setDisabled(true);

    //操作openGL图像
    bigAction = new QAction(tr("放大"),this);
    bigAction->setStatusTip(tr("放大图像"));
    connect(bigAction,SIGNAL(triggered()),this,SLOT(bigger()));
    bigAction->setDisabled(true);

    littleAction = new QAction(tr("缩小"),this);
    littleAction->setStatusTip(tr("缩小图像"));
    connect(littleAction,SIGNAL(triggered()),this,SLOT(little()));
    littleAction->setDisabled(true);

    moveleftAction = new QAction(tr("左移"),this);
    moveleftAction->setStatusTip(tr("左移图像"));
    connect(moveleftAction,SIGNAL(triggered()),this,SLOT(moveleft()));
    moveleftAction->setDisabled(true);

    moverightAction = new QAction(tr("右移"),this);
    moverightAction->setStatusTip(tr("图像右移"));
    connect(moverightAction,SIGNAL(triggered()),this,SLOT(moveright()));
    moverightAction->setDisabled(true);

    moveupAction = new QAction(tr("上移"),this);
    moveupAction->setStatusTip(tr("上移图像"));
    connect(moveupAction,SIGNAL(triggered()),this,SLOT(moveup()));
    moveupAction->setDisabled(true);

    movedownAction = new QAction(tr("下移"),this);
    movedownAction->setStatusTip(tr("下移图像"));
    connect(movedownAction,SIGNAL(triggered()),this,SLOT(movedown()));
    movedownAction->setDisabled(true);

    moveMouseAction = new QAction(tr("移动"),this);
    moveMouseAction->setStatusTip(tr("使用鼠标移动图像"));
    connect(moveMouseAction,SIGNAL(triggered()),this,SLOT(moveMouse()));
    moveMouseAction->setDisabled(true);

    rotateMouseAction = new QAction(tr("旋转"),this);
    rotateMouseAction->setStatusTip(tr("旋转图像"));
    connect(rotateMouseAction,SIGNAL(triggered()),this,SLOT(rotateMouse()));
    rotateMouseAction->setDisabled(true);

    nextSliceAction = new QAction(tr("下一条剖面"),this);
    nextSliceAction->setStatusTip(tr("选择下一条剖面"));
    connect(nextSliceAction,SIGNAL(triggered()),this,SLOT(nextSlice()));
    nextSliceAction->setDisabled(true);

    preSliceAction = new QAction(tr("上一条剖面"),this);
    preSliceAction->setStatusTip(tr("选择上一条剖面"));
    connect(preSliceAction,SIGNAL(triggered()),this,SLOT(preSlice()));
    preSliceAction->setDisabled(true);

    drawGridAction = new QAction(tr("关闭网格"),this);
    drawGridAction->setStatusTip(tr("打开/关闭剖面图像上的网格"));
    connect(drawGridAction,SIGNAL(triggered()),this,SLOT(drawGrid()));
    drawGridAction->setDisabled(true);
}
Exemplo n.º 5
0
/*Function used to build process tree*/
void  spawn()
{
	pid_t  pid;
	int    status;
	int j;

	pid = fork();

	/*Error*/
	if (pid < 0) {		
	        printf("*** ERROR: forking child process failed\n");
		myLog = fopen("log.txt", "a+");
		fprintf(myLog, "*** ERROR: forking child process failed\n");
		fclose(myLog);
	        exit(1);
	}

	/* Parent*/
	else if(pid>0) {                                  
		printf("Parent: my pid = %d, parent pid = %d \n", getpid(), getppid());
		myLog = fopen("log.txt", "a+");
		fprintf(myLog, "Parent: my pid = %d, parent pid = %d \n", getpid(), getppid());
		fclose(myLog);
				

		/*Left Side*/
		if( (pid=fork()) ==0){
			printf("	Child: my pid = %d, parent pid = %d \n", getpid(), getppid());
			myLog = fopen("log.txt", "a+");
			fprintf(myLog, "	Child: my pid = %d, parent pid = %d \n", getpid(), getppid());
			fclose(myLog);		

			/*Grandchild process*/
			for(j=0; j<2; j++){	
				if( (pid=fork()) ==0){
					printf("		Grandchild: my pid = %d, parent pid = %d \n", getpid(), getppid());
					myLog = fopen("log.txt", "a+");
					fprintf(myLog, "		Grandchild: my pid = %d, parent pid = %d \n", getpid(), getppid());
					fclose(myLog);

					/*Pipes for Left Grandchildren*/					
					/*First Left Grandkid*/					
					if(j==0){					
						dup2(pipeLeft[WRITE], pipeUp[WRITE]);					
					}
					/*Second Left Grandkid*/
					else{
						dup2(pipeRight[WRITE], pipeUp[WRITE]);
					}

					close(pipeUp[READ]);
					close(pipeLeft[READ]);
					close(pipeLeft[WRITE]);
					close(pipeRight[READ]);
					close(pipeRight[WRITE]);

					sortFile(getpid(), files[j+1]);				
					
				}//end of if
		
			}//end of for - Grandchildren	

		/*Children Wait for Left GrandChildren*/
		
		/*Pipes for left child*/
		dup2(pipeLeft[WRITE], pipeUp[WRITE]);		
		dup2(pipeLeft[READ], pipeUp[READ]);
		dup2(pipeRight[READ], pipeUp[READ]);

		close(pipeUp[READ]);
		close(pipeLeft[WRITE]);
		close(pipeRight[WRITE]);
		waitpid(0,&status,0);
		waitpid(0,&status,0);
		
		read_pipe(pipeLeft[READ], getpid());
		read_pipe(pipeRight[READ], getpid());
		}//end of Left Child
		
		/*Parent Waits for Children*/

		/*Pipes for Parent*/
		//dup2(pipeLeft[READ], pipeUp[READ]);	//connect left pipe to up read
		//dup2(pipeRight[READ], pipeUp[READ]); 	//connect right pipe to up read

		close(pipeUp[WRITE]);
		close(pipeUp[READ]);
		close(pipeLeft[WRITE]);
		close(pipeRight[WRITE]);
		waitpid(0,&status,0);
		waitpid(0,&status,0);
		
		read_pipe(pipeLeft[READ], getpid());
		read_pipe(pipeRight[READ], getpid());	

	}//end of Parent

	/*Right Side*/
	else if (pid == 0) {          /* for the child process:         */
		printf("	Child: my pid = %d, parent pid = %d \n", getpid(), getppid());
		myLog = fopen("log.txt", "a+");
		fprintf(myLog, "	Child: my pid = %d, parent pid = %d \n", getpid(), getppid());
		fclose(myLog);				

		/*Grandchild process*/
		for(j=0; j<2; j++){	
			if( (pid=fork()) ==0){
				printf("		Grandchild: my pid = %d, parent pid = %d \n", getpid(), getppid());
				myLog = fopen("log.txt", "a+");
				fprintf(myLog, "		Grandchild: my pid = %d, parent pid = %d \n", getpid(), getppid());
				fclose(myLog);

				/*Pipes for Right Grandchildren*/
				//dup2(pipeUp[WRITE], 1);	//redirect standard output to pipeUp[WRITE]
				
				/*First Right Grandkid*/					
				if(j==0){					
					dup2(pipeLeft[WRITE], pipeUp[WRITE]);					
				}
				/*Second Right Grandkid*/
				else{
					dup2(pipeRight[WRITE], pipeUp[WRITE]);
				}

				close(pipeUp[READ]);
				close(pipeLeft[READ]);
				close(pipeLeft[WRITE]);
				close(pipeRight[READ]);
				close(pipeRight[WRITE]);

				sortFile(getpid(), files[j+3]);

			}//end of if	
	
		}//end of for Grandchildren

		/*Children Wait for Right GrandChildren*/
		
		/*Pipes for Right Child*/
		dup2(pipeRight[WRITE], pipeUp[WRITE]);
		dup2(pipeLeft[READ], pipeUp[READ]);
		dup2(pipeRight[READ], pipeUp[READ]);

		close(pipeUp[READ]);
		close(pipeLeft[WRITE]);
		close(pipeRight[WRITE]);

		waitpid(0,&status,0);
		waitpid(0,&status,0);

		read_pipe(pipeLeft[READ], getpid());
		read_pipe(pipeRight[READ], getpid());
		
	}//end of Right Child

}//end of spawn