1 /* Loglan82 Compiler&Interpreter
\r
2 Copyright (C) 1993 Institute of Informatics, University of Warsaw
\r
3 Copyright (C) 1993, 1994 LITA, Pau
\r
5 This program is free software; you can redistribute it and/or modify
\r
6 it under the terms of the GNU General Public License as published by
\r
7 the Free Software Foundation; either version 2 of the License, or
\r
8 (at your option) any later version.
\r
10 This program is distributed in the hope that it will be useful,
\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 GNU General Public License for more details.
\r
15 You should have received a copy of the GNU General Public License
\r
16 along with this program; if not, write to the Free Software
\r
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\r
19 contacts: Andrzej.Salwicki@univ-pau.fr
\r
22 LITA Departement d'Informatique
\r
24 Avenue de l'Universite
\r
26 tel. ++33 59923154 fax. ++33 59841696
\r
28 =======================================================================
\r
31 #include "nonstand.h"
\r
35 #include <X11/cursorfont.h>
\r
36 #include <X11/keysym.h>
\r
38 /*#include <X11/Xos.h>*/
\r
39 #include <X11/Xlib.h>
\r
40 #include <X11/Xutil.h>
\r
41 #include <X11/Xatom.h>
\r
43 #include <X11/MwmUtil.h>
\r
49 XSizeHints theHints;
\r
51 int theDepth, theScreen, dispcells;
\r
53 Window rootW, window, father;
\r
55 unsigned long fcol,bcol,white,black,style=1;
\r
57 XFontStruct *mfinfo;
\r
60 XClientMessageEvent toFatherEv;
\r
65 int mouse_x=0,mouse_y=0,mouse_l=0,mouse_r=0,mouse_c=0,
\r
66 mouse_l_prs=0,mouse_r_prs=0,mouse_c_prs=0,
\r
67 mouse_l_p_x=0,mouse_r_p_x=0,mouse_c_p_x=0,
\r
68 mouse_l_p_y=0,mouse_r_p_y=0,mouse_c_p_y=0,
\r
69 mouse_l_rel=0,mouse_r_rel=0,mouse_c_rel=0,
\r
70 mouse_l_r_x=0,mouse_r_r_x=0,mouse_c_r_x=0,
\r
71 mouse_l_r_y=0,mouse_r_r_y=0,mouse_c_r_y=0;
\r
73 #define END_OF_TRACK -9999
\r
77 #define get_shrt(w) w=(int)(*(pars++));
\r
78 #define get_word(w) w=((int)(pars[0])&0xffff)|((int)pars[1]<<16); pars+=2;
\r
80 #define put_shrt(w) toFatherEv.data.s[cnt++] = (short)(w);
\r
81 #define put_word(w) toFatherEv.data.s[cnt++] = (short)((w) & 0xffff); \
\r
82 toFatherEv.data.s[cnt++] = (short)(((w) >> 16) & 0xffff);
\r
83 #define snd_father toFatherEv.type=ClientMessage; \
\r
84 toFatherEv.format = 16; \
\r
85 XSendEvent(theDisp,father,False,NoEventMask,&toFatherEv); \
\r
88 #ifndef NO_PROTOTYPES
\r
89 void RealiseCmd(int,short *);
\r
95 static char *application_name="IIUWGRAPH";
\r
99 static KeySym keycodes[QSIZE];
\r
100 static int keyhead=0,keytail=0;
\r
110 father = atoi(argv[1]);
\r
112 for( i=2; i<argc; i++ ) argv[i-1]=argv[i];
\r
115 if ((theDisp = XOpenDisplay(NULL)) == NULL){
\r
116 fprintf (stderr,"\n%s: Can't open display\n", argv[0]);
\r
120 theScreen = DefaultScreen(theDisp);
\r
121 theDepth = DefaultDepth(theDisp, theScreen);
\r
122 rootW = RootWindow(theDisp,theScreen);
\r
123 fcol=white= WhitePixel(theDisp,theScreen);
\r
124 bcol=black= BlackPixel(theDisp,theScreen);
\r
125 theVisual = DefaultVisual(theDisp,theScreen);
\r
126 theCmap = XCreateColormap(theDisp,rootW,theVisual,AllocNone);
\r
127 dispcells = DisplayCells(theDisp, theScreen);
\r
128 theCursor = XCreateFontCursor(theDisp,XC_arrow);
\r
130 iWIDE = 720; iHIGH = 348;
\r
132 if ((mfinfo = XLoadQueryFont(theDisp,"fixed"))==NULL){
\r
133 fprintf (stderr,"\n%s: Can't open 'fixed' font\n", argv[0]);
\r
138 theHints.width =iWIDE;
\r
139 theHints.height=iHIGH;
\r
140 theHints.flags=PSize;
\r
141 window = XCreateSimpleWindow(theDisp,rootW,10,10,iWIDE,iHIGH,3,fcol,bcol);
\r
143 XSetStandardProperties(theDisp,window,"HERCULES","HERCULES",
\r
144 None,argv,argc,theHints);
\r
145 XDefineCursor(theDisp,window,theCursor);
\r
147 XChangeProperty(theDisp,window,XA_WM_CLASS,XA_STRING,8,PropModeReplace,
\r
148 application_name,strlen(application_name));
\r
157 Atom a=XInternAtom(theDisp,_XA_MWM_HINTS,False);
\r
158 hints.flags = MWM_HINTS_FUNCTIONS;
\r
159 hints.functions = MWM_FUNC_CLOSE | MWM_FUNC_MOVE;
\r
160 hints.decorations = 0;
\r
161 hints.input_mode = 0;
\r
162 XChangeProperty(theDisp,window,a,a,32,PropModeReplace,&hints,4);
\r
165 theGC = XCreateGC(theDisp,window,0,0);
\r
166 XSetFont(theDisp,theGC,mfont);
\r
167 XSetForeground(theDisp,theGC,fcol);
\r
168 XSetBackground(theDisp,theGC,bcol);
\r
170 XSelectInput(theDisp,window,
\r
173 PointerMotionMask |
\r
177 XMapRaised(theDisp,window);
\r
179 pixmap = XCreatePixmap(theDisp,window,iWIDE,iHIGH,theDepth);
\r
183 XNextEvent(theDisp,&event);
\r
185 switch (event.type){
\r
189 int x=event.xexpose.x;
\r
190 int y=event.xexpose.y;
\r
191 int w=event.xexpose.width;
\r
192 int h=event.xexpose.height;
\r
194 XCopyArea(theDisp,pixmap,window,theGC,x,y,w,h,x,y);
\r
203 case ClientMessage:
\r
204 RealiseCmd( (int)(event.xclient.message_type),event.xclient.data.s);
\r
207 case MappingNotify:
\r
208 if( event.xmapping.request == MappingModifier ||
\r
209 event.xmapping.request == MappingKeyboard )
\r
210 XRefreshKeyboardMapping(&event);
\r
217 int i=XLookupString( &(event.xkey), &ch, 1, &key, NULL );
\r
220 if( ch == '\177' ) keycodes[ keytail++ ] = -83;
\r
221 else keycodes[ keytail++ ] = (int)ch;
\r
223 if( key == NoSymbol ) break;
\r
225 if( IsModifierKey( key ) ) break;
\r
230 case XK_F1 : to_return = -59; break;
\r
231 case XK_F2 : to_return = -60; break;
\r
232 case XK_F3 : to_return = -61; break;
\r
233 case XK_F4 : to_return = -62; break;
\r
234 case XK_F5 : to_return = -63; break;
\r
235 case XK_F6 : to_return = -64; break;
\r
236 case XK_F7 : to_return = -65; break;
\r
237 case XK_F8 : to_return = -66; break;
\r
238 case XK_F9 : to_return = -67; break;
\r
239 case XK_F10 : to_return = -68; break;
\r
240 case XK_Home : to_return = -71; break;
\r
241 case XK_Left : to_return = -75; break;
\r
242 case XK_Up : to_return = -72; break;
\r
243 case XK_Right : to_return = -77; break;
\r
244 case XK_Down : to_return = -80; break;
\r
245 case XK_End : to_return = -79; break;
\r
246 case XK_Insert: to_return = -82; break;
\r
247 case XK_Break : to_return = -3; break;
\r
248 case XK_Prior : to_return = -73; break;
\r
249 case XK_Next : to_return = -81; break;
\r
251 if( to_return!=0 ) keycodes[ keytail++ ] = to_return;
\r
255 if( keytail == QSIZE ) keytail = 0;
\r
256 if( keytail == keyhead ){
\r
258 if( keytail < 0 ) keytail = QSIZE ;
\r
265 case ButtonRelease:
\r
266 mouse_x = event.xmotion.x;
\r
267 mouse_y = event.xmotion.y;
\r
268 if( event.type == ButtonPress ){
\r
269 switch( event.xbutton.button ){
\r
270 case Button1 : mouse_l=1; mouse_l_prs++;
\r
271 mouse_l_p_x = mouse_x;
\r
272 mouse_l_p_y = mouse_y;
\r
275 RealiseCmd( END_OF_TRACK, NULL );
\r
278 case Button2 : mouse_c=1; mouse_c_prs++;
\r
279 mouse_c_p_x = mouse_x;
\r
280 mouse_c_p_y = mouse_y;
\r
282 case Button3 : mouse_r=1; mouse_r_prs++;
\r
283 mouse_r_p_x = mouse_x;
\r
284 mouse_r_p_y = mouse_y;
\r
288 if( event.type == ButtonRelease ){
\r
289 switch( event.xbutton.button ){
\r
290 case Button1 : mouse_l=0; mouse_l_rel++;
\r
291 mouse_l_r_x = mouse_x;
\r
292 mouse_l_r_y = mouse_y;
\r
294 case Button2 : mouse_c=0; mouse_c_rel++;
\r
295 mouse_c_r_x = mouse_x;
\r
296 mouse_c_r_y = mouse_y;
\r
298 case Button3 : mouse_r=0; mouse_r_rel++;
\r
299 mouse_r_r_x = mouse_x;
\r
300 mouse_r_r_y = mouse_y;
\r
306 } /* end of switch */
\r
314 word cmd=0,w,h,x,y,curx,cury,kolb,wwyp,p,q,r,color;
\r
315 word alfa,beta,aspect;
\r
318 XImage *XGetImage();
\r
322 void RealiseCmd( cmd, pars ) int cmd; short *pars; {
\r
330 XSetForeground(theDisp,theGC,bcol);
\r
331 XFillRectangle(theDisp,pixmap,theGC,0,0,iWIDE,iHIGH);
\r
332 XFillRectangle(theDisp,window,theGC,0,0,iWIDE,iHIGH);
\r
333 XSetForeground(theDisp,theGC,fcol);
\r
337 XFreePixmap(theDisp,pixmap);
\r
338 XDestroyWindow(theDisp,window);
\r
339 XCloseDisplay(theDisp);
\r
346 if( keyhead != keytail ){
\r
347 keycode = keycodes[ keyhead++ ];
\r
348 if( keyhead == QSIZE ) keyhead = 0;
\r
358 XDrawPoint(theDisp,pixmap,theGC,x,y);
\r
359 XDrawPoint(theDisp,window,theGC,x,y);
\r
367 XDrawLine(theDisp,pixmap,theGC,curx,cury,x,y);
\r
368 XDrawLine(theDisp,window,theGC,curx,cury,x,y);
\r
375 get_shrt( aspect );
\r
378 XDrawArc(theDisp,pixmap,theGC,x,y,r,aspect,alfa,beta);
\r
379 XDrawArc(theDisp,window,theGC,x,y,r,aspect,alfa,beta);
\r
386 XDrawLine(theDisp,pixmap,theGC,curx,cury,x,cury);
\r
387 XDrawLine(theDisp,window,theGC,curx,cury,x,cury);
\r
394 XDrawLine(theDisp,pixmap,theGC,curx,cury,curx,y);
\r
395 XDrawLine(theDisp,window,theGC,curx,cury,curx,y);
\r
401 image=XGetImage(theDisp,pixmap,x,y,1,1,0x7fffffffL,ZPixmap);
\r
402 color = XGetPixel(image,0,0);
\r
403 XDestroyImage(image);
\r
415 if( w>iWIDE ) w=iWIDE;
\r
416 if( h>iHIGH ) h=iHIGH;
\r
417 map = XCreatePixmap(theDisp,window,w,h,theDepth);
\r
418 XCopyArea(theDisp,pixmap,map,theGC,x,y,w,h,0,0);
\r
430 case XORMAP: XSetFunction(theDisp,theGC,GXxor); break;
\r
431 case ORMAP: XSetFunction(theDisp,theGC,GXor ); break;
\r
438 if( w>iWIDE ) w=iWIDE;
\r
439 if( h>iHIGH ) h=iHIGH;
\r
440 XCopyArea(theDisp,map,pixmap,theGC,0,0,w,h,curx,cury);
\r
441 XCopyArea(theDisp,map,window,theGC,0,0,w,h,curx,cury);
\r
442 if( cmd != PUTMAP ) XSetFunction(theDisp,theGC,GXcopy);
\r
448 if( color == 0 ) fcol = black ;
\r
449 else fcol = white ;
\r
450 XSetForeground(theDisp,theGC,fcol);
\r
455 if( color == 0 ) bcol = black ;
\r
456 else bcol = white ;
\r
457 XSetBackground(theDisp,theGC,bcol);
\r
462 static char style_2[]={ 6, 3 };
\r
463 static char style_3[]={ 4, 6 };
\r
464 static char style_4[]={ 2, 3 };
\r
465 static char style_5[]={ 2, 9 };
\r
470 XSetForeground(theDisp,theGC,bcol);
\r
471 XSetLineAttributes(theDisp,theGC,0,LineSolid,CapButt,JoinMiter);
\r
474 XSetForeground(theDisp,theGC,fcol);
\r
475 XSetLineAttributes(theDisp,theGC,0,LineSolid,CapButt,JoinMiter);
\r
478 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
\r
479 CapButt,JoinMiter);
\r
480 XSetDashes(theDisp,theGC,0,style_2,2);
\r
483 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
\r
484 CapButt,JoinMiter);
\r
485 XSetDashes(theDisp,theGC,0,style_3,2);
\r
488 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
\r
489 CapButt,JoinMiter);
\r
490 XSetDashes(theDisp,theGC,0,style_4,2);
\r
493 XSetLineAttributes(theDisp,theGC,0,LineDoubleDash,
\r
494 CapButt,JoinMiter);
\r
495 XSetDashes(theDisp,theGC,0,style_5,2);
\r
506 XSetForeground(theDisp,theGC,bcol);
\r
507 XFillRectangle(theDisp,pixmap,theGC,curx,cury,8,8);
\r
508 XFillRectangle(theDisp,window,theGC,curx,cury,8,8);
\r
509 XSetForeground(theDisp,theGC,fcol);
\r
512 XDrawString(theDisp,pixmap,theGC,curx,cury+8,&c,1);
\r
513 XDrawString(theDisp,window,theGC,curx,cury+8,&c,1);
\r
531 if( cmd == GETPRESS )
\r
535 put_shrt( mouse_l_p_x );
\r
536 put_shrt( mouse_l_p_y );
\r
537 put_shrt( mouse_l_prs );
\r
542 put_shrt( mouse_r_p_x );
\r
543 put_shrt( mouse_r_p_y );
\r
544 put_shrt( mouse_r_prs );
\r
549 put_shrt( mouse_c_p_x );
\r
550 put_shrt( mouse_c_p_y );
\r
551 put_shrt( mouse_c_prs );
\r
555 default:put_shrt( 0 );
\r
565 put_shrt( mouse_l_r_x );
\r
566 put_shrt( mouse_l_r_y );
\r
567 put_shrt( mouse_l_rel );
\r
572 put_shrt( mouse_r_r_x );
\r
573 put_shrt( mouse_r_r_y );
\r
574 put_shrt( mouse_r_rel );
\r
579 put_shrt( mouse_c_r_x );
\r
580 put_shrt( mouse_c_r_y );
\r
581 put_shrt( mouse_c_rel );
\r
585 default:put_shrt( 0 );
\r
600 static int x=0,y=0;
\r
601 put_shrt(mouse_x-x)
\r
602 put_shrt(mouse_y-y)
\r
612 get_shrt( x ) /* these parameters are not used */
\r
615 /* now we wait to point and press left button */
\r
620 put_shrt( mouse_x )
\r
621 put_shrt( mouse_y )
\r
626 fprintf(stderr,"UKNOWN COMMAND for HERCULES emulation - %d\n",cmd);
\r
628 XFreePixmap(theDisp,pixmap);
\r
629 XDestroyWindow(theDisp,window);
\r
630 XCloseDisplay(theDisp);
\r