Annotation of OpenXM_contrib2/windows/engine2000/plot.c, Revision 1.7
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.7 ! noro 48: * $OpenXM: OpenXM_contrib2/windows/engine2000/plot.c,v 1.6 2002/08/02 09:30:23 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: extern int asir_OperandStackSize;
61: extern Obj *asir_OperandStack;
62: extern int asir_OperandStackPtr;
63:
64: extern jmp_buf environnement;
65:
66: extern int do_message;
67: extern int ox_flushing;
68: extern jmp_buf ox_env;
69: extern MATHCAP my_mathcap;
70: extern char LastError[];
71:
72: void create_error(ERR *,unsigned int ,char *);
73:
74: void ox_io_init();
1.5 noro 75: void ox_asir_init(int,char **,char *);
1.1 noro 76: Obj asir_pop_one();
77: void asir_push_one(Obj);
78: void asir_end_flush();
79: int asir_executeString();
80: void asir_evalName(unsigned int);
81: void asir_setName(unsigned int);
82: void asir_pops();
83: void asir_popString();
84: void asir_popCMO(unsigned int);
85: void asir_popSerializedLocalObject();
86: char *name_of_cmd(unsigned int);
87: char *name_of_id(int);
88: LIST asir_GetErrorList();
89:
90: static void asir_do_cmd(unsigned int,unsigned int);
91: static void process_ox();
92: static void asir_executeFunction();
1.3 noro 93: static void process_resize(struct canvas *can,POINT startp,POINT endp);
1.1 noro 94:
95: #if defined(VISUAL)
96:
97: #include<windows.h>
98:
99: extern HANDLE hStreamNotify,hStreamNotify_Ack;
100: extern HANDLE hResizeNotify,hResizeNotify_Ack;
101:
102: void ox_plot_main()
103: #else
104: void ox_plot_main(int argc,char **argv)
105: #endif
106: {
1.3 noro 107: #if !defined(VISUAL)
1.1 noro 108: int ds;
109: fd_set r;
110: int n;
1.3 noro 111: #endif
1.1 noro 112: int id;
113: Obj obj;
114: unsigned int serial;
115: USINT ui;
116:
117: #if defined(VISUAL)
118: extern int plot_argc;
119: extern char **plot_argv;
120:
1.5 noro 121: ox_asir_init(plot_argc,plot_argv,"ox_plot");
1.1 noro 122: /* inform the watch thread of the completion of initialization */
123: SetEvent(hStreamNotify_Ack);
124: #else
1.5 noro 125: ox_asir_init(argc,argv,"ox_plot");
1.1 noro 126: init_plot_display(argc,argv);
127: ds = ConnectionNumber(display);
128: #endif
129: if ( do_message )
130: fprintf(stderr,"I'm an ox_plot, Version %d.\n",ASIR_VERSION);
131:
132: /* XXX: dummy */
133: MKUSINT(ui,0); GC_free(ui);
134:
135: if ( setjmp(ox_env) ) {
136: while ( NEXT(asir_infile) )
137: closecurrentinput();
138: reset_current_computation();
139: ox_send_sync(0);
140: }
141: while ( 1 ) {
142: if ( ox_data_is_available(0) ) {
143: serial = ox_recv(0,&id,&obj);
144: process_ox(id,obj,serial);
145: } else {
146: #if defined(VISUAL)
147: HANDLE handle[2];
148: DWORD ret;
149: struct canvas *curcan;
150: POINT startp,endp;
151:
152: handle[0] = hStreamNotify; handle[1] = hResizeNotify;
153: ret = WaitForMultipleObjects(2,(CONST HANDLE *)handle,FALSE,(DWORD)-1);
154: switch ( ret ) {
155: case WAIT_OBJECT_0: /* hStreamNotify */
156: ResetEvent(hStreamNotify);
157: serial = ox_recv(0,&id,&obj);
158: SetEvent(hStreamNotify_Ack);
159: process_ox(id,obj,serial);
160: break;
161: case WAIT_OBJECT_0+1: /* hResizeNotify */
162: ResetEvent(hResizeNotify);
163: curcan = current_can; startp = start_point; endp = end_point;
164: SetEvent(hResizeNotify_Ack);
165: process_resize(curcan,startp,endp);
166: break;
167: }
168: #else
169: FD_ZERO(&r);
170: FD_SET(3,&r); FD_SET(ds,&r);
171: select(FD_SETSIZE,&r,NULL,NULL,NULL);
172: if ( FD_ISSET(3,&r) )
173: process_ox();
174: else if ( FD_ISSET(ds,&r) )
175: process_xevent();
176: #endif
177: }
178: }
179: }
180:
181: static void process_ox(int id, Obj obj, unsigned int serial)
182: {
183: unsigned int cmd;
184: ERR err;
185: int ret;
186: extern char LastError[];
187: extern int recv_intr;
188:
189: #if defined(VISUAL)
190: if ( recv_intr ) {
191: if ( recv_intr == 1 ) {
192: recv_intr = 0;
193: int_handler(SIGINT);
194: } else {
195: recv_intr = 0;
196: ox_usr1_handler(0);
197: }
198: }
199: #endif
200: if ( do_message )
201: fprintf(stderr,"#%d Got %s",serial,name_of_id(id));
202: switch ( id ) {
203: case OX_COMMAND:
204: cmd = ((USINT)obj)->body;
205: if ( ox_flushing )
206: break;
207: if ( do_message )
208: fprintf(stderr," %s\n",name_of_cmd(cmd));
1.2 noro 209: if ( ret = setjmp(main_env) ) {
1.1 noro 210: if ( ret == 1 ) {
211: create_error(&err,serial,LastError);
212: asir_push_one((Obj)err);
213: }
214: break;
215: }
216: asir_do_cmd(cmd,serial);
217: break;
218: case OX_DATA:
219: case OX_LOCAL_OBJECT_ASIR:
220: if ( ox_flushing )
221: break;
222: if ( do_message )
223: fprintf(stderr," -> data pushed");
224: asir_push_one(obj);
225: break;
226: case OX_SYNC_BALL:
227: asir_end_flush();
228: break;
229: default:
230: break;
231: }
232: if ( do_message )
233: fprintf(stderr,"\n");
234: }
235:
1.3 noro 236: static void process_resize(struct canvas *can,POINT startp,POINT endp)
1.1 noro 237: {
1.6 noro 238: if ( can->mode == MODE_INTERACTIVE || can->mode == MODE_POLARPLOT )
1.1 noro 239: return;
240:
241: if ( can->mode == MODE_PLOT )
242: plot_resize(can,startp,endp);
243: else
244: ifplot_resize(can,startp,endp);
245: }
246:
247: static void asir_do_cmd(unsigned int cmd,unsigned int serial)
248: {
249: MATHCAP client_mathcap;
250: LIST list;
251: int i;
252: Q q;
253:
254: switch ( cmd ) {
255: case SM_dupErrors:
256: list = asir_GetErrorList();
257: asir_push_one((Obj)list);
258: break;
259: case SM_getsp:
260: i = asir_OperandStackPtr+1;
261: STOQ(i,q);
262: asir_push_one((Obj)q);
263: break;
264: case SM_popSerializedLocalObject:
265: asir_popSerializedLocalObject();
266: break;
267: case SM_popCMO:
268: asir_popCMO(serial);
269: break;
270: case SM_popString:
271: asir_popString();
272: break;
273: case SM_setName:
274: asir_setName(serial);
275: break;
276: case SM_evalName:
277: asir_evalName(serial);
278: break;
279: case SM_executeStringByLocalParser:
280: asir_executeString();
281: break;
282: case SM_executeFunction:
283: asir_executeFunction();
284: break;
285: case SM_shutdown:
1.7 ! noro 286: asir_infile = 0;
! 287: asir_terminate(3);
1.1 noro 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:
1.3 noro 304: static void asir_executeFunction(int serial)
1.1 noro 305: {
306: char *func;
307: int argc;
308: int id;
309: Q ret;
310: ERR err;
311: NODE n,n1;
312:
313: func = ((STRING)asir_pop_one())->body;
314: argc = (int)(((USINT)asir_pop_one())->body);
315:
316: for ( n = 0; argc; argc-- ) {
317: NEXTNODE(n,n1);
318: BDY(n1) = (pointer)asir_pop_one();
319: }
320: if ( n )
321: NEXT(n1) = 0;
322: id = -1;
323: if ( !strcmp(func,"plot") ) {
324: id = plot(n);
325: STOQ(id,ret); asir_push_one((Obj)ret);
326: } else if ( !strcmp(func,"arrayplot") ) {
327: id = arrayplot(n);
328: STOQ(id,ret); asir_push_one((Obj)ret);
329: } else if ( !strcmp(func,"open_canvas") ) {
330: id = open_canvas(n);
331: STOQ(id,ret); asir_push_one((Obj)ret);
332: } else if ( !strcmp(func,"plotover") ) {
333: plotover(n);
334: } else if ( !strcmp(func,"drawcircle") ) {
335: drawcircle(n);
336: } else if ( !strcmp(func,"draw_obj") ) {
337: if ( draw_obj(n) < 0 ) {
1.4 noro 338: create_error(&err,serial,LastError);
339: asir_push_one((Obj)err);
340: }
341: } else if ( !strcmp(func,"draw_string") ) {
342: if ( draw_string(n) < 0 ) {
1.1 noro 343: create_error(&err,serial,LastError);
344: asir_push_one((Obj)err);
345: }
346: } else if ( !strcmp(func,"clear_canvas") ) {
347: clear_canvas(n);
348: }
349: }
350:
1.3 noro 351: void print_rect(int x, int y, int z, int w)
1.1 noro 352: {
353: extern DWORD MainThread;
354:
355: fprintf(stderr,"(%d %d %d %d MainThread=%x)\n",x,y,z,w,MainThread);
356: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>