1 Program SystemedeFenetrage;
\r
4 (* version lightweight processus *)
\r
5 Const Noir =0,Bleu =1,Vert =2,Cyan =3,
\r
6 Rouge =4,Magenta =5,Marron =6,GrisCLair =7,
\r
7 GrisFonce =8,BleuClair =9,VertClair =10,CyanClair =11,
\r
8 RougeClair =12,MagentaClair =13,Jaune =14,Blanc =15;
\r
11 (*********************************************************************)
\r
12 (* notion de lightweight process *)
\r
13 (*********************************************************************)
\r
14 var actualp: proces;
\r
18 unit semafor : class;
\r
19 hidden close SEM, SUSPENDED;
\r
21 var SUSPENDED : set;
\r
23 unit tsp : function : boolean;
\r
29 unit up : procedure;
\r
34 unit lockp : procedure;
\r
38 call active.delete(actualp);
\r
39 call suspended.insert(actualp);
\r
40 actualp.suspndd := true;
\r
41 actualp := active.amember;
\r
48 unit unlockp : procedure;
\r
56 aux := suspended.min;
\r
57 call suspended.delete(aux);
\r
58 aux.suspndd := false;
\r
59 call active.insert(aux)
\r
63 begin (* initialization of a semaphore*)
\r
64 suspended := new set
\r
69 (* in this version it will be a queue *)
\r
71 unit link : class(x : proces);
\r
75 var head, tail : link;
\r
77 unit insert : procedure(x : proces);
\r
80 ogniwo := new link(x);
\r
90 unit empty : function : boolean;
\r
92 result := (head = none)
\r
95 unit min : function : proces;
\r
100 unit delete : procedure (x : proces);
\r
101 var o,ogniwo : link;
\r
104 while ogniwo.x =/= x
\r
107 ogniwo := ogniwo.next;
\r
110 writeln(" deleted process does not exist");
\r
118 o.next := ogniwo.next;
\r
127 unit amember : function : proces;
\r
131 if head.next =/= none
\r
145 unit proces : coroutine;
\r
146 (* this class implements notion of process*)
\r
147 var nrofsons : integer;
\r
148 var waiting, terminated, suspndd : boolean;
\r
149 var father, nameofson : proces;
\r
151 unit resumep : procedure(x : proces);
\r
155 call suspended.delete(x);
\r
156 call active.insert(x);
\r
157 x.suspndd := false;
\r
162 writeln(" you are resuming a terminated process?!");
\r
169 unit stopp : procedure;
\r
171 call active.delete(actualp);
\r
172 call suspended.insert(actualp);
\r
174 actualp := active.amember;
\r
178 unit waitp : function(y : proces) : proces;
\r
183 writeln(" waiting for a process which does not exist");
\r
190 if y.father =/= this proces
\r
193 writeln(" y is not your son!");
\r
201 (* here we shall return upon termination of son*)
\r
202 result := nameofson;
\r
207 unit stoppar :procedure (z:semafor);
\r
213 unit waitn : function : proces;
\r
217 writeln(" you wait for a son, but it does not exist ");
\r
223 (* you return here *)
\r
229 unit xqmulti : procedure;
\r
231 actualp:=active.amember;
\r
235 begin (*prologue of process*)
\r
239 father.nrofsons:=father.nrofsons +1;
\r
241 call suspended.insert (this proces);
\r
244 inner; (* here comes the body of your process *)
\r
246 (* process epilogue *)
\r
248 call active.delete(actualp);
\r
251 father.nrofsons:=father.nrofsons - 1;
\r
254 if father.nameofson = none
\r
256 father.nameofson := this proces
\r
258 if father.nameofson = this proces
\r
260 call resumep(father)
\r
263 actualp:=active.amember;
\r
269 unit resumep : procedure(x : proces);
\r
273 call suspended.delete(x);
\r
274 call active.insert(x);
\r
275 x.suspndd := false;
\r
280 writeln(" you are resuming a terminated process?!");
\r
286 unit Arbitrage : procedure;
\r
288 actualp:=active.amember;
\r
296 (*****************************************************************************)
\r
297 (* premiere famille de classes : les classes graphiques *)
\r
298 (*****************************************************************************)
\r
302 Unit Windows : Ptr Class(father :windows,x1,y1,x2,y2 : integer);
\r
303 Close hauteur,largeur;
\r
304 Var lborder,cfond,cborder : integer,
\r
305 lbande,cfbande,cbbande : integer,
\r
306 hauteur,largeur : integer,
\r
307 xpos,ypos,xmax,ymax : integer,
\r
308 xdeb,ydeb : integer,
\r
312 nombande : arrayof char,
\r
314 save_map : arrayof integer;
\r
316 Unit option : procedure (l1,l2,l3,l4,l5,l6 : integer,l7 : arrayof char);
\r
318 cfond:=l1; lborder:=l2; cborder:=l3; lbande:=l4;
\r
319 cfbande:=l5; cbbande:=l6;
\r
320 nombande:=copy(l7);
\r
321 writeln("coucou2 l1=",l1);
\r
324 Unit Affiche : procedure;
\r
325 Var i,j,k :integer;
\r
327 call father.rectanglef(x1,y1,x2,y2,cfond);
\r
328 for i:=0 to lborder
\r
330 call father.rectangle(x1+i,y1+i,x2-i,y2-i,cborder);
\r
333 call father.rectanglef(x1+lborder+1,i,x2-lborder-1,i+imax(14,lbande),cfbande);
\r
334 j:=(x2-x1-2*lborder-8*(upper(nombande)-lower(nombande)))/2;
\r
335 for i:=lower(nombande) to upper(nombande)
\r
337 k:=x1+lborder+j+i*8;
\r
338 call father.outxyascii(k,y1+lborder+2,ord(nombande(i)),cbbande,cfbande);
\r
342 then call barcde.affichemenu;
\r
346 Unit virtual affichesuite :procedure;
\r
349 Unit virtual rectangle : procedure(xx1,yy1,xx2,yy2,c :integer);
\r
352 Unit virtual rectanglef : procedure(xx1,yy1,xx2,yy2,c : integer);
\r
355 Unit virtual outxyascii : procedure(x,y,car,cf,cb : integer);
\r
358 Unit virtual outxytext : procedure(x,y:integer,chaine:string,c1,c2:integer);
\r
362 hauteur:=y2-y1-2*lborder;
\r
363 largeur:=x2-x1-2*lborder;
\r
366 Unit Bitmap : Windows Class;
\r
369 Unit Son : Windows Class;
\r
372 Unit Maine : Windows Class;
\r
375 Unit Dialogue : Son Class;
\r
378 Unit Catalogue : Dialogue Class;
\r
381 Unit Question : Dialogue Class;
\r
384 Unit Widgets : Ptr Class(father : windows);
\r
387 (**********************************************************************)
\r
388 Unit Menu : Widgets Class(x,y,col_e,col_f: integer);
\r
389 Var liste : ensemble;
\r
391 Unit item : element class(nom : string,key : integer,suite :Menu);
\r
394 Unit insert : procedure(nom : string,key : integer,s : menu);
\r
397 e:=new item(nom,key,s);
\r
399 then liste:=new ensemble;
\r
401 call liste.insert(e);
\r
404 Unit virtual affichemenu : procedure;
\r
409 Unit Menu_V : Menu Class;
\r
411 Unit virtual affichemenu : procedure;
\r
413 tlen : arrayof char,
\r
417 call liste.initialise;
\r
419 if(liste.getelm(cour))
\r
420 then while(cour<>none)
\r
422 call father.outxytext(xx,yy,cour.nom,col_e,col_f);
\r
423 tlen:=unpack(cour.nom);
\r
424 len:=upper(tlen)-lower(tlen)+1;
\r
426 if(father.ListM=none)
\r
427 then father.ListM:=new LClic;
\r
429 call father.ListM.insert(new elm_c(0 ,xx,yy,xx+len*8,yy+14));
\r
432 if not liste.getelm(cour)
\r
441 Unit Menu_H : Menu Class;
\r
444 Unit Bottons : Widgets Class;
\r
447 Unit Racc : Bottons Class;
\r
450 Unit Opt_list : Bottons Class;
\r
453 Unit Oneline : Opt_list Class;
\r
456 Unit Multiline : Opt_list Class;
\r
459 Unit Botton : Bottons Class;
\r
462 Unit Lift : Widgets Class;
\r
465 Unit Lift_V : Lift Class;
\r
468 Unit Lift_H : Lift Class;
\r
471 (*****************************************************************************)
\r
472 (* deuxieme famille de classes : les structures de donnees *)
\r
473 (*****************************************************************************)
\r
474 Unit element : class; (* general *)
\r
477 Unit elm_c : element class(id,x1,y1,x2,y2 : integer); (* listclic *)
\r
480 Unit elm_a : element class(p : Applications); (* liste application *)
\r
484 Unit Ensemble : CLass;
\r
485 Var root,last : node,
\r
488 Unit node : class(elm : element);
\r
492 Unit virtual insert : procedure(e : element);
\r
496 then root:=new node(e);
\r
498 else last.next:=new node(e);
\r
504 Unit virtual delete : procedure(e : element);
\r
508 then flag:=courant.next;
\r
510 then last:=courant;
\r
511 courant.next:=none;
\r
513 else if courant.next<>none
\r
514 then courant.next:=courant.next.next;
\r
521 Unit virtual member : function (e : element) : boolean;
\r
522 Var savecou : node,
\r
528 while(courant<>none)
\r
530 if not egalite(courant.elm,e)
\r
531 then savecou:=courant;
\r
532 courant:=courant.next;
\r
541 Unit virtual egalite : function (e1,e2 :element) :boolean;
\r
544 Unit empty : function : boolean;
\r
546 result:=(root=none);
\r
549 Unit initialise : procedure;
\r
554 Unit getelm : function(output e : element) :boolean;
\r
557 then e:=courant.elm;
\r
559 courant:=courant.next;
\r
560 else result:=false;
\r
566 Unit Queue : Ensemble Class;
\r
569 Unit Ofpriority : Queue Class;
\r
572 Unit ListD : Ensemble Class;
\r
575 Unit LClic : ListD Class;
\r
577 Unit virtual egalite : function (e1,e2 :element) :boolean;
\r
579 if (e1 qua elm_c.x1=e2 qua elm_c.x1 and e1 qua elm_c.x2=e2 qua elm_c.x2
\r
580 and e1 qua elm_c.y1=e2 qua elm_c.y1 and e1 qua elm_c.y2=e2 qua elm_c.y2)
\r
582 else result:=FALSE;
\r
586 Unit appartient : function (x,y : integer) : boolean;
\r
594 if (x>=e.x1 and x<=e.x2 and y>=e.y1 and y<=e.y2)
\r
604 Unit LBot : ListD Class;
\r
607 Unit LAppli : ListD Class;
\r
610 Unit LKey : ListD Class;
\r
613 Unit LWin : ListD Class;
\r
616 Unit Stack : Ensemble Class;
\r
620 (*****************************************************************************)
\r
621 (* Famille de process *)
\r
622 (*****************************************************************************)
\r
623 Unit Applications : proces class(x1,y1,x2,y2 : integer,father : Gest_Wind);
\r
624 Var w : windows, (* maine *)
\r
625 Filles : windows, (* son *)
\r
628 Unit virtual gestionnaire : procedure(id : integer);
\r
634 w:=new windows(father.getw,x1,y1,x2,y2);
\r
637 call w.option(Noir,3,VertClair,15,VertCLair,Noir,unpack("nom"));
\r
645 (************************************************************************)
\r
646 (************************************************************************)
\r
647 Unit Gest_event : proces class(gest : gest_wind);
\r
649 Unit ready : procedure;
\r
651 writeln("Gest_events READY");
\r
654 Unit souris: Mouse coroutine;
\r
659 (* ici on peut mettre la fermeture de la souris *)
\r
662 Var myszka: souris;
\r
664 Unit event : function(output v,h,p,l,r,c : integer) : boolean;
\r
666 result:=myszka.getpress(v,h,p,l,r,c);
\r
670 v,h,p,l,r,c : integer;
\r
672 myszka := new souris;
\r
673 (* accept ready; *)
\r
674 (* call init(1,1); *)
\r
675 call myszka.showcursor;
\r
678 if event(v,h,p,l,r,c)
\r
680 call gest.event(v,h,p,l,r,c);
\r
686 (***********************************************************************)
\r
687 (***********************************************************************)
\r
688 Unit Gest_wind : proces class(x1,y1,x2,y2 : integer,gest:gest_event);
\r
690 v,p,h,l,r,c : integer,
\r
698 Unit getinfo : procedure (g : gest_event);
\r
702 writeln("getinfo");
\r
705 Unit event : procedure (input lv,lh,lp,ll,lr,lc : integer);
\r
707 v:=lv; h:=lh; p:=lp; l:=ll; r:=lr; c:=lc;
\r
710 Unit traitement : procedure;
\r
712 if((h=164 and l=27) or c=3)
\r
716 (* recherche dans un arbre des fenetres filles si l'evenement *)
\r
717 (* appartient a qqn *)
\r
723 Unit fin : procedure;
\r
726 attach (j.gr); (* pour terminer iiuwgraph *)
\r
727 writeln("on ferme");
\r
731 (***********************************************************************)
\r
732 Unit graph : windows class;
\r
734 unit graphi: iiuwgraph coroutine;
\r
743 Unit virtual rectangle : procedure (x1,y1,x2,y2,c : integer);
\r
745 call gr.patern(x1,y1,x2,y2,c,0);
\r
748 Unit virtual rectanglef : procedure (x1,y1,x2,y2,c : integer);
\r
750 writeln("coucou3 x1=",x1,"x2=",x2,"y1=",y1,"y2=",y2,"c=",c);
\r
751 if gr=none then writeln("NONE!") fi;
\r
752 call gr.patern(x1,y1,x2,y2,c,1);
\r
756 Unit virtual ligne : procedure (x1,y1,x2,y2,c : integer);
\r
759 call gr.move(x1,y1);
\r
760 call gr.draw(x2,y2);
\r
763 Unit virtual outxyascii : procedure (x,y,car,cf,cb :integer);
\r
767 call gr.border(cb);
\r
768 call gr.hascii(car);
\r
771 Unit virtual outxytext : procedure (x,y :integer, chaine :string,c1,c2 :integer);
\r
773 call gr.outstring(x,y,chaine,c1,c2);
\r
776 Unit virtual affichesuite : procedure;
\r
779 x:=x1+100-lborder; y:=y1+lbande+lborder+1;
\r
780 call rectanglef(x,y,x+lborder,y2-lborder-1,cborder);
\r
781 x:=x+lborder; y:=y2-100-lborder;
\r
782 call rectanglef(x,y,x2-lborder,y+lborder,cborder);
\r
784 ydeb:=y1+lborder+lbande+10;
\r
788 (* gr := new graphi; *)
\r
791 Unit initialisation1 : procedure;
\r
792 Var itermed1 : menu_v,
\r
795 i:=w.lborder+10+20; j:=y1+w.lborder+10+w.lbande+20*4;
\r
796 itermed1:=new menu_V(w.father,i,j,Blanc,GrisFonce);
\r
797 call itermed1.insert("Nouveau",319,none);
\r
798 call itermed1.insert("Ouvrir",320,none);
\r
799 call itermed1.insert("D
\82placer",321,none);
\r
800 call itermed1.insert("Copier",322,none);
\r
801 call itermed1.insert("Supprimer",323,none);
\r
802 call itermed1.insert("Propri
\82t
\82",324,none);
\r
803 i:=w.lborder+10; j:=y1+w.lborder+10+w.lbande;
\r
804 w.barcde:=new menu_V(w.father,i,j,Blanc,GrisFonce);
\r
805 call w.barcde.insert("Fichier",315,itermed1);
\r
806 call w.barcde.insert("Options",316,none);
\r
807 call w.barcde.insert("Fenetre",317,none);
\r
808 call w.barcde.insert("Aide",318,none);
\r
809 End initialisation1;
\r
811 Unit initialisation2 : procedure;
\r
814 End initialisation2;
\r
816 Unit xdeb : function : integer;
\r
821 Unit ydeb : function : integer;
\r
826 Unit getw : function : windows;
\r
833 call gron(0 ); (* 3 = 1024x768x256 *)
\r
834 j:=new graph(none,x1,y1,x2,y2);
\r
835 w:=new windows(j,x1,y1,x2,y2);
\r
837 call w.option(Grisfonce,3,BleuClair,15,BleuCLair,Blanc,unpack("Gest_Wind"));
\r
838 call initialisation1;
\r
841 call J.option(Grisfonce,3,BleuClair,15,BleuCLair,Blanc,unpack("Gest_Wind"));
\r
842 call j.affichesuite;
\r
843 (* accept getinfo; *)
\r
844 (* enable xdeb,ydeb,getw; *)
\r
845 (* call gest.ready; *)
\r
846 call initialisation2;
\r
850 (* accept event; *)
\r
859 (*****************************************************************************)
\r
860 (* P r o g r a m m e P r i n c i p a l *)
\r
861 (*****************************************************************************)
\r
870 suspended :=new set;
\r
871 G1:=new Gest_wind(0,0,640,480,none);
\r
872 G2:=new Gest_event(G1);
\r
875 call G1.getinfo(G2);
\r
881 Z1:=new applications(x+10,y+10,x+330,y+210,G1);
\r
884 call G1.ListA.insert(new elm_a(Z1));
\r
887 writeln("Dobro doszli");
\r