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