Annotation of OpenXM_contrib2/asir2000/plot/ox_plot.c, Revision 1.9
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.9 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/ox_plot.c,v 1.8 2000/10/06 06:05:24 noro 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.2 noro 56: #if PARI
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.1 noro 66: extern jmp_buf environnement;
67:
68: extern int do_message;
69: extern int ox_flushing;
70: extern jmp_buf ox_env;
71: extern MATHCAP my_mathcap;
72:
1.8 noro 73: void create_error(ERR *,unsigned int ,char *);
1.1 noro 74:
1.8 noro 75: void ox_io_init();
76: void ox_asir_init(int,char **);
77: Obj asir_pop_one();
78: void asir_push_one(Obj);
79: void asir_end_flush();
80: int asir_executeString();
81: void asir_evalName(unsigned int);
82: void asir_setName(unsigned int);
83: void asir_pops();
84: void asir_popString();
85: void asir_popCMO(unsigned int);
86: void asir_popSerializedLocalObject();
87: char *name_of_cmd(unsigned int);
88: char *name_of_id(int);
89: LIST asir_GetErrorList();
1.7 noro 90:
1.8 noro 91: static void asir_do_cmd(unsigned int,unsigned int);
1.1 noro 92: static void process_ox();
93: static void asir_executeFunction();
94:
1.9 ! noro 95: #if defined(VISUAL)
! 96: void ox_plot_main()
! 97: #else
! 98: void ox_plot_main(int argc,char **argv)
! 99: #endif
! 100: {
1.1 noro 101: int ds;
102: fd_set r;
103: int n;
104:
1.9 ! noro 105: #if !defined(VISUAL)
1.1 noro 106: ox_asir_init(argc,argv);
107: init_plot_display(argc,argv);
108: ds = ConnectionNumber(display);
1.9 ! noro 109: #endif
1.1 noro 110: if ( do_message )
111: fprintf(stderr,"I'm an ox_plot, Version %d.\n",ASIR_VERSION);
112:
113: if ( setjmp(ox_env) ) {
114: while ( NEXT(asir_infile) )
115: closecurrentinput();
116: reset_current_computation();
117: ox_send_sync(0);
118: }
119: while ( 1 ) {
1.9 ! noro 120: #if defined(VISUAL)
! 121: process_ox();
! 122: #else
1.1 noro 123: if ( ox_data_is_available(0) )
124: process_ox();
125: else {
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) )
130: process_ox();
131: else if ( FD_ISSET(ds,&r) )
132: process_xevent();
133: }
134: }
1.9 ! noro 135: #endif
1.1 noro 136: }
137:
138: static void process_ox()
139: {
140: int id;
141: unsigned int cmd;
142: Obj obj;
143: ERR err;
144: unsigned int serial;
145: int ret;
146: extern char LastError[];
147:
148: serial = ox_recv(0,&id,&obj);
149: if ( do_message )
150: fprintf(stderr,"#%d Got %s",serial,name_of_id(id));
151: switch ( id ) {
152: case OX_COMMAND:
153: cmd = ((USINT)obj)->body;
154: if ( ox_flushing )
155: break;
156: if ( do_message )
157: fprintf(stderr," %s\n",name_of_cmd(cmd));
158: if ( ret = setjmp(env) ) {
159: if ( ret == 1 ) {
160: create_error(&err,serial,LastError);
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 )
170: break;
171: if ( do_message )
172: fprintf(stderr," -> data pushed");
173: asir_push_one(obj);
174: break;
175: case OX_SYNC_BALL:
176: asir_end_flush();
177: break;
178: default:
179: break;
180: }
181: if ( do_message )
182: fprintf(stderr,"\n");
183: }
184:
185: static void asir_do_cmd(unsigned int cmd,unsigned int serial)
186: {
187: MATHCAP client_mathcap;
1.4 noro 188: LIST list;
189: int i;
190: Q q;
1.1 noro 191:
192: switch ( cmd ) {
1.4 noro 193: case SM_dupErrors:
194: list = asir_GetErrorList();
195: asir_push_one((Obj)list);
196: break;
197: case SM_getsp:
1.8 noro 198: i = asir_OperandStackPtr+1;
1.4 noro 199: STOQ(i,q);
200: asir_push_one((Obj)q);
201: break;
1.1 noro 202: case SM_popSerializedLocalObject:
203: asir_popSerializedLocalObject();
204: break;
205: case SM_popCMO:
206: asir_popCMO(serial);
207: break;
208: case SM_popString:
209: asir_popString();
210: break;
211: case SM_setName:
212: asir_setName(serial);
213: break;
214: case SM_evalName:
215: asir_evalName(serial);
216: break;
217: case SM_executeStringByLocalParser:
218: asir_executeString();
219: break;
220: case SM_executeFunction:
221: asir_executeFunction();
222: break;
223: case SM_shutdown:
224: asir_terminate(2);
225: break;
226: case SM_pops:
227: asir_pops();
228: break;
229: case SM_mathcap:
230: asir_push_one((Obj)my_mathcap);
231: break;
232: case SM_setMathcap:
233: client_mathcap = (MATHCAP)asir_pop_one();
234: store_remote_mathcap(0,client_mathcap);
235: break;
236: default:
237: break;
238: }
239: }
240:
241: static void asir_executeFunction()
242: {
243: char *func;
244: int argc;
245: int id;
246: FUNC f;
247: Q ret;
248: VL vl;
249: NODE n,n1;
250:
251: func = ((STRING)asir_pop_one())->body;
252: argc = (int)(((USINT)asir_pop_one())->body);
253:
254: for ( n = 0; argc; argc-- ) {
255: NEXTNODE(n,n1);
256: BDY(n1) = (pointer)asir_pop_one();
257: }
258: if ( n )
259: NEXT(n1) = 0;
260: id = -1;
1.9 ! noro 261: if ( !strcmp(func,"plot") ) {
1.1 noro 262: id = plot(n);
1.9 ! noro 263: STOQ(id,ret); asir_push_one((Obj)ret);
! 264: } else if ( !strcmp(func,"arrayplot") ) {
1.1 noro 265: id = arrayplot(n);
1.9 ! noro 266: STOQ(id,ret); asir_push_one((Obj)ret);
! 267: } else if ( !strcmp(func,"open_canvas") ) {
! 268: id = open_canvas(n);
! 269: STOQ(id,ret); asir_push_one((Obj)ret);
! 270: } else if ( !strcmp(func,"plotover") ) {
! 271: plotover(n);
! 272: } else if ( !strcmp(func,"drawcircle") ) {
! 273: drawcircle(n);
! 274: } else if ( !strcmp(func,"draw_obj") ) {
! 275: draw_obj(n);
! 276: } else if ( !strcmp(func,"clear_canvas") ) {
! 277: clear_canvas(n);
! 278: }
1.1 noro 279: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>