1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <dirent.h>
/* ***********************************************************
STRUCTURES :
MOT : définie la structure d'un mot de l'index. Constitue une liste chainée de mots
LIGNE : liste des occurences d'un même mot
INDEX : structure de l'index : - un mot
- la liste des lignes où il apparait
- la liste des mots qui le suivent
*/
#define cLk_Tck CLOCKS_PER_SEC
#define BUFFER_SIZE 20
//structure LIGNE
// - une ligne
// - un pointeur sur la structure ligne suivante
typedef struct LIGNE
{
int lg;
struct LIGNE *suiv;
}*ligne;
//structure MOT :
// - un tableau de caractères représentant le mot
// _ une structure ligne
// - un pointeur sur le mot suivant
typedef struct MOT
{
char *mt;
ligne l_lg;
struct MOT * suiv;
int occ;
} *mot;
//structure INDEX
// -il s'agit d'un tableau de pointeurs sur des structures MOT
// - liste simple, un pointeur sur mot
// - hachage : tableau de 26 pointeurs sur un mot
typedef struct INDEX
{
mot *tab;
unsigned int tab_size;
unsigned int count_mot;
}*s_index;
static int index_taille = 0;
/* ***********************************************************************
* *
* Ensemble des fonctions du programme *
* *
***********************************************************************
*/
//fonction d'allocation pour la création de l'index
s_index create_index(unsigned tab_taille);
ligne create_ligne (int n);
void insere_ligne (ligne *o_l, ligne t_l);
mot create_mot (char * txt, int nl);
void insere_mot (mot *o_mt, mot t_mt, s_index *index);
void supp_mot (char *c, s_index *index);
// recherche dans l'index
mot seek_mot(char * mod, mot fich);
mot seek_occ_max(s_index index);
// création de l'index
char sup_accent(char c);
int is_sep (char c);
s_index make_index(int index_size, char *ad);
s_index m_create(char ch);
//libération de l'espace mémoire
void detruire_ligne(ligne l);
void detruire_mot(mot m);
void detruire(s_index index);
// fonction d'affichage
void vide_ecran();
void aff_mot_one(mot m);
void affiche_mot_all(mot m);
void affiche_ligne(ligne l);
void aff_ligne_seek(int nl, s_index index);
void aff_mot_seek(char *c, s_index index);
void aff_nbmot (s_index index);
void affiche_index (s_index index);
void aff_occ_max(s_index index);
//affichage des caractéristiques des fonctions
void aff_tab(float temps[], int taille[]);
void f_temps(float temps[], int taille[], int i, s_index ind, mot dernier, int ml);
void t_calc();
// menus
char t_menu();
char s_menu(char ch);
//fonction annexes
void get_continue();
int count_nb_ligne(mot m);
// *********************************************************************
// * FONCTIONS D'ALLOCATIONS POUR LA CREATION DE L'INDEX *
// *********************************************************************
// fonction de creation de l'index
s_index create_index(unsigned int tab_taille)
{
s_index index;
unsigned int i;
index = (s_index)malloc(sizeof(struct INDEX));
index->tab_size = tab_taille;
index->tab = (mot *)malloc(sizeof(mot)*index->tab_size);
index->count_mot=0;
for (i = 0; i < index->tab_size; i++)
{
index->tab[i] = (mot)malloc(sizeof(struct MOT));
index->tab[i]->suiv = NULL;
index->tab[i]->occ = 0;
}
index_taille = 4;
return index;
}
// crétion d'une structure ligne, utilisée par la fonction insere_mot
ligne create_ligne (int n)
{
ligne L;
L = (ligne)malloc(sizeof(struct LIGNE));
L->lg = n;
L->suiv = NULL;
return L;
}
// insertion d'une ligne dans une struture mot
void insere_ligne (ligne *o_l, ligne t_l)
{
ligne temp, ptr;
ptr = *o_l;
while (ptr->suiv != NULL)
ptr = ptr->suiv;
if (ptr->lg != t_l->lg)
{
index_taille += 2;
temp = ptr->suiv;
ptr->suiv = t_l;
t_l->suiv = temp;
}
else free(t_l);
}
//création d'un mot utilisée par l'index
mot create_mot (char * txt, int nl)
{
mot m_ph;
ligne t_l;
m_ph = (mot)malloc(sizeof(struct MOT));
m_ph->l_lg = (ligne)malloc(sizeof(struct LIGNE));
m_ph->l_lg->suiv= NULL;
m_ph->mt = (char*)malloc(strlen(txt) + 1);
strcpy(m_ph->mt,txt);
t_l = create_ligne(nl);
insere_ligne(&m_ph->l_lg,t_l);
m_ph->suiv = NULL;
m_ph->occ = 1;
return m_ph;
}
// insertion d'un mot dans l'index
void insere_mot (mot *o_mt, mot t_mt, s_index *index)
{
mot temp, ptr;
ptr = *o_mt;
while( ptr->suiv != NULL && strcmp(t_mt->mt,ptr->suiv->mt) >0)
ptr = ptr->suiv;
if (ptr->suiv != NULL && strcmp(t_mt->mt, ptr->suiv->mt) == 0)
{
ptr->suiv->occ++;
insere_ligne(&ptr->suiv->l_lg, t_mt->l_lg->suiv);
free(t_mt);
}
else
{
index_taille += (strlen(t_mt->mt) + 1 + 2);
(*index)->count_mot++;
temp = ptr->suiv;
ptr->suiv = t_mt;
t_mt->suiv = temp;
}
}
//suppression d'un mot de l'index
void supp_mot (char *c, s_index *index)
{
mot temp, ptr;
if ((*index)->tab_size == 26)
ptr = seek_mot(c,(*index)->tab[c[0] - 'a']);
else
ptr = seek_mot(c,(*index)->tab[0]);
if (ptr != NULL)
{
index_taille -= (strlen(c) + 1 + count_nb_ligne(ptr->suiv)*2 + 2);
temp = ptr->suiv->suiv;
detruire_ligne(ptr->suiv->l_lg);
free(ptr->suiv);
ptr->suiv = temp;
(*index)->count_mot -= 1;
}
}
//********************************************************
//* RECHERCHE DANS L'INDEX *
//********************************************************
//recherche d'un mot dans l'index
mot seek_mot(char * mod, mot fich)
{
while(fich->suiv != NULL)
{
if(strcmp(fich->suiv->mt, mod) == 0)
return fich;
else fich = fich->suiv;
}
puts("le mot n'est pas dans l'index");
return NULL;
}
//mot apparaissant le plus souvent
mot seek_occ_max(s_index index)
{
unsigned int i;
mot max;
mot ptr;
max = index->tab[0];
for(i = 0; i < index->tab_size; i++)
{
ptr = index->tab[i];
while(ptr->suiv != NULL)
{
if (ptr->suiv->occ > max->occ)
max = ptr->suiv;
ptr = ptr->suiv;
}
}
return max;
}
// ****************************************************
// * CREATION DE L'INDEX *
// ****************************************************
//
// retourne un caractère sans accents à partir d'un caractère accentué
/*
char sup_accent(char c)
{
char tab[5][5] = { {'à', 'â', 'ä', 0}, {'é', 'è', 'ê', 'ë'}, {'î', 'ï', 0, 0}, {'ô', 'ö', 0, 0}, {'ù', 'û', 'ü', 0} };
char ele[5] = {'a', 'e', 'i', 'o', 'u'};
int i, j;
for (i = 0; i < (sizeof(ele)/sizeof(char)); i++)
{
for (j = 0; j < (sizeof(tab[i])/sizeof(char)); j++)
{
if (c == tab[i][j])
return ele[i];
}
}
return c;
}
*/
// distingue les caractères séparateurs des autres
// - retourne 1 si le char 'c' est un caractère séparateur
// - retourne 0 sinon
int is_sep (char c)
{
int i;
char sep[] = { ',', ':' , ';' , '"', ' ' , '.', '\'', '\0', '\n', '(', ')', '=', '\t', EOF};
for (i = 0; i < (sizeof(sep)/sizeof(char)); i++)
if (c == sep[i]) return 1;
return 0;
}
// création de l'index
s_index make_index(int index_size, char *ad)
{
int i;
int nbl = 1;
mot t_mot;
s_index index;
char buffer[BUFFER_SIZE];
char temp[40], *tpm, c_tpm, c;
FILE *fic;
DIR * rep = opendir(ad);
index_taille = 0;
char fn[256];
//allocation de l'index
index = create_index(index_size);
if (rep != NULL){
struct dirent * ent;
while ((ent = readdir(rep)) != NULL){
//puts("ERREUR : le dossier existe");
printf("%s\n", ent->d_name);
if(strcmp(ent->d_name,".")==0|| strcmp(ent->d_name,"..")==0){
continue;
}
snprintf(fn,sizeof fn,ad,ent->d_name);
if (fic = fopen(fn, "r")){
while ((c = fgetc(fic))!=EOF){
i = 0;
while (!is_sep(c)){
// suppression des accents et transformation en minuscule
c_tpm = tolower(c);
temp[i] = c_tpm;
c = fgetc(fic);
i++;//printf("okkkk\n");
}
temp[i] = '\0';
if (temp[0] != '\0'){
tpm = (char *)malloc(strlen(temp+1));
strcpy(tpm,temp);
}
else tpm = NULL;
if (tpm != NULL){
t_mot = create_mot(tpm, nbl);
if(index->tab_size == 26)
insere_mot(&index->tab[tpm[0]-'a'], t_mot, &index);
else
insere_mot(&index->tab[0], t_mot, &index);
}
if (c == '\n')
nbl++;
}
}close(fic);
}
closedir(rep);
puts("les fichiers ont bien ete indexe");
}
return index;
}
//creation de l'index pour le menu principal
s_index m_create(char ch)
{
s_index index;
char c2[40];
puts("entrez l'adresse du repertoire a indexer : ");
puts(" .l'adresse ne doit pas comporter d'espaces");
scanf(" %s", c2);
if(ch == '2')
{
index = make_index(26, c2);
}
if (ch == '1')
{
index = make_index(1, c2);
}
return index;
}
//***************************************************
//* LIBERATION DE L'ESPACE MEMOIRE *
//***************************************************
//suppression d'une lisste chainée de ligne
void detruire_ligne(ligne l)
{
ligne ptl;
while(l->suiv != NULL)
{
ptl = l;
while(ptl->suiv->suiv != NULL)
ptl = ptl->suiv;
free(ptl->suiv);
ptl->suiv = NULL;
}
}
//suppression d'une liste chainée de mots
void detruire_mot(mot m)
{
mot ptm;
while(m->suiv != NULL)
{
ptm = m;
while(ptm->suiv->suiv != NULL)
ptm = ptm->suiv;
detruire_ligne(ptm->suiv->l_lg);
free(ptm->suiv->l_lg);
free(ptm->suiv);
ptm->suiv = NULL;
}
}
//suppression d'une liste chainée de mots
void detruire(s_index index)
{
unsigned int i;
if (index != NULL)
{
for (i = 0; i < index->tab_size; i++)
{
detruire_mot(index->tab[i]);
free(index->tab[i]);
}
free(index);
index_taille = 0;
}
}
// ***************************************************************
// * ENSEMBLE DES FONCTIONS D'AFFICHAGE *
// ***************************************************************
// affichage des mots appartenant à une ligne nl
// affiche "l'index est vide" si le compteur de mots de 'index est nul
void aff_ligne_seek (int nl, s_index index)
{
mot ptm;
ligne ptl;
unsigned int i, j = 0;
int test;
vide_ecran();
if (!index->count_mot) puts("l'index est vide");
else
{
for (i = 0; i < index->tab_size; i++)
{
ptm = index->tab[i]->suiv;
while(ptm != NULL)
{
ptl = ptm->l_lg->suiv;
test = 0;
while(test != 1)
{
if(ptl->lg == nl)
{
printf("mot : %s\n", ptm->mt);
test = 1;
}
if (ptl->suiv == NULL)
test = 1;
else ptl = ptl->suiv;
}
ptm = ptm->suiv;
}
}
}
}
//affichage d'un mot cherché
void aff_mot_seek(char *c, s_index index)
{
mot m;
vide_ecran();
if (!index->count_mot) puts("l'index est vide!");
else
{ if(index->tab_size == 26)
if ((m = seek_mot(c, index->tab[c[0]-'a'])) != NULL)
{
aff_mot_one(m->suiv);
}
if (index->tab_size == 1)
if ((m = seek_mot(c, index->tab[0])) != NULL)
{
aff_mot_one(m->suiv);
}
}
}
// affichage d'une liste chainée de lignes
// utilsée par la fonction aff_mot_one
void affiche_ligne (ligne l)
{
ligne ptr = l->suiv;
printf("\nligne(s) : ");
while(ptr)
{
printf("%d; ", ptr->lg);
ptr = ptr->suiv;
}
}
// affichage d'un mot
void aff_mot_one(mot m)
{
printf("mot : %-15s\t\t", m->mt);
affiche_ligne(m->l_lg);
printf("\n\n");
}
// affichage d'une liste chainée de mots
void affiche_mot_all (mot m)
{
while(m)
{
aff_mot_one(m);
m = m->suiv;
}
}
//affichage du nombre de mots de l'index
void aff_nbmot (s_index index)
{
printf("il y a %d mots dans l'index\n", index->count_mot);
}
// affichage de l'index
void affiche_index (s_index index)
{
unsigned int i;
vide_ecran();
printf("\n");
puts("****************************");
puts("* INDEX *");
puts("****************************");
if (!index->count_mot) puts("l'index est vide");
else
{ for (i = 0; i < index->tab_size; i++)
affiche_mot_all(index->tab[i]->suiv);
}
}
//effacage de l'écran
void vide_ecran()
{
if (system("cls"))
system("clear");
}
//affiche les mots apparaissant le plus de fois
void aff_occ_max(s_index index)
{
unsigned int i;
mot ptr, max;
max = seek_occ_max(index);
vide_ecran();
puts("**************************************");
puts("*Mot(s) apparraissant le plus de fois*");
puts("**************************************");
for(i = 0; i < index->tab_size; i++)
{
ptr = index->tab[i];
while(ptr->suiv != NULL)
{
if (ptr->suiv->occ == max->occ)
aff_mot_one(ptr->suiv);
ptr = ptr->suiv;
}
}
printf("\n\noccurence : %d fois\n", max->occ);
}
//*********************
//* FONCTIONS ANNEXES *
//*********************
//fonction demandant à l'utilisateur s'il souhaite continuer
void get_continue()
{
char c;
do{
puts("continuer : c");
scanf(" %c", &c);
}while(c != 'c');
}
//compte le nombre de lignes où apparait un mot
int count_nb_ligne(mot m)
{
ligne ptr;
int nbl = 0;
ptr = m->l_lg;
while (ptr->suiv != NULL)
{
ptr = ptr->suiv;
nbl++;
}
return nbl;
}
//**********************************************
//* AFFICHAGE DES CARACTERISIQUE DES FONCTIONS *
//**********************************************
//affichage du tableau
//
void aff_tab(float temps[], int taille[])
{
int i;
vide_ecran();
for (i = 0; i < 2; i++)
{
if (i == 0)
{
printf("\n");
puts("****************************");
puts("* methode 1 : liste simple *");
puts("****************************");
}
if (i == 1)
{
printf("\n");
puts("***********************");
puts("* methode 2 : tableau *");
puts("***********************");
}
puts("---------------------------------------------------------------------");
printf("fonctions \t\t\t\t temps\t\t taille\n");
puts("---------------------------------------------------------------------");
printf("indexation du fichier : \t\t%-5g s\t\t%d octet(s)\n\n", temps[0 + i*7], taille[0 + i*7]);
printf("affichage de l'index : \t\t\t%-5g s\t\t%d octet(s)\n\n", temps[1 + i*7], taille[1 + i*7]);
printf("affichage du nombre de mots : \t\t%-5g s\t\t%d octet(s)\n\n", temps[2 + i*7], taille[2 + i*7]);
printf("recherche d'un mot : \t\t\t%-5g s\t\t%d octet(s)\n\n", temps[3 + i*7], taille[3 + i*7]);
printf("recherche des mots d'une ligne : \t%-5g s\t\t%d octet(s)\n\n", temps[4 + i*7], taille[4 + i*7]);
printf("suppression d'un mot : \t\t\t%-5g s\t\t%d octet(s)\n\n", temps[5 + i*7], taille[5 + i*7]);
printf("suppression de l'index : \t\t%-5g s\t\t%d octet(s)\n\n", temps[6 + i*7], taille[6 + i*7]);
}
}
//fonctions de calcul du temps pour chaque methode
void f_temps(float temps[], int taille[], int i, s_index ind, mot dernier, int ml)
{
clock_t start, end;
start = clock();
affiche_index(ind);
end = clock();
temps[i + 1] = ((float)(end-start)/(float)cLk_Tck);
taille[i + 1] = 0;
start = clock();
aff_nbmot(ind);
end = clock();
temps[i + 2] = ((float)(end-start)/(float)cLk_Tck);
taille[i + 2] = 0;
start = clock();
aff_mot_seek(dernier->mt,ind);
end = clock();
temps[i + 3] = ((float)(end-start)/(float)cLk_Tck);
taille[i + 3] = 0;
start = clock();
aff_ligne_seek(ml,ind);
end = clock();
temps[i + 4] = ((float)(end-start)/(float)cLk_Tck);
taille[i + 4] = 0;
start = clock();
supp_mot(dernier->mt,&ind);
end = clock();
temps[i + 5] = ((float)(end-start)/(float)cLk_Tck);
taille[i + 5] = 0;
start = clock();
detruire(ind);
end = clock();
temps[i + 6] = ((float)(end-start)/(float)cLk_Tck);
taille[i + 6] = 0;
}
void t_calc()
{
mot dernier, ptr;
ligne ptl;
int max, t, i, ml, taille[14];
clock_t start, end;
char c[40];
float temps[14];
s_index tindex;
puts("entrez le nom du fichier a tester");
scanf(" %s", c);
start = clock();
tindex = make_index(1, c);
if (tindex == NULL)
{
get_continue();
t_menu();
}
end = clock();
temps[0] = ((float)(end-start)/(float)cLk_Tck);
taille[0] = index_taille;
if (tindex->count_mot > 0)
{
dernier = tindex->tab[0];
while (dernier->suiv != NULL)
dernier = dernier->suiv;
ptl = dernier->l_lg; //dernier élément de la liste
while(ptl->suiv != NULL)
ptl = ptl->suiv; //dernièreligne
ml = ptl->lg;
f_temps(temps, taille, 0, tindex, dernier, ml);
}
start = clock();
tindex = make_index(26, c);
end = clock();
temps[7] = ((float)(end-start)/(float)cLk_Tck);
taille[7] = index_taille;
if (tindex->count_mot > 0)
{
max = 0;
for (i = 0; i < 26; i++)
{
t = 0;
ptr = tindex->tab[i];
while (ptr->suiv != NULL)
{
ptr = ptr->suiv;
t++;
}
if (t>=max)
{
max = t;
dernier = ptr;
}
}
f_temps(temps, taille, 7, tindex, dernier, ml);
}
aff_tab(temps, taille);
}
//****************************
//* MENU *
//****************************
char s_menu(char ch)
{
s_index index;
char c, c2[40];
index = m_create(ch);
get_continue();
while(1)
{
vide_ecran();
puts(" *****************************");
puts(" * GESTION DE L'INDEX *");
puts(" *****************************");
printf("\n METHODE %c\n", ch);
puts("pour des raisons de lisibilite et de compatibilite : ");
puts(" .les accents ne sont pas affiches");
puts(" .tous les mots sont ecris en minuscules");
printf("\n");
puts("c : Indexation d'un fichier");
puts("q : Quitter le programme");
puts("h : Pour afficher le menu principal");
puts("m : Liste tous les mots de l'index");
puts("n : Affiche le nombre de mot de l'index");
puts("r mot : Affiche toutes les lignes ou apparait le mot");
puts("l nl : Liste tous les mots se trouvant a la ligne nl");
puts("s mot : Supprime le mot de l'index");
puts("p : Taille de l'index");
puts("x : Affiche le mot qui est apparu le plus souvent");
puts("t : Affiche le tableau recapitulatif des 2 methodes");
puts(" (efface l'index en cours)");
if (index == NULL)
printf("\n!IL N'Y A PAS D'INDEX EN MEMOIRE!\n");
printf("\n");
scanf(" %c", &c);
if (c == 'c')
{
detruire(index);
s_menu(ch);
}
if (index != NULL) //ci-dessous les fonctions ne pouvant s'effectuer que lorsque l'index n'est pas vide
{
if (c =='m')
{
affiche_index(index);
get_continue();
}
if (c == 'n')
{
aff_nbmot(index);
get_continue();
}
if (c == 'r')
{
scanf(" %s", c2);
if(c2[0] < 'a' || c2[0] > 'z')
{
puts("je vous rappelle que : ");
puts(" .le mot ne peut etre accentue");
puts(" .le mot doit etre ecrit en minuscules");
printf("\n");
}
else
aff_mot_seek(c2, index);
get_continue();
}
if (c == 'l')
{
scanf(" %s", c2);
aff_ligne_seek(atoi(c2), index);
get_continue();
}
if (c == 's')
{
scanf(" %s", c2);
supp_mot(c2, &index);
get_continue();
}
if (c == 'p')
{
printf(" l'index occupe une taille de %d octets\n", index_taille);
get_continue();
}
if (c == 'x')
{
aff_occ_max(index);
get_continue();
}
}
//fonction pouvant s'effectuer tout le temps
if (c == 't')
{
detruire(index);
t_calc();
get_continue();
vide_ecran();
s_menu(ch);
}
if (c == 'q')
{
detruire(index);
exit(0);
}
if (c == 'h')
{
detruire(index);
t_menu();
}
}
}
// menu principal
char t_menu()
{
char c;
while(1)
{
vide_ecran();
puts("*****************************");
puts("* MENU *");
puts("*****************************");
puts("q : Quitter le programme");
puts("o : Choix de la methode utilisee lors de la construction de l'index");
printf("\n");
scanf("%c", &c);
if (c == 'q') exit(0);
if (c == 'o')
{
do{
vide_ecran();
puts("*********************");
puts("* methode *");
puts("*********************");
puts("h : menu");
puts("1 : simple");
puts("2 : hachage");
printf("\n");
c = getchar();
}while(c != '1' && c != '2' && c!= 'h' && c!='1');
if (c == '2' || c == '1')
{
vide_ecran();
s_menu(c);
}
if (c == 'h') t_menu();
}
}
}
//*****************************
//* MAIN *
//*****************************
int main()
{
t_menu();
} |
Partager