Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / int / net / ip / graph.c
1 #include <stdio.h>
2
3 #include <X11/Xlib.h>
4 #include <X11/Xutil.h>
5
6 #include <math.h>
7
8 #include "graph.h"
9
10
11 static int child_no=0;
12 static int fcol=1,bcol=0;
13
14 static Display *theDisplay;
15 static Window myWindow,theWindow;
16 static XClientMessageEvent theMessage;
17 static XEvent retEv;
18
19 static void send_sig(nrproc) int nrproc; {
20    theMessage.type=ClientMessage;
21    theMessage.format = 16;
22    theMessage.message_type = nrproc;
23    XSendEvent(theDisplay,theWindow,True,NoEventMask,&theMessage);
24    XFlush(theDisplay);
25 }
26
27 static void nxtev(){
28    do XNextEvent( theDisplay, &retEv );
29    while( retEv.type!=ClientMessage );
30 }
31
32
33
34
35 void graph_on(x,y,title) int x,y; char *title; {
36
37    if ((theDisplay = XOpenDisplay(NULL)) == NULL){
38       fprintf (stderr,"\ngraph:  Can't open display\n");
39       exit(1);
40    }
41
42    myWindow = XCreateWindow(
43       theDisplay,
44       RootWindow(theDisplay,DefaultScreen(theDisplay)),
45       0,0,1,1,0,
46       CopyFromParent,InputOnly,CopyFromParent,
47       0,NULL
48       );
49
50    if( (child_no=fork())==0 ){
51       char me[16];
52       char xs[16];
53       char ys[16];
54       sprintf(me,"%d",(int)myWindow);
55       sprintf(xs,"%d",x);
56       sprintf(ys,"%d",y);
57       execlp("./graph","graph",me,xs,ys,title,NULL);
58    }
59
60    nxtev();
61    theWindow = (int)(retEv.xclient.data.l[0]);
62 }
63                 
64
65 void graph_off(){
66    send_sig(GRAPH_CMD_END);
67    child_no=0;
68 }
69
70
71 void graph_point( x,c ) int x,c; {
72    theMessage.data.l[0]=x;
73    theMessage.data.l[1]=c;
74    send_sig(GRAPH_CMD_POINT);
75 }
76
77 void graph_board( size ) int size; {
78    theMessage.data.l[0]=size;
79    send_sig(GRAPH_CMD_LINE);
80 }
81