/* ====================================================== */ /* libraries.h */ /* ====================================================== */ #include #include #include /* ====================================================== */ /* Statheres, katholikes metablhtes kai structures */ /* ====================================================== */ #ifdef WIN32 #define clear_screen "cls" #else #define clear_screen "clear" #endif #define D 3 /* Megistos arithmos upo diagrafh eggrafwn prin thn anasugkrothsh */ #define N 5 /* Megisto plithos eisagwghs eggrafwn prin thn anadiorganwsh */ #define INDEX ".ndx" /* Epektash tou arxeioy eyrethriou */ #define MASTER ".dat" /* Epektash tou arxeioy dedomenwn */ #define STRINGS 30 /* Megethos twn alfarithmitikwn */ FILE *dataf; FILE *indexf; char oad[STRINGS+1]="tenies.dat"; /* proepilegmeno onoma */ char oai[STRINGS+1]="tenies.ndx"; struct tenies{ char code[10]; /* Kodikos tainias */ char title[STRINGS+1]; /* Titlos */ char genre[STRINGS+1]; /* Eidos */ char director[STRINGS+1]; /* Skinotheths */ char actor1[STRINGS+1]; /* Protagonisths 1 */ char actor2[STRINGS+1]; /* Protagonisths 2 */ int year; /* Etos */ int avail; /* diathesimothta */ }; struct teniesIndex{ char code[10]; /* Pedio kleidi */ int dief; /* Dieuthunsh eggrafhs sto arxeio dedomenwn */ }; struct tenies film; struct teniesIndex *ifilm; /* ====================================================== */ /* Protupa sunartisewn */ /* ====================================================== */ void mainmenu(); /* Emfanish tou menou epilogwn */ void eksodos(); /* Emfanish munhmatos telous */ void epektash(); /* Dhmiourgia/epektash arxeiou */ int anazhthsh(); /* Anazhthsh mesw tou index file, epistrefei th dieuthinsh ths eggrafhs sto index arxeio 'h -1 se apotuxia */ void probolh(); /* Menou tupwn probolhs */ void probolh_index(); /* Probolh tou index arxeiou */ void probolh_all(); /* Probolh olou tou arxeio master */ void probolh_one(); /* Probolh mias eggrafhs */ void prob_genre(char *); /* Probolh ana eidos */ void prob_gen_av(char *); /* Probolh ana eidos k diathesimothta */ void prob_titl_taksin(); /* Probolh ana titlo, taksinomhmena */ char* select_genre(); /* Epilogh tou eidous tenias */ void diorthosh(); /* Diorthwsh eggrafhs */ void diagrafh(); /* Diagrafh eggrafhs */ int check_files(); /* Elegxos uparkshs arxeiwn kai epistrofh tou megethous */ void anasugkrothsh(); /* Anasugkrothsh tou index arxeiou */ void selection_sort(struct teniesIndex *, int); /* ====================================================== */ /* Sunartish emfanishs tou menou epilogwn */ /* ====================================================== */ void mainmenu(){ // system(clear_screen); printf(".------------| Main menu |------------.\n"); printf("| |\n"); printf("| 1. Dhmiourgia / Epektash |\n"); printf("| 2. Anazhthsh |\n"); printf("| 3. Probolh |\n"); printf("| 4. Diorthosh |\n"); printf("| 5. Diagrafh |\n"); printf("| 6. Eksodos |\n"); printf("| |\n"); printf("|-------------------------------------'\n"); printf("| Epilogh : |\n"); printf("'-------------------------------------'\n"); return; } /* ====================================================== */ /* Sunartish Emfanish munhmatos telous */ /* ====================================================== */ void eksodos(){ // system(clear_screen); printf(".------------| Eksodos |------------.\n"); printf("| |\n"); printf("| Organwsh kai diaxeirhsh arxeiwn |\n"); printf("| Project |\n"); printf("| |\n"); printf("| |\n"); printf("| XXXXXXXXXXXXXXXXXXXX T-1786 |\n"); printf("| XXXXXXXXXXXXXXXXXXXX T-1800 |\n"); printf("| |\n"); printf("'-------------------------------------'\n"); // system(clear_screen); exit; } /* ====================================================== */ /* Sunartish taksinomhshs tou index arxeiou */ /* ====================================================== */ void selection_sort(struct teniesIndex X[], int k){ int i,j,t; struct teniesIndex temp; for (i=0; i0 ) t=j; temp = X[i]; X[i] = X[t]; X[t] = temp; } } /* ====================================================== */ /* Sunartish Dhmiourgias/Epektashs */ /* ====================================================== */ void epektash(){ int pl, m=0, i, j, tm; int synexeia; pl = check_files(); m = pl; dataf = fopen(oad, "rb+"); fseek(dataf, 0, SEEK_END); ifilm = (struct teniesIndex *) malloc((pl+N) * sizeof(struct teniesIndex)); fputs("\n\nEISAGOGI EGGRAFON\n\n", stdout); do { printf("\nEisagogi kwdikou tenias : "); scanf("%s", &film.code); printf("\nEisagogi titlou tenias : "); scanf("%s", &film.title); printf("\nEisagogi eidous tenias : \n"); strcpy(film.genre,select_genre()); printf("\nEisagogi skhnotheth : "); scanf("%s", &film.director); printf("\nEisagogi prwtou protagwnisth : "); scanf("%s", &film.actor1); printf("\nEisagogi deuterou protagwnisth : "); scanf("%s", &film.actor2); printf("\nEisagogi etous tenias : "); scanf("%d", &film.year); printf("\nDiatheshmothta (1=NAI, 0=OXI) : "); scanf("%d", &film.avail); /* Kataxwrisi eggrafhs sto arxeio dedomenwn */ fwrite(&film, sizeof(struct tenies), 1, dataf); /* Enhmerwsh pinaka euretiriou */ strcpy(ifilm[m].code, film.code); ifilm[m].dief = m; m++; printf("\n\n Thelete nea eisagogi (1=NAI, 0=OXI) : "); scanf("%d", &synexeia); if ( synexeia==1 ) if ( m == pl+N ) { /* Enhmerwsh arxeiou deiktwn kai anadiorganwsh pinaka deiktwn */ indexf = fopen(oai, "rb+"); fseek(indexf, 0, SEEK_END); for (i=pl; i0 ) arxi = meso + 1; else if (strcmp(anaz, ifilm[meso].code)<0 ) telos = meso - 1; else flag = 1; } if ( flag == 0 ){ printf("\n\nH eggrafi den vrethike...\n\n"); return -1; } else { do{ printf("\nH eggrafh brethike! Na problithei twra?"); printf("(1=NAI, 0=OXI) : "); scanf("%d", &choice); }while(choice != 0 && choice != 1); if (choice == 1){ deiktis = ifilm[meso].dief; probolh_one(deiktis); } } free(ifilm); return meso; } /* ====================================================== */ /* Sunartish diagrafhs */ /* ====================================================== */ void diagrafh(){ struct tenies temp; struct teniesIndex *itemp; int pl, i, m=0, meso; /* Πλήθος εγγραφών - δείκτης */ int diag; char dg[10] = "*****", oadg[10] = "diag.dat", choice; /* Χαρακτήρες διαγραφής και όνομα αρχείου διαγραφής */ int eld; /* Πλήθος διαγραφέντων */ int deiktis; /* Dieuthinsh eggrafhs sto master arxeio */ FILE *diagf; /* Αρχείο ελέγχου διαγραφής */ FILE *tempf; /* Προσωρινό αρχείο */ pl = check_files(); /* perasma tou arxeiou index se pinaka */ indexf = fopen(oai, "rb"); ifilm = malloc( pl * sizeof(struct teniesIndex)); fread(&ifilm[0], sizeof(struct teniesIndex), pl, indexf); fclose(indexf); meso = anazhthsh(); if (meso == -1) /* An h eggrafh de brethike sthn anazhthsh */ return; else{ do{ printf("\nNa diagrafei oristika h eggrafh?"); printf("(1=NAI, 0=OXI) : "); choice = getchar(); }while(choice != '0' && choice != '1'); if (choice == 1){ printf("\n\nH eggrafi diagrafetai...\nPerimenete...\n\n"); deiktis = ifilm[meso].dief; fseek(dataf, deiktis * sizeof(struct tenies), SEEK_SET); temp = film; strcpy(temp.code, dg); fwrite(&temp, sizeof(struct tenies), 1, dataf); /* Ενημέρωση πίνακα ευρετηρίου */ for (i=meso; i