Example #1
0
//SLOT podejmujący akcję na zmianę w pliku, jeśli nastąpiłą zmiana pliku ale plik nie jest pusty to odpala metode  Read_clear_file
void MainWindow::fileChangedSlot(QString Filename)
{
//#ifdef QT_DEBUG
//qDebug() << "files watched: " << fw->files() << fw->directories();
//#endif
//QMessageBox::information(this,"test","Zmiana pliku2: "+Filename);
    QFile mFile(Filename);
    mFile.open( QIODevice::WriteOnly|QIODevice::Append);
        if (mFile.pos() != 0) {
            //Read_clear_file(Filename); // some data inside
            //QMessageBox::information(this,"test","Zmiana pliku2: "+Filename);
            ui->lineEdit_2->setText(Read_file(Wygrany));
            ui->pushButton->hide();
            ui->pushButton_3->show();
        }
}
Example #2
0
int Emit_log(Chk_log_type *log, int handle)
{
  int   size = 0;
  int   index = 0;
  int   return_status = REG_SUCCESS;

  if(log->log_type == PARAM){
    index = Param_index_from_handle(&Params_table, handle);
    if(index == REG_PARAM_HANDLE_NOTSET)return REG_FAILURE;
  }

  if(log->emit_in_progress == REG_TRUE){

    if(Emit_log_entries(log, log->file_content, handle) == REG_UNFINISHED){
      return return_status;
    }
    log->emit_in_progress = REG_FALSE;

    free(log->file_content);
    log->file_content = NULL;

    /* Now send the entries that we have stored in memory -
       need to send all current log entries to the steerer */
    if(Log_to_xml(log, handle, &(log->file_content), &size,
		  REG_FALSE) != REG_SUCCESS){

      return REG_FAILURE;
    }
  }
  else if((log->log_type == CHKPT && log->send_all == REG_TRUE)||
	  (log->log_type == PARAM && log->param_send_all[index] == REG_TRUE)){

#ifdef REG_DEBUG_FULL
    fprintf(stderr, "STEER: Emit_log: sending all saved log entries...\n");
#endif
    /* Then we have to send any entries we've saved to file too... */
    Close_log_file(log);

    /* Read the log file and get back contents in buffer pointed
       to by pbuf.  We must free() this once we're done. */
    if(log->log_type == CHKPT){
      return_status = Read_file(log->filename, &(log->file_content),
				&size, REG_FALSE);
    }
    else if(log->log_type == PARAM){
      return_status = Read_file(log->filename, &(log->file_content),
				&size, REG_TRUE);
    }

    if(return_status != REG_SUCCESS){
      if(!log->file_content)free(log->file_content);
      log->file_content = NULL;
      return REG_FAILURE;
    }

    if (size > 0) Emit_log_entries(log, log->file_content, handle);

    /* Re-open log-file for future buffering */
    if( Open_log_file(log) != REG_SUCCESS){

#ifdef REG_DEBUG
      fprintf(stderr, "STEER: Emit_log: Open_log_file failed\n");
#endif
    }

    if(log->emit_in_progress == REG_TRUE){
      /* Don't set log->send_all if going to continue to Log_to_xml
	 as will affect what log entries are returned */
      log->send_all = REG_FALSE;
      return REG_SUCCESS;
    }

    free(log->file_content);
    log->file_content = NULL;

    /* End of sending buffered entries */

    /* Now send the entries that we have stored in memory -
       need to send all current log entries to the steerer */
    if(Log_to_xml(log, handle, &(log->file_content), &size,
		  REG_FALSE) != REG_SUCCESS){

      return REG_FAILURE;
    }

    if(log->log_type == PARAM){
      log->param_send_all[index] = REG_FALSE;
    }
    else{
      log->send_all = REG_FALSE;
    }
  }
  else{

#ifdef REG_DEBUG_FULL
    fprintf(stderr, "STEER: Emit_log: sending unsent log entries...\n");
#endif
    /* Fifth argument specifies that we only want those entries that haven't
       already been sent to the steerer */
    if(Log_to_xml(log, handle, &(log->file_content),
		  &size, REG_TRUE) != REG_SUCCESS){
      return REG_FAILURE;
    }
  }

#ifdef REG_DEBUG_FULL
  fprintf(stderr, "STEER: Emit_log: calling Emit_log_entries...\n");
#endif

  /* Pull the entries out of the buffer returned by Log_to_xml and
     send them to the steerer */
  if(size > 0){
    if( (return_status = Emit_log_entries(log, log->file_content,
					  handle)) == REG_UNFINISHED){
      return REG_SUCCESS;
    }
  }
  free(log->file_content);
  log->file_content = NULL;

#ifdef REG_DEBUG_FULL
  fprintf(stderr, "STEER: Emit_log: sending logged steering commands...\n");
#endif

  /* Send log of steering commands */
  if(strlen(log->pSteer_cmds) > 0){

    Emit_log_entries(log, log->pSteer_cmds, handle);
    log->pSteer_cmds[0]='\0';
    log->pSteer_cmds_slot = log->pSteer_cmds;
  }

  if(return_status == REG_SUCCESS){

    /* Zero counter since we've just told steerer all about any log
       entries it hadn't got */
    log->num_unsent = 0;
  }

  return return_status;
}
Example #3
0
int Set_log_primary_key(Chk_log_type *log)
{
  int   size;
  int   return_status = REG_SUCCESS;
  char *pbuf = NULL;
  char *ptr = NULL;
  char *old_ptr = NULL;

  Close_log_file(log);

  /* Read the log file and get back contents in buffer pointed
     to by pbuf.  We must free() this once we're done. */

  if(Read_file(log->filename, &pbuf, &size, REG_TRUE) != REG_SUCCESS){

    log->primary_key_value = 0;
    if(pbuf)free(pbuf);
    return REG_SUCCESS;
  }

  if(size == 0){

    /* Log file existed but was empty */
    log->primary_key_value = 0;
    if(pbuf)free(pbuf);
    return REG_SUCCESS;
  }

  ptr = pbuf;

  /* Check whether we've got xml or columns... */
  if(!strstr(pbuf, "<Key>")){
    /* We have columns of data, first column holds key values... */

    while( (ptr = strstr((ptr+1), "\n")) ){

      if(*(ptr+1) == '\0')break;
      old_ptr = ptr;
    }

#ifdef REG_DEBUG
    fprintf(stderr, "STEER: Set_log_primary_key: last chunk = >>%s<<\n", old_ptr);
#endif

    if(2 != sscanf(old_ptr, "%d %s", &(log->primary_key_value),
		   Steer_lib_config.scratch_buffer)){
      log->primary_key_value = 0;
      return_status = REG_FAILURE;
    }
    else{
      log->primary_key_value++;
    }
  }
  else{
    /* We have xml...*/

    while( (ptr = strstr((ptr+1), "<Key>")) ){
      old_ptr = ptr;
    }

#ifdef REG_DEBUG
    fprintf(stderr, "STEER: Set_log_primary_key: last chunk = >>%s<<\n", old_ptr);
#endif

    if( 1 != sscanf(old_ptr, "<Key>%d</Key>", &(log->primary_key_value))){

      log->primary_key_value = 0;
      return_status = REG_FAILURE;
    }
    else{
      log->primary_key_value++;
    }
  }

  free(pbuf);
  Open_log_file(log);

  return return_status;
}
Example #4
0
int main(int argc, char**argv){
	
	char * ficheiroIn;
	char * connectivity = malloc(100*sizeof(char));
	node * list;
	int option;
	int initial_node, final_node;

	if(argc<2){
		printf("TOO FEW ARGUMENTS\n");
		exit(-1);
	}
	
	printf("PLEASE CHOOSE AN OPTION \n");
	printf("1. CALCULATE THE NODES SEPARATING NODE A FROM B\n");
	printf("2. CALCULATE STATISTICS AND CONNECTIVITY OF THE GRAPH\n");
	
	if(scanf("%d", &option)!=1){
		printf("ERROR: SPECIFY A VALID SOURCE AND DESTINATION\n");
		exit(0);
	}	

		ficheiroIn = argv[1];
		
		int size = Read_file(ficheiroIn, &list);
		
		/*********************VECTOR DE ESTATISTICAS***************************/
		
		int * node_statistics = malloc(size*sizeof(int));
		
		init_vector(&node_statistics, size, 0);
		
		int * parent = malloc(size*sizeof(int));

		/**********************************************************************/
		int min = 100;	
		
		if(option == 1){
			printf("PLEASE CHOOSE A SOURCE AND DESTINATION.\n");

			if(scanf("%d %d", &initial_node, &final_node)!=2){
				printf("ERROR: SPECIFY A VALID SOURCE AND DESTINATION\n");
				exit(0);
			}
			if(contiguous(list, initial_node, final_node)!=0) printf("THERE IS NO WAY OF SEPARATING NODE %d FROM NODE %d BECAUSE THEY ARE CONTIGUOUS\n", initial_node, final_node);
			else printf("FOR SPECIFIED SET OF NODES, IS NECESSARY TO TAKE %d NODE(S) WHICH IS/ARE:%s\n", ford_fulkerson(&list, size, &parent, initial_node, final_node, &connectivity, min), connectivity);
			
		}else{
		

		int colum;
		int row;
		
		
		for(colum=0; colum<size; colum++){
			for(row=0; row<size; row++){
				if(row!=colum){
					if(contiguous(list, colum, row)!=0){
						(node_statistics[0]) ++;
					}else{
						(node_statistics[ford_fulkerson(&list, size, &parent, colum, row, &connectivity, min)]) ++;
						Read_file(ficheiroIn, &list);
					}
				}
			}
		}
		
		cumulative_statistics(node_statistics, size);
		printf("IF YOU TAKE THE NODE(S)%s THE GRAPH WILL SPLIT\n", connectivity);
	}
	
	exit(0);
}