=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/cpexpr.c,v retrieving revision 1.2 retrieving revision 1.17 diff -u -p -r1.2 -r1.17 --- OpenXM_contrib2/asir2000/io/cpexpr.c 2000/02/07 03:14:39 1.2 +++ OpenXM_contrib2/asir2000/io/cpexpr.c 2004/02/09 08:23:30 1.17 @@ -1,10 +1,60 @@ -/* $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.1.1.1 1999/12/03 07:39:11 noro Exp $ */ +/* + * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED + * All rights reserved. + * + * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited, + * non-exclusive and royalty-free license to use, copy, modify and + * redistribute, solely for non-commercial and non-profit purposes, the + * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and + * conditions of this Agreement. For the avoidance of doubt, you acquire + * only a limited right to use the SOFTWARE hereunder, and FLL or any + * third party developer retains all rights, including but not limited to + * copyrights, in and to the SOFTWARE. + * + * (1) FLL does not grant you a license in any way for commercial + * purposes. You may use the SOFTWARE only for non-commercial and + * non-profit purposes only, such as academic, research and internal + * business use. + * (2) The SOFTWARE is protected by the Copyright Law of Japan and + * international copyright treaties. If you make copies of the SOFTWARE, + * with or without modification, as permitted hereunder, you shall affix + * to all such copies of the SOFTWARE the above copyright notice. + * (3) An explicit reference to this SOFTWARE and its copyright owner + * shall be made on your publication or presentation in any form of the + * results obtained by use of the SOFTWARE. + * (4) In the event that you modify the SOFTWARE, you shall notify FLL by + * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification + * for such modification or the source code of the modified part of the + * SOFTWARE. + * + * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL + * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND + * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES' + * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY + * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY. + * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT, + * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL + * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES + * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES + * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY + * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF + * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART + * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY + * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, + * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. + * $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.16 2003/12/25 02:40:24 noro Exp $ +*/ #include "ca.h" #include "parse.h" #include "al.h" #include "base.h" +#if PARI +#include "genpari.h" +#endif -extern int hex_output,fortran_output; +extern int hex_output,fortran_output,double_output,real_digit; #define PRINTHAT (fortran_output?PUTS("**"):PUTS("^")) @@ -29,6 +79,10 @@ extern int hex_output,fortran_output; #define PRINTUI length_ui #define PRINTGF2MAT length_gf2mat #define PRINTGFMMAT length_gfmmat +#define PRINTBYTEARRAY length_bytearray +#define PRINTQUOTE length_QUOTE +#define PRINTSYMBOL length_SYMBOL +#define PRINTRANGE length_RANGE #define PRINTERR length_err #define PRINTLF length_lf #define PRINTLOP length_lop @@ -36,6 +90,8 @@ extern int hex_output,fortran_output; #define PRINTEOP length_eop #define PRINTQOP length_qop #define PRINTUP length_up +#define PRINTUM length_um +#define PRINTSF length_sf void PRINTEXPR(); void PRINTNUM(); @@ -52,39 +108,50 @@ void PRINTDP(); void PRINTUI(); void PRINTGF2MAT(); void PRINTGFMMAT(); +void PRINTBYTEARRAY(); +void PRINTQUOTE(); +void PRINTSYMBOL(); +void PRINTRANGE(); void PRINTERR(); void PRINTCPLX(); void PRINTLM(); void PRINTLF(); +void PRINTUP(); +void PRINTUM(); void PRINTUP2(); +void PRINTFOP(); +void PRINTEOP(); +void PRINTLOP(); +void PRINTQOP(); +void PRINTSF(); static int total_length; -int estimate_length(vl,p) -VL vl; -pointer p; +int estimate_length(VL vl,pointer p) { total_length = 0; PRINTEXPR(vl,p); return total_length; } -#if PARI -void PRINTBF(a) -BF a; +#if defined(PARI) +void PRINTBF(BF a) { char *str; - char *GENtostr(); + char *GENtostr0(); + void myoutbrute(); - str = GENtostr(a->body); + if ( double_output ) { + str = GENtostr0(a->body,myoutbrute); + } else { + str = GENtostr(a->body); + } total_length += strlen(str); free(str); } #endif -void PRINTEXPR(vl,p) -VL vl; -pointer p; +void PRINTEXPR(VL vl,pointer p) { if ( !p ) { total_length++; @@ -122,13 +189,20 @@ pointer p; PRINTLF(vl,(F)p); break; case O_GFMMAT: PRINTGFMMAT(vl,(GFMMAT)p); break; + case O_BYTEARRAY: + PRINTBYTEARRAY(vl,(BYTEARRAY)p); break; + case O_QUOTE: + PRINTQUOTE(vl,(QUOTE)p); break; + case O_SYMBOL: + PRINTSYMBOL((SYMBOL)p); break; + case O_RANGE: + PRINTRANGE(vl,(RANGE)p); break; default: break; } } -void PRINTN(n) -N n; +void PRINTN(N n) { double ceil(); @@ -140,8 +214,7 @@ N n; total_length += (int)(ceil(0.31*((double)(BSH*PL(n))))+1); } -void PRINTNUM(q) -Num q; +void PRINTNUM(Num q) { if ( !q ) { PUTS("0"); @@ -157,12 +230,15 @@ Num q; } break; case N_R: - total_length += 20; /* XXX */ + if ( double_output ) + total_length += 400+real_digit; /* XXX */ + else + total_length += 20+real_digit; /* XXX */ break; case N_A: PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")"); break; -#if PARI +#if defined(PARI) case N_B: PRINTBF((BF)q); break; #endif @@ -182,13 +258,18 @@ Num q; case N_GFPN: PRINTUP((UP)(((GFPN)q)->body)); break; + case N_GFS: + total_length += 13; /* XXX */ + break; + case N_GFSN: + PRINTUM(BDY((GFSN)q)); + break; default: break; } } -void PRINTCPLX(a) -C a; +void PRINTCPLX(C a) { PUTS("("); if ( a->r ) @@ -201,13 +282,10 @@ C a; PUTS(")"); } -void PRINTP(vl,p) -VL vl; -P p; +void PRINTP(VL vl,P p) { V v; DCP dc; - int t; if ( !p ) PUTS("0"); @@ -259,9 +337,7 @@ P p; extern int hideargs; -void PRINTV(vl,v) -VL vl; -V v; +void PRINTV(VL vl,V v) { PF pf; PFAD ad; @@ -272,8 +348,8 @@ V v; else if ( (vid)v->attr == V_PF ) { pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad; if ( !strcmp(NAME(pf),"pow") ) { - PUTS("("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("("); - PRINTR(vl,(R)ad[1].arg); PUTS(")"); + PUTS("(("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("("); + PRINTR(vl,(R)ad[1].arg); PUTS("))"); } else if ( !pf->argc ) PUTS(NAME(pf)); else { @@ -317,9 +393,7 @@ V v; } } -void PRINTR(vl,a) -VL vl; -R a; +void PRINTR(VL vl,R a) { if ( !a ) PUTS("0"); @@ -333,9 +407,7 @@ R a; } } -void PRINTVECT(vl,vect) -VL vl; -VECT vect; +void PRINTVECT(VL vl,VECT vect) { int i; pointer *ptr; @@ -347,9 +419,7 @@ VECT vect; PUTS("]"); } -void PRINTMAT(vl,mat) -VL vl; -MAT mat; +void PRINTMAT(VL vl,MAT mat) { int i,j,r,c; pointer *ptr; @@ -365,9 +435,7 @@ MAT mat; } } -void PRINTLIST(vl,list) -VL vl; -LIST list; +void PRINTLIST(VL vl,LIST list) { NODE tnode; @@ -380,8 +448,7 @@ LIST list; PUTS("]"); } -void PRINTSTR(str) -STRING str; +void PRINTSTR(STRING str) { char *p; @@ -393,9 +460,7 @@ STRING str; } } -void PRINTCOMP(vl,c) -VL vl; -COMP c; +void PRINTCOMP(VL vl,COMP c) { int n,i; @@ -409,9 +474,7 @@ COMP c; PUTS("}"); } -void PRINTDP(vl,d) -VL vl; -DP d; +void PRINTDP(VL vl,DP d) { int n,i; MP m; @@ -429,16 +492,12 @@ DP d; } } -void PRINTUI(vl,u) -VL vl; -USINT u; +void PRINTUI(VL vl,USINT u) { total_length += 10; } -void PRINTGF2MAT(vl,mat) -VL vl; -GF2MAT mat; +void PRINTGF2MAT(VL vl,GF2MAT mat) { int row,col,w,i,j,k,m; unsigned int t; @@ -461,12 +520,9 @@ GF2MAT mat; } } -void PRINTGFMMAT(vl,mat) -VL vl; -GFMMAT mat; +void PRINTGFMMAT(VL vl,GFMMAT mat) { int row,col,i,j; - unsigned int t; unsigned int **b; row = mat->row; @@ -481,15 +537,35 @@ GFMMAT mat; } } -void PRINTERR(vl,e) -VL vl; -ERR e; +void PRINTBYTEARRAY(VL vl,BYTEARRAY array) { + /* |xx xx ... xx| */ + total_length += 1+3*array->len; +} + +void PRINTQUOTE(VL vl,QUOTE quote) +{ + /* <...quoted...> */ + total_length += 20; +} + +void PRINTSYMBOL(SYMBOL sym) +{ + total_length += strlen(sym->name); +} + +void PRINTRANGE(VL vl,RANGE r) +{ + PUTS("range("); PRINTEXPR(vl,r->start); + PUTS(","); PRINTEXPR(vl,r->end); PUTS(")"); +} + +void PRINTERR(VL vl,ERR e) +{ PUTS("error("); PRINTEXPR(vl,e->body); PUTS(")"); } -void PRINTUP2(p) -UP2 p; +void PRINTUP2(UP2 p) { int d,i; @@ -521,9 +597,7 @@ UP2 p; } } -void PRINTLF(vl,f) -VL vl; -F f; +void PRINTLF(VL vl,F f) { switch ( FOP(f) ) { case AL_TRUE: @@ -549,9 +623,7 @@ F f; } } -PRINTFOP(vl,f) -VL vl; -F f; +void PRINTFOP(VL vl,F f) { char *op; NODE n; @@ -564,9 +636,7 @@ F f; } } -PRINTEOP(vl,f) -VL vl; -F f; +void PRINTEOP(VL vl,F f) { oFOP op; char *sop; @@ -591,9 +661,7 @@ F f; PUTS(")"); } -PRINTLOP(vl,f) -VL vl; -F f; +void PRINTLOP(VL vl,F f) { char *op; @@ -617,9 +685,7 @@ F f; PRINTEXPR(vl,(Obj)FPL(f)); PUTS(op); PUTS("0"); } -PRINTQOP(vl,f) -VL vl; -F f; +void PRINTQOP(VL vl,F f) { char *op; @@ -629,8 +695,7 @@ F f; PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")"); } -PRINTUP(n) -UP n; +void PRINTUP(UP n) { int i,d; @@ -663,4 +728,45 @@ UP n; } PUTS(")"); } +} + +void PRINTUM(UM n) +{ + int i,d; + + if ( !n ) + PUTS("0"); + else if ( !n->d ) + PRINTSF(n->c[0]); + else { + d = n->d; + PUTS("("); + if ( !d ) { + PRINTSF(n->c[d]); + } else if ( d == 1 ) { + PRINTSF(n->c[d]); + PUTS("*@s"); + } else { + PRINTSF(n->c[d]); + PUTS("*@s"); PRINTHAT; total_length += 13; + } + for ( i = d-1; i >= 0; i-- ) { + if ( n->c[i] ) { + PUTS("+("); PRINTSF(n->c[i]); PUTS(")"); + if ( i >= 2 ) { + PUTS("*@s"); PRINTHAT; total_length += 13; + } else if ( i == 1 ) + PUTS("*@s"); + } + } + PUTS(")"); + } +} + +void PRINTSF(unsigned int i) +{ + if ( !i ) { + PUTS("0"); + } else + total_length += 15; }