-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
158 lines (147 loc) · 5.18 KB
/
main.c
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
#include "headers/function.h"
char *ERROR_MEMORY = "SET UP THE MEMORY PLEASE !";
char *ERROR_QUEUE = "SET UP THE QUEUE PLEASE ! ";
char *ERROR_W = "SHIT'S NOT READY YET!";
char *MENU_MAIN ="MAIN MENU:";
char *MENU_FIT="FIT MENU:";
char *MENU_INS="INSERTION MENU: ";
char *choices[] = {
"SetUp the Memory",
"Display Memory",
"Set up queue",
"Display Processes queue",
"Choose Allocation method",
"Load process into memory",
"Setup Pile",
"Display Pile"
};
char *Fit[] = {
"First Fit",
"Best Fit",
"Worst Fit",
};
char *Insert[]={
"inserer un seule processus",
"Tout inserer",
"Iserer depuis la pile"
};
int main(void) {
int highlight;
int choix, fitChoix;
Pile s=NULL;
Memo (*fitFuncPointer)(Memo, process)=NULL;
initscr();
noecho();
cbreak();
refresh();
// start_color();
//afficheAlarme(ERROR_MEMORY);
getch();
Memo maMemoire = NULL;
FILE *a;
File f={NULL,NULL};
process p;
// affichemen(2);
do {
choix = afficheMen(2, choices, SIZE_CHOICES,MENU_MAIN);
initscr();
switch (choix) {
case 0 : {
maMemoire = Creat_Ram();
afficheAlarme("MEMORY SETUP",0,10);
getch();
break;
}
case 1: {
if (maMemoire) {
start_color();
Affiche_Ram(maMemoire, 2);
getch();
break;
}
else {
afficheAlarme(ERROR_MEMORY,0,13);
sleep(2);
break;
}
case 2: {
a = fopen("FILE0.txt", "r");
f = Creat_File(a);
break;
}
case 3: {
if(Filevide(f))
{afficheAlarme(ERROR_QUEUE,0,10);sleep(1);}
else {
affiche_File(f, 0);
getch();
}
break;
}
case 4: {
fitChoix = afficheMen(2, Fit, SIZE_FIT,MENU_FIT);
switch (fitChoix) {
case 0: {
fitFuncPointer = &(Firstfit);
break;
}
case 1: {
fitFuncPointer = &(Bestfit);
break;
}
case 2: {
fitFuncPointer = &(Worstfit);
break;
}
default: break;
}
break;
}
case 5: {
switch(afficheMen(2,Insert,SIZE_INS,MENU_INS))
{
case 0: {
if(!f.h ) afficheAlarme(ERROR_QUEUE,0,16);
if(!maMemoire) afficheAlarme(ERROR_MEMORY,0,13);
if(!fitFuncPointer) afficheAlarme("FITFUNC !!! ",0,19);
if(!f.h || !maMemoire || !fitFuncPointer)
{getch();afficheAlarme("khrraaa",0,16);break;}
p = Defiler(&f);
if(!insertProc(fitFuncPointer(maMemoire, p), p)) Enfiler(&f,p);
break;}
case 1:{
if(!f.h ) afficheAlarme(ERROR_QUEUE,0,16);
if(!maMemoire) afficheAlarme(ERROR_MEMORY,0,13);
if(!fitFuncPointer) afficheAlarme("FITFUNC !!! ",0,19);
if(!f.h || !maMemoire || !fitFuncPointer)
{getch();break;}
partOne(&f,fitFuncPointer,maMemoire);
break;}
case 2:{
if(!s ) afficheAlarme("SETUP PILE !",0,16);
if(!maMemoire) afficheAlarme(ERROR_MEMORY,0,13);
if(!fitFuncPointer) afficheAlarme("FITFUNC !!! ",0,19);
if(!s|| !maMemoire || !fitFuncPointer)
{getch();break;}
partTwo(&s,fitFuncPointer,maMemoire);
break;}
default: break;
}
break;
}
case 6: {s=Creat_Pile(3);afficheAlarme("Pile setup",0,16);getch();break;}
case 7: {if(!s){afficheAlarme("SETUP PILE!",0,16);getch();break;}else affichePile(&s);getch();break;}
}
default: break;
}
//getch();
delAlarme();
refresh();
if(maMemoire)
{checkUsed(maMemoire);
gestionDeMemoire(&maMemoire);}
} while (choix !=-1 );
getch();
endwin();
return 0;
}