Ejemplo n.º 1
0
int main(int argc, char** argv)
{
  if(testFichier(argv[1], argv[2], argc) == 0)
    return 0;
	
  int i = 0; 
  int compteur = 0;
  float tailleCodage = 0.0;
  int iNoeudRacine = 256;
	
  calculFreq(argv[1]);
  construcArbre(&iNoeudRacine);
  parcours(&iNoeudRacine, "");
  unsigned long int *tabTaille;
  tabTaille = compression(argv[1], argv[2]);
	
  printf("Fréquences des caractères présents dans le fichier :\n");
  for(i=0;i<256;i++) {
    if(frequences[i]!=0)
      printf("\t(%d)\t%.2f <=> %.2f%%\n", i, frequences[i],frequences[i]*100);
  }
	
  printf("\nValeurs de l'arbre :\n\n\tNoeud\tPere\tFils G\tFils D\n");
  for(i=0;i<511;i++) {
    if(Arbre[i].fr != 0) {
      printf("\t(%d)\t%d\t%d\t%d\n", i, Arbre[i].pere, Arbre[i].fg, Arbre[i].fd);
    }
  }
  printf("\nCodes Huffman\n");
  for(i=0;i<256;i++) {
    if(tableCodes[i] != NULL){
      if(i>=0 && i<10)
	printf("\t(00%d) : %s\n", i, tableCodes[i]);
      if(i>=10 && i<100)
	printf("\t(0%d) : %s\n", i, tableCodes[i]);
      if(i>=100)
	printf("\t(%d) : %s\n", i, tableCodes[i]);
      ++compteur;
      tailleCodage += (float)strlen(tableCodes[i]);
    }
  }
  tailleCodage /= (float)compteur;
  printf("\nLong. moy. du codage : %.4f\n\n", tailleCodage);
	
  float gain;
  gain = ((float)tabTaille[1])/((float)(tabTaille[0]));
  gain = 1.0 - gain;
	
  printf("Données:\n\tTaille originelle : \t%ld\n\tTaille compressée : \t%ld\n\tGain : \t\t\t%.3f\n\tGain en %% : \t\t%.3f%%\n", tabTaille[0], tabTaille[1], gain, gain*100.0);
  for(i=0;i<256;i++){
    free(tableCodes[i]);
  }
  free(tabTaille); //tabTaille est le tableau retourné par unsigned long int compression()
	
  return 0;
}
Ejemplo n.º 2
0
int main(void)
{
  SDL_Surface *img = load_image("visage");
  display_image(img);
  unsigned long **array = img_to_tab(img);
  parcours(array, img->w, img->h);
  img = tab_to_img(array, img->w, img->h);
  display_image(img);
  return 0;
}
Ejemplo n.º 3
0
void EditorWindows::parcours(Note* n) {
    if(typeid(*n).name() != typeid(Document).name())
        return n->load();
    else {
        Document::Iterator it2=dynamic_cast<Document*>(n)->begin();
        while (it2!=dynamic_cast<Document*>(n)->end()) {
            parcours(*it2);
            it2++;
        }
    }
}
Ejemplo n.º 4
0
Archivo: ls.c Proyecto: cmgnn/42
int		parcours(t_file *f)
{
	int i = 0;
	while (f)
	{
		i++;
		printf("%s\n", f->name);
		if (f->dir)
			printf("\t");
		parcours(f->dir);
		f = f->next;
	};
	return (i);
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
    if (argc != NB_ARG)
    {
        printf("Nombre d'arguments incorrect ... Exit.\n");
        return -1;
    }

	struct tm tm;
	if (strptime(argv[2],"%Y-%m-%d %H:%M:%S", &tm) != NULL)
	    parcours(argv[1], strlen(argv[1]), 0, mktime(&tm));
	else
	    printf("Impossible de récupérer une date valide avec les valeurs entrées. Exit.\n");
      

    return 0;
}	 
Ejemplo n.º 6
0
/**
 * Réalise le parcours récursif dans l'arborescence
 * @param path : le chemin
 * @param pathLength : la longueur du chemin 
 * @param indent : le nombre d'indentations
 * @param timeToCompare : la date entrée par l'utilisateur
 */
void parcours(const char* path, int pathLength, int indent,
time_t timeToCompare)
{
  DIR* folder = opendir(path);

  if(folder != NULL)
  {
   	struct dirent* dir;

	//tant qu'on a pas atteint la fin du répertoires
    while((dir = readdir(folder)) != NULL)
    {
		if((strcmp(dir->d_name,".")!=0) && (strcmp(dir->d_name,"..") !=0))
		{
			//on construit le nouveau chemin
			char* filename;
			filename = dir->d_name;
			int PathSize = pathLength + dir->d_reclen + 1;
			char* NewPath = (char*) malloc(PathSize);
			strncpy(NewPath, path, pathLength);
			strncat(NewPath,"/", 1);
			strncat(NewPath, filename, dir->d_reclen);
				
			//on regarde si la date est valide
			if (estFichierValide(NewPath, timeToCompare) >= 0)
			{
				int i = 0;
				for(i; i < indent; i++)
					printf(" ");
				
				printf(" -%s\n", filename);
			}
			if (dir->d_type == DT_DIR) //si c'est un dossier
			{
				 printf("|-Dossier : %s\n", filename);    
				 parcours(NewPath, PathSize, indent + 1,
				 timeToCompare);
			}
		}
    }
		closedir(folder);
  }
}
Ejemplo n.º 7
0
void EditorWindows::loadNote() {
    if(typeid(*Fenetre::getInstance().getNote()).name() == typeid(Article).name()) {
        contentArticle->show();
        contentImage->hide();
        contentVideo->hide();
        contentAudio->hide();
        contentDocument->hide();
        //**
        Fenetre::getInstance().getNote()->load();
        titre->setText(Fenetre::getInstance().getNote()->getTitle());
        description1->setText(dynamic_cast<Article*>(Fenetre::getInstance().getNote())->getText());
    }
    else if(typeid(*Fenetre::getInstance().getNote()).name() == typeid(Image).name()) {
        contentArticle->hide();
        contentImage->show();
        contentVideo->hide();
        contentAudio->hide();
        contentDocument->hide();
        //**
        Fenetre::getInstance().getNote()->load();
        titre->setText(Fenetre::getInstance().getNote()->getTitle());
        path1->setText(dynamic_cast<Image*>(Fenetre::getInstance().getNote())->getPath());
        description2->setText(dynamic_cast<Image*>(Fenetre::getInstance().getNote())->getDescription());
        //Pour Image
        QPixmap affImage(dynamic_cast<Image*>(Fenetre::getInstance().getNote())->getPath());
        labImage->setPixmap(affImage);
    }
    else if(typeid(*Fenetre::getInstance().getNote()).name() == typeid(Video).name()) {
        contentArticle->hide();
        contentImage->hide();
        contentVideo->show();
        contentAudio->hide();
        contentDocument->hide();
        //**
        Fenetre::getInstance().getNote()->load();
        titre->setText(Fenetre::getInstance().getNote()->getTitle());
        path2->setText(dynamic_cast<Video*>(Fenetre::getInstance().getNote())->getPath());
        description3->setText(dynamic_cast<Video*>(Fenetre::getInstance().getNote())->getDescription());
    }
    else if(typeid(*Fenetre::getInstance().getNote()).name() == typeid(Audio).name()) {
        contentArticle->hide();
        contentImage->hide();
        contentVideo->hide();
        contentAudio->show();
        contentDocument->hide();
        //**
        Fenetre::getInstance().getNote()->load();
        titre->setText(Fenetre::getInstance().getNote()->getTitle());
        path3->setText(dynamic_cast<Audio*>(Fenetre::getInstance().getNote())->getPath());
        description4->setText(dynamic_cast<Audio*>(Fenetre::getInstance().getNote())->getDescription());
    }
    else if(typeid(*Fenetre::getInstance().getNote()).name() == typeid(Document).name()) {
        contentArticle->hide();
        contentImage->hide();
        contentVideo->hide();
        contentAudio->hide();
        contentDocument->show();
        //**
        Fenetre::getInstance().getNote()->load();
        for (NotesManager::Iterator it=NotesManager::getInstance().begin(); it!=NotesManager::getInstance().end(); it++) {
            parcours(*it);
        }
        titre->setText(Fenetre::getInstance().getNote()->getTitle());
    }
}
Ejemplo n.º 8
0
void parcours(int *iNoeud, char* code)
{
  int i = 0;
	
  char* nouveauCode1;
  char* nouveauCode2;
  
	
  nouveauCode1 = (char*)malloc((strlen(code)+2)*sizeof(char));  
  nouveauCode2 = (char*)malloc((strlen(code)+2)*sizeof(char));
 
  if(Arbre[*iNoeud].fd != -1 && Arbre[*iNoeud].fg != -1) {
    for(i = 0;i < (int)(strlen(code)+1);i++){
      if(i < (int)(strlen(code)) ) {
	nouveauCode1[i] = code[i];
      }
      else
	nouveauCode1[i] = '1';
    }
    
    
    for(i = 0;i < (int)(strlen(code)+1);i++){
      if(i < (int)(strlen(code)) ) {
	nouveauCode2[i] = code[i];
      }
      else
	nouveauCode2[i] = '0';
    }
    parcours(&Arbre[*iNoeud].fd, nouveauCode1);
    parcours(&Arbre[*iNoeud].fg, nouveauCode2);
    
  }
  else if(Arbre[*iNoeud].fd != -1 && Arbre[*iNoeud].fg == -1) {
    nouveauCode1[0] = '1';
    parcours(&Arbre[*iNoeud].fd, nouveauCode1);
  }
  
  else if(Arbre[*iNoeud].fd == -1 && Arbre[*iNoeud].fg != -1) {

    nouveauCode2[0] = '0';
    parcours(&Arbre[*iNoeud].fg, nouveauCode2);
  }
  else { 
    nouveauCode1 = strcat(code, "\0");
    nouveauCode2 = strcat(code, "\0");
    
    if(Arbre[*iNoeud].fd == -1) {
     
      tableCodes[*iNoeud] = (char*)malloc((strlen(nouveauCode1)+1)*sizeof(char));
      
      for(i = 0;i < (int)(strlen(nouveauCode1));i++)
	tableCodes[*iNoeud][i] = nouveauCode1[i];
      
      free(nouveauCode1);
    }
    else {
      tableCodes[*iNoeud] = (char*)malloc((strlen(nouveauCode2)+1)*sizeof(char));
      
      for(i = 0;i < (int)(strlen(nouveauCode2));i++)
	tableCodes[*iNoeud][i] = nouveauCode2[i];
      
    
      free(nouveauCode2);
    }
  }
}