Annotation of OpenXM_contrib2/windows/engine2000/plot.c, Revision 1.14
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.14 ! ohara 48: * $OpenXM: OpenXM_contrib2/windows/engine2000/plot.c,v 1.13 2019/03/28 07:04: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: 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.14 ! ohara 94: int Im_ox_plot;
1.1 noro 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: {
1.3 noro 108: #if !defined(VISUAL)
1.1 noro 109: int ds;
110: fd_set r;
111: int n;
1.3 noro 112: #endif
1.1 noro 113: int id;
114: Obj obj;
115: unsigned int serial;
116: USINT ui;
117:
118: #if defined(VISUAL)
119: extern int plot_argc;
120: extern char **plot_argv;
121:
1.5 noro 122: ox_asir_init(plot_argc,plot_argv,"ox_plot");
1.1 noro 123: /* inform the watch thread of the completion of initialization */
124: SetEvent(hStreamNotify_Ack);
125: #else
1.5 noro 126: ox_asir_init(argc,argv,"ox_plot");
1.1 noro 127: init_plot_display(argc,argv);
128: ds = ConnectionNumber(display);
129: #endif
130: if ( do_message )
131: fprintf(stderr,"I'm an ox_plot, Version %d.\n",ASIR_VERSION);
1.14 ! ohara 132: Im_ox_plot=1;
1.1 noro 133:
134: /* XXX: dummy */
135: MKUSINT(ui,0); GC_free(ui);
136:
137: if ( setjmp(ox_env) ) {
138: while ( NEXT(asir_infile) )
139: closecurrentinput();
140: reset_current_computation();
141: ox_send_sync(0);
142: }
143: while ( 1 ) {
144: if ( ox_data_is_available(0) ) {
145: serial = ox_recv(0,&id,&obj);
146: process_ox(id,obj,serial);
147: } else {
148: #if defined(VISUAL)
149: HANDLE handle[2];
150: DWORD ret;
151: struct canvas *curcan;
152: POINT startp,endp;
153:
154: handle[0] = hStreamNotify; handle[1] = hResizeNotify;
155: ret = WaitForMultipleObjects(2,(CONST HANDLE *)handle,FALSE,(DWORD)-1);
156: switch ( ret ) {
157: case WAIT_OBJECT_0: /* hStreamNotify */
158: ResetEvent(hStreamNotify);
159: serial = ox_recv(0,&id,&obj);
160: SetEvent(hStreamNotify_Ack);
161: process_ox(id,obj,serial);
162: break;
163: case WAIT_OBJECT_0+1: /* hResizeNotify */
164: ResetEvent(hResizeNotify);
165: curcan = current_can; startp = start_point; endp = end_point;
166: SetEvent(hResizeNotify_Ack);
167: process_resize(curcan,startp,endp);
168: break;
169: }
170: #else
171: FD_ZERO(&r);
172: FD_SET(3,&r); FD_SET(ds,&r);
173: select(FD_SETSIZE,&r,NULL,NULL,NULL);
174: if ( FD_ISSET(3,&r) )
175: process_ox();
176: else if ( FD_ISSET(ds,&r) )
177: process_xevent();
178: #endif
179: }
180: }
181: }
182:
183: static void process_ox(int id, Obj obj, unsigned int serial)
184: {
185: unsigned int cmd;
186: ERR err;
187: int ret;
188: extern char LastError[];
189:
1.12 ohara 190: check_intr();
1.1 noro 191: if ( do_message )
192: fprintf(stderr,"#%d Got %s",serial,name_of_id(id));
193: switch ( id ) {
194: case OX_COMMAND:
195: cmd = ((USINT)obj)->body;
196: if ( ox_flushing )
197: break;
198: if ( do_message )
199: fprintf(stderr," %s\n",name_of_cmd(cmd));
1.2 noro 200: if ( ret = setjmp(main_env) ) {
1.1 noro 201: if ( ret == 1 ) {
1.8 ohara 202: create_error(&err,serial,LastError,0);
1.1 noro 203: asir_push_one((Obj)err);
204: }
205: break;
206: }
207: asir_do_cmd(cmd,serial);
208: break;
209: case OX_DATA:
210: case OX_LOCAL_OBJECT_ASIR:
211: if ( ox_flushing )
212: break;
213: if ( do_message )
214: fprintf(stderr," -> data pushed");
215: asir_push_one(obj);
216: break;
217: case OX_SYNC_BALL:
218: asir_end_flush();
219: break;
220: default:
221: break;
222: }
223: if ( do_message )
224: fprintf(stderr,"\n");
225: }
226:
1.3 noro 227: static void process_resize(struct canvas *can,POINT startp,POINT endp)
1.1 noro 228: {
1.10 ohara 229: if ( can->mode == modeNO(INTERACTIVE) || can->mode == modeNO(POLARPLOT) )
1.1 noro 230: return;
231:
1.11 ohara 232: #if 0
1.10 ohara 233: if ( can->mode == modeNO(PLOT) )
1.1 noro 234: plot_resize(can,startp,endp);
235: else
236: ifplot_resize(can,startp,endp);
1.11 ohara 237: #else
238: plot_resize(can,startp,endp);
239: #endif
1.1 noro 240: }
241:
242: static void asir_do_cmd(unsigned int cmd,unsigned int serial)
243: {
244: MATHCAP client_mathcap;
245: LIST list;
246: int i;
1.13 noro 247: Z q;
1.1 noro 248:
249: switch ( cmd ) {
250: case SM_dupErrors:
251: list = asir_GetErrorList();
252: asir_push_one((Obj)list);
253: break;
254: case SM_getsp:
255: i = asir_OperandStackPtr+1;
1.13 noro 256: STOZ(i,q);
1.1 noro 257: asir_push_one((Obj)q);
258: break;
259: case SM_popSerializedLocalObject:
260: asir_popSerializedLocalObject();
261: break;
262: case SM_popCMO:
263: asir_popCMO(serial);
264: break;
265: case SM_popString:
266: asir_popString();
267: break;
268: case SM_setName:
269: asir_setName(serial);
270: break;
271: case SM_evalName:
272: asir_evalName(serial);
273: break;
274: case SM_executeStringByLocalParser:
275: asir_executeString();
276: break;
277: case SM_executeFunction:
278: asir_executeFunction();
279: break;
280: case SM_shutdown:
1.7 noro 281: asir_infile = 0;
282: asir_terminate(3);
1.1 noro 283: break;
284: case SM_pops:
285: asir_pops();
286: break;
287: case SM_mathcap:
288: asir_push_one((Obj)my_mathcap);
289: break;
290: case SM_setMathcap:
291: client_mathcap = (MATHCAP)asir_pop_one();
292: store_remote_mathcap(0,client_mathcap);
293: break;
294: default:
295: break;
296: }
297: }
298:
1.3 noro 299: static void asir_executeFunction(int serial)
1.1 noro 300: {
301: char *func;
302: int argc;
303: int id;
1.13 noro 304: Z ret;
1.1 noro 305: ERR err;
306: NODE n,n1;
307:
308: func = ((STRING)asir_pop_one())->body;
309: argc = (int)(((USINT)asir_pop_one())->body);
310:
311: for ( n = 0; argc; argc-- ) {
312: NEXTNODE(n,n1);
313: BDY(n1) = (pointer)asir_pop_one();
314: }
315: if ( n )
316: NEXT(n1) = 0;
317: id = -1;
318: if ( !strcmp(func,"plot") ) {
1.11 ohara 319: id = plot(n,modeNO(PLOT));
1.13 noro 320: STOZ(id,ret); asir_push_one((Obj)ret);
1.9 ohara 321: }else if ( !strcmp(func,"ifplot") ) {
1.11 ohara 322: id = plot(n,modeNO(IFPLOT));
1.13 noro 323: STOZ(id,ret); asir_push_one((Obj)ret);
1.1 noro 324: } else if ( !strcmp(func,"arrayplot") ) {
325: id = arrayplot(n);
1.13 noro 326: STOZ(id,ret); asir_push_one((Obj)ret);
1.1 noro 327: } else if ( !strcmp(func,"open_canvas") ) {
328: id = open_canvas(n);
1.13 noro 329: STOZ(id,ret); asir_push_one((Obj)ret);
1.1 noro 330: } else if ( !strcmp(func,"plotover") ) {
331: plotover(n);
332: } else if ( !strcmp(func,"drawcircle") ) {
333: drawcircle(n);
334: } else if ( !strcmp(func,"draw_obj") ) {
335: if ( draw_obj(n) < 0 ) {
1.8 ohara 336: create_error(&err,serial,LastError,0);
1.4 noro 337: asir_push_one((Obj)err);
338: }
339: } else if ( !strcmp(func,"draw_string") ) {
340: if ( draw_string(n) < 0 ) {
1.8 ohara 341: create_error(&err,serial,LastError,0);
1.1 noro 342: asir_push_one((Obj)err);
343: }
344: } else if ( !strcmp(func,"clear_canvas") ) {
345: clear_canvas(n);
346: }
347: }
348:
1.3 noro 349: void print_rect(int x, int y, int z, int w)
1.1 noro 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>