Added upstream version.
[vlp.git] / int / nonstand.c
1 #include "depend.h"
2 #include "genint.h" 
3 #include "int.h"
4 #include "process.h"
5 #include "intproto.h"
6
7 #include "nonstand.h"
8
9
10 /* Call (non)standard procedures.
11  * Almost totaly implementation dependent.
12  */
13
14 bool graphmode = FALSE;                 /* TRUE iff graphics mode active */
15 param_struct par;
16
17 char *s;
18 char ss[255];
19 char ii[50],ff[50];
20 int scc,lastmsg;
21
22 int wait_for_key()
23 {
24  G_MESSAGE msg;
25
26  bzero(&msg,sizeof(G_MESSAGE));
27  while ((msg.msg_type != MSG_GRAPH) && (msg.param.pword[0] != GRAPH_INKEY_RESPONSE))
28 { read_from_graph(&msg);
29   
30  }
31  return(msg.param.pword[3]);
32 }
33
34
35 void nonstandard(nrproc)                /* Call (non)standard procedure */
36 word nrproc;
37 {
38
39    word am;
40    int cnt=0;
41    float r1, r2;
42    word ax,bx,cx,dx,i,t1,t2;
43    unsigned int v,p,h,l,r,c,sc;
44    unsigned int Res_graph_X,Res_graph_Y;
45    G_MESSAGE msg;
46    MESSAGE msg1;
47
48
49    switch ((int) nrproc)
50     {
51         case GRON :
52         case GROFF :break;
53
54         case CLS : msg.msg_type = MSG_GRAPH;
55                    msg.param.pword[0] = GRAPH_CLEAR;
56                    msg.param.pword[1] = GraphRes;
57                    send_to_graph(&msg);
58         break;  
59
60         case POINT :
61                  msg.msg_type = MSG_GRAPH;
62                  msg.param.pword[0]=GRAPH_POINT;
63                  msg.param.pword[1] = GraphRes;
64                  msg.param.pword[3]=param[0].xword;
65                  msg.param.pword[4]=param[1].xword;
66                  send_to_graph(&msg);
67                 break;
68         case MOVE :
69                  msg.msg_type = MSG_GRAPH;
70                  msg.param.pword[0]=GRAPH_MOVE;
71                  msg.param.pword[1] = GraphRes;
72                  msg.param.pword[2]=param[0].xword;
73                  msg.param.pword[3]=param[1].xword;
74                  send_to_graph(&msg);
75                 break;
76                 
77         case DRAW :
78                  msg.msg_type = MSG_GRAPH;
79                  msg.param.pword[0]=GRAPH_LINETO;
80                  msg.param.pword[1] = GraphRes;
81                  msg.param.pword[3]=param[0].xword;
82                  msg.param.pword[4]=param[1].xword;
83                  send_to_graph(&msg);
84                break;
85                 
86         case INXPOS :
87                  msg.msg_type = MSG_GRAPH;
88                  msg.param.pword[0]=GRAPH_CURPOS;
89                  msg.param.pword[1] = GraphRes;                 
90                  send_to_graph(&msg);
91                  while ((msg.msg_type!=MSG_GRAPH)&&(msg.param.pword[0]!=GRAPH_CURPOS_RESPONSE))
92                   read_from_graph(&msg);
93                 param[0].xword = msg.param.pword[3];
94                 break;
95         
96         case INYPOS :
97                  msg.msg_type = MSG_GRAPH;
98                  msg.param.pword[0]=GRAPH_CURPOS;
99                  msg.param.pword[1] = GraphRes;                 
100                  send_to_graph(&msg);
101                  while ((msg.msg_type!=MSG_GRAPH)||(msg.param.pword[0]!=GRAPH_CURPOS_RESPONSE))
102                   read_from_graph(&msg);
103                  param[0].xword = msg.param.pword[4];
104                 break;
105         
106         case HFILL :
107                  break;
108         case VFILL :
109                         break;
110                 
111         case HASCII :
112                         msg.msg_type = MSG_GRAPH;
113                         msg.param.pword[0]=GRAPH_HASCII;
114                         msg.param.pword[1]=param[0].xword;
115                         send_to_graph(&msg);
116                         break;
117                 
118         case COLOR :
119                  msg.msg_type = MSG_GRAPH;
120                  msg.param.pword[0]=GRAPH_FOREGROUND;
121                  msg.param.pword[1] = GraphRes;                 
122                  msg.param.pword[3] = param[0].xword;
123                  send_to_graph(&msg);
124                break;
125                 
126         case BORDER :
127                  msg.msg_type = MSG_GRAPH;
128                  msg.param.pword[0]=GRAPH_BACKGROUND;
129                  msg.param.pword[1] = GraphRes;                 
130                  msg.param.pword[3] = param[0].xword;
131                  send_to_graph(&msg);
132         break;
133                 
134         case STYLE :
135                 break;
136                 
137         case INPIX :
138                 break;
139
140         case OUTSTRING :
141                  msg.msg_type = MSG_GRAPH;
142                  msg.param.pword[0]=GRAPH_OUTSTRING;
143                  msg.param.pword[1] = GraphRes;                 
144                  msg.param.pword[2] = param[0].xword;
145                  msg.param.pword[3] = param[1].xword;
146                  msg.param.pword[4] = param[3].xword;
147                  msg.param.pword[5] = param[4].xword; 
148                 {
149                  s= (char *)(M + strings + param[ 2 ].xword + 1);
150                  strcpy(msg.param.pstr,s);
151                  send_to_graph(&msg);
152                  }
153                  break;
154
155         case GETMAP :
156                msg.msg_type = MSG_GRAPH;
157                msg.param.pword[0] = GRAPH_GETMAP;
158                msg.param.pword[1] = GraphRes;
159                msg.param.pword[2] = param[0].xword;
160                msg.param.pword[3] = param[1].xword;
161                send_to_graph(&msg);
162                while ((msg.msg_type!=MSG_GRAPH)||(msg.param.pword[0]!=GRAPH_GETMAP_RESPONSE))
163                read_from_graph(&msg);
164                
165                {
166                 int map;
167                 
168                 map =msg.param.pword[2]; 
169                 newarry((word) 1, 3, (word)AINT, &param[ 2 ].xvirt, &am);
170                 M[ am+3 ] = map;
171                 M[ am+4 ] = msg.param.pword[3];
172                 M[ am+5 ] = msg.param.pword[4];
173
174                }
175         break;
176          
177         
178         case PUTMAP :
179         if (member(&param[ 0 ].xvirt, &am)){
180              msg.msg_type = MSG_GRAPH;
181              msg.param.pword[0] = GRAPH_PUTMAP;
182              msg.param.pword[1] = GraphRes;
183              msg.param.pword[2] = M[am+3];
184              msg.param.pword[4] = M[am+4];
185              msg.param.pword[5] = M[am+5];
186              send_to_graph(&msg);
187           }   
188         break;
189         
190         case ORMAP :
191         case XORMAP :break;
192                 
193
194         case PATERN :
195                  msg.msg_type = MSG_GRAPH;
196                  msg.param.pword[0]=GRAPH_RECT;
197                  msg.param.pword[1] = GraphRes;
198                  msg.param.pword[3] = param[0].xword;
199                  msg.param.pword[4] = param[1].xword;
200                  msg.param.pword[5] = param[2].xword;
201                  msg.param.pword[6] = param[3].xword;
202                  msg.param.pword[7] = param[4].xword; 
203                  msg.param.pword[8] = param[5].xword;
204                  send_to_graph(&msg);                                                                                                   break;
205         case PALLET:break;              
206         
207         case TRACK :
208                 msg.msg_type = MSG_GRAPH;
209                 msg.param.pword[0] = GRAPH_WRITEINTXY;
210                 msg.param.pword[1] = GraphRes;
211                 msg.param.pword[2] = param[0].xword;
212                 msg.param.pword[3] = param[1].xword;
213                 msg.param.pword[4] = param[4].xword;
214                 msg.param.pword[5] = param[2].xword; 
215                 send_to_graph(&msg);    
216                 break;
217
218         case INKEY :
219                  msg.msg_type = MSG_GRAPH;
220                  msg.param.pword[0]=GRAPH_INKEY;
221                  msg.param.pword[1] = GraphRes;                 
222                  send_to_graph(&msg);
223                  param[0].xword = wait_for_key();
224                     break;
225
226
227         case CIRB :
228                 msg.msg_type = MSG_GRAPH;
229                 msg.param.pword[0]=GRAPH_ELLIPSE;
230                 msg.param.pword[1] = GraphRes;                 
231                 msg.param.pword[3]=param[0].xword; msg.param.pword[4]=param[1].xword;       
232                 msg.param.pword[5]=param[2].xword; msg.param.pword[6]=param[3].xword;
233                 msg.param.pword[7]=(double)param[4].xword;
234                 msg.param.pword[8]=(double) param[5].xword;
235                 msg.param.pword[9]=param[7].xword;
236                 send_to_graph(&msg);
237                 break;
238
239         case HFONT8: /* ___________ magic library ____________ */
240                   
241                    if (param[0].xword==1000)
242                    {
243                     strcpy(ss,"");
244                    } else
245                    if (param[0].xword==1001)
246                    {
247                      sprintf(ss,"%s%c",ss,(char)(param[1].xword));
248                    } else
249                    if (param[0].xword==303)
250                    {
251                     msg.param.pword[1] = param[0].xword;
252                     msg.param.pword[2] = param[1].xword;
253                     msg.param.pword[3] = param[2].xword;
254                     msg.param.pword[4] = param[3].xword;
255                     msg.param.pword[5] = param[5].xword;
256                     msg.msg_type = MSG_GRAPH;
257                     msg.param.pword[0] = GRAPH_MAGIC;
258                     strcpy(msg.param.pstr,ss);
259                     send_to_graph(&msg);
260                    } else
261                    if (param[0].xword>500)
262                    {
263                        msg1.param.pword[1] = param[0].xword;
264                        msg1.param.pword[2] = param[1].xword;
265                        msg1.param.pword[3] = param[2].xword;
266                        msg1.param.pword[4] = param[3].xword;
267                        s= (char *)(M + strings + param[ 4 ].xword + 1);
268                        strcpy(msg1.param.pstr,s);
269                        msg1.param.pword[5] = param[5].xword;
270                        msg1.param.pword[6] = param[6].xword;
271                        msg1.param.pword[7] = param[7].xword;    
272           
273                     switch(msg1.param.pword[1]) /* Machine class */
274                     {
275                      case 501: /* get local node */
276                               newarry((word)0,2,(word)AINT,&param[8].xvirt,&ax);
277                               ax+=3;
278                               M[ax++]=my_ctx.node;
279                               break;
280                      case 502: /* number of nodes */
281                               msg1.msg_type = MSG_NET;
282                               msg1.param.pword[0]=NET_NODES_NUM;
283                               write(net_sock,&msg1,sizeof(MESSAGE));
284                               while ((msg1.msg_type!=MSG_NET) || (msg1.param.pword[0]!=NET_NODES_NUM_RESPONSE) )
285                                read_from_net(&msg1);
286                               newarry((word)0,2,(word)AINT,&param[8].xvirt,&ax);
287                               ax+=3;
288                               M[ax++]=msg1.param.pword[1];
289                               break;
290                      case 503: /* node exists */ 
291                               msg1.msg_type = MSG_NET;
292                               msg1.param.pword[0]=NET_NODE_EXIST;
293                               msg1.param.pword[1]=msg1.param.pword[2];
294                               write(net_sock,&msg1,sizeof(MESSAGE));
295                               bzero(&msg1,sizeof(msg1));
296                               while ((msg1.msg_type!=MSG_NET) || (msg1.param.pword[0]!=NET_NODE_EXIST) )
297                                read_from_net(&msg1); 
298                               newarry((word)0,2,(word)AINT,&param[8].xvirt,&ax);
299                               ax+=3;
300                               M[ax++]=msg1.param.pword[1];
301                               break;
302                      case 504: /* get nodes info */
303                               {
304                                char ss[1024];
305                                strcpy(ss,"");
306                                msg1.msg_type = MSG_NET;
307                                msg1.param.pword[0]=NET_GET_INFO;
308                                write(net_sock,&msg1,sizeof(MESSAGE));
309                                while ( (msg1.msg_type!=MSG_NET) ||(msg1.param.pword[0]!=NET_INFO_END) )
310                                {
311                                 read_from_net(&msg1);
312                                 if (msg1.param.pword[0]==NET_INFO)
313                                 strcat(ss,msg1.param.pstr);
314                                }
315                               newarry((word)0,strlen(ss),(word)AINT,
316                                          &param[8].xvirt,&ax);
317                                   ax+=3;
318                                   s=ss;
319                                   while(*s!='\0')
320                                    M[ax++]=*(s++);
321                               } ;break;
322           
323                               
324                     }/* switch */
325                    }   
326                    else
327                    {   /* graphic */
328                        
329                    msg.param.pword[1] = param[0].xword;
330                    msg.param.pword[2] = param[1].xword;
331                    msg.param.pword[3] = param[2].xword;
332                    msg.param.pword[4] = param[3].xword;
333                    s= (char *)(M + strings + param[ 4 ].xword + 1);
334                    strcpy(msg.param.pstr,s);
335                    msg.param.pword[5] = param[5].xword;
336                    msg.param.pword[6] = param[6].xword;
337                    msg.param.pword[7] = param[7].xword;    
338               
339                    msg.msg_type = MSG_GRAPH;
340                    msg.param.pword[0] = GRAPH_MAGIC;
341                   
342                    send_to_graph(&msg);
343                    
344                    if (msg.param.pword[1]<0)
345                    {
346                     lastmsg=msg.param.pword[1];
347                     bzero(&msg,sizeof(G_MESSAGE));
348                     while (msg.param.pword[0]!=GRAPH_MAGIC_RESPONSE)
349                      read_from_graph(&msg);
350                     if (lastmsg==-305) // Read integer
351                     {
352                      newarry((word)0,10,(word)AINT,&param[8].xvirt,&ax);
353                      ax+=3;
354                      M[ax++]=atoi(msg.param.pstr);
355                     }
356                     else
357                     if (lastmsg==-306) // Read char
358                     {
359                      newarry((word)0,10,(word)AINT,&param[8].xvirt,&ax);
360                      ax+=3;
361                      M[ax++]=msg.param.pchar;
362                     }
363                     else
364                     if (lastmsg==-307) // Read real
365                     {
366                      newarry((word)0,10,(word)AINT,&param[8].xvirt,&ax);
367                      ax+=3;
368                      strcpy(ii,"");strcpy(ff,"");sc=0;
369                      while ((sc<strlen(msg.param.pstr)) && (msg.param.pstr[sc]!='.'))
370                      {
371                       ii[sc]=msg.param.pstr[sc];
372                       sc++;
373                      }
374                      ii[sc++]='\0';scc=sc;sc=0;
375                      while (scc<strlen(msg.param.pstr))
376                       {
377                        ff[sc++]=msg.param.pstr[scc++];
378                        }
379                      ff[sc]='\0';  
380                      M[ax++]=atoi(ii);
381                      M[ax++]=atoi(ff);                     
382                      
383                     }
384                     else
385                     if (msg.param.pword[1]==1)
386                     {
387                      newarry((word)0,10,(word)AINT,&param[8].xvirt,&ax);
388                      ax+=3;
389                      for(l=2;l<7;l++)
390                       M[ax++]=msg.param.pword[l];
391                     } 
392                      else
393                      {
394                        newarry((word)0,strlen(msg.param.pstr)+2,(word)AINT,
395                          &param[8].xvirt,&ax);
396                        ax+=3;
397                        s=msg.param.pstr;
398                       while(*s!='\0')
399                        M[ax++]=*(s++);
400                      }
401                    }
402                    } /* graphic */
403                    break;
404
405         case INIT :
406         
407                 break;
408         
409         case STATUS :
410                         break;
411         
412         case GETPRESS :
413                  msg.msg_type = MSG_GRAPH;
414                  msg.param.pword[0]=GRAPH_MGETPRESS;
415                  msg.param.pword[1] = GraphRes;                 
416                  send_to_graph(&msg);
417                  while (1)
418                  {
419                     read_from_graph(&msg);
420                     if ( (msg.msg_type==MSG_GRAPH)&&(msg.param.pword[0]==GRAPH_MGETPRESS_RESPONSE)) break;
421                  }
422                  param[0].xword = msg.param.pword[2];
423                  param[1].xword = msg.param.pword[3];
424                  param[2].xword = msg.param.pword[4];
425                  param[3].xword = msg.param.pword[5];
426                  param[4].xword = msg.param.pword[6];
427                  param[5].xword = msg.param.pword[7];
428                 break;
429
430                       
431                         break;
432         case GETRELEASE :
433                         break;
434         
435         case SHOWCURSOR :
436         case HIDECURSOR :
437         case SETPOSITION :
438         case SETWINDOW :
439         case DEFCURSOR :
440         case SETSPEED :
441         case SETMARGINS :
442         case SETTHRESHOLD :
443                 break;
444
445         case GETMOVEMENT :
446                                 break;
447
448
449
450
451         default  :
452                 errsignal(RTEUNSTP);
453     }
454
455 }
456