Annotation of OpenXM_contrib2/windows/engine2000/plot.c, Revision 1.2
1.1 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.2 ! noro 48: * $OpenXM: OpenXM_contrib2/windows/engine2000/plot.c,v 1.1.1.1 2000/11/22 06:20:13 noro Exp $
1.1 noro 49: */
50: #include "ca.h"
51: #include "parse.h"
52: #include "ox.h"
53: #include "ifplot.h"
54: #include "version.h"
55: #include <signal.h>
56: #if PARI
57: #include "genpari.h"
58: #endif
59:
60: void ox_usr1_handler();
61:
62: extern int asir_OperandStackSize;
63: extern Obj *asir_OperandStack;
64: extern int asir_OperandStackPtr;
65:
66: extern jmp_buf environnement;
67:
68: extern int do_message;
69: extern int ox_flushing;
70: extern jmp_buf ox_env;
71: extern MATHCAP my_mathcap;
72: extern char LastError[];
73:
74: void create_error(ERR *,unsigned int ,char *);
75:
76: void ox_io_init();
77: void ox_asir_init(int,char **);
78: Obj asir_pop_one();
79: void asir_push_one(Obj);
80: void asir_end_flush();
81: int asir_executeString();
82: void asir_evalName(unsigned int);
83: void asir_setName(unsigned int);
84: void asir_pops();
85: void asir_popString();
86: void asir_popCMO(unsigned int);
87: void asir_popSerializedLocalObject();
88: char *name_of_cmd(unsigned int);
89: char *name_of_id(int);
90: LIST asir_GetErrorList();
91:
92: static void asir_do_cmd(unsigned int,unsigned int);
93: static void process_ox();
94: static void asir_executeFunction();
95:
96: #if defined(VISUAL)
97:
98: #include<windows.h>
99:
100: extern HANDLE hStreamNotify,hStreamNotify_Ack;
101: extern HANDLE hResizeNotify,hResizeNotify_Ack;
102:
103: void ox_plot_main()
104: #else
105: void ox_plot_main(int argc,char **argv)
106: #endif
107: {
108: int ds;
109: fd_set r;
110: int n;
111: int id;
112: Obj obj;
113: unsigned int serial;
114: USINT ui;
115:
116: #if defined(VISUAL)
117: extern int plot_argc;
118: extern char **plot_argv;
119:
120: ox_asir_init(plot_argc,plot_argv);
121: /* inform the watch thread of the completion of initialization */
122: SetEvent(hStreamNotify_Ack);
123: #else
124: ox_asir_init(argc,argv);
125: init_plot_display(argc,argv);
126: ds = ConnectionNumber(display);
127: #endif
128: if ( do_message )
129: fprintf(stderr,"I'm an ox_plot, Version %d.\n",ASIR_VERSION);
130:
131: /* XXX: dummy */
132: MKUSINT(ui,0); GC_free(ui);
133:
134: if ( setjmp(ox_env) ) {
135: while ( NEXT(asir_infile) )
136: closecurrentinput();
137: reset_current_computation();
138: ox_send_sync(0);
139: }
140: while ( 1 ) {
141: if ( ox_data_is_available(0) ) {
142: serial = ox_recv(0,&id,&obj);
143: process_ox(id,obj,serial);
144: } else {
145: #if defined(VISUAL)
146: HANDLE handle[2];
147: DWORD ret;
148: struct canvas *curcan;
149: POINT startp,endp;
150:
151: handle[0] = hStreamNotify; handle[1] = hResizeNotify;
152: ret = WaitForMultipleObjects(2,(CONST HANDLE *)handle,FALSE,(DWORD)-1);
153: switch ( ret ) {
154: case WAIT_OBJECT_0: /* hStreamNotify */
155: ResetEvent(hStreamNotify);
156: serial = ox_recv(0,&id,&obj);
157: SetEvent(hStreamNotify_Ack);
158: process_ox(id,obj,serial);
159: break;
160: case WAIT_OBJECT_0+1: /* hResizeNotify */
161: ResetEvent(hResizeNotify);
162: curcan = current_can; startp = start_point; endp = end_point;
163: SetEvent(hResizeNotify_Ack);
164: process_resize(curcan,startp,endp);
165: break;
166: }
167: #else
168: FD_ZERO(&r);
169: FD_SET(3,&r); FD_SET(ds,&r);
170: select(FD_SETSIZE,&r,NULL,NULL,NULL);
171: if ( FD_ISSET(3,&r) )
172: process_ox();
173: else if ( FD_ISSET(ds,&r) )
174: process_xevent();
175: #endif
176: }
177: }
178: }
179:
180: static void process_ox(int id, Obj obj, unsigned int serial)
181: {
182: unsigned int cmd;
183: ERR err;
184: int ret;
185: extern char LastError[];
186: extern int recv_intr;
187:
188: #if defined(VISUAL)
189: if ( recv_intr ) {
190: if ( recv_intr == 1 ) {
191: recv_intr = 0;
192: int_handler(SIGINT);
193: } else {
194: recv_intr = 0;
195: ox_usr1_handler(0);
196: }
197: }
198: #endif
199: if ( do_message )
200: fprintf(stderr,"#%d Got %s",serial,name_of_id(id));
201: switch ( id ) {
202: case OX_COMMAND:
203: cmd = ((USINT)obj)->body;
204: if ( ox_flushing )
205: break;
206: if ( do_message )
207: fprintf(stderr," %s\n",name_of_cmd(cmd));
1.2 ! noro 208: if ( ret = setjmp(main_env) ) {
1.1 noro 209: if ( ret == 1 ) {
210: create_error(&err,serial,LastError);
211: asir_push_one((Obj)err);
212: }
213: break;
214: }
215: asir_do_cmd(cmd,serial);
216: break;
217: case OX_DATA:
218: case OX_LOCAL_OBJECT_ASIR:
219: if ( ox_flushing )
220: break;
221: if ( do_message )
222: fprintf(stderr," -> data pushed");
223: asir_push_one(obj);
224: break;
225: case OX_SYNC_BALL:
226: asir_end_flush();
227: break;
228: default:
229: break;
230: }
231: if ( do_message )
232: fprintf(stderr,"\n");
233: }
234:
235: static process_resize(can,startp,endp)
236: struct canvas *can;
237: POINT startp,endp;
238: {
239: if ( can->mode == MODE_INTERACTIVE )
240: return;
241:
242: if ( can->mode == MODE_PLOT )
243: plot_resize(can,startp,endp);
244: else
245: ifplot_resize(can,startp,endp);
246: }
247:
248: static void asir_do_cmd(unsigned int cmd,unsigned int serial)
249: {
250: MATHCAP client_mathcap;
251: LIST list;
252: int i;
253: Q q;
254:
255: switch ( cmd ) {
256: case SM_dupErrors:
257: list = asir_GetErrorList();
258: asir_push_one((Obj)list);
259: break;
260: case SM_getsp:
261: i = asir_OperandStackPtr+1;
262: STOQ(i,q);
263: asir_push_one((Obj)q);
264: break;
265: case SM_popSerializedLocalObject:
266: asir_popSerializedLocalObject();
267: break;
268: case SM_popCMO:
269: asir_popCMO(serial);
270: break;
271: case SM_popString:
272: asir_popString();
273: break;
274: case SM_setName:
275: asir_setName(serial);
276: break;
277: case SM_evalName:
278: asir_evalName(serial);
279: break;
280: case SM_executeStringByLocalParser:
281: asir_executeString();
282: break;
283: case SM_executeFunction:
284: asir_executeFunction();
285: break;
286: case SM_shutdown:
287: asir_terminate(2);
288: break;
289: case SM_pops:
290: asir_pops();
291: break;
292: case SM_mathcap:
293: asir_push_one((Obj)my_mathcap);
294: break;
295: case SM_setMathcap:
296: client_mathcap = (MATHCAP)asir_pop_one();
297: store_remote_mathcap(0,client_mathcap);
298: break;
299: default:
300: break;
301: }
302: }
303:
304: static void asir_executeFunction(serial)
305: int serial;
306: {
307: char *func;
308: int argc;
309: int id;
310: FUNC f;
311: Q ret;
312: VL vl;
313: ERR err;
314: NODE n,n1;
315:
316: func = ((STRING)asir_pop_one())->body;
317: argc = (int)(((USINT)asir_pop_one())->body);
318:
319: for ( n = 0; argc; argc-- ) {
320: NEXTNODE(n,n1);
321: BDY(n1) = (pointer)asir_pop_one();
322: }
323: if ( n )
324: NEXT(n1) = 0;
325: id = -1;
326: if ( !strcmp(func,"plot") ) {
327: id = plot(n);
328: STOQ(id,ret); asir_push_one((Obj)ret);
329: } else if ( !strcmp(func,"arrayplot") ) {
330: id = arrayplot(n);
331: STOQ(id,ret); asir_push_one((Obj)ret);
332: } else if ( !strcmp(func,"open_canvas") ) {
333: id = open_canvas(n);
334: STOQ(id,ret); asir_push_one((Obj)ret);
335: } else if ( !strcmp(func,"plotover") ) {
336: plotover(n);
337: } else if ( !strcmp(func,"drawcircle") ) {
338: drawcircle(n);
339: } else if ( !strcmp(func,"draw_obj") ) {
340: if ( draw_obj(n) < 0 ) {
341: create_error(&err,serial,LastError);
342: asir_push_one((Obj)err);
343: }
344: } else if ( !strcmp(func,"clear_canvas") ) {
345: clear_canvas(n);
346: }
347: }
348:
349: print_rect(int x, int y, int z, int w)
350: {
351: extern DWORD MainThread;
352:
353: fprintf(stderr,"(%d %d %d %d MainThread=%x)\n",x,y,z,w,MainThread);
354: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>