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