Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
xpred.c
Go to the documentation of this file.
1 
7 /* Copyright 1991 Digital Equipment Corporation.
8  ** Distributed only by permission.
9  **
10  ** Last modified on Wed Mar 2 11:32:59 MET 1994 by rmeyer
11  ** modified on Fri Jan 28 14:24:13 MET 1994 by dumant
12  ** modified on Thu Jun 24 06:55:40 1993 by Rmeyer
13  ** modified on Thu Nov 26 20:13:50 1992 by herve
14  *****************************************************************/
15 
16 #include "defs.h"
17 
18 
19 #ifdef X11
20 
21 
22 /*****************************************/
23 
24 #define stdin_fileno fileno(stdin)
25 #define CR 0x0d
26 #define BS 0x08
27 
28 
29 /* a closure for enum xevents_list */
30 typedef struct wl_EventClosure
31 {
32  Display *display;
33  Window window;
34  long mask;
36 } EventClosure;
37 
38 
39 /*****************************************/
40 
41 
44 
47 
48  xenter_event,xleave_event,xmisc_event,/* RM: 3rd May 93 */
49 
52 
54 
55 /*****************************************/
56 
57 static long xevent_mask[] = {
58 0, /* ??? 0 */
59 0, /* ??? 1 */
60 KeyPressMask, /* KeyPress 2 */
61 KeyReleaseMask, /* KeyRelease 3 */
62 ButtonPressMask, /* ButtonPress 4 */
63 ButtonReleaseMask, /* ButtonRelease 5 */
64 
65 PointerMotionMask | PointerMotionHintMask | ButtonMotionMask |
66 Button1MotionMask | Button2MotionMask | Button3MotionMask |
67 Button4MotionMask | Button5MotionMask,
68  /* MotionNotify 6 */
69 EnterWindowMask, /* EnterNotify 7 */
70 LeaveWindowMask, /* LeaveNotify 8 */
71 FocusChangeMask, /* FocusIn 9 */
72 FocusChangeMask, /* FocusOut 10 */
73 KeymapStateMask, /* KeymapNotify 11 */
74 ExposureMask, /* Expose 12 */
75 0, /* GraphicsExpose 13 */
76 0, /* NoExpose 14 */
77 VisibilityChangeMask, /* VisibilityNotify 15 */
78 SubstructureNotifyMask, /* CreateNotify 16 */
79 SubstructureNotifyMask, /* DestroyNotify 17 */
80 StructureNotifyMask, /* UnmapNotify 18 */
81 StructureNotifyMask, /* MapNotify 19 */
82 SubstructureRedirectMask, /* MapRequest 20 */
83 SubstructureNotifyMask, /* ReparentNotify 21 */
84 StructureNotifyMask, /* ConfigureNotify 22 */
85 SubstructureRedirectMask, /* ConfigureRequest 23 */
86 StructureNotifyMask, /* GravityNotify 24 */
87 ResizeRedirectMask, /* ResizeRequest 25 */
88 StructureNotifyMask, /* CirculateNotify 26 */
89 SubstructureRedirectMask, /* CirculateRequest 27 */
90 PropertyChangeMask, /* PropertyNotify 28 */
91 0, /* SelectionClear 29 */
92 0, /* SelectionRequest 30 */
93 0, /* SelectionNotify 31 */
94 ColormapChangeMask, /* ColormapNotify 32 */
95 0, /* ClientMessage 33 */
96 0 /* MappingNotify 34 */
97 };
98 
99 
100 
101 static char* xevent_name[] = {
102  "???",
103  "???",
104  "KeyPress",
105  "KeyRelease",
106  "ButtonPress",
107  "ButtonRelease",
108  "MotionNotify",
109  "EnterNotify",
110  "LeaveNotify",
111  "FocusIn",
112  "FocusOut",
113  "KeymapNotify",
114  "Expose",
115  "GraphicsExpose",
116  "NoExpose",
117  "VisibilityNotify",
118  "CreateNotify",
119  "DestroyNotify",
120  "UnmapNotify",
121  "MapNotify",
122  "MapRequest",
123  "ReparentNotify",
124  "ConfigureNotify",
125  "ConfigureRequest",
126  "GravityNotify",
127  "ResizeRequest",
128  "CirculateNotify",
129  "CirculateRequest",
130  "PropertyNotify",
131  "SelectionClear",
132  "SelectionRequest",
133  "SelectionNotify",
134  "ColormapNotify",
135  "ClientMessage",
136  "MappingNotify"
137 };
138 
139 
140 
141 
142 /*****************************************************************/
143 /* Macros */
144 
145 #define DrawableGC(w)(GC)GetIntAttr(GetPsiAttr(w,"graphic_context"),"id")
146 #define WindowDisplayList(w) GetIntAttr(GetPsiAttr(w,"display_list"),"id")
147 
148 /* Macros to keep GCC happy. RM: Feb 9 1994 */
149 #define DISP(X)(Display *)val[X]
150 #define DRAW(X)(Drawable)val[X]
151 #define WIND(X)(Window)val[X]
152 #define GCVAL(X)(GC)val[X]
153 #define FONT(X)(Font)val[X]
154 #define CMAP(X)(Colormap)val[X]
155 #define STRG(X) ((char *)val[X])
156 
157 
158 
159 /*****************************************************************/
160 /* Static */
161 /* handle the errors X */
162 
170 static int x_handle_error(Display *display,XErrorEvent *x_error)
171 {
172  char msg[128];
173  XGetErrorText(display,x_error->error_code,msg,128);
174  Errorline("X error message: %s.\n",msg);
175  /* don't use abort_life(TRUE) because it tries to destroy windows ...
176  and loops because the window is yet in the stack !!
177  jch - Fri Aug 7 17:58:27 MET DST 1992
178  */
179  exit_life(TRUE);
180 }
181 
188 static int x_handle_fatal_error(Display *display)
189 {
190  Errorline("fatal X Error.\n");
191  exit_life(TRUE);
192 }
193 
194 
195 /* RM: Jun 24 1993 */
196 /* JCH didn't understand ANYTHING about trailing! */
197 
206 void bk_stack_add_int_attr(ptr_psi_term t,char *attrname,long value)
207 {
208  ptr_psi_term t1;
209  ptr_node n;
210  char *perm;
211 
212  perm=(char *)heap_copy_string(attrname);
213  n=find(FEATCMP,perm,t->attr_list);
214  if(n) {
215  t1=(ptr_psi_term)n->data;
216  deref_ptr(t1);
217  if(!t1->value_3) {
219  t1->value_3=heap_alloc(sizeof(REAL));
220  }
221  *((REAL *)(t1->value_3)) = *(REAL *) value; // debugged 12/11/2016 DJD
222  }
223  else {
224  t1=stack_psi_term(4);
225  t1->type=integer;
226  t1->value_3=heap_alloc(sizeof(REAL));
227  *((REAL *)(t1->value_3)) = *(REAL *) value; // debugged 12/11/2016 DJD
228  bk_stack_insert(FEATCMP,perm,&(t->attr_list),(GENERIC)t1);
229  }
230 }
231 
240 void bk_change_psi_attr(ptr_psi_term t,char *attrname,ptr_psi_term value)
241 {
242  ptr_psi_term t1;
243  ptr_node n;
244  char *perm;
245 
246 
247  perm=(char *)heap_copy_string(attrname);
248  n=find(FEATCMP,perm,t->attr_list);
249  if(n) {
250  t1=(ptr_psi_term)n->data;
251  deref_ptr(t1);
252  *t1= *value;
253  /*push_ptr_value(psi_term_ptr,(GENERIC *)&(t1->coref));*/
254  if(value!=t1)
255  value->coref=t1;
256  }
257  else
258  bk_stack_insert(FEATCMP,perm,&(t->attr_list),(GENERIC)value);
259 }
260 
272 {
273  long smaller;
274  long success=TRUE;
275 
276 
277  deref_ptr(t);
279  t->value_3 = heap_alloc(sizeof(REAL));
280  *(REAL *) t->value_3 = v;
281 
282  matches(t->type,integer,&smaller);
283 
284  if(!smaller)
285  {
287  t->type = integer;
288  t->status = 0;
289  }
290  else
291  success = FALSE;
292 
293  if(success)
294  {
295  i_check_out(t);
296  if(t->resid)
297  release_resid(t);
298  }
299 
300  return success;
301 }
302 
303 
314 static ptr_psi_term NewPsi(ptr_definition t,char *f,long v)
315 {
316  ptr_psi_term p;
317 
318  p = stack_psi_term(4);
319  p->type = t;
320  bk_stack_add_int_attr(p,f,v);
321  return p;
322 }
323 
333 long GetIntAttr(ptr_psi_term psiTerm,char *attributeName)
334 {
335  ptr_node nodeAttr;
336  ptr_psi_term psiValue;
337 
338 
339  deref_ptr(psiTerm);
340  nodeAttr=find(FEATCMP,attributeName,psiTerm->attr_list);
341  if(!nodeAttr) {
342  Errorline("in GetIntAttr: didn't find %s on %P\n",
343  attributeName,
344  psiTerm);
345  exit_life(TRUE);
346  }
347 
348  psiValue=(ptr_psi_term)nodeAttr->data;
349  deref_ptr(psiValue);
350  if(psiValue->value_3)
351  return *(REAL *) psiValue->value_3;
352  else {
353  /* Errorline("in GetIntAttr: no value!\n"); */
354  return -34466; /* Real nasty hack for now RM: Apr 23 1993 */
355  }
356 }
357 
367 ptr_psi_term GetPsiAttr(ptr_psi_term psiTerm,char *attributeName)
368 {
369  ptr_node nodeAttr;
370  ptr_psi_term psiValue;
371 
372 
373  if((nodeAttr = find(FEATCMP,attributeName,psiTerm->attr_list)) == NULL)
374  {
375  Errorline("in GetPsiAttr: no attribute name on psi-term ?\n");
376  exit_life(TRUE);
377  }
378 
379  if((psiValue =(ptr_psi_term) nodeAttr->data) == NULL)
380  {
381  Errorline("in GetPsiAttr: no value on psi-term ?\n");
382  exit_life(TRUE);
383  }
384 
385  return psiValue;
386 }
387 
400 static void ResizePixmap(ptr_psi_term psi_window,Display *display,Window window,unsigned long width,unsigned long height)
401 {
402  Pixmap pixmap;
403  GC pixmapGC;
404  ptr_psi_term psiPixmap,psiPixmapGC;
405  XGCValues gcvalues;
406  XWindowAttributes attr;
407  ptr_psi_term psi_gc;
408 
409 
410  /* free the old pixmap */
411  psiPixmap = GetPsiAttr(psi_window,"pixmap");
412  psiPixmapGC=NULL;
413 
414  if((pixmap = GetIntAttr(psiPixmap,"id")) != 0)
415  {
416  /* change the pixmap */
417  XFreePixmap(display,pixmap);
418  /* change the pixmap'gc too,because the gc is created on the pixmap ! */
419 
420  psiPixmapGC = GetPsiAttr(psiPixmap,"graphic_context");
421 
422  /* RM: Jun 24 1993 */
423  pixmapGC=(GC)GetIntAttr(psiPixmapGC,"id");
424  if(pixmapGC)
425  XFreeGC(display,pixmapGC);
426 
427  bk_stack_add_int_attr(psiPixmap,"id",(long)NULL);
428  bk_stack_add_int_attr(psiPixmapGC,"id",(long)NULL);
429  }
430 
431  /* init a new pixmap on the window */
432  XGetWindowAttributes(display,window,&attr);
433  if((pixmap = XCreatePixmap(display,window,
434  attr.width+1,attr.height+1,
435  attr.depth)) != 0)
436  {
437  bk_stack_add_int_attr(psiPixmap,"id",(long)pixmap);
438  gcvalues.cap_style = CapRound;
439  gcvalues.join_style = JoinRound;
440  pixmapGC = XCreateGC(display,pixmap,
441  GCJoinStyle|GCCapStyle,&gcvalues);
442 
443  /* RM: Jun 24 1993 */
444  if(psiPixmapGC)
445  bk_stack_add_int_attr(psiPixmapGC,"id",(long)pixmapGC); // add cast DJD
446  else
447  psiPixmapGC=NewPsi(xgc,"id",(long)pixmapGC); // add cast DJD
448  bk_change_psi_attr(psiPixmap,"graphic_context",psiPixmapGC);
449  }
450 }
451 
452 
463 static void FreeWindow(Display *display,ptr_psi_term psi_window)
464 {
465  ptr_psi_term psiPixmap;
466 
467 
468  XFreeGC(display,DrawableGC(psi_window));
470 
471  psiPixmap = GetPsiAttr(psi_window,"pixmap");
472  XFreeGC(display,DrawableGC(psiPixmap));
473  XFreePixmap(display,GetIntAttr(psiPixmap,"id"));
474 }
475 
476 
486 {
488  ptr_definition types[2];
489  char *display;
490  Display * connection;
491  ptr_psi_term psiConnection;
492 
493 
494  types[0] = quoted_string;
495  types[1] = xdisplay;
496 
497 
498  begin_builtin(xcOpenConnection,2,1,types);
499 
500  if(strcmp(STRG(0),""))
501  display =STRG(0);
502  else
503  display = NULL;
504 
505  if(connection = XOpenDisplay(display))
506  {
507  psiConnection = NewPsi(xdisplay,"id",(long)connection); // add cast DJD
508  push_goal(unify,psiConnection,args[1],NULL);
509 
510  success = TRUE;
511  }
512  else
513  {
514  Errorline("could not open connection in %P.\n",g);
515  success = FALSE;
516  }
517 
518  end_builtin();
519 }
520 
530 {
532  ptr_definition types[2];
533  Display *display;
534  ptr_psi_term psiRoot;
535 
536  types[0] = real;
537  types[1] = xdrawable;
538 
540 
541  display = DISP(0);
542 
543  psiRoot = NewPsi(xwindow,"id",(long)DefaultRootWindow(display)); // added cast DJD
544 
545  push_goal(unify,psiRoot,args[1],NULL);
546  success = TRUE;
547 
548  end_builtin();
549 }
550 
560 static long GetConnectionAttribute(Display *display,long attributeId,long *attribute)
561 {
562  switch(attributeId)
563  {
564  case 0:
565  *attribute =(unsigned long) ConnectionNumber(display);
566  break;
567  case 1:
568 #ifndef __alpha
569  *attribute = display->proto_major_version;
570 #endif
571  break;
572  case 2:
573 #ifndef __alpha
574  *attribute =(unsigned long)(display->proto_minor_version);
575 #endif
576  break;
577  case 3:
578  *attribute =(unsigned long) ServerVendor(display);
579  break;
580  case 4:
581  *attribute =(unsigned long) ImageByteOrder(display);
582  break;
583  case 5:
584  *attribute =(unsigned long) BitmapUnit(display);
585  break;
586  case 6:
587  *attribute =(unsigned long) BitmapPad(display);
588  break;
589  case 7:
590  *attribute =(unsigned long) BitmapBitOrder(display);
591  break;
592  case 8:
593  *attribute =(unsigned long) VendorRelease(display);
594  break;
595  case 9:
596 #ifndef __alpha
597  *attribute =(unsigned long)(display->qlen);
598 #endif
599  break;
600  case 10:
601  *attribute =(unsigned long) LastKnownRequestProcessed(display);
602  break;
603  case 11:
604 #ifndef __alpha
605  *attribute =(unsigned long)(display->request);
606 #endif
607  break;
608  case 12:
609  *attribute =(unsigned long) DisplayString(display);
610  break;
611  case 13:
612  *attribute =(unsigned long) DefaultScreen(display);
613  break;
614  case 14:
615 #ifndef __alpha
616  *attribute =(unsigned long)(display->min_keycode);
617 #endif
618  break;
619  case 15:
620 #ifndef __alpha
621  *attribute =(unsigned long)(display->max_keycode);
622 #endif
623  break;
624  default:
625  return FALSE;
626  break;
627  }
628 
629  return TRUE;
630 }
631 
642 {
644  ptr_definition types[3];
645  long attr;
646 
647  types[0] = real;
648  types[1] = real;
649  types[2] = real;
650 
652 
653  if(GetConnectionAttribute(DISP(0),DRAW(1),&attr))
654  {
655  unify_real_result(args[2],(REAL) attr);
656  success = TRUE;
657  }
658  else
659  {
660  Errorline("could not get connection attribute in %P.\n",g);
661  success = FALSE;
662  }
663 
664  end_builtin();
665 }
666 
677 static long GetScreenAttribute(Display *display,long screen,long attributeId,long *attribute)
678 {
679  Screen *s;
680 
681 
682  s = ScreenOfDisplay(display,screen);
683  switch(attributeId)
684  {
685  case 0:
686  *attribute =(unsigned long) DisplayOfScreen(s);
687  break;
688  case 1:
689  *attribute =(unsigned long) RootWindowOfScreen(s);
690  break;
691  case 2:
692  *attribute =(unsigned long) WidthOfScreen(s);
693  break;
694  case 3:
695  *attribute =(unsigned long) HeightOfScreen(s);
696  break;
697  case 4:
698  *attribute =(unsigned long) WidthMMOfScreen(s);
699  break;
700  case 5:
701  *attribute =(unsigned long) HeightMMOfScreen(s);
702  break;
703  case 6:
704  *attribute =(unsigned long) DefaultDepthOfScreen(s);
705  break;
706  case 7:
707  *attribute =(unsigned long) DefaultVisualOfScreen(s);
708  break;
709  case 8:
710  *attribute =(unsigned long) DefaultGCOfScreen(s);
711  break;
712  case 9:
713  *attribute =(unsigned long) DefaultColormapOfScreen(s);
714  break;
715  case 10:
716  *attribute =(unsigned long) WhitePixelOfScreen(s);
717  break;
718  case 11:
719  *attribute =(unsigned long) BlackPixelOfScreen(s);
720  break;
721  case 12:
722  *attribute =(unsigned long) MaxCmapsOfScreen(s);
723  break;
724  case 13:
725  *attribute =(unsigned long) MinCmapsOfScreen(s);
726  break;
727  case 14:
728  *attribute =(unsigned long) DoesBackingStore(s);
729  break;
730  case 15:
731  *attribute =(unsigned long) DoesSaveUnders(s);
732  break;
733  case 16:
734  *attribute =(unsigned long) EventMaskOfScreen(s);
735  break;
736  default:
737  return FALSE;
738  break;
739  }
740 
741  return TRUE;
742 }
743 
753 {
755  ptr_definition types[4];
756  long attr;
757 
758  types[0] = real;
759  types[1] = real;
760  types[2] = real;
761  types[3] = real;
762 
764 
765  if(GetScreenAttribute(DISP(0),DRAW(1),val[2],&attr))
766  {
767  unify_real_result(args[3],(REAL) attr);
768  success = TRUE;
769  }
770  else
771  {
772  Errorline("could not get screen attribute in %P.\n",g);
773  success = FALSE;
774  }
775 
776  end_builtin();
777 }
778 
788 {
790  ptr_definition types[1];
791 
792 
793  types[0] = real;
794 
795  begin_builtin(xcCloseConnection,1,1,types);
796 
797  XCloseDisplay(DISP(0));
798  success = TRUE;
799 
800  end_builtin();
801 }
802 
817 {
819  ptr_definition types[14];
820  Window window;
821  Pixmap life_icon;
822  XSizeHints hints;
823  XWindowChanges changes;
824  unsigned long changesMask;
825  XSetWindowAttributes attributes;
826  unsigned long attributesMask;
827  long j;
828  long permanent,show;
829  Display *display;
830  GC gc;
831  XGCValues gcvalues;
832  ptr_psi_term psiWindow;
833 
834  for(j = 0; j < 14; j++)
835  types[j] = real;
836  types[7]= quoted_string;
837  types[8]= quoted_string;
838  types[11]= boolean;
839  types[12]= boolean;
840 
841  begin_builtin(xcCreateSimpleWindow,14,13,types);
842 
843  permanent = val[11];
844  show = val[12];
845 
846  if(window = XCreateSimpleWindow(DISP(0),WIND(1),/* display,parent */
847  val[2],val[3],/* X,Y */
848  val[4],val[5],/* Width,Height */
849  val[9],val[10],/* BorderWidth,BorderColor */
850  val[6])) /* BackGround */
851  {
852  psiWindow = stack_psi_term(4);
853  psiWindow->type = xwindow;
854  bk_stack_add_int_attr(psiWindow,"id",(long)window); // added cast DJD
855 
856  /* attach the icon of life */
857  life_icon = XCreateBitmapFromData(DISP(0),window,life_icon_bits,
858  life_icon_width,life_icon_height);
859  /* set properties */
860 #if 0
861  hints.x = val[2];
862  hints.y = val[3];
863  hints.width =val[4] ;
864  hints.height = val[5];
865  hints.flags = PPosition | PSize;
866 #endif
867  hints.flags = 0;
868  XSetStandardProperties(DISP(0),window,
869  STRG(7),STRG(8),
870  life_icon,arg_v,arg_c,
871  &hints);
872 #if 0
873  changes.x = val[2];
874  changes.y = val[3];
875  changes.width =val[4] ;
876  changes.height = val[5];
877  changesMask = CWX | CWY | CWWidth | CWHeight;
878  display = DISP(0);
879  XReconfigureWMWindow(DISP(0),window,DefaultScreen(display),
880  changesMask,&changes);
881 #endif
882  /* set the background color */
883  XSetWindowBackground(DISP(0),window,val[6]);
884 #if 0
885  /* set the geometry before to show the window */
886  XMoveResizeWindow(DISP(0),window,
887  val[2],val[3],val[4],val[5]);
888 #endif
889  /* set the back pixel in order to have the color when deiconify */
890  attributes.background_pixel = val[6];
891  attributes.backing_pixel = val[6];
892  attributesMask = CWBackingPixel|CWBackPixel;
893  XChangeWindowAttributes(DISP(0),window,
894  attributesMask,&attributes);
895 
896  if(!permanent)
897  {
898  push_window(destroy_window,(long)DISP(0),window);
900  }
901  else
902  if(show)
903  push_window(show_window,(long)DISP(0),window);
904 
905 #if 0
906  /* map window is made in xCreateWindow(see xpred.lf) */
907  /* due to the flag overrideRedirect */
908  if(show)
909  x_show_window(DISP(0),window);
910 #endif
911 
912  /* create a GC on the window for the next outputs */
913  gcvalues.cap_style = CapRound;
914  gcvalues.join_style = JoinRound;
915  gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
916  bk_change_psi_attr(psiWindow,"graphic_context",
917  NewPsi(xgc,"id",(long)gc)); // added cast DJD
918 
919  /* init a display list on the window for the refresh window */
920  bk_change_psi_attr(psiWindow,"display_list",
921  NewPsi(xdisplaylist,"id",(long)x_display_list())); // added cast DJD
922 
923  /* init a pixmap on the window for the refresh mechanism */
924  bk_change_psi_attr(psiWindow,"pixmap",
925  NewPsi(xpixmap,"id",(long)NULL));
926  ResizePixmap(psiWindow,DISP(0),window,val[4],val[5]);
927 
928  push_goal(unify,psiWindow,args[13],NULL);
929  success = TRUE;
930  }
931  else
932  {
933  Errorline("could not create a simple window in %P.\n",g);
934  success = FALSE;
935  }
936 
937  end_builtin();
938 }
939 
940 /*****************************************************************/
941 #if 0
942 
943 /*xcCreateWindow is not used anymore since we use xcCreateSimpleWindow.
944  I just keep this code in case - jch - Thu Aug 6 16:11:23 MET DST 1992
945 */
957 long xcCreateWindow()
958 {
960  ptr_definition types[13];
961  Window window;
962  XWindowChanges changes;
963  unsigned long changesMask;
964  XSizeHints hints;
965  long j,permanent,show;
966  GC gc;
967  XGCValues gcvalues;
968 
969  for(j = 0; j < 13; j++)
970  types[j] = real;
971 
972  begin_builtin(xcCreateWindow,13,12,types);
973 
974  permanent = val[10];
975  show = val[11];
976 
977  if(window = XCreateWindow(DISP(0),WIND(1),/* display,parent */
978  val[2],val[3],/* X,Y */
979  val[4],val[5],/* Width,Height */
980  val[6],val[7],/* BorderWidth,Depth */
981  val[8],val[9],/* Class,Visual */
982  0,(XSetWindowAttributes *) NULL))
983  {
984  unify_real_result(args[12],(REAL) window);
985 
986  changes.x = val[2];
987  changes.y = val[3];
988  changes.width =val[4] ;
989  changes.height = val[5];
990  changesMask = CWX | CWY | CWWidth | CWHeight;
991  XConfigureWindow(DISP(0),window,changesMask,&changes);
992 
993  hints.x = val[2];
994  hints.y = val[3];
995  hints.width =val[4] ;
996  hints.height = val[5];
997  hints.flags = PPosition | PSize;
998  XSetNormalHints(DISP(0),window,&hints);
999 
1000  if(!permanent)
1001  {
1002  push_window(destroy_window,(long)DISP(0),window);
1004  }
1005  else
1006  if(show)
1007  push_window(show_window,(long)DISP(0),window);
1008 
1009  if(show)
1010  x_show_window(DISP(0),window);
1011 
1012  /* create a GC on the window for the next outputs */
1013  gcvalues.cap_style = CapRound;
1014  gcvalues.join_style = JoinRound;
1015  gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
1016  bk_stack_add_int_attr(args[12],"gc",gc);
1017 
1018  /* init a display list on the window for the refresh window */
1019  bk_stack_add_int_attr(args[12],"display_list",NULL);
1020 
1021  success = TRUE;
1022  }
1023  else
1024  {
1025  Errorline("could not create window in %P.\n",g);
1026  success = FALSE;
1027  }
1028 
1029  end_builtin();
1030 }
1031 
1032 #endif
1033 
1044 {
1046  ptr_definition types[8];
1047  long j;
1048  XSizeHints hints;
1049 
1050 
1051  for(j=0; j<8; j++)
1052  types[j] = real;
1053  types[1] = xwindow;
1054  types[2] = quoted_string;
1055  types[3] = quoted_string;
1056 
1058 
1059  hints.x = val[4];
1060  hints.y = val[5];
1061  hints.width = val[6] ;
1062  hints.height = val[7];
1063  hints.flags = PPosition | PSize;
1064 
1065  XSetStandardProperties(DISP(0),WIND(1),
1066  (char*)val[2],(char*)val[3],/* window title,icon title */
1067  None, /* icon pixmap */
1068  (char **) NULL,0, /* argv,argc */
1069  &hints);
1070 
1071  ResizePixmap(args[1],(Display *)val[0],val[1],val[6],val[7]);
1072 
1073  success = TRUE;
1074 
1075  end_builtin();
1076 
1077 }
1078 
1088 {
1090  ptr_definition types[6];
1091  int j,x,y;
1092  unsigned int w,h,bw,d;
1093  Window r;
1094 
1095  for(j=0; j<6; j++)
1096  types[j] = real;
1097  types[1] = xdrawable;
1098 
1100 
1101  if(XGetGeometry(DISP(0),DRAW(1),
1102  &r,&x,&y,&w,&h,&bw,&d))
1103  {
1104  unify_real_result(args[2],(REAL) x);
1105  unify_real_result(args[3],(REAL) y);
1106  unify_real_result(args[4],(REAL) w);
1107  unify_real_result(args[5],(REAL) h);
1108  success = TRUE;
1109  }
1110  else
1111  {
1112  Errorline("could not get the geometry in %P.\n",g);
1113  success = FALSE;
1114  }
1115 
1116  end_builtin();
1117 }
1118 
1129 static long GetWindowAttribute(Display *display,long window,long attributeId,long *attribute)
1130 {
1131  XWindowAttributes windowAttributes;
1132 
1133 
1134  XGetWindowAttributes(display,window,&windowAttributes);
1135  switch(attributeId)
1136  {
1137  case 0:
1138  *attribute = windowAttributes.x;
1139  break;
1140  case 1:
1141  *attribute = windowAttributes.y;
1142  break;
1143  case 2:
1144  *attribute = windowAttributes.width;
1145  break;
1146  case 3:
1147  *attribute = windowAttributes.height;
1148  break;
1149  case 4:
1150  *attribute = windowAttributes.border_width;
1151  break;
1152  case 5:
1153  *attribute = windowAttributes.depth;
1154  break;
1155  case 6:
1156  *attribute = windowAttributes.root;
1157  break;
1158  case 7:
1159  *attribute =(unsigned long)windowAttributes.screen;
1160  break;
1161  case 8:
1162  *attribute =(unsigned long)windowAttributes.visual;
1163  break;
1164  case 9:
1165  *attribute = windowAttributes.class;
1166  break;
1167  case 10:
1168  *attribute = windowAttributes.all_event_masks;
1169  break;
1170  case 11:
1171  *attribute = windowAttributes.bit_gravity;
1172  break;
1173  case 12:
1174  *attribute = windowAttributes.win_gravity;
1175  break;
1176  case 13:
1177  *attribute = windowAttributes.backing_store;
1178  break;
1179  case 14:
1180  *attribute = windowAttributes.backing_planes;
1181  break;
1182  case 15:
1183  *attribute = windowAttributes.backing_pixel;
1184  break;
1185  case 16:
1186  *attribute = windowAttributes.override_redirect;
1187  break;
1188  case 17:
1189  *attribute = windowAttributes.save_under;
1190  break;
1191  case 18:
1192  *attribute = windowAttributes.your_event_mask;
1193  break;
1194  case 19:
1195  *attribute = windowAttributes.do_not_propagate_mask;
1196  break;
1197  case 20:
1198  *attribute = windowAttributes.colormap;
1199  break;
1200  case 21:
1201  *attribute = windowAttributes.map_installed;
1202  break;
1203  case 22:
1204  *attribute = windowAttributes.map_state;
1205  break;
1206  default:
1207  return FALSE;
1208  break;
1209  }
1210  return TRUE;
1211 }
1212 
1222 {
1224  ptr_definition types[4];
1225  long attr;
1226 
1227 
1228  types[0] = real;
1229  types[1] = xwindow;
1230  types[2] = real;
1231  types[3] = real;
1232 
1234 
1235  if(GetWindowAttribute(DISP(0),WIND(1),val[2],&attr))
1236  {
1237  unify_real_result(args[3],(REAL) attr);
1238  success = TRUE;
1239  }
1240  else
1241  {
1242  Errorline("could not get a window attribute in %P.\n",g);
1243  success = FALSE;
1244  }
1245 
1246  end_builtin();
1247 }
1248 
1258 {
1260  ptr_definition types[6];
1261  long j;
1262 
1263  for(j=0; j<6; j++)
1264  types[j] = real;
1265  types[1] = xdrawable;
1266 
1268 
1269  XMoveResizeWindow(DISP(0),DRAW(1),
1270  val[2],val[3],val[4],val[5]);
1271 
1272  /* modify the pixmap */
1273  ResizePixmap(args[1],(Display *)val[0],val[1],val[4],val[5]);
1274 
1275  success = TRUE;
1276 
1277  end_builtin();
1278 }
1279 
1288 long xcMoveWindow() /* RM: May 4 1993 */
1289 {
1291  ptr_definition types[4];
1292  long j;
1293 
1294  for(j=0; j<4; j++)
1295  types[j] = real;
1296  types[1] = xdrawable;
1297 
1298  begin_builtin(xcMoveWindow,4,4,types);
1299 
1300  XMoveWindow(DISP(0),DRAW(1), val[2],val[3]);
1301 
1302  success = TRUE;
1303 
1304  end_builtin();
1305 }
1306 
1318 static long SetWindowAttribute(ptr_psi_term psi_window,Display *display,Drawable window,unsigned long attributeId,unsigned long attribute)
1319 {
1320  XSetWindowAttributes attributes;
1321  XWindowChanges changes;
1322  unsigned long attributesMask = 0;
1323  unsigned long changesMask = 0;
1324  long backgroundChange = FALSE;
1325  long sizeChange = FALSE;
1326  unsigned int width,height;
1327  int x,y;
1328  unsigned int bw,d;
1329  Window r;
1330 
1331  switch(attributeId)
1332  {
1333  case 0:
1334  changes.x = attribute;
1335  changesMask |= CWX;
1336  break;
1337  case 1:
1338  changes.y = attribute;
1339  changesMask |= CWY;
1340  break;
1341  case 2:
1342  changes.width = attribute;
1343  changesMask |= CWWidth;
1344  XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
1345  width = attribute;
1346  sizeChange = TRUE;
1347  break;
1348  case 3:
1349  changes.height = attribute;
1350  changesMask |= CWHeight;
1351  XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
1352  height = attribute;
1353  sizeChange = TRUE;
1354  break;
1355  case 4:
1356  changes.border_width = attribute;
1357  changesMask |= CWBorderWidth;
1358  break;
1359  case 11:
1360  attributes.bit_gravity = attribute;
1361  attributesMask |= CWBitGravity;
1362  break;
1363  case 12:
1364  attributes.win_gravity = attribute;
1365  attributesMask |= CWWinGravity;
1366  break;
1367  case 13:
1368  attributes.backing_store = attribute;
1369  attributesMask |= CWBackingStore;
1370  break;
1371  case 14:
1372  attributes.backing_planes = attribute;
1373  attributesMask |= CWBackingPlanes;
1374  break;
1375  case 15:
1376  attributes.backing_pixel = attribute;
1377  attributesMask |= CWBackingPixel;
1378  break;
1379  case 16:
1380  attributes.override_redirect = attribute;
1381  attributesMask |= CWOverrideRedirect;
1382  break;
1383  case 17:
1384  attributes.save_under = attribute;
1385  attributesMask |= CWSaveUnder;
1386  break;
1387  case 18:
1388  attributes.event_mask = attribute;
1389  attributesMask |= CWEventMask;
1390  break;
1391  case 19:
1392  attributes.do_not_propagate_mask = attribute;
1393  attributesMask |= CWDontPropagate;
1394  break;
1395  case 20:
1396  attributes.colormap = attribute;
1397  attributesMask |= CWColormap;
1398  break;
1399  case 23:
1400  changes.sibling = attribute;
1401  changesMask |= CWSibling;
1402  break;
1403  case 24:
1404  changes.stack_mode = attribute;
1405  changesMask |= CWStackMode;
1406  break;
1407  case 25:
1408  attributes.background_pixmap = attribute;
1409  attributesMask |= CWBackPixmap;
1410  break;
1411  case 26:
1412  attributes.background_pixel = attribute;
1413  attributesMask |= CWBackPixel;
1414  backgroundChange = TRUE;
1415 
1416  /* change the backing_pixel in order to fill the pixmap with */
1417  attributes.backing_pixel = attribute;
1418  attributesMask |= CWBackingPixel;
1419  break;
1420  case 27:
1421  attributes.border_pixmap = attribute;
1422  attributesMask |= CWBorderPixmap;
1423  break;
1424  case 28:
1425  attributes.border_pixel = attribute;
1426  attributesMask |= CWBorderPixel;
1427  break;
1428  case 29:
1429  attributes.cursor = attribute;
1430  attributesMask |= CWCursor;
1431  break;
1432  default:
1433  return FALSE;
1434  break;
1435  }
1436 
1437  if(changesMask)
1438  XConfigureWindow(display,window,changesMask,&changes);
1439 
1440  if(attributesMask)
1441  XChangeWindowAttributes(display,window,attributesMask,&attributes);
1442 
1443  if(backgroundChange)
1444  XClearArea(display,window,0,0,0,0,True);
1445 
1446  if(sizeChange)
1447  ResizePixmap(psi_window,display,window,width,height);
1448 
1449  return TRUE;
1450 }
1451 
1461 {
1463  ptr_definition types[4];
1464 
1465  types[0] = real;
1466  types[1] = xwindow;
1467  types[2] = real;
1468  types[3] = real;
1469 
1471 
1472  if(SetWindowAttribute(args[1],(Display *)val[0],val[1],val[2],val[3]))
1473  {
1474  XSync(DISP(0),0);
1475  success = TRUE;
1476  }
1477  else
1478  {
1479  Errorline("could not set window attribute in %P.\n",g);
1480  success = FALSE;
1481  }
1482 
1483  end_builtin();
1484 }
1485 
1495 
1496 {
1498  ptr_definition types[2];
1499 
1500  types[0] = real;
1501  types[1] = real;
1502 
1503  begin_builtin(xcMapWindow,2,2,types);
1504 
1505  XMapWindow(DISP(0),WIND(1));
1506  XSync(DISP(0),0);
1507 
1508  push_window(hide_window,(long)DISP(0),val[1]);
1509  success = TRUE;
1510 
1511  end_builtin();
1512 }
1513 
1523 {
1525  ptr_definition types[2];
1526 
1527  types[0] = real;
1528  types[1] = real;
1529 
1530  begin_builtin(xcRaiseWindow,2,2,types);
1531 
1532  XRaiseWindow(DISP(0),WIND(1));
1533  XSync(DISP(0),0);
1534 
1535  push_window(hide_window,(long)DISP(0),WIND(1));
1536  success = TRUE;
1537 
1538  end_builtin();
1539 }
1540 
1550 {
1552  ptr_definition types[2];
1553 
1554  types[0] = real;
1555  types[1] = real;
1556 
1557  begin_builtin(xcUnmapWindow,2,2,types);
1558 
1559  XUnmapWindow(DISP(0),WIND(1));
1560  XSync(DISP(0),0);
1561 
1562  push_window(show_window,(long)DISP(0),WIND(1));
1563  success = TRUE;
1564 
1565  end_builtin();
1566 }
1567 
1568 /*** RM 8/12/92 START ***/
1578 {
1580  ptr_definition types[2];
1581 
1582  types[0] = real;
1583  types[1] = real;
1584 
1585  begin_builtin(xcMapSubwindow,2,2,types);
1586 
1587  XMapSubwindows(DISP(0),WIND(1));
1588  XSync(DISP(0),0);
1589 
1590  push_window(hide_subwindow,(long)DISP(0),WIND(1));
1591  success = TRUE;
1592 
1593  end_builtin();
1594 }
1595 
1605 {
1607  ptr_definition types[2];
1608 
1609  types[0] = real;
1610  types[1] = real;
1611 
1612  begin_builtin(xcUnmapSubwindows,2,2,types);
1613 
1614  XUnmapSubwindows(DISP(0),WIND(1));
1615  XSync(DISP(0),0);
1616 
1617  push_window(show_subwindow,(long)DISP(0),WIND(1));
1618  success = TRUE;
1619 
1620  end_builtin();
1621 }
1622 
1623 /*** RM 8/12/82 END ***/
1624 
1634 {
1636  ptr_definition types[2];
1637 
1638  types[0] = real;
1639  types[1] = xwindow;
1640 
1641  begin_builtin(xcClearWindow,2,2,types);
1642 
1643  XClearWindow(DISP(0),WIND(1));
1644 XSync(DISP(0),0);
1645 
1647  success = TRUE;
1648 
1649  end_builtin();
1650 }
1651 
1662 {
1664  ptr_definition types[4];
1665  long j;
1666 
1667  for(j=0; j<4; j++)
1668  types[j] = real;
1669  types[1] = xdrawable;
1670 
1672 
1673  /* modify the pixmap */
1674  ResizePixmap(args[1],(Display *)val[0],val[1],val[2],val[3]);
1675 
1676  success = TRUE;
1677 
1678  end_builtin();
1679 }
1680 
1690 {
1692  ptr_definition types[3];
1693 
1694  types[0] = real;
1695  types[1] = real;
1696  types[2] = real;
1697 
1698  begin_builtin(xcSelectInput,3,3,types);
1699 
1700  XSelectInput(DISP(0),WIND(1),val[2]);
1701  success = TRUE;
1702 
1703  end_builtin();
1704 }
1705 
1715 {
1717  ptr_definition types[2];
1718  Pixmap pixmap;
1719  ptr_psi_term psiPixmap;
1720 
1721  types[0] = real;
1722  types[1] = xwindow;
1723 
1724  begin_builtin(xcRefreshWindow,2,2,types);
1725 
1726  psiPixmap = GetPsiAttr(args[1],"pixmap");
1727  if((pixmap =(Pixmap) GetIntAttr(psiPixmap,"id")) != 0)
1728  x_refresh_window((Display *)val[0],val[1],pixmap,
1729  DrawableGC(psiPixmap),
1730  (ListHeader *)WindowDisplayList(args[1]));
1731  else
1732  x_refresh_window((Display *)val[0],val[1],val[1],
1733  DrawableGC(args[1]),
1734  (ListHeader *)WindowDisplayList(args[1]));
1735 
1736  success = TRUE;
1737 
1738  end_builtin();
1739 }
1740 
1750 {
1752  ptr_definition types[3];
1753 
1754  types[0] = real;
1755  types[1] = xwindow;
1756  types[2] = quoted_string;
1757 
1758  begin_builtin(xcPostScriptWindow,3,3,types);
1759 
1760  success = x_postscript_window((Display *) val[0],val[1],(ListHeader *)GetIntAttr(GetPsiAttr(args[1],"display_list"),"id"),(char *)val[2]);
1761 
1762  end_builtin();
1763 }
1764 
1774 {
1776  ptr_definition types[2];
1777  ptr_psi_term psi;
1778 
1779  types[0] = real;
1780  types[1] = xwindow;
1781 
1782  begin_builtin(xcDestroyWindow,2,2,types);
1783 
1784  psi = GetPsiAttr(args[1],"permanent");
1785  if(!strcmp(psi->type->keyword->symbol,"true"))
1786  {
1787  Errorline("cannot destroy a permanent window.\n");
1788  exit_life(TRUE); /* was: main_loop_ok=FALSE; - jch */
1789  success = FALSE;
1790  }
1791  else
1792  {
1793  FreeWindow((Display *)val[0],args[1]);
1794  XDestroyWindow(DISP(0),WIND(1));
1795 XSync(DISP(0),0);
1796  clean_undo_window((long)DISP(0),WIND(1));
1797  success = TRUE;
1798  }
1799 
1800  end_builtin();
1801 }
1802 
1811 {
1813  ptr_definition types[3];
1814  GC gc;
1815  XGCValues GCvalues;
1816 
1817  types[0] = real;
1818  types[1] = xdrawable;
1819  types[2] = real;
1820 
1821  begin_builtin(xcCreateGC,3,2,types);
1822 
1823  if(gc = XCreateGC(DISP(0),WIND(1),0,&GCvalues)) /* RM: Feb 7 1994 */
1824  {
1825  unify_real_result(args[2],(REAL)(unsigned long) gc);
1826  success = TRUE;
1827  }
1828  else
1829  {
1830  Errorline("could not create gc in %P.\n",g);
1831  success = FALSE;
1832  }
1833 
1834  end_builtin();
1835 }
1836 
1846 static long GetGCAttribute(GC gc,long attributeId,long *attribute)
1847 {
1848 #ifndef __alpha
1849  switch(attributeId)
1850  {
1851  case 0:
1852  *attribute = gc->values.function;
1853  break;
1854  case 1:
1855  *attribute = gc->values.plane_mask;
1856  break;
1857  case 2:
1858  *attribute = gc->values.foreground;
1859  break;
1860  case 3:
1861  *attribute = gc->values.background;
1862  break;
1863  case 4:
1864  *attribute = gc->values.line_width;
1865  break;
1866  case 5:
1867  *attribute = gc->values.line_style;
1868  break;
1869  case 6:
1870  *attribute = gc->values.cap_style;
1871  break;
1872  case 7:
1873  *attribute = gc->values.join_style;
1874  break;
1875  case 8:
1876  *attribute = gc->values.fill_style;
1877  break;
1878  case 9:
1879  *attribute = gc->values.fill_rule;
1880  break;
1881  case 10:
1882  *attribute = gc->values.tile;
1883  break;
1884  case 11:
1885  *attribute = gc->values.stipple;
1886  break;
1887  case 12:
1888  *attribute = gc->values.ts_x_origin;
1889  break;
1890  case 13:
1891  *attribute = gc->values.ts_y_origin;
1892  break;
1893  case 14:
1894  *attribute = gc->values.font;
1895  break;
1896  case 15:
1897  *attribute = gc->values.subwindow_mode;
1898  break;
1899  case 16:
1900  *attribute = gc->values.graphics_exposures;
1901  break;
1902  case 17:
1903  *attribute = gc->values.clip_x_origin;
1904  break;
1905  case 18:
1906  *attribute = gc->values.clip_y_origin;
1907  break;
1908  case 19:
1909  *attribute = gc->values.clip_mask;
1910  break;
1911  case 20:
1912  *attribute = gc->values.dash_offset;
1913  break;
1914  case 21:
1915  *attribute =(unsigned char)(gc->values.dashes);
1916  break;
1917  case 22:
1918  *attribute = gc->values.arc_mode;
1919  break;
1920  case 23:
1921  *attribute = gc->rects;
1922  break;
1923  case 24:
1924  *attribute = gc->dashes;
1925  break;
1926  default:
1927  return FALSE;
1928  break;
1929  }
1930 #endif
1931  return TRUE;
1932 }
1933 
1943 {
1945  ptr_definition types[3];
1946  long attr;
1947 
1948  types[0] = real;
1949  types[1] = real;
1950  types[2] = real;
1951 
1952  begin_builtin(xcGetGCAttribute,3,2,types);
1953 
1954  if(GetGCAttribute((GC)DISP(0),(long)GCVAL(1),&attr))
1955  {
1956  unify_real_result(args[2],(REAL) attr);
1957  success = TRUE;
1958  }
1959  else
1960  {
1961  Errorline("could not get gc attribute in %P.\n",g);
1962  success = FALSE;
1963  }
1964 
1965  end_builtin();
1966 }
1967 
1978 static long SetGCAttribute(Display *display,GC gc,long attributeId,long attribute)
1979 {
1980  XGCValues attributes;
1981  unsigned long attributesMask = 0;
1982 
1983  switch(attributeId)
1984  {
1985  case 0:
1986  attributes.function = attribute;
1987  attributesMask |= GCFunction;
1988  break;
1989  case 1:
1990  attributes.plane_mask = attribute;
1991  attributesMask |= GCPlaneMask;
1992  break;
1993  case 2:
1994  attributes.foreground = attribute;
1995  attributesMask |= GCForeground;
1996  break;
1997  case 3:
1998  attributes.background = attribute;
1999  attributesMask |= GCBackground;
2000  break;
2001  case 4:
2002  attributes.line_width = attribute;
2003  attributesMask |= GCLineWidth;
2004  break;
2005  case 5:
2006  attributes.line_style = attribute;
2007  attributesMask |= GCLineStyle;
2008  break;
2009  case 6:
2010  attributes.cap_style = attribute;
2011  attributesMask |= GCCapStyle;
2012  break;
2013  case 7:
2014  attributes.join_style = attribute;
2015  attributesMask |= GCJoinStyle;
2016  break;
2017  case 8:
2018  attributes.fill_style = attribute;
2019  attributesMask |= GCFillStyle;
2020  break;
2021  case 9:
2022  attributes.fill_rule = attribute;
2023  attributesMask |= GCFillRule;
2024  break;
2025  case 10:
2026  attributes.tile = attribute;
2027  attributesMask |= GCTile;
2028  break;
2029  case 11:
2030  attributes.stipple = attribute;
2031  attributesMask |= GCStipple;
2032  break;
2033  case 12:
2034  attributes.ts_x_origin = attribute;
2035  attributesMask |= GCTileStipXOrigin;
2036  break;
2037  case 13:
2038  attributes.ts_y_origin = attribute;
2039  attributesMask |= GCTileStipYOrigin;
2040  break;
2041  case 14:
2042  attributes.font = attribute;
2043  attributesMask |= GCFont;
2044  break;
2045  case 15:
2046  attributes.subwindow_mode = attribute;
2047  attributesMask |= GCSubwindowMode;
2048  break;
2049  case 16:
2050  attributes.graphics_exposures = attribute;
2051  attributesMask |= GCGraphicsExposures;
2052  break;
2053  case 17:
2054  attributes.clip_x_origin = attribute;
2055  attributesMask |= GCClipXOrigin;
2056  break;
2057  case 18:
2058  attributes.clip_y_origin = attribute;
2059  attributesMask |= GCClipYOrigin;
2060  break;
2061  case 19:
2062  attributes.clip_mask = attribute;
2063  attributesMask |= GCClipMask;
2064  break;
2065  case 20:
2066  attributes.dash_offset = attribute;
2067  attributesMask |= GCDashOffset;
2068  break;
2069  case 21:
2070  attributes.dashes =(char)(0xFF & attribute);
2071  attributesMask |= GCDashList;
2072  break;
2073  case 22:
2074  attributes.arc_mode = attribute;
2075  attributesMask |= GCArcMode;
2076  break;
2077  default:
2078  return FALSE;
2079  break;
2080  }
2081 
2082  XChangeGC(display,gc,attributesMask,&attributes);
2083  return TRUE;
2084 }
2085 
2095 {
2097  ptr_definition types[4];
2098 
2099 
2100  types[0] = real;
2101  types[1] = real;
2102  types[2] = real;
2103  types[3] = real;
2104 
2105  begin_builtin(xcSetGCAttribute,4,4,types);
2106 
2107  if(SetGCAttribute((Display *)DISP(0),GCVAL(1),val[2],val[3]))
2108  success = TRUE;
2109  else
2110  {
2111  Errorline("could not set gc attribute in %P.\n",g);
2112  success = FALSE;
2113  }
2114 
2115  end_builtin();
2116 }
2117 
2127 {
2129  ptr_definition types[2];
2130 
2131  types[0] = real;
2132  types[1] = real;
2133 
2134  begin_builtin(xcDestroyGC,2,2,types);
2135 
2136  XFreeGC(DISP(0),GCVAL(1));
2137  success = TRUE;
2138 
2139  end_builtin();
2140 }
2141 
2151 {
2153  ptr_definition types[6];
2154  long j;
2155  XColor color;
2156 
2157  for(j=0; j<6; j++)
2158  types[j] = real;
2159 
2160  begin_builtin(xcRequestColor,6,5,types);
2161 
2162  color.red =(val[2]) << 8;
2163  color.green =(val[3]) << 8;
2164  color.blue =(val[4]) << 8;
2165  color.flags = DoRed|DoGreen|DoBlue;
2166 
2167  if(XAllocColor(DISP(0),CMAP(1),&color))
2168  {
2169  unify_real_result(args[5],(REAL) color.pixel);
2170  success = TRUE;
2171  }
2172  else
2173  {
2174  Errorline("could not request a color in %P.\n",g);
2175  success = FALSE;
2176  }
2177 
2178  end_builtin();
2179 }
2180 
2190 {
2192  ptr_definition types[4];
2193  long j;
2194  XColor cell,rgb;
2195 
2196  types[0] = real;
2197  types[1] = real;
2198  types[2] = quoted_string;
2199  types[3] = real;
2200 
2202 
2203  if(XAllocNamedColor(DISP(0),CMAP(1),STRG(2),&cell,&rgb))
2204  {
2205  unify_real_result(args[3],(REAL) cell.pixel);
2206  success = TRUE;
2207  }
2208  else
2209  {
2210  Errorline("could not request a named color in %P.\n",g);
2211  success = FALSE;
2212  }
2213 
2214  end_builtin();
2215 }
2216 
2226 {
2228  ptr_definition types[3];
2229  long j;
2230  unsigned long pixel;
2231 
2232  for(j=0; j<3; j++)
2233  types[j] = real;
2234 
2235  begin_builtin(xcFreeColor,3,3,types);
2236 
2237  pixel = val[2];
2238  XFreeColors(DISP(0),CMAP(1),&pixel,1,0);
2239  success = TRUE;
2240 
2241  end_builtin();
2242 }
2243 
2254 {
2256  ptr_definition types[9];
2257  long j;
2258  GC gc;
2259 
2260  for(j = 0; j < 9; j++)
2261  types[j] = real;
2262  types[1] = xdrawable;
2263 
2264  begin_builtin(xcDrawLine,9,9,types);
2265 
2266  gc = DrawableGC(args[1]);
2267  x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],xDefaultFont);
2268 
2269  XDrawLine(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
2270  val[2],val[3],val[4],val[5]); /* X0,Y0,X1,Y1 */
2271 
2272  x_record_line((ListHeader *)WindowDisplayList(args[1]),DRAW_LINE,
2273  val[2],val[3],val[4],val[5],
2274  val[6],val[7],val[8]);
2275 
2276 XSync(DISP(0),0);
2277  success = TRUE;
2278 
2279  end_builtin();
2280 }
2281 
2292 {
2293  include_var_builtin(11);
2294  ptr_definition types[11];
2295  long j;
2296  GC gc;
2297 
2298  for(j = 0; j < 11; j++)
2299  types[j] = real;
2300  types[1] = xdrawable;
2301 
2302  begin_builtin(xcDrawArc,11,11,types);
2303 
2304  gc = DrawableGC(args[1]);
2305  x_set_gc((Display *)val[0],gc,val[8],val[9],val[10],xDefaultFont);
2306 
2307  XDrawArc(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
2308  val[2],val[3],val[4],val[5], /* X,Y,Width,Height */
2309  val[6],val[7]); /* StartAngle,ArcAngle */
2310 
2311  x_record_arc((ListHeader *)WindowDisplayList(args[1]),DRAW_ARC,
2312  val[2],val[3],val[4],val[5],
2313  val[6],val[7],val[8],val[9],val[10]);
2314 
2315 XSync(DISP(0),0);
2316  success = TRUE;
2317 
2318  end_builtin();
2319 }
2320 
2331 {
2333  ptr_definition types[9];
2334  long j;
2335  GC gc;
2336 
2337  for(j = 0; j < 9; j++)
2338  types[j] = real;
2339  types[1] = xdrawable;
2340 
2341  begin_builtin(xcDrawRectangle,9,9,types);
2342 
2343  gc = DrawableGC(args[1]);
2344  x_set_gc((Display *)val[0],gc,val[6],val[7],val[8],xDefaultFont);
2345 
2346  XDrawRectangle(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
2347  val[2],val[3],val[4],val[5]); /* X,Y,Width,Height */
2348 
2349  x_record_rectangle((ListHeader *)WindowDisplayList(args[1]),DRAW_RECTANGLE,
2350  val[2],val[3],val[4],val[5],
2351  val[6],val[7],val[8]);
2352 
2353 XSync(DISP(0),0);
2354  success = TRUE;
2355 
2356  end_builtin();
2357 }
2358 
2369 {
2371  ptr_definition types[8];
2372  long j;
2373  GC gc;
2374 
2375  for(j = 0; j < 8; j++)
2376  types[j] = real;
2377  types[1] = xdrawable;
2378 
2379  begin_builtin(xcFillRectangle,8,8,types);
2380 
2381  gc = DrawableGC(args[1]);
2382  x_set_gc((Display *)val[0],gc,val[6],val[7],xDefaultLineWidth,xDefaultFont);
2383 
2384  XFillRectangle(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
2385  val[2],val[3],val[4],val[5]); /* X,Y,Width,Height */
2386 
2387  x_record_rectangle((ListHeader *)WindowDisplayList(args[1]),FILL_RECTANGLE,
2388  val[2],val[3],val[4],val[5],
2389  val[6],val[7],
2391 
2392 XSync(DISP(0),0);
2393  success = TRUE;
2394 
2395  end_builtin();
2396 }
2397 
2408 {
2409  include_var_builtin(10);
2410  ptr_definition types[10];
2411  long j;
2412  GC gc;
2413 
2414  for(j = 0; j < 10; j++)
2415  types[j] = real;
2416  types[1] = xdrawable;
2417 
2418  begin_builtin(xcFillArc,10,10,types);
2419 
2420  gc = DrawableGC(args[1]);
2421  x_set_gc((Display *)val[0],gc,val[8],val[9],xDefaultLineWidth,xDefaultFont);
2422 
2423  XFillArc(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
2424  val[2],val[3],val[4],val[5], /* X,Y,Width,Height */
2425  val[6],val[7]); /* StartAngle,ArcAngle */
2426 
2427  x_record_arc((ListHeader *)WindowDisplayList(args[1]),FILL_ARC,
2428  val[2],val[3],val[4],val[5],
2429  val[6],val[7],val[8],val[9],
2431 
2432 XSync(DISP(0),0);
2433  success = TRUE;
2434 
2435  end_builtin();
2436 }
2446 {
2448  ptr_definition types[2];
2449  long Points;
2450 
2451  types[0] = real;
2452  types[1] = real;
2453 
2454  begin_builtin(xcPointsAlloc,2,1,types);
2455  Points =(long) malloc((val [0]) * 2 * sizeof(short));
2456  unify_real_result(args[1],(REAL) Points);
2457 
2458  success = TRUE;
2459 
2460  end_builtin();
2461 }
2462 
2472 {
2474  ptr_definition types[3];
2475  short *Points;
2476 
2477  types[0] = real;
2478  types[1] = real;
2479  types[2] = real;
2480 
2481  begin_builtin(xcCoordPut,3,3,types);
2482 
2483  Points =(short *) val [0];
2484  Points += val[1];
2485  *Points = val[2];
2486 
2487  success = TRUE;
2488 
2489  end_builtin();
2490 }
2491 
2501 {
2503  ptr_definition types[1];
2504 
2505  types[0] = real;
2506 
2507  begin_builtin(xcPointsFree,1,1,types);
2508  free((void *)val [0]);
2509  success = TRUE;
2510 
2511  end_builtin();
2512 }
2513 
2524 {
2526  ptr_definition types[7];
2527  long j;
2528  GC gc;
2529 
2530  for(j = 0; j < 7; j++)
2531  types[j] = real;
2532  types[1] = xdrawable;
2533 
2534  begin_builtin(xcDrawPolygon,7,7,types);
2535 
2536  gc = DrawableGC(args[1]);
2537  x_set_gc((Display *)val[0],gc,val[4],val[5],val[6],xDefaultFont);
2538 
2539  XDrawLines(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
2540  (XPoint *)val[2],val[3],CoordModeOrigin); /* Points,NbPoints,mode */
2541 
2542  x_record_polygon((ListHeader *)WindowDisplayList(args[1]),DRAW_POLYGON,
2543  (XPoint *)val[2],val[3],val[4],val[5],val[6]);
2544 
2545 XSync(DISP(0),0);
2546  success = TRUE;
2547 
2548  end_builtin();
2549 }
2559 {
2561  ptr_definition types[6];
2562  long j;
2563  GC gc;
2564 
2565  for(j = 0; j < 6; j++)
2566  types[j] = real;
2567  types[1] = xdrawable;
2568 
2569  begin_builtin(xcFillPolygon,6,6,types);
2570 
2571  gc = DrawableGC(args[1]);
2572  x_set_gc((Display *)val[0],gc,val[4],val[5],xDefaultLineWidth,xDefaultFont);
2573 
2574  XFillPolygon(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
2575  (XPoint *)val[2],val[3], /* Points,NbPoints */
2576  Complex,CoordModeOrigin); /* shape,mode */
2577 
2578  x_record_polygon((ListHeader *)WindowDisplayList(args[1]),FILL_POLYGON,
2579  (XPoint *)val[2],val[3],val[4],val[5],
2581 
2582  XSync(DISP(0),0);
2583  success = TRUE;
2584 
2585  end_builtin();
2586 }
2587 
2597 {
2599  ptr_definition types[3];
2600  Font font;
2601 
2602  types[0] = real;
2603  types[1] = quoted_string;
2604  types[2] = real;
2605 
2606  begin_builtin(xcLoadFont,3,2,types);
2607 
2608  if(font=XLoadFont(DISP(0),STRG(1)))
2609  {
2610  unify_real_result(args[2],(REAL) font);
2611  XSync(DISP(0),0);
2612  success = TRUE;
2613  }
2614  else
2615  {
2616  Errorline("could not load a font in %P.\n",g);
2617  success = FALSE;
2618  }
2619 
2620  end_builtin();
2621 }
2622 
2632 {
2634  ptr_definition types[2];
2635 
2636  types[0] = real;
2637  types[1] = real;
2638 
2639  begin_builtin(xcUnloadFont,2,2,types);
2640 
2641  XUnloadFont(DISP(0),FONT(1));
2642  XSync(DISP(0),0);
2643  success = TRUE;
2644 
2645  end_builtin();
2646 }
2647 
2658 {
2660  ptr_definition types[8];
2661  long j;
2662  GC gc;
2663 
2664  for(j = 0; j < 8; j++)
2665  types[j] = real;
2666  types[1] = xdrawable;
2667  types[4] = quoted_string;
2668 
2669  begin_builtin(xcDrawString,8,8,types);
2670 
2671  gc = DrawableGC(args[1]);
2672  x_set_gc((Display *)val[0],gc,val[6],val[7],xDefaultLineWidth,val[5]);
2673 
2674  XDrawString(DISP(0),(Window) val[1],gc, /* Display,Window,GC */
2675  val[2],val[3],STRG(4), /* X,Y *//* String */
2676  strlen(STRG(4))); /* Length */
2677 
2678  x_record_string((ListHeader *)WindowDisplayList(args[1]),DRAW_STRING,
2679  val[2],val[3], /* X,Y */
2680  STRG(4), /* String */
2681  val[5], /* Font */
2682  val[6],val[7]); /* Function,Color */
2683 
2684  XSync(DISP(0),0);
2685  success = TRUE;
2686 
2687  end_builtin();
2688 }
2689 
2700 {
2702  ptr_definition types[8];
2703  long j;
2704  GC gc;
2705 
2706  for(j = 0; j < 8; j++)
2707  types[j] = real;
2708  types[1] = xdrawable;
2709  types[4] = quoted_string;
2710 
2711  begin_builtin(xcDrawImageString,8,8,types);
2712 
2713  gc = DrawableGC(args[1]);
2714  x_set_gc((Display *)val[0],gc,val[6],val[7],xDefaultLineWidth,val[5]);
2715 
2716  XDrawImageString(DISP(0),WIND(1),gc, /* Display,Window,GC */
2717  val[2],val[3], /* X,Y */
2718  STRG(4), /* String */
2719  strlen(STRG(4))); /* Length */
2720 
2721  x_record_string((ListHeader *)WindowDisplayList(args[1]),DRAW_IMAGE_STRING,
2722  val[2],val[3], /* X,Y */
2723  STRG(4), /* String */
2724  val[5], /* Font */
2725  val[6],val[7]); /* Function,Color */
2726 
2727  XSync(DISP(0),0);
2728  success = TRUE;
2729 
2730  end_builtin();
2731 }
2732 
2742 {
2744  ptr_definition types[3];
2745  int direction,ascent,descent;
2746  XCharStruct overall;
2747 
2748 
2749  types[0] = real;
2750  types[1] = real;
2751  types[2] = quoted_string;
2752 
2753  begin_builtin(xcStringWidth,3,3,types);
2754 
2755  if(XQueryTextExtents(DISP(0),FONT(1),
2756  STRG(2),strlen(STRG(2)),/* string,nbchars */
2757  &direction,&ascent,&descent,&overall))
2758  {
2759  unify_real_result(aim->bbbb_1,(REAL) overall.width);
2760  success = TRUE;
2761  }
2762  else
2763  {
2764  Errorline("bad font in %P.\n",g);
2765  success = FALSE;
2766  }
2767 
2768  end_builtin();
2769 }
2770 
2779 long xcSync()
2780 {
2782  ptr_definition types[2];
2783 
2784  types[0] = real;
2785  types[1] = real;
2786 
2787  begin_builtin(xcSync,2,2,types);
2788 
2789  XSync(DISP(0),val[1]);
2790  success = TRUE;
2791 
2792  end_builtin();
2793 }
2794 
2802 static ptr_psi_term xcEventToPsiTerm(XEvent *event)
2803 {
2804  ptr_psi_term psiEvent,psi_str;
2805  KeySym keysym;
2806  char buffer[10];
2807  char tstr[2], *str;
2808 
2809  str=tstr;
2810  tstr[1]=0;
2811 
2812  psiEvent = stack_psi_term(4);
2813  bk_stack_add_int_attr(psiEvent,"display",(long)event->xany.display);
2814  bk_stack_add_int_attr(psiEvent,"window",(long)event->xany.window);
2815 
2816  switch(event->type) {
2817  case KeyPress:
2818  case KeyRelease:
2819  psiEvent->type = xkeyboard_event;
2820  bk_stack_add_int_attr(psiEvent,"x",event->xkey.x);
2821  bk_stack_add_int_attr(psiEvent,"y",event->xkey.y);
2822  bk_stack_add_int_attr(psiEvent,"state",event->xkey.state);
2823 
2824  buffer[0] = 0;
2825  *str = 0;
2826  XLookupString((XKeyEvent*)event,buffer,sizeof(buffer),&keysym,NULL);
2827  bk_stack_add_int_attr(psiEvent,"keycode",(long)buffer[0]);
2828  if(keysym==XK_Return || keysym==XK_KP_Enter || keysym==XK_Linefeed)
2829  *str = CR;
2830  else
2831  if(keysym == XK_BackSpace || keysym == XK_Delete)
2832  *str = BS;
2833  else
2834  if(isascii(buffer[0]))
2835  /* if(isalnum(buffer[0]) || isspace(buffer[0])) 8.10 */
2836  *str = buffer[0];
2837 
2838  bk_stack_add_int_attr(psiEvent,"char",(long)*str);
2839  break;
2840 
2841  case ButtonPress:
2842  case ButtonRelease:
2843  psiEvent->type = xbutton_event;
2844  bk_stack_add_int_attr(psiEvent,"x",(long)event->xbutton.x);
2845  bk_stack_add_int_attr(psiEvent,"y",(long)event->xbutton.y);
2846  bk_stack_add_int_attr(psiEvent,"x_root",(long)event->xbutton.x_root);
2847  bk_stack_add_int_attr(psiEvent,"y_root",(long)event->xbutton.y_root);
2848  bk_stack_add_int_attr(psiEvent,"state",(long)event->xbutton.state);
2849  bk_stack_add_int_attr(psiEvent,"button",(long)event->xbutton.button);
2850  break;
2851 
2852  case Expose:
2853  psiEvent->type = xexpose_event;
2854  bk_stack_add_int_attr(psiEvent,"width",(long)event->xexpose.width);
2855  bk_stack_add_int_attr(psiEvent,"height",(long)event->xexpose.height);
2856  break;
2857 
2858  case DestroyNotify:
2859  psiEvent->type = xdestroy_event;
2860  break;
2861 
2862  /*** RM 7/12/92 ***/
2863  case MotionNotify:
2864  psiEvent->type = xmotion_event;
2865  bk_stack_add_int_attr(psiEvent,"x",(long)event->xbutton.x);
2866  bk_stack_add_int_attr(psiEvent,"y",(long)event->xbutton.y);
2867  bk_stack_add_int_attr(psiEvent,"x_root",(long)event->xbutton.x_root);
2868  bk_stack_add_int_attr(psiEvent,"y_root",(long)event->xbutton.y_root);
2869  break;
2870 
2871  case ConfigureNotify:
2872  psiEvent->type = xconfigure_event;
2873  bk_stack_add_int_attr(psiEvent,"x",(long)event->xconfigure.x);
2874  bk_stack_add_int_attr(psiEvent,"y",(long)event->xconfigure.y);
2875  bk_stack_add_int_attr(psiEvent,"width",(long)event->xconfigure.width);
2876  bk_stack_add_int_attr(psiEvent,"height",(long)event->xconfigure.height);
2877  bk_stack_add_int_attr(psiEvent,"border_width",
2878  (long)event->xconfigure.border_width);
2879  break;
2880  /*** RM 7/12/92(END) ***/
2881 
2882 
2883  /*** RM: May 3rd 1993 ***/
2884  case EnterNotify:
2885  psiEvent->type = xenter_event;
2886  goto LeaveEnterCommon;
2887 
2888  case LeaveNotify:
2889  psiEvent->type = xleave_event;
2890 
2891  LeaveEnterCommon:
2892  bk_stack_add_int_attr(psiEvent,"root", (long) event->xcrossing.root);
2893  bk_stack_add_int_attr(psiEvent,"subwindow",(long)event->xcrossing.subwindow);
2894 
2895  bk_stack_add_int_attr(psiEvent,"x",(long)event->xcrossing.x);
2896  bk_stack_add_int_attr(psiEvent,"y",(long)event->xcrossing.y);
2897 
2898  bk_stack_add_int_attr(psiEvent,"focus",(long)event->xcrossing.focus);
2899  bk_stack_add_int_attr(psiEvent,"state",(long)event->xcrossing.state);
2900 
2901  break;
2902 
2903 
2904  default:
2905  psiEvent->type = xmisc_event;
2906  bk_stack_add_int_attr(psiEvent,"event_type",(long)event->type);
2907  break;
2908  }
2909 
2910  return psiEvent;
2911 }
2912 
2924 {
2925  deref_ptr(lst);
2926  return lst->type==nil;
2927 }
2928 
2937 {
2938  ptr_psi_term car;
2939  ptr_psi_term cdr;
2940 
2941  deref_ptr(lst);
2942  if(lst->type==alist) {
2943  get_two_args(lst->attr_list,&car,&cdr);
2944  if(cdr) {
2945  deref_ptr(cdr);
2946  return cdr;
2947  }
2948  }
2949 
2950  Errorline("X event handling error in CDR(%P)\n",lst);
2951  return lst;
2952 }
2953 
2954 /* RM: Dec 15 1992 Return the CAR of a list */
2955 
2964 {
2965  ptr_psi_term car;
2966  ptr_psi_term cdr;
2967 
2968  deref_ptr(lst);
2969  if(lst->type==alist) {
2970  get_two_args(lst->attr_list,&car,&cdr);
2971  if(car) {
2972  deref_ptr(car);
2973  return car;
2974  }
2975  }
2976 
2977  Errorline("X event handling error in CAR(%P)\n",lst);
2978  return lst;
2979 }
2980 
2981 /* RM: Dec 15 1992 Set the CAR of a list */
2982 
2991 {
2992  deref_ptr(lst);
2993  stack_insert(FEATCMP,one,&(lst->attr_list),(GENERIC)value);
2994 }
2995 
2996 /* RM: Dec 15 1992 Set the CDR of a list */
2997 
3006 {
3007  deref_ptr(lst);
3008  stack_insert(FEATCMP,two,&(lst->attr_list),(GENERIC)value);
3009 }
3010 
3011 /* RM: Dec 15 1992 Return the last element of a list */
3012 
3020 {
3021  while(!list_is_nil(lst))
3022  lst=list_cdr(lst);
3023  return lst;
3024 }
3025 
3026 /* RM: Dec 15 1992 Append an element to a list,return the new CONS cell */
3027 
3036 {
3037  ptr_psi_term end;
3038 
3039  end=list_last_cdr(lst);
3041  end->coref=stack_cons(value,stack_nil());
3042  return end->coref;
3043 }
3044 
3045 /* RM: Dec 15 1992
3046  Map a function,while TRUE,over the CONS cells of a list */
3047 
3056 long map_funct_over_list(ptr_psi_term lst,long(*proc)(),long *closure)
3057 {
3058  long notInterrupted=TRUE;
3059 
3060  while(notInterrupted && !list_is_nil(lst)) {
3061  notInterrupted =(*proc)(lst,closure);
3062  lst=list_cdr(lst);
3063  }
3064 
3065  return notInterrupted;
3066 }
3067 
3068 /* RM: Dec 15 1992 Same thing,except map over the CARs of the list */
3069 
3078 long map_funct_over_cars(ptr_psi_term lst,long(*proc)(),long *closure)
3079 {
3080  ptr_psi_term cdr;
3081  int notInterrupted = TRUE;
3082 
3083  while(notInterrupted && !list_is_nil(lst)) {
3084  /* save the next because the current could be removed
3085  (eg: xcFlushEvents) */
3086 
3087  cdr=list_cdr(lst);
3088  notInterrupted=(*proc)(list_car(lst),closure);
3089  lst=cdr;
3090  }
3091 
3092  return notInterrupted;
3093 }
3094 /* RM: Dec 15 1992 Re-written for new lists */
3095 
3104 {
3105  ptr_psi_term car,cdr;
3106  long still_there=TRUE;
3107 
3108  deref_ptr(value);
3109  while(!list_is_nil(lst) && still_there) {
3110  car=list_car(lst);
3111  cdr=list_cdr(lst);
3112  if(car==value) {
3113  still_there=FALSE;
3115  lst->coref=cdr;
3116  }
3117  lst=cdr;
3118  }
3119 }
3120 
3130 static long x_union_event(ptr_psi_term psiEvent,EventClosure *closure)
3131 {
3132  return !((Display *)GetIntAttr(psiEvent,"display") == closure->display
3133  && (Window)GetIntAttr(psiEvent,"window") == closure->window
3134  &&(GetIntAttr(psiEvent,"mask") & closure->mask) != 0);
3135 }
3136 
3147 {
3149  ptr_definition types[3];
3150  XEvent event;
3151  ptr_psi_term psiEvent;
3152  ptr_psi_term eventElt;
3153  EventClosure eventClosure;
3154  ptr_psi_term result;
3155 
3156  types[0] = real;
3157  types[1] = xwindow;
3158  types[2] = real;
3159 
3160  result=aim->bbbb_1;
3161 
3162  begin_builtin(xcGetEvent,3,3,types);
3163 
3164  if(!xevent_existing) {
3165 
3166  /* warning if a same event is already waiting */
3167  eventClosure.display =DISP(0);
3168  eventClosure.window =WIND(1);
3169  eventClosure.mask = val[2];
3170  if(!map_funct_over_cars(xevent_list,x_union_event,(long *)&eventClosure))
3171  warningline("you have coinciding event handlers on the same window");
3172 
3173  /* transform the request into a psi-term */
3174  eventElt = stack_psi_term(4);
3175  bk_stack_add_int_attr(eventElt,"display",(long)val[0]);
3176  bk_stack_add_int_attr(eventElt,"window",(long)val[1]);
3177  bk_stack_add_int_attr(eventElt,"mask",(long)val[2]);
3178 
3179  /* stack_insert(FEATURECMP,"event",&(eventElt->attr_list),(GENERIC)result); */
3180 
3181  /* add the request in the list of waiting events */
3182  append_to_list(xevent_list,eventElt); /* RM: Dec 15 1992 */
3183 
3184  /* residuate the call */
3185  residuate(eventElt); /* RM: May 5 1993 */
3186 
3187  /* return a psi-term containing an `empty' event */
3188  /* psiEvent = stack_psi_term(4);
3189  psiEvent->type = xevent; RM: May 5 1993 */
3190  }
3191  else {
3192  /* get the event built by x_exist_event */
3193  psiEvent = GetPsiAttr(xevent_existing,"event");
3194  push_ptr_value_global(psi_term_ptr,(GENERIC *)&xevent_existing);
3195  xevent_existing = NULL;
3196  push_goal(unify,psiEvent,aim->bbbb_1,NULL); /* RM: May 5 1993 */
3197  }
3198 
3199  /* push_goal(unify,psiEvent,aim->bbbb_1,NULL); RM: May 5 1993 */
3200 
3201  success = TRUE;
3202 
3203  end_builtin();
3204 }
3205 
3215 static long x_flush_event(ptr_psi_term eventElt,EventClosure *closure)
3216 {
3217  ptr_psi_term psiEvent;
3218 
3219  psiEvent = list_car(eventElt);
3220  if ((Display *)GetIntAttr(psiEvent,"display") == closure->display
3221  && (Window)GetIntAttr(psiEvent,"window") ==closure->window
3222  && (GetIntAttr(psiEvent,"mask") & closure->mask) != 0)
3223  {
3224  /* 9.10 */
3225  /* if(xevent_list == eventElt) */
3226  /* push_ptr_value_global(psi_term_ptr,(GENERIC *)&xevent_list); */
3227  /* xevent_list = list_remove_value(xevent_list,psiEvent); */
3228  list_remove_value(xevent_list,psiEvent); /* RM: Dec 15 1992 */
3229  }
3230 
3231  return TRUE;
3232 }
3233 
3243 {
3245  ptr_definition types[3];
3246  EventClosure eventClosure;
3247 
3248  types[0] = real;
3249  types[1] = xwindow;
3250  types[2] = real;
3251 
3252  begin_builtin(xcFlushEvents,3,3,types);
3253 
3254  eventClosure.display =DISP(0);
3255  eventClosure.window = val[1];
3256  eventClosure.mask = val[2];
3257  map_funct_over_list(xevent_list,x_flush_event,(long *)&eventClosure);
3258 
3259  success = TRUE;
3260 
3261  end_builtin();
3262 }
3263 
3264 #if 0
3265 
3274 long xcSendEvent()
3275 {
3277  ptr_definition types[3];
3278  XEvent event;
3279  ptr_psi_term psiEvent;
3280  ptr_node nodeAttr;
3281  ptr_psi_term psiValue;
3282 
3283  types[0] = real;
3284  types[1] = xwindow;
3285  types[2] = xevent;
3286 
3287  begin_builtin(xcSendEvent,3,3,types);
3288 
3289  if(xcPsiEventToEvent(val[2],&event))
3290  {
3291  XSendEvent((GENERIC)DISP(0),WIND(1),False,?,&event);
3292  success = TRUE;
3293  }
3294  else
3295  {
3296  Errorline("%P is not an event in %P.\n",val[2],g);
3297  success = FALSE;
3298  }
3299 
3300  end_builtin();
3301 }
3302 
3303 #endif
3304 
3305 /*** RM: 7/12/92 ***/
3306 
3323 {
3324  include_var_builtin(10);
3325  ptr_definition types[10];
3326  Window root_return,child_return;
3327  int root_x_return,root_y_return;
3328  int win_x_return,win_y_return;
3329  unsigned int mask_return;
3330  long same_screen;
3331  long j;
3332 
3333  for(j=0; j<10; j++)
3334  types[j] = real;
3335 
3336  types[1] = xdrawable;
3337 
3338  begin_builtin(xcQueryPointer,10,2,types);
3339 
3340 
3341  same_screen=XQueryPointer(DISP(0),
3342  WIND(1),
3343  &root_return, &child_return,
3344  &root_x_return,&root_y_return,
3345  &win_x_return, &win_y_return,
3346  &mask_return);
3347 
3348 
3349  unify_real_result(args[2],(REAL)root_return);
3350  unify_real_result(args[3],(REAL)child_return);
3351  unify_real_result(args[4],(REAL)root_x_return);
3352  unify_real_result(args[5],(REAL)root_y_return);
3353  unify_real_result(args[6],(REAL)win_x_return);
3354  unify_real_result(args[7],(REAL)win_y_return);
3355  unify_real_result(args[8],(REAL)mask_return);
3356  unify_real_result(args[9],(REAL)same_screen);
3357 
3358  /* printf("root: %ld\nchild: %ld\n",root_return,child_return); */
3359 
3360  success = TRUE;
3361 
3362  end_builtin();
3363 }
3364 
3365 /*** RM: 7/12/92(END) ***/
3366 
3375 {
3376  set_current_module(x_module); /* RM: Feb 3 1993 */
3377 
3378  raw_setup_builtins(); /* to move in life.c */
3379 
3380  XSetErrorHandler(x_handle_error);
3381  XSetIOErrorHandler(x_handle_fatal_error);
3382 
3383  set_current_module(x_module); /* RM: Feb 3 1993 */
3384  xevent = update_symbol(x_module,"event");
3385  xkeyboard_event = update_symbol(x_module,"keyboard_event");
3386  xbutton_event = update_symbol(x_module,"button_event");
3387  xexpose_event = update_symbol(x_module,"expose_event");
3388  xdestroy_event = update_symbol(x_module,"destroy_event");
3389 
3390  /*** RM: 7/12/92 ***/
3391  xconfigure_event = update_symbol(x_module,"configure_event");
3392  xmotion_event = update_symbol(x_module,"motion_event");
3393  /*** RM: 7/12/92 ***/
3394 
3395 
3396  /*** RM: 3 May 92 ***/
3397  xenter_event = update_symbol(x_module,"enter_event");
3398  xleave_event = update_symbol(x_module,"leave_event");
3399  xmisc_event = update_symbol(x_module,"misc_event");
3400 
3401  /*** RM: 3 May 92 ***/
3402 
3403  xdisplay = update_symbol(x_module,"display");
3404  xdrawable = update_symbol(x_module,"drawable");
3405  xwindow = update_symbol(x_module,"window");
3406  xpixmap = update_symbol(x_module,"pixmap");
3407 
3408  xgc = update_symbol(x_module,"graphic_context");
3409  xdisplaylist = update_symbol(x_module,"display_list");
3410 
3412  new_built_in(x_module,"xcDefaultRootWindow", (def_type) predicate_it,xcDefaultRootWindow);
3413  new_built_in(x_module,"xcGetScreenAttribute", (def_type) predicate_it,xcGetScreenAttribute);
3414  new_built_in(x_module,"xcGetConnectionAttribute",(def_type) predicate_it,xcGetConnectionAttribute);
3415  new_built_in(x_module,"xcCloseConnection", (def_type) predicate_it,xcCloseConnection);
3416 
3417  new_built_in(x_module,"xcCreateSimpleWindow", (def_type) predicate_it,xcCreateSimpleWindow);
3418 #if 0
3419  new_built_in(x_module,"xcCreateWindow", (def_type) predicate_it,xcCreateWindow);
3420 #endif
3421 
3422  new_built_in(x_module,"xcSetStandardProperties", (def_type) predicate_it,xcSetStandardProperties);
3423  new_built_in(x_module,"xcGetWindowGeometry", (def_type) predicate_it,xcGetWindowGeometry);
3424  new_built_in(x_module,"xcSetWindowGeometry", (def_type) predicate_it,xcSetWindowGeometry);
3425  new_built_in(x_module,"xcGetWindowAttribute", (def_type) predicate_it,xcGetWindowAttribute);
3426  new_built_in(x_module,"xcSetWindowAttribute", (def_type) predicate_it,xcSetWindowAttribute);
3427  new_built_in(x_module,"xcMapWindow", (def_type) predicate_it,xcMapWindow);
3428 
3429  /* RM: May 6 1993 */
3430  new_built_in(x_module,"xcRaiseWindow", (def_type) predicate_it,xcRaiseWindow);
3431 
3432  new_built_in(x_module,"xcUnmapWindow", (def_type) predicate_it,xcUnmapWindow);
3433 
3434  /*** RM 8/12/92 ***/
3435  new_built_in(x_module,"xcMapSubwindows", (def_type) predicate_it,xcMapSubwindows);
3436  new_built_in(x_module,"xcUnmapSubwindows", (def_type) predicate_it,xcUnmapSubwindows);
3437  /*** RM 8/12/92 ***/
3438 
3439  new_built_in(x_module,"xcClearWindow", (def_type) predicate_it,xcClearWindow);
3440  new_built_in(x_module,"xcResizeWindowPixmap", (def_type) predicate_it,xcResizeWindowPixmap);
3441 
3442  new_built_in(x_module,"xcSelectInput", (def_type) predicate_it,xcSelectInput);
3443  new_built_in(x_module,"xcRefreshWindow", (def_type) predicate_it,xcRefreshWindow);
3444  new_built_in(x_module,"xcPostScriptWindow", (def_type) predicate_it,xcPostScriptWindow);
3445  new_built_in(x_module,"xcDestroyWindow", (def_type) predicate_it,xcDestroyWindow);
3446 
3447  new_built_in(x_module,"xcCreateGC", (def_type) predicate_it,xcCreateGC);
3448  new_built_in(x_module,"xcGetGCAttribute", (def_type) predicate_it,xcGetGCAttribute);
3449  new_built_in(x_module,"xcSetGCAttribute", (def_type) predicate_it,xcSetGCAttribute);
3450  new_built_in(x_module,"xcDestroyGC", (def_type) predicate_it,xcDestroyGC);
3451 
3452  new_built_in(x_module,"xcDrawLine", (def_type) predicate_it,xcDrawLine);
3453  new_built_in(x_module,"xcMoveWindow", (def_type) predicate_it,xcMoveWindow);
3454  new_built_in(x_module,"xcDrawArc", (def_type) predicate_it,xcDrawArc);
3455  new_built_in(x_module,"xcDrawRectangle", (def_type) predicate_it,xcDrawRectangle);
3456  new_built_in(x_module,"xcDrawPolygon", (def_type) predicate_it,xcDrawPolygon);
3457 
3458  new_built_in(x_module,"xcLoadFont", (def_type) predicate_it,xcLoadFont);
3459  new_built_in(x_module,"xcUnloadFont", (def_type) predicate_it,xcUnloadFont);
3460  new_built_in(x_module,"xcDrawString", (def_type) predicate_it,xcDrawString);
3461  new_built_in(x_module,"xcDrawImageString", (def_type) predicate_it,xcDrawImageString);
3463 
3464  new_built_in(x_module,"xcRequestColor", (def_type) predicate_it,xcRequestColor);
3465  new_built_in(x_module,"xcRequestNamedColor", (def_type) predicate_it,xcRequestNamedColor);
3466  new_built_in(x_module,"xcFreeColor", (def_type) predicate_it,xcFreeColor);
3467 
3468  new_built_in(x_module,"xcFillRectangle", (def_type) predicate_it,xcFillRectangle);
3469  new_built_in(x_module,"xcFillArc", (def_type) predicate_it,xcFillArc);
3470  new_built_in(x_module,"xcFillPolygon", (def_type) predicate_it,xcFillPolygon);
3471 
3472  new_built_in(x_module,"xcPointsAlloc", (def_type) predicate_it,xcPointsAlloc);
3473  new_built_in(x_module,"xcCoordPut", (def_type) predicate_it,xcCoordPut);
3474  new_built_in(x_module,"xcPointsFree", (def_type) predicate_it,xcPointsFree);
3475 
3476  new_built_in(x_module,"xcSync", (def_type) predicate_it,xcSync);
3477  new_built_in(x_module,"xcGetEvent", (def_type) function_it, xcGetEvent);
3478  new_built_in(x_module,"xcFlushEvents", (def_type) predicate_it,xcFlushEvents);
3479 
3480  /*** RM: 7/12/92 ***/
3481  new_built_in(x_module,"xcQueryPointer", (def_type) predicate_it,xcQueryPointer);
3482  /*** RM: 7/12/92 ***/
3483 
3484  /* RM: Apr 20 1993 */
3485  new_built_in(x_module,"xcQueryTextExtents",(def_type) predicate_it,xcQueryTextExtents);
3486 }
3487 
3496 static long WaitNextEvent(long *ptreventflag)
3497 {
3498  long nfds;
3499  fd_set readfd,writefd,exceptfd;
3500  struct timeval timeout;
3501  long charflag = FALSE,nbchar;
3502  char c = 0;
3503 
3504  *ptreventflag = FALSE;
3505 
3506  do
3507  {
3508  FD_ZERO(&readfd);
3509  FD_SET(stdin_fileno, &readfd);
3510  FD_ZERO(&writefd);
3511  FD_ZERO(&exceptfd);
3512  timeout.tv_sec = 0;
3513  timeout.tv_usec = 100000;
3514 
3515  nfds = select(32,&readfd,&writefd,&exceptfd,&timeout);
3516  if(nfds == -1)
3517  {
3518 #if 0
3519  /* not an error,but a signal has been occured */
3520  /* handle_interrupt(); does not work */
3521  exit();
3522 #endif
3523  if(errno != EINTR)
3524  {
3525  Errorline("in select: interruption error.\n");
3526  exit_life(TRUE);
3527  }
3528  else
3529  interrupt();
3530  }
3531 
3532  else
3533  if(nfds == 0)
3534  {
3535 #ifdef X11
3536  if(x_exist_event())
3537  {
3538  *ptreventflag = TRUE;
3539  start_of_line = TRUE;
3540  }
3541 #endif
3542  }
3543  else
3544  {
3545  if(FD_ISSET(stdin_fileno, &readfd) != 0)
3546  {
3547 #if 0
3548  if((nbchar = read(stdin_fileno,&c,1)) == -1)
3549  {
3550  Errorline("in select: keyboard error.\n");
3551  exit_life(TRUE);
3552  }
3553 
3554  /* see manpage of read */
3555  if(nbchar == 0)
3556  c = EOF;
3557 #endif
3558  c = fgetc(input_stream);
3559  charflag = TRUE;
3560  }
3561  else
3562  {
3563  Errorline("select error.\n");
3564  exit_life(TRUE);
3565  }
3566  }
3567  } while(!(charflag || *ptreventflag));
3568 
3569  return c;
3570 }
3571 
3578 long x_read_stdin_or_event(long *ptreventflag)
3579 {
3580  long c = 0;
3581 
3582  *ptreventflag = FALSE;
3583 
3584  if(c = saved_char) /* not an error ;-) */
3585  {
3587  old_saved_char=0;
3588  }
3589  else
3590  {
3591  if(input_stream == NULL || feof(input_stream))
3592  c = EOF;
3593  else
3594  {
3595  if(start_of_line)
3596  {
3597  start_of_line = FALSE;
3598  line_count ++ ;
3599  infoline("%s",prompt);
3600  fflush(output_stream);
3601  }
3602 
3603  c = WaitNextEvent(ptreventflag);
3604 
3605  if(*ptreventflag)
3606  {
3607  if(verbose) printf("<X event>");
3608  if(NOTQUIET) printf("\n"); /* 21.1 */
3609  }
3610 
3611  if(c == EOLN)
3612  start_of_line = TRUE;
3613  }
3614  }
3615 
3616  return c;
3617 }
3618 
3628 static long mask_match_type(long mask,long type)
3629 {
3630  long em;
3631 
3632  /* printf("mask=%d,type=%d=%s\n",mask,type,xevent_name[type]); */
3633 
3634  em=xevent_mask[type];
3635  if(!em ||(em & mask))
3636  return TRUE;
3637 
3638  /* printf("FALSE\n"); printf("event mask=%d\n",em); */
3639 
3640  return FALSE;
3641 }
3642 
3653 static ptr_psi_term x_what_psi_event(ptr_psi_term beginSpan,ptr_psi_term endSpan,long eventType)
3654 {
3655  if(beginSpan == endSpan)
3656  return list_car(beginSpan);
3657  else
3658  if(mask_match_type(GetIntAttr(list_car(beginSpan),"mask"),
3659  eventType))
3660  return list_car(beginSpan);
3661  else
3662  return x_what_psi_event(list_cdr(beginSpan),
3663  endSpan,eventType);
3664 }
3665 
3677 static void x_build_existing_event(XEvent *event,ptr_psi_term beginSpan,ptr_psi_term endSpan,long eventType)
3678 {
3679  ptr_psi_term psiEvent;
3680 
3681  /* printf("building event: type=%s event=%s\n",
3682  xevent_name[type],xevent_name[event->type]); */
3683 
3684  /* get the event from the list */
3685  psiEvent = x_what_psi_event(beginSpan,endSpan,eventType);
3686 
3687  /* put the event on the waiting event */
3688  bk_change_psi_attr(psiEvent,"event",xcEventToPsiTerm(event));
3689 
3690  /* set the global */
3691  if(xevent_existing)
3692  warningline("xevent_existing is non-null in x_build_existing_event");
3693  push_ptr_value_global(psi_term_ptr,(GENERIC *)&xevent_existing);
3694  xevent_existing = psiEvent;
3695 
3696  /* remove the event from the list */
3697  /* 9.10 */
3698  /* if(list_car(xevent_list) == psiEvent) */
3699  /* push_ptr_value_global(psi_term_ptr,(GENERIC *)&xevent_list); */
3700  /* xevent_list = list_remove_value(xevent_list,psiEvent); */
3701  list_remove_value(xevent_list,psiEvent); /* RM: Dec 15 1992 */
3702 }
3703 
3713 static long x_next_event_span(ptr_psi_term eventElt,EventClosure *eventClosure)
3714 {
3715  ptr_psi_term psiEvent;
3716  Display *display;
3717  Window window;
3718  long mask;
3719  XEvent event;
3720 
3721 
3722  psiEvent = list_car(eventElt);
3723  display =(Display *)GetIntAttr(psiEvent,"display");
3724  window =(Window)GetIntAttr(psiEvent,"window");
3725  mask = GetIntAttr(psiEvent,"mask");
3726 
3727  if(eventClosure->display == NULL) {
3728  /* new span */
3729  eventClosure->display = display;
3730  eventClosure->window = window;
3731  eventClosure->mask = mask;
3732  eventClosure->beginSpan = eventElt;
3733  return TRUE;
3734  }
3735  else
3736  if(eventClosure->display == display && eventClosure->window == window) {
3737  /* same span */
3738  eventClosure->mask |= mask;
3739  return TRUE;
3740  }
3741  else {
3742  /* a next span begins,check the current span */
3743  Repeat:
3744  if(XCheckWindowEvent(eventClosure->display,eventClosure->window,
3745  eventClosure->mask,&event)
3746  /* && event.xany.window == eventClosure->window */)
3747  {
3748  /* 9.10 */
3749  /* printf("Event type = %ld.\n",event.type); */
3750 
3751 
3752  if((event.type==Expose || event.type==GraphicsExpose)
3753  && event.xexpose.count!=0) {
3754  /* printf("Expose count = %ld.\n", event.xexpose.count); */
3755  goto Repeat;
3756  }
3757 
3758  /* build a psi-term containing the event */
3759 
3760  /* printf("*** event %d ***\n",event.type); */
3761 
3762  x_build_existing_event(&event,
3763  eventClosure->beginSpan,
3764  eventElt,event.type);
3765 
3766  return FALSE; /* stop ! we have an existing event !! */
3767  }
3768  else
3769  {
3770  /* init the new span */
3771  eventClosure->display = display;
3772  eventClosure->window = window;
3773  eventClosure->mask = mask;
3774  eventClosure->beginSpan = eventElt;
3775  return TRUE;
3776  }
3777  }
3778 }
3779 
3788 {
3789  XEvent event,exposeEvent;
3790  ptr_psi_term eventElt;
3791  EventClosure eventClosure;
3792 
3793 
3794  /*Infoline("xevent_list=%P\n",xevent_list); */
3795 
3796  if(xevent_existing)
3797  return TRUE;
3798 
3799  if(list_is_nil(xevent_list)) {
3800  /* printf("nil event list\n"); */
3801  return FALSE;
3802  }
3803 
3804 
3805  /* traverse the list of waiting events */
3806  eventClosure.display = NULL;
3807  if(!map_funct_over_list(xevent_list,x_next_event_span,(long *)&eventClosure))
3808  return TRUE;
3809 
3810  /* printf("display=%d,window=%d,mask=%d\n",
3811  eventClosure.display,eventClosure.window,eventClosure.mask); */
3812 
3813 
3814 
3815  /* check the last span */
3816  if(XCheckWindowEvent(eventClosure.display,
3817  eventClosure.window,
3818  eventClosure.mask,
3819  &event)) {
3820 
3821  /* printf("*** here event %d ***\n",event.xany.type); */
3822 
3823  if(event.xany.window==eventClosure.window) {
3824  if(event.type == Expose)
3825  while(XCheckWindowEvent(eventClosure.display,
3826  eventClosure.window,
3827  ExposureMask,
3828  &exposeEvent))
3829  ; /* that is continue until no expose event */
3830 
3831  /* build a psi-term containing the event */
3832  x_build_existing_event(&event,
3833  eventClosure.beginSpan,
3834  list_last_cdr(xevent_list),/* RM: Dec 15 1992*/
3835  event.type);
3836  return TRUE;
3837  }
3838  }
3839  else
3840  return FALSE;
3841 }
3842 
3843 
3852 void x_destroy_window(Display *display,Window window)
3853 {
3854  /* we need the psi-term window(not the value) to get the display list,the pixmap ...
3855  jch - Fri Aug 7 15:29:14 MET DST 1992
3856 
3857  FreeWindow(display,window);
3858  */
3859  XDestroyWindow(display,window);
3860  XSync(display,0);
3861 }
3862 
3871 void x_show_window(Display *display,long window)
3872 {
3873  XMapWindow(display,window);
3874  XSync(display,0);
3875 }
3876 
3885 void x_hide_window(Display *display,long window)
3886 {
3887  XUnmapWindow(display,window);
3888  XSync(display,0);
3889 }
3890 
3891 /*** RM 8/12/92 ***/
3892 
3901 void x_show_subwindow(Display *display,long window)
3902 {
3903  XMapSubwindows(display,window);
3904  XSync(display,0);
3905 }
3906 
3915 void x_hide_subwindow(Display *display,long window)
3916 {
3917  XUnmapSubwindows(display,window);
3918  XSync(display,0);
3919 }
3920 
3921 /*** RM 8/12/92 ***/
3922 
3923 /*** RM: Apr 20 1993 ***/
3924 
3934 {
3935  include_var_builtin(11);
3936  ptr_definition types[11];
3937  Font font;
3938  XCharStruct over;
3939  int i;
3940  int direction,ascent,descent; /* RM: 28 Jan 94 */
3941 
3942  types[0] = real; /* +Display */
3943  types[1] = real; /* +Font ID */
3944  types[2] = quoted_string; /* +String */
3945  types[3] = real; /* -Direction */
3946  types[4] = real; /* -Font-ascent */
3947  types[5] = real; /* -Font-descent */
3948  types[6] = real; /* -left bearing */
3949  types[7] = real; /* -right bearing */
3950  types[8] = real; /* -width */
3951  types[9] = real; /* -ascent */
3952  types[10]= real; /* -descent */
3953 
3954 
3955 
3956  begin_builtin(xcLoadFont,11,3,types);
3957 
3958 
3959  XQueryTextExtents(DISP(0),
3960  (XID)val[1],
3961  STRG(2),
3962  strlen(STRG(2)),
3963  &direction,
3964  &ascent,
3965  &descent,
3966  &over);
3967 
3968  val[3]=direction;
3969  val[4]=ascent;
3970  val[5]=descent;
3971 
3972  val[6] =over.lbearing;
3973  val[7] =over.rbearing;
3974  val[8] =over.width;
3975  val[9] =over.ascent;
3976  val[10]=over.descent;
3977 
3978  for(i=3;i<11;i++)
3979  unify_real_result(args[i],(REAL)val[i]);
3980 
3981  end_builtin();
3982 }
3983 /*** RM: Apr 20 1993 ***/
3984 
3993 {
3994  ptr_residuation resid;
3995  ptr_goal aim;
3996 
3997  if(psiTerm == NULL)
3998  {
3999  Errorline("X error in GoalFromPsiTerm: psiTerm is null\n");
4000  return FALSE;
4001  }
4002 
4003  if((resid = psiTerm->resid) == NULL)
4004  {
4005  Errorline("X error in GoalFromPsiTerm: psiTerm has no residuating functions\n");
4006  return FALSE;
4007  }
4008 
4009  if(resid->next != NULL)
4010  {
4011  Errorline("X error in GoalFromPsiTerm: psiTerm has more than one residuating function\n");
4012  return FALSE;
4013  }
4014 
4015  if((aim = resid->goal) == NULL)
4016  {
4017  Errorline("X error in GoalFromPsiTerm: psiTerm has no goal\n");
4018  return FALSE;
4019  }
4020 
4021  return aim;
4022 }
4023 
4024 
4025 #endif
ptr_goal GoalFromPsiTerm(ptr_psi_term psiTerm)
GoalFromPsiTerm.
Definition: xpred.c:3992
#define FONT(X)
Definition: xpred.c:153
#define show_subwindow
To backtrack on show sub windows RM 8/12/92.
Definition: def_const.h:470
long xcPointsAlloc()
xcPointsAlloc
Definition: xpred.c:2445
long x_exist_event()
x_exist_event
Definition: xpred.c:3787
void new_built_in(ptr_module m, char *s, def_type t, long(*r)())
new_built_in
Definition: built_ins.c:5375
long xcSync()
xcSync
Definition: xpred.c:2779
struct wl_EventClosure EventClosure
Display * display
Definition: xpred.c:32
#define STRG(X)
Definition: xpred.c:155
#define xDefaultLineWidth
Definition: def_const.h:944
ptr_definition alist
symbol in bi module
Definition: def_glob.h:319
ptr_residuation resid
Definition: def_struct.h:189
#define hide_subwindow
To backtrack on hide sub windows RM 8/12/92.
Definition: def_const.h:477
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
long xcCreateSimpleWindow()
xcCreateSimpleWindow
Definition: xpred.c:816
long xcGetWindowGeometry()
xcGetWindowGeometry
Definition: xpred.c:1087
ptr_psi_term list_car(ptr_psi_term lst)
list_car
Definition: xpred.c:2963
void interrupt()
INTERRUPT()
Definition: interrupt.c:21
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
ptr_definition xdisplaylist
Definition: xpred.c:45
void show(long limit)
show
Definition: parser.c:64
long xcDrawString()
xcDrawString
Definition: xpred.c:2657
ptr_psi_term stack_cons(ptr_psi_term head, ptr_psi_term tail)
stack_cons
Definition: built_ins.c:46
void residuate(ptr_psi_term t)
residuate
Definition: lefun.c:125
#define CR
Definition: xpred.c:25
void exit_life(long nl_flag)
exit_life
Definition: built_ins.c:2219
long xcRefreshWindow()
xcRefreshWindow
Definition: xpred.c:1714
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
long xcMoveWindow()
xcMoveWindow
Definition: xpred.c:1288
static long x_flush_event(ptr_psi_term eventElt, EventClosure *closure)
x_flush_event
Definition: xpred.c:3215
static ptr_psi_term x_what_psi_event(ptr_psi_term beginSpan, ptr_psi_term endSpan, long eventType)
x_what_psi_event
Definition: xpred.c:3653
void x_record_arc(ListHeader *displaylist, Action action, long x, long y, long width, long height, long startangle, long arcangle, unsigned long function, unsigned long color, unsigned long linewidth)
x_record_arc
Definition: xdisplaylist.c:221
#define stdin_fileno
Definition: xpred.c:24
ptr_psi_term list_last_cdr(ptr_psi_term lst)
list_last_cdr
Definition: xpred.c:3019
#define show_window
To backtrack on show window.
Definition: def_const.h:456
#define NOTQUIET
Definition: def_macro.h:15
void x_show_subwindow(Display *display, long window)
x_show_subwindow
Definition: xpred.c:3901
static long SetGCAttribute(Display *display, GC gc, long attributeId, long attribute)
SetGCAttribute.
Definition: xpred.c:1978
long xcDrawArc()
xcDrawArc
Definition: xpred.c:2291
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
Definition: login.c:600
ptr_definition xmisc_event
Definition: xpred.c:45
#define def_ptr
values of type_ptr
Definition: def_const.h:404
ptr_node bk_stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
bk_stack_insert
Definition: trees.c:357
ptr_goal goal
Definition: def_struct.h:172
long xcRequestNamedColor()
xcRequestNamedColor
Definition: xpred.c:2189
long xcGetEvent()
xcGetEvent
Definition: xpred.c:3146
long xcLoadFont()
xcLoadFont
Definition: xpred.c:2596
long xcSelectInput()
xcSelectInput
Definition: xpred.c:1689
void x_hide_subwindow(Display *display, long window)
x_hide_subwindow
Definition: xpred.c:3915
ptr_residuation next
Definition: def_struct.h:173
static long mask_match_type(long mask, long type)
mask_match_type
Definition: xpred.c:3628
#define CMAP(X)
Definition: xpred.c:154
static void x_build_existing_event(XEvent *event, ptr_psi_term beginSpan, ptr_psi_term endSpan, long eventType)
x_build_existing_event
Definition: xpred.c:3677
#define DRAW(X)
Definition: xpred.c:150
long verbose
Definition: def_glob.h:914
long xcStringWidth()
xcStringWidth
Definition: xpred.c:2741
char * two
Definition: def_glob.h:892
static long SetWindowAttribute(ptr_psi_term psi_window, Display *display, Drawable window, unsigned long attributeId, unsigned long attribute)
SetWindowAttribute.
Definition: xpred.c:1318
long xcDrawRectangle()
xcDrawRectangle
Definition: xpred.c:2330
void push_ptr_value_global(type_ptr t, GENERIC *p)
push_ptr_value_global
Definition: login.c:523
ptr_psi_term xevent_list
Definition: xpred.c:43
long xcCoordPut()
xcCoordPut
Definition: xpred.c:2471
void x_show_window(Display *display, long window)
x_show_window
Definition: xpred.c:3871
includes
long xcDrawLine()
xcDrawLine
Definition: xpred.c:2253
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
static long x_union_event(ptr_psi_term psiEvent, EventClosure *closure)
x_union_event
Definition: xpred.c:3130
void x_record_rectangle(ListHeader *displaylist, Action action, long x, long y, long width, long height, unsigned long function, unsigned long color, unsigned long linewidth)
x_record_rectangle
Definition: xdisplaylist.c:255
void list_set_car(ptr_psi_term lst, ptr_psi_term value)
list_set_car
Definition: xpred.c:2990
long xcPointsFree()
xcPointsFree
Definition: xpred.c:2500
long matches(ptr_definition t1, ptr_definition t2, long *smaller)
matches
Definition: types.c:1666
ptr_definition xdrawable
Definition: xpred.c:45
#define destroy_window
To backtrack on window creation.
Definition: def_const.h:449
long xcDefaultRootWindow()
xcDefaultRootWindow
Definition: xpred.c:529
long x_postscript_window(Display *display, Window window, ListHeader *displaylist, char *filename)
x_postscript_window
Definition: xdisplaylist.c:839
ptr_keyword keyword
Definition: def_struct.h:147
#define WindowDisplayList(w)
Definition: xpred.c:146
long unify_int_result(ptr_psi_term t, long v)
unify_int_result
Definition: xpred.c:271
long xcGetScreenAttribute()
xcGetScreenAttribute
Definition: xpred.c:752
ptr_definition xdisplay
Definition: xpred.c:45
long xcUnmapWindow()
xcUnmapWindow
Definition: xpred.c:1549
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
long old_saved_char
Definition: def_glob.h:850
ptr_definition xgc
Definition: xpred.c:45
#define NULL
Definition: def_const.h:533
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
ptr_psi_term GetPsiAttr(ptr_psi_term psiTerm, char *attributeName)
GetPsiAttr.
Definition: xpred.c:367
long xcFillArc()
xcFillArc
Definition: xpred.c:2407
char * symbol
Definition: def_struct.h:118
long saved_char
Definition: def_glob.h:849
#define BS
Definition: xpred.c:26
ptr_psi_term append_to_list(ptr_psi_term lst, ptr_psi_term value)
append_to_list
Definition: xpred.c:3035
ptr_definition xexpose_event
Definition: xpred.c:45
static void FreeWindow(Display *display, ptr_psi_term psi_window)
FreeWindow.
Definition: xpred.c:463
ptr_definition boolean
symbol in bi module
Definition: def_glob.h:185
long xcQueryPointer()
xcQueryPointer
Definition: xpred.c:3322
long xcRequestColor()
xcRequestColor
Definition: xpred.c:2150
long xcDestroyWindow()
xcDestroyWindow
Definition: xpred.c:1773
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
Definition: modules.c:270
static long GetWindowAttribute(Display *display, long window, long attributeId, long *attribute)
GetWindowAttribute.
Definition: xpred.c:1129
static long GetGCAttribute(GC gc, long attributeId, long *attribute)
GetGCAttribute.
Definition: xpred.c:1846
#define begin_builtin(FUNCNAME, NBARGS, NBARGSIN, TYPES)
Definition: def_macro.h:203
ptr_definition xpixmap
Definition: xpred.c:45
static long GetScreenAttribute(Display *display, long screen, long attributeId, long *attribute)
GetScreenAttribute.
Definition: xpred.c:677
long xcDrawPolygon()
xcDrawPolygon
Definition: xpred.c:2523
void release_resid(ptr_psi_term t)
release_resid
Definition: lefun.c:445
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
void x_record_polygon(ListHeader *displaylist, Action action, XPoint *points, long npoints, unsigned long function, unsigned long color, unsigned long linewidth)
x_record_polygon
Definition: xdisplaylist.c:285
long xcMapWindow()
xcMapWindow
Definition: xpred.c:1494
static char * xevent_name[]
Definition: xpred.c:101
long line_count
Definition: def_glob.h:1015
#define hide_window
To backtrack on hide window.
Definition: def_const.h:463
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
long xcDestroyGC()
xcDestroyGC
Definition: xpred.c:2126
char * buffer
buffer used only in print.c - there is local with same name in xpred.c
Definition: def_glob.h:781
long xcFreeColor()
xcFreeColor
Definition: xpred.c:2225
#define EOLN
End of line.
Definition: def_const.h:309
long x_read_stdin_or_event(long *ptreventflag)
x_read_stdin_or_event
Definition: xpred.c:3578
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
stack_insert
Definition: trees.c:337
#define deref_ptr(P)
Definition: def_macro.h:100
void infoline(char *format,...)
infoline
Definition: error.c:281
static int x_handle_fatal_error(Display *display)
x_handle_fatal_error
Definition: xpred.c:188
void x_set_gc(Display *display, GC gc, long function, unsigned long color, long linewidth, Font font)
x_set_gc
Definition: xdisplaylist.c:142
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
static long WaitNextEvent(long *ptreventflag)
WaitNextEvent.
Definition: xpred.c:3496
long xcSetGCAttribute()
xcSetGCAttribute
Definition: xpred.c:2094
long xcGetWindowAttribute()
xcGetWindowAttribute
Definition: xpred.c:1221
ptr_definition xwindow
Definition: xpred.c:45
int arg_c
set from argc in either life.c or lib.c
Definition: def_glob.h:20
#define DrawableGC(w)
Definition: xpred.c:145
#define TRUE
Standard boolean.
Definition: def_const.h:268
long x_window_creation
Definition: xpred.c:53
long xcSetWindowGeometry()
xcSetWindowGeometry
Definition: xpred.c:1257
#define FALSE
Standard boolean.
Definition: def_const.h:275
long xcCreateGC()
xcCreateGC
Definition: xpred.c:1810
void list_set_cdr(ptr_psi_term lst, ptr_psi_term value)
list_set_cdr
Definition: xpred.c:3005
long map_funct_over_list(ptr_psi_term lst, long(*proc)(), long *closure)
map_funct_over_list
Definition: xpred.c:3056
ptr_definition xconfigure_event
Definition: xpred.c:45
static long x_next_event_span(ptr_psi_term eventElt, EventClosure *eventClosure)
x_next_event_span
Definition: xpred.c:3713
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
Definition: lefun.c:21
void x_hide_window(Display *display, long window)
x_hide_window
Definition: xpred.c:3885
ptr_definition nil
symbol in bi module
Definition: def_glob.h:340
FILE * input_stream
Definition: def_glob.h:1014
ptr_psi_term beginSpan
Definition: xpred.c:35
GENERIC value_3
Definition: def_struct.h:186
long map_funct_over_cars(ptr_psi_term lst, long(*proc)(), long *closure)
map_funct_over_cars
Definition: xpred.c:3078
long start_of_line
???
Definition: def_glob.h:846
ptr_psi_term stack_nil()
stack_nil
Definition: built_ins.c:26
ptr_goal aim
Definition: def_glob.h:1024
long xcOpenConnection()
xcOpenConnection
Definition: xpred.c:485
ptr_psi_term coref
Definition: def_struct.h:188
#define GCVAL(X)
Definition: xpred.c:152
char * one
Definition: def_glob.h:891
static ptr_psi_term xcEventToPsiTerm(XEvent *event)
xcEventToPsiTerm
Definition: xpred.c:2802
ptr_definition xdestroy_event
Definition: xpred.c:45
void clean_undo_window(long disp, long wind)
clean_undo_window
Definition: login.c:848
static long xevent_mask[]
Definition: xpred.c:57
#define xDefaultFont
Definition: def_const.h:943
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
long xcDrawImageString()
xcDrawImageString
Definition: xpred.c:2699
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
long xcCloseConnection()
xcCloseConnection
Definition: xpred.c:787
long xcFillPolygon()
xcFillPolygon
Definition: xpred.c:2558
#define DISP(X)
Definition: xpred.c:149
char * arg_v[ARGNN]
set from argv in either life.c or lib.c
Definition: def_glob.h:27
void x_record_string(ListHeader *displaylist, Action action, long x, long y, char *str, Font font, unsigned long function, unsigned long color)
x_record_string
Definition: xdisplaylist.c:318
void bk_change_psi_attr(ptr_psi_term t, char *attrname, ptr_psi_term value)
bk_change_psi_attr
Definition: xpred.c:240
long xcGetGCAttribute()
xcGetGCAttribute
Definition: xpred.c:1942
long xcUnmapSubwindows()
xcUnmapSubwindows
Definition: xpred.c:1604
void push_window(long type, long disp, long wind)
push_window
Definition: login.c:548
long list_is_nil(ptr_psi_term lst)
Definition: xpred.c:2923
long xcFillRectangle()
xcFillRectangle
Definition: xpred.c:2368
ptr_definition xmotion_event
Definition: xpred.c:45
long xcGetConnectionAttribute()
xcGetConnectionAttribute
Definition: xpred.c:641
void x_free_display_list(ListHeader *displaylist)
x_free_display_list
Definition: xdisplaylist.c:548
void raw_setup_builtins()
raw_setup_builtins
Definition: raw.c:303
long xcResizeWindowPixmap()
xcResizeWindowPixmap
Definition: xpred.c:1661
char * prompt
Definition: def_glob.h:1018
void bk_stack_add_int_attr(ptr_psi_term t, char *attrname, long value)
bk_stack_add_int_attr
Definition: xpred.c:206
static ptr_psi_term NewPsi(ptr_definition t, char *f, long v)
ptr_psi_term NewPsi
Definition: xpred.c:314
void x_setup_builtins()
x_setup_builtins
Definition: xpred.c:3374
long mask
Definition: xpred.c:34
long unify_real_result(ptr_psi_term t, REAL v)
unify_real_result
Definition: built_ins.c:386
ptr_psi_term list_cdr(ptr_psi_term lst)
list_cdr
Definition: xpred.c:2936
FILE * output_stream
Definition: def_glob.h:1017
long xcRaiseWindow()
xcRaiseWindow
Definition: xpred.c:1522
long xcPostScriptWindow()
xcPostScriptWindow
Definition: xpred.c:1749
ptr_psi_term xevent_existing
Definition: xpred.c:42
static void ResizePixmap(ptr_psi_term psi_window, Display *display, Window window, unsigned long width, unsigned long height)
ResizePixmap.
Definition: xpred.c:400
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition xkeyboard_event
Definition: xpred.c:45
long xcClearWindow()
xcClearWindow
Definition: xpred.c:1633
ptr_definition type
Definition: def_struct.h:181
long xcFlushEvents()
xcFlushEvents
Definition: xpred.c:3242
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ListHeader * x_display_list()
x_display_list
Definition: xdisplaylist.c:120
long xcUnloadFont()
xcUnloadFont
Definition: xpred.c:2631
long xcSetWindowAttribute()
xcSetWindowAttribute
Definition: xpred.c:1460
#define include_var_builtin(NBARGS)
Definition: def_macro.h:196
void x_record_line(ListHeader *displaylist, Action action, long x0, long y0, long x1, long y1, unsigned long function, unsigned long color, unsigned long linewidth)
x_record_line
Definition: xdisplaylist.c:186
#define WIND(X)
Definition: xpred.c:151
#define end_builtin()
Definition: def_macro.h:259
void list_remove_value(ptr_psi_term lst, ptr_psi_term value)
list_remove_value
Definition: xpred.c:3103
Window window
Definition: xpred.c:33
long GetIntAttr(ptr_psi_term psiTerm, char *attributeName)
GetIntAttr.
Definition: xpred.c:333
void x_refresh_window(Display *display, Window window, Pixmap pixmap, GC pixmapgc, ListHeader *displaylist)
x_refresh_window
Definition: xdisplaylist.c:447
long xcMapSubwindows()
xcMapSubwindows
Definition: xpred.c:1577
ptr_node attr_list
Definition: def_struct.h:187
ptr_module x_module
'ifdef X11' unnecessary
Definition: def_glob.h:708
ptr_module set_current_module(ptr_module module)
set_current_module
Definition: modules.c:100
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
ptr_definition xenter_event
Definition: xpred.c:45
long xcSetStandardProperties()
xcSetStandardProperties
Definition: xpred.c:1043
long xcQueryTextExtents()
xcQueryTextExtents
Definition: xpred.c:3933
ptr_definition xevent
Definition: xpred.c:45
long i_check_out(ptr_psi_term t)
i_check_out
Definition: lefun.c:1033
GENERIC heap_alloc(long s)
heap_alloc
Definition: memory.c:1616
ptr_definition xbutton_event
Definition: xpred.c:45
static int x_handle_error(Display *display, XErrorEvent *x_error)
x_handle_error
Definition: xpred.c:170
void x_destroy_window(Display *display, Window window)
x_destroy_window
Definition: xpred.c:3852
static long GetConnectionAttribute(Display *display, long attributeId, long *attribute)
GetConnectionAttribute.
Definition: xpred.c:560
#define psi_term_ptr
values of type_ptr
Definition: def_const.h:383
ptr_definition xleave_event
Definition: xpred.c:45
#define int_ptr
values of type_ptr
Definition: def_const.h:397