Annotation of OpenXM_contrib2/asir2018/plot/ox_plot.c, Revision 1.3
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.3 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2018/plot/ox_plot.c,v 1.2 2018/09/28 08:20:29 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 defined(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: // environement is defined in libpari.a
65: #if !(PARI_VERSION_CODE > 131588)
66: extern jmp_buf environnement;
67: #endif
68:
69: extern int do_message;
70: extern int ox_flushing;
71: extern JMP_BUF ox_env;
72: extern MATHCAP my_mathcap;
73: extern char LastError[];
74:
75: void create_error(ERR *,unsigned int ,char *,LIST );
76: int objcp(NODE arg);
77:
78: void ox_io_init();
79: void ox_asir_init(int,char **,char *);
80: Obj asir_pop_one();
81: void asir_push_one(Obj);
82: void asir_end_flush();
83: int asir_executeString();
84: void asir_evalName(unsigned int);
85: void asir_setName(unsigned int);
86: void asir_pops();
87: void asir_popString();
88: void asir_popCMO(unsigned int);
89: void asir_popSerializedLocalObject();
90: char *name_of_cmd(unsigned int);
91: char *name_of_id(int);
92: LIST asir_GetErrorList();
93:
94: static void asir_do_cmd(unsigned int,unsigned int);
95: static void process_ox();
96: static void asir_executeFunction();
97:
1.3 ! noro 98: int Im_ox_plot;
! 99:
1.1 noro 100: #if defined(VISUAL) || defined(__MINGW32__)
101: void ox_plot_main()
102: #else
103: void ox_plot_main(int argc,char **argv)
104: #endif
105: {
106: int ds;
107: fd_set r;
108: int n;
109: int use_x;
110:
111: #if !defined(VISUAL) && !defined(__MINGW32__)
112: ox_asir_init(argc,argv,"ox_plot");
113: use_x=init_plot_display(argc,argv);
114: if(use_x) ds=ConnectionNumber(display);
115: else fprintf(stderr,"Entering no X mode\n");
116: #endif
117: if(do_message)fprintf(stderr,"I'm an ox_plot, Version %d.\n",ASIR_VERSION);
1.3 ! noro 118: Im_ox_plot = 1;
! 119: #if 0
1.1 noro 120: if(SETJMP(ox_env)){
121: while(NEXT(asir_infile))closecurrentinput();
122: reset_current_computation();
123: ox_send_sync(0);
124: }
1.3 ! noro 125: #endif
1.1 noro 126: while (1){
127: #if defined(VISUAL) || defined(__MINGW32__)
128: process_ox();
129: #else
130: if(ox_data_is_available(0)) process_ox();
131: else if(use_x){
132: FD_ZERO(&r);
133: FD_SET(3,&r); FD_SET(ds,&r);
134: select(FD_SETSIZE,&r,NULL,NULL,NULL);
135: if(FD_ISSET(3,&r)) process_ox();
136: else if(FD_ISSET(ds,&r)) process_xevent();
137: }
138: }
139: #endif
140: }
141:
142: static void process_ox(){
143: int id;
144: unsigned int cmd;
145: Obj obj;
146: ERR err;
147: unsigned int serial;
148: int ret;
149:
150: serial=ox_recv(0,&id,&obj);
151: if(do_message) fprintf(stderr,"#%d Got %s",serial,name_of_id(id));
152: switch (id){
153: case OX_COMMAND:
154: cmd=((USINT)obj)->body;
155: if(ox_flushing) break;
156: if(do_message) fprintf(stderr," %s\n",name_of_cmd(cmd));
157: ret=SETJMP(main_env);
158: if(ret){
159: if(ret==1){
160: create_error(&err,serial,LastError,0);
161: asir_push_one((Obj)err);
162: }
163: break;
164: }
165: asir_do_cmd(cmd,serial);
166: break;
167: case OX_DATA:
168: case OX_LOCAL_OBJECT_ASIR:
169: if(ox_flushing)break;
170: if(do_message)fprintf(stderr," -> data pushed");
171: asir_push_one(obj);
172: break;
173: case OX_SYNC_BALL:
174: asir_end_flush();
175: break;
176: default:
177: break;
178: }
179: if(do_message)fprintf(stderr,"\n");
180: }
181:
182: static void asir_do_cmd(unsigned int cmd,unsigned int serial){
183: MATHCAP client_mathcap;
184: LIST list;
185: int i;
186: Z q;
187:
188: switch (cmd){
189: case SM_dupErrors:
190: list=asir_GetErrorList();
191: asir_push_one((Obj)list);
192: break;
193: case SM_getsp:
194: i=asir_OperandStackPtr+1;
1.2 noro 195: STOZ(i,q);
1.1 noro 196: asir_push_one((Obj)q);
197: break;
198: case SM_popSerializedLocalObject:
199: asir_popSerializedLocalObject();
200: break;
201: case SM_popCMO:
202: asir_popCMO(serial);
203: break;
204: case SM_popString:
205: asir_popString();
206: break;
207: case SM_setName:
208: asir_setName(serial);
209: break;
210: case SM_evalName:
211: asir_evalName(serial);
212: break;
213: case SM_executeStringByLocalParser:
214: asir_executeString();
215: break;
216: case SM_executeFunction:
217: asir_executeFunction(serial);
218: break;
219: case SM_shutdown:
220: asir_terminate(2);
221: break;
222: case SM_pops:
223: asir_pops();
224: break;
225: case SM_mathcap:
226: asir_push_one((Obj)my_mathcap);
227: break;
228: case SM_setMathcap:
229: client_mathcap=(MATHCAP)asir_pop_one();
230: store_remote_mathcap(0,client_mathcap);
231: break;
232: case SM_nop:
233: default:
234: break;
235: }
236: }
237:
238: static void asir_executeFunction(int serial){
239: char *fn;
240: int argc,id,fno;
241: FUNC f;
242: Z ret;
243: VL vl;
244: ERR err;
245: NODE n,n1;
246: LIST bytes;
247:
248: fn=((STRING)asir_pop_one())->body;
249: argc=(int)(((USINT)asir_pop_one())->body);
250: for(n=0;argc;argc--){
251: NEXTNODE(n,n1);
252: BDY(n1)=(pointer)asir_pop_one();
253: }
254: if(n)NEXT(n1)=0;
255: id=-1;
256: fno=modeNO(fn);
257: switch (fno){
258: case 0://IFPLOT
259: id=plot(n,fno);
1.2 noro 260: STOZ(id,ret);
1.1 noro 261: asir_push_one((Obj)ret);
262: break;
263: case 1://CONPLOT
264: id=plot(n,fno);
1.2 noro 265: STOZ(id,ret);
1.1 noro 266: asir_push_one((Obj)ret);
267: break;
268: case 2://PLOT
269: id=plot(n,fno);
1.2 noro 270: STOZ(id,ret);
1.1 noro 271: asir_push_one((Obj)ret);
272: break;
273: case 4://POLARPLOT
274: id=plot(n,fno);
1.2 noro 275: STOZ(id,ret);
1.1 noro 276: asir_push_one((Obj)ret);
277: break;
278: case 30://MEMORY_PLOT
279: memory_plot(n,&bytes);
280: asir_push_one((Obj)bytes);
281: break;
282: case 31://ARRAYPLOT
283: id=arrayplot(n);
1.2 noro 284: STOZ(id,ret);
1.1 noro 285: asir_push_one((Obj)ret);
286: break;
287: case 32://OPEN_CANVAS
288: id=open_canvas(n);
1.2 noro 289: STOZ(id,ret);
1.1 noro 290: asir_push_one((Obj)ret);
291: break;
292: case 5://PLOTOVER
293: plotover(n);
294: break;
295: case 33://DRAWCIRCLE
296: drawcircle(n);
297: break;
298: case 34://DRAW_OBJ
299: if(draw_obj(n) < 0 ){
300: create_error(&err,serial,LastError,0);
301: asir_push_one((Obj)err);
302: }
303: break;
304: case 35://DRAW_STRING
305: if(draw_string(n)<0){
306: create_error(&err,serial,LastError,0);
307: asir_push_one((Obj)err);
308: }
309: break;
310: case 37://CLEAR_CANVAS
311: clear_canvas(n);
312: break;
313: // ifplotNG
314: case 36://OBJ_CP
315: id=objcp(n);
1.2 noro 316: STOZ(id,ret);
1.1 noro 317: asir_push_one((Obj)ret);
318: break;
319: case 6://IFPLOTD
320: case 7://IFPLOTQ
321: case 8://IFPLOTB
322: case 9://INEQND
323: case 10://INEQNQ
324: case 11://INEQNB
325: case 21://CONPLOTD
326: case 22://CONPLOTQ
327: case 23://CONPLOTB
328: #if defined(INTERVAL)
329: case 24://ITVIFPLOT
330: #endif
331: id=ifplotNG(n,fno);
1.2 noro 332: STOZ(id,ret);
1.1 noro 333: asir_push_one((Obj)ret);
334: break;
335: case 12://INEQNDAND
336: case 13://INEQNQAND
337: case 14://INEQNBAND
338: case 15://INEQNDOR
339: case 16://INEQNQOR
340: case 17://INEQNBOR
341: case 18://INEQNDXOR
342: case 19://INEQNQXOR
343: case 20://INEQNBXOR
344: case 25://PLOTOVERD
345: case 26://PLOTOVERQ
346: case 27://PLOTOVERB
347: id=ifplotOP(n,fno);
1.2 noro 348: STOZ(id,ret);
1.1 noro 349: asir_push_one((Obj)ret);
350: break;
351: case 38://POLARPLOTD
352: id=polarplotNG(n);
1.2 noro 353: STOZ(id,ret);
1.1 noro 354: asir_push_one((Obj)ret);
355: break;
356: }
357: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>