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