Annotation of OpenXM_contrib2/asir2000/plot/ox_plot.c, Revision 1.8
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.8 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/ox_plot.c,v 1.7 2000/09/12 06:05:31 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:
95: void ox_plot_main(int argc,char **argv) {
96: int ds;
97: fd_set r;
98: int n;
99:
100: ox_asir_init(argc,argv);
101: init_plot_display(argc,argv);
102: ds = ConnectionNumber(display);
103: if ( do_message )
104: fprintf(stderr,"I'm an ox_plot, Version %d.\n",ASIR_VERSION);
105:
106: if ( setjmp(ox_env) ) {
107: while ( NEXT(asir_infile) )
108: closecurrentinput();
109: reset_current_computation();
110: ox_send_sync(0);
111: }
112: while ( 1 ) {
113: if ( ox_data_is_available(0) )
114: process_ox();
115: else {
116: FD_ZERO(&r);
117: FD_SET(3,&r); FD_SET(ds,&r);
118: select(FD_SETSIZE,&r,NULL,NULL,NULL);
119: if ( FD_ISSET(3,&r) )
120: process_ox();
121: else if ( FD_ISSET(ds,&r) )
122: process_xevent();
123: }
124: }
125: }
126:
127: static void process_ox()
128: {
129: int id;
130: unsigned int cmd;
131: Obj obj;
132: ERR err;
133: unsigned int serial;
134: int ret;
135: extern char LastError[];
136:
137: serial = ox_recv(0,&id,&obj);
138: if ( do_message )
139: fprintf(stderr,"#%d Got %s",serial,name_of_id(id));
140: switch ( id ) {
141: case OX_COMMAND:
142: cmd = ((USINT)obj)->body;
143: if ( ox_flushing )
144: break;
145: if ( do_message )
146: fprintf(stderr," %s\n",name_of_cmd(cmd));
147: if ( ret = setjmp(env) ) {
148: if ( ret == 1 ) {
149: create_error(&err,serial,LastError);
150: asir_push_one((Obj)err);
151: }
152: break;
153: }
154: asir_do_cmd(cmd,serial);
155: break;
156: case OX_DATA:
157: case OX_LOCAL_OBJECT_ASIR:
158: if ( ox_flushing )
159: break;
160: if ( do_message )
161: fprintf(stderr," -> data pushed");
162: asir_push_one(obj);
163: break;
164: case OX_SYNC_BALL:
165: asir_end_flush();
166: break;
167: default:
168: break;
169: }
170: if ( do_message )
171: fprintf(stderr,"\n");
172: }
173:
174: static void asir_do_cmd(unsigned int cmd,unsigned int serial)
175: {
176: MATHCAP client_mathcap;
1.4 noro 177: LIST list;
178: int i;
179: Q q;
1.1 noro 180:
181: switch ( cmd ) {
1.4 noro 182: case SM_dupErrors:
183: list = asir_GetErrorList();
184: asir_push_one((Obj)list);
185: break;
186: case SM_getsp:
1.8 ! noro 187: i = asir_OperandStackPtr+1;
1.4 noro 188: STOQ(i,q);
189: asir_push_one((Obj)q);
190: break;
1.1 noro 191: case SM_popSerializedLocalObject:
192: asir_popSerializedLocalObject();
193: break;
194: case SM_popCMO:
195: asir_popCMO(serial);
196: break;
197: case SM_popString:
198: asir_popString();
199: break;
200: case SM_setName:
201: asir_setName(serial);
202: break;
203: case SM_evalName:
204: asir_evalName(serial);
205: break;
206: case SM_executeStringByLocalParser:
207: asir_executeString();
208: break;
209: case SM_executeFunction:
210: asir_executeFunction();
211: break;
212: case SM_shutdown:
213: asir_terminate(2);
214: break;
215: case SM_pops:
216: asir_pops();
217: break;
218: case SM_mathcap:
219: asir_push_one((Obj)my_mathcap);
220: break;
221: case SM_setMathcap:
222: client_mathcap = (MATHCAP)asir_pop_one();
223: store_remote_mathcap(0,client_mathcap);
224: break;
225: default:
226: break;
227: }
228: }
229:
230: static void asir_executeFunction()
231: {
232: char *func;
233: int argc;
234: int id;
235: FUNC f;
236: Q ret;
237: VL vl;
238: NODE n,n1;
239:
240: func = ((STRING)asir_pop_one())->body;
241: argc = (int)(((USINT)asir_pop_one())->body);
242:
243: for ( n = 0; argc; argc-- ) {
244: NEXTNODE(n,n1);
245: BDY(n1) = (pointer)asir_pop_one();
246: }
247: if ( n )
248: NEXT(n1) = 0;
249: id = -1;
250: if ( !strcmp(func,"plot") )
251: id = plot(n);
252: else if ( !strcmp(func,"arrayplot") )
253: id = arrayplot(n);
254: else if ( !strcmp(func,"plotover") )
255: id = plotover(n);
256: else if ( !strcmp(func,"drawcircle") )
257: id = drawcircle(n);
258: STOQ(id,ret);
259: #if 0
260: asir_push_one((Obj)ret);
261: #endif
262: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>