Annotation of OpenXM_contrib2/windows/engine2000/plot.c, Revision 1.13
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.13 ! noro 48: * $OpenXM: OpenXM_contrib2/windows/engine2000/plot.c,v 1.12 2017/08/30 09:40:31 ohara 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:
1.8 ohara 72: void create_error(ERR *,unsigned int ,char *,LIST);
1.1 noro 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:
1.12 ohara 188: check_intr();
1.1 noro 189: if ( do_message )
190: fprintf(stderr,"#%d Got %s",serial,name_of_id(id));
191: switch ( id ) {
192: case OX_COMMAND:
193: cmd = ((USINT)obj)->body;
194: if ( ox_flushing )
195: break;
196: if ( do_message )
197: fprintf(stderr," %s\n",name_of_cmd(cmd));
1.2 noro 198: if ( ret = setjmp(main_env) ) {
1.1 noro 199: if ( ret == 1 ) {
1.8 ohara 200: create_error(&err,serial,LastError,0);
1.1 noro 201: asir_push_one((Obj)err);
202: }
203: break;
204: }
205: asir_do_cmd(cmd,serial);
206: break;
207: case OX_DATA:
208: case OX_LOCAL_OBJECT_ASIR:
209: if ( ox_flushing )
210: break;
211: if ( do_message )
212: fprintf(stderr," -> data pushed");
213: asir_push_one(obj);
214: break;
215: case OX_SYNC_BALL:
216: asir_end_flush();
217: break;
218: default:
219: break;
220: }
221: if ( do_message )
222: fprintf(stderr,"\n");
223: }
224:
1.3 noro 225: static void process_resize(struct canvas *can,POINT startp,POINT endp)
1.1 noro 226: {
1.10 ohara 227: if ( can->mode == modeNO(INTERACTIVE) || can->mode == modeNO(POLARPLOT) )
1.1 noro 228: return;
229:
1.11 ohara 230: #if 0
1.10 ohara 231: if ( can->mode == modeNO(PLOT) )
1.1 noro 232: plot_resize(can,startp,endp);
233: else
234: ifplot_resize(can,startp,endp);
1.11 ohara 235: #else
236: plot_resize(can,startp,endp);
237: #endif
1.1 noro 238: }
239:
240: static void asir_do_cmd(unsigned int cmd,unsigned int serial)
241: {
242: MATHCAP client_mathcap;
243: LIST list;
244: int i;
1.13 ! noro 245: Z q;
1.1 noro 246:
247: switch ( cmd ) {
248: case SM_dupErrors:
249: list = asir_GetErrorList();
250: asir_push_one((Obj)list);
251: break;
252: case SM_getsp:
253: i = asir_OperandStackPtr+1;
1.13 ! noro 254: STOZ(i,q);
1.1 noro 255: asir_push_one((Obj)q);
256: break;
257: case SM_popSerializedLocalObject:
258: asir_popSerializedLocalObject();
259: break;
260: case SM_popCMO:
261: asir_popCMO(serial);
262: break;
263: case SM_popString:
264: asir_popString();
265: break;
266: case SM_setName:
267: asir_setName(serial);
268: break;
269: case SM_evalName:
270: asir_evalName(serial);
271: break;
272: case SM_executeStringByLocalParser:
273: asir_executeString();
274: break;
275: case SM_executeFunction:
276: asir_executeFunction();
277: break;
278: case SM_shutdown:
1.7 noro 279: asir_infile = 0;
280: asir_terminate(3);
1.1 noro 281: break;
282: case SM_pops:
283: asir_pops();
284: break;
285: case SM_mathcap:
286: asir_push_one((Obj)my_mathcap);
287: break;
288: case SM_setMathcap:
289: client_mathcap = (MATHCAP)asir_pop_one();
290: store_remote_mathcap(0,client_mathcap);
291: break;
292: default:
293: break;
294: }
295: }
296:
1.3 noro 297: static void asir_executeFunction(int serial)
1.1 noro 298: {
299: char *func;
300: int argc;
301: int id;
1.13 ! noro 302: Z ret;
1.1 noro 303: ERR err;
304: NODE n,n1;
305:
306: func = ((STRING)asir_pop_one())->body;
307: argc = (int)(((USINT)asir_pop_one())->body);
308:
309: for ( n = 0; argc; argc-- ) {
310: NEXTNODE(n,n1);
311: BDY(n1) = (pointer)asir_pop_one();
312: }
313: if ( n )
314: NEXT(n1) = 0;
315: id = -1;
316: if ( !strcmp(func,"plot") ) {
1.11 ohara 317: id = plot(n,modeNO(PLOT));
1.13 ! noro 318: STOZ(id,ret); asir_push_one((Obj)ret);
1.9 ohara 319: }else if ( !strcmp(func,"ifplot") ) {
1.11 ohara 320: id = plot(n,modeNO(IFPLOT));
1.13 ! noro 321: STOZ(id,ret); asir_push_one((Obj)ret);
1.1 noro 322: } else if ( !strcmp(func,"arrayplot") ) {
323: id = arrayplot(n);
1.13 ! noro 324: STOZ(id,ret); asir_push_one((Obj)ret);
1.1 noro 325: } else if ( !strcmp(func,"open_canvas") ) {
326: id = open_canvas(n);
1.13 ! noro 327: STOZ(id,ret); asir_push_one((Obj)ret);
1.1 noro 328: } else if ( !strcmp(func,"plotover") ) {
329: plotover(n);
330: } else if ( !strcmp(func,"drawcircle") ) {
331: drawcircle(n);
332: } else if ( !strcmp(func,"draw_obj") ) {
333: if ( draw_obj(n) < 0 ) {
1.8 ohara 334: create_error(&err,serial,LastError,0);
1.4 noro 335: asir_push_one((Obj)err);
336: }
337: } else if ( !strcmp(func,"draw_string") ) {
338: if ( draw_string(n) < 0 ) {
1.8 ohara 339: create_error(&err,serial,LastError,0);
1.1 noro 340: asir_push_one((Obj)err);
341: }
342: } else if ( !strcmp(func,"clear_canvas") ) {
343: clear_canvas(n);
344: }
345: }
346:
1.3 noro 347: void print_rect(int x, int y, int z, int w)
1.1 noro 348: {
349: extern DWORD MainThread;
350:
351: fprintf(stderr,"(%d %d %d %d MainThread=%x)\n",x,y,z,w,MainThread);
352: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>