Annotation of OpenXM_contrib2/asir2000/parse/asir_sm.c, Revision 1.4
1.2 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.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 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.4 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/asir_sm.c,v 1.3 2000/08/22 05:04:25 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #if defined(THINK_C)
53: #include <console.h>
54: #endif
55:
56: #if PARI
57: #include "genpari.h"
58:
59: extern jmp_buf environnement;
60: #endif
61:
62: extern jmp_buf env;
63: extern int ox_do_copy, ox_do_count, ox_count_length;
64: extern char *ox_copy_bptr;
65:
66: Obj Asir_OperandStack[BUFSIZ];
67: char *Asir_DebugStack[BUFSIZ];
68: int Asir_OperandStackPtr;
69: int Asir_DebugStackPtr;
70:
71: Asir_Start()
72: {
73: int tmp;
74: FILE *ifp;
75: char ifname[BUFSIZ];
76: extern int GC_dont_gc;
77: extern int read_exec_file;
78: extern int do_asirrc;
79: char *getenv();
80: static ox_asir_initialized = 0;
81:
82: asir_save_handler();
83: if ( ox_asir_initialized )
84: return;
85: ox_asir_initialized = 1;
86: ox_do_copy = 1;
87: #if defined(THINK_C)
88: param_init();
89: #endif
90: rtime_init();
91: env_init();
92: endian_init();
93: #if !defined(TOWNS) && !defined(THINK_C)
94: /* check_key(); */
95: #endif
96: #if defined(TOWNS) && !defined(GO32) && !defined(__WIN32__)
97: disable_ctrl_c();
98: #endif
99: GC_init();
100: /* process_args(argc,argv); */
101: #if 0
102: copyright();
103: #endif
104: output_init();
105: arf_init();
106: nglob_init();
107: glob_init();
108: sig_init();
109: tty_init();
110: debug_init();
111: pf_init();
112: sysf_init();
113: parif_init();
114: #if defined(UINIT)
115: reg_sysf();
116: #endif
117: #if defined(THINK_C) || defined(TOWNS)
118: sprintf(ifname,"asirrc");
119: #else
120: sprintf(ifname,"%s/.asirrc",getenv("HOME"));
121: #endif
122: asir_set_handler();
123: if ( do_asirrc && (ifp = fopen(ifname,"r")) ) {
124: input_init(ifp,ifname);
125: if ( !setjmp(env) ) {
126: read_exec_file = 1;
127: read_eval_loop();
128: }
129: fclose(ifp);
130: }
131: asir_reset_handler();
132: input_init(0,"string");
133: Asir_OperandStackPtr = Asir_DebugStackPtr = -1;
134: }
135:
136: char *Asir_PopBinary();
137: char *Asir_PopString();
138: Obj asir_pop_obj();
139:
140: extern char *parse_strp;
141: extern int ox_do_copy;
142:
143: int Asir_ExecuteString(s)
144: char *s;
145: {
146: SNODE snode;
147: pointer val;
148: #if PARI
149: static long tloc,listloc;
150: extern long avloc;
151:
152: Asir_Start();
153: asir_set_handler();
154: avloc = avma; tloc = tglobal; listloc = marklist();
155: if ( setjmp(environnement) ) {
156: avma = avloc; tglobal = tloc; recover(listloc);
157: resetenv("");
158: }
159: #endif
160: if ( setjmp(env) ) {
161: asir_reset_handler();
162: return -1;
163: }
164: parse_strp = s;
165: if ( mainparse(&snode) ) {
166: asir_reset_handler();
167: return -1;
168: }
169: val = evalstat(snode);
170: if ( NEXT(asir_infile) ) {
171: while ( NEXT(asir_infile) ) {
172: if ( mainparse(&snode) ) {
173: asir_push_obj(val);
174: asir_reset_handler();
175: return -1;
176: }
177: nextbp = 0;
178: val = evalstat(snode);
179: }
180: }
181: asir_push_obj(val);
182: asir_reset_handler();
183: return 0;
184: }
185:
186: char *Asir_PopString()
187: {
188: Obj val;
189: char *buf,*obuf;
190: int l;
191:
192: Asir_Start();
193: val = asir_pop_obj();
194: if ( !val )
195: return 0;
196: else {
197: l = estimate_length(CO,val);
198: buf = (char *)ALLOCA(l+1);
199: soutput_init(buf);
200: sprintexpr(CO,val);
201: l = strlen(buf);
202: obuf = (char *)GC_malloc(l+1);
203: strcpy(obuf,buf);
204: return obuf;
205: }
206: }
207:
208: int Asir_Set(name)
209: char *name;
210: {
211: int l,n;
212: char *dummy = "=0;";
213: SNODE snode;
214:
215: Asir_Start();
216: l = strlen(name);
217: n = l+strlen(dummy)+1;
218: parse_strp = (char *)ALLOCA(n);
219: sprintf(parse_strp,"%s%s",name,dummy);
220: if ( mainparse(&snode) )
221: return -1;
222: FA1((FNODE)FA0(snode)) = (pointer)mkfnode(1,I_FORMULA,asir_pop_obj());
223: evalstat(snode);
224: return 0;
225: }
226:
227: int Asir_PushBinary(size,data)
228: int size;
229: char *data;
230: {
231: Obj val;
232:
233: Asir_Start();
234: ox_copy_bptr = data;
235: loadvl(0);
236: loadobj(0,&val);
237: asir_push_obj(val);
238: ox_copy_bptr = 0;
239: }
240:
241: char *Asir_PopBinary(size)
242: int *size;
243: {
244: Obj val;
245: char *buf;
246: VL vl,t;
247:
248: Asir_Start();
249: val = asir_pop_obj();
250: get_vars(val,&vl);
251: for ( t = vl; t; t = NEXT(t) )
252: if ( t->v->attr == (pointer)V_UC || t->v->attr == (pointer)V_PF )
253: error("bsave : not implemented");
254: ox_count_length = 0; ox_do_count = 1;
255: savevl(0,vl);
256: saveobj(0,val);
257: *size = ox_count_length;
258: ox_count_length = 0; ox_do_count = 0;
259: ox_copy_bptr = buf = (char *)GC_malloc(*size);
260: savevl(0,vl);
261: saveobj(0,val);
262: ox_copy_bptr = 0;
263: return buf;
264: }
265:
266: asir_push_obj(obj)
267: Obj obj;
268: {
269: Asir_OperandStack[++Asir_OperandStackPtr] = obj;
270: }
271:
272: Obj asir_pop_obj() {
273: if ( Asir_OperandStackPtr < 0 )
274: return 0;
275: else
276: return Asir_OperandStack[Asir_OperandStackPtr--];
277: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>