diff --git a/pointer.adb b/pointer.adb index b2a72bc..feb6c76 100644 --- a/pointer.adb +++ b/pointer.adb @@ -237,12 +237,14 @@ procedure pointer is - procedure addcirc(Listout: HlistC) is + procedure addcirc(Listout, backup: HlistC) is valuesR : returned3; values : list; L : Integer := 1; add : listc; + add2 : listc; auxc : listc; + auxc2 : listc; aux : list; N : Integer := 0; Done: boolean := False; -- to check if the person entered the right number of variable @@ -253,6 +255,7 @@ procedure pointer is begin N := integer'Value(s); listOut.all.num := N; + backup.all.num := N; Put_line("Please type in each process' number of tasks separated by spaces"); while (not Done) loop valuesR := saisir3; @@ -271,15 +274,21 @@ procedure pointer is for L in 1..N loop if(L=1) then listOut.all.first:= new tasks'(L,values.all.info,listOut.all.first); + backup.all.first:= new tasks'(L,values.all.info,backup.all.first); auxc := listOut.all.first; + auxc2 := backup.all.first; aux := values.all.next; else add:= new tasks'(L,aux.all.info,listOut.all.first); + add2:= new tasks'(L,aux.all.info,backup.all.first); aux:= aux.all.next; auxc.all.next:= add; + auxc2.all.next:= add2; auxc := add; + auxc2 := add2; if (L=N) then listOut.all.last := auxc; + backup.all.last := auxc2; end if; end if; end loop; @@ -409,9 +418,35 @@ procedure DisplayCSmall(list:HlistC) is -- list.all.num := list.all.num-remove; -- end run; + procedure copy(l1,l2:Hlistc) is + I : Integer :=1; + aux1 : listc; + aux2 : listc; + add : listc; + begin -- we're actually leaving all the memory behind but well... we should free it + aux1 := l1.all.first; + l2.all.num := l1.all.num; + for L in 1..l1.all.num loop + if(L=1) then + l2.all.first:= new tasks'(L,aux1.all.num,l2.all.first); + aux2 := l2.all.first; + aux1:= aux1.all.next; + else + add:= new tasks'(L,aux1.all.num,l2.all.first); + aux1:= aux1.all.next; + aux2.all.next:= add; + aux2 := add; + if (L=l1.all.num) then + l2.all.last := aux2; + end if; + end if; + end loop; + end copy; + + -- list1: list; -- list2: list; -- list3: list; @@ -419,8 +454,9 @@ procedure DisplayCSmall(list:HlistC) is Q : Integer:= 0; I : Integer:= 0; +stop:boolean := False; list1 : Hlistc; - +list2 : Hlistc; begin -- List3 := new cell'(3,NULL); @@ -453,18 +489,35 @@ begin -- afficher(list1); list1:= new Hcell'(0,null,null); - addcirc(list1); + list2:= new Hcell'(0,null,null); + addcirc(list1,list2); displayc(list1); - Put_line("Please type the value of a quantum Q"); - declare - s : string := get_line; - begin - Q := integer'Value(s); - while (list1.all.num > 0) loop - runsilent(list1,Q); - displayCsmall(list1); - end loop; - end; + displayc(list2); + while (not stop) loop + displaycsmall(list1); + Put_line("Please type the value of a quantum Q"); + declare + s : string := get_line; + begin + Q := integer'Value(s); + while (list1.all.num > 0) loop + runsilent(list1,Q); + displayCsmall(list1); + end loop; + end; + Put_Line("press 1 if you want to try again with an other value for Q, anything else if you're good"); + declare + Ans : Integer; + s: string := get_line; + begin + Ans := integer'Value(s); + if (Ans /= 1) then + stop := True; + else + copy(list2,list1); + end if; + end; + end loop; end pointer;