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