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