printer.c
Go to the documentation of this file.
00001 /****************************************************************/
00002 /* printer.c --- euslisp printer
00003 /* Copyright(c) 1986, Toshihiro MATSUI, Electrotechnical Laboratory
00004 /*
00005 /****************************************************************/
00006 static char *rcsid="@(#)$Id$";
00007 
00008 #include <ctype.h>
00009 #include "eus.h"
00010 
00011 #define g_marked(p) (bpointerof(p)->h.mark)
00012 #define s_marked(p) (bpointerof(p)->h.smark)
00013 #define p_marked(p) (bpointerof(p)->h.pmark)
00014 #define g_mark_on(p) (bpointerof(p)->h.mark=1)
00015 #define s_mark_on(p) (bpointerof(p)->h.smark=1)
00016 #define p_mark_on(p) (bpointerof(p)->h.pmark=1)
00017 #define g_mark_off(p) (bpointerof(p)->h.mark=0)
00018 #define s_mark_off(p) (bpointerof(p)->h.smark=0)
00019 #define p_mark_off(p) (bpointerof(p)->h.pmark=0)
00020 #define to_upper(c) (islower(c) ? ((c)-'a'+'A') : (c))
00021 #define to_lower(c) (isupper(c) ? ((c)-'A'+'a') : (c))
00022 
00023 extern pointer PRCIRCLE,PROBJECT,PRSTRUCTURE,PRCASE,PRLENGTH,PRLEVEL,PRINTBASE;
00024 extern pointer QREADTABLE;
00025 extern pointer K_PRIN1;
00026 static void prin1(context *, pointer, pointer, int);
00027 
00028 static pointer *ixvec;
00029 static int ix;
00030 static char ixbuf[16];
00031 extern enum ch_type chartype[256];
00032 extern enum ch_attr charattr[256];
00033 
00034 static void print_symbol_prefix(ctx,f,pkg,colon)
00035 context *ctx;
00036 register pointer f,pkg;
00037 char *colon;
00038 { register pointer pkgname;
00039   register int l;
00040   byte *s, c;
00041   pkgname=ccar(pkg->c.pkg.names);
00042   l=strlength(pkgname);
00043   s=pkgname->c.str.chars;
00044   if (Spevalof(PRCASE)==K_DOWNCASE) 
00045     while (l-->0) { c= *s++; writech(f,to_lower(c));}
00046   else while (l-->0) { writech(f,*s++);}
00047   writestr(f,(byte *)colon,strlen(colon));}
00048 
00049 
00050 static void symprefix(sym,f)
00051 register pointer sym,f;
00052 { register int l,c;
00053   register byte *s;
00054   register pointer pkg,pkgname,pkgs,pnam;
00055   register pointer cursym;
00056   int hash;
00057   context *ctx=euscontexts[thr_self()];
00058   pointer curpkg;
00059 
00060   curpkg=Spevalof(PACKAGE);
00061   pkg=sym->c.sym.homepkg;
00062   pnam=sym->c.sym.pname;
00063   if (pkg==curpkg) return;
00064   if (pkg==NIL) { writestr(f,(byte *)"#:",2); return;}
00065   if (pkg==keywordpkg) { writech(f,':'); return; }
00066   else if ((cursym=findsymbol(pnam->c.str.chars, strlength(pnam),
00067                         curpkg->c.pkg.intsymvector, &hash))==NULL) {
00068     pkgs=curpkg->c.pkg.use;
00069     while (islist(pkgs)) 
00070       if (pkg==ccar(pkgs))      /*the home pkg is in use-list*/
00071         if (sym==findsymbol(pnam->c.str.chars, strlength(pnam),
00072                         ccar(pkgs)->c.pkg.symvector, &hash))
00073           return; /*found in external symbols*/
00074         else { print_symbol_prefix(ctx,f,ccar(pkgs),"::"); return;}
00075       else pkgs=ccdr(pkgs); }
00076   else if (sym==cursym) return;
00077   /* the home package is not used by the current *PACKAGE* */
00078   if (findsymbol(pnam->c.str.chars, strlength(pnam), pkg->c.pkg.symvector, &hash)) 
00079         /* external symbol in the home package?*/
00080     print_symbol_prefix(ctx,f,pkg,":");
00081   else print_symbol_prefix(ctx,f,pkg,"::"); }
00082         
00083 static pointer printsym(ctx,sym,f)
00084 context *ctx;
00085 register pointer sym;
00086 register pointer f;
00087 { register unsigned char *s;
00088   pointer pnm;
00089   register int i,l,c,down,escape=0,alldigits=1;
00090   int base=intval(Spevalof(PRINTBASE));
00091   byte b[256];
00092 
00093   symprefix(sym,f);
00094   pnm=sym->c.sym.pname;
00095   if (!isstring(pnm)) {
00096     printf("printsym: illegal pname %p\n",pnm);
00097     return(sym);}
00098   l=vecsize(pnm);
00099   s=pnm->c.str.chars;
00100   down=(Spevalof(PRCASE)==K_DOWNCASE);
00101   if (!ctx->slashflag) {
00102     for (i=0; i<l; i++) {
00103       c=s[i];
00104       if (chartype[c]!=ch_constituent || islower(c)) { escape=1; break;}
00105       else if (charattr[c]==package_marker || c=='`') {escape=1; break;}
00106       else if (Spevalof(QREADTABLE)->c.rdtab.macro->c.vec.v[c] != NIL) 
00107         {escape=1; break;};
00108       if (!is_digit(c,base)) alldigits=0;}
00109     if ((escape=(escape | alldigits))) writech(f,'|');}
00110   while (l>0) {
00111     i=0;
00112     if (!ctx->slashflag) {
00113       while (i<l && i<256) {
00114         c= *s++;
00115         if (chartype[c]==ch_multiescape) b[i++]='\\';
00116         b[i++]=((!escape && down)?to_lower(c):c);
00117         l--;}
00118       writestr(f,b,i);}
00119     else 
00120       if (down) { /*convert to lower*/
00121         while (i<l && i<256) { c= *s++; b[i++]=to_lower(c);}
00122         writestr(f,b,i);
00123         l-=i;}
00124       else { writestr(f,s,l); l=0;}
00125     }
00126   if (escape) writech(f,'|');
00127   return(sym);}
00128 
00129 static void printstr(ctx,leng,str,f)
00130 context *ctx;
00131 register int leng;
00132 register byte *str;
00133 register pointer f;
00134 { if (!ctx->slashflag) {
00135     writech(f,'"');
00136     while (leng-->0) {
00137       if (*str=='"' || *str=='\\') writech(f,'\\'); /*escape char*/
00138       writech(f,*str++);}
00139     writech(f,'"');}
00140   else writestr(f,str,leng);}
00141 
00142 /****************************************************************
00143 /* printing numbers
00144 /* num ----+-->  fixnum
00145 /*         +-->  float
00146 /*         +-->  big
00147 /*         +-->  ratio
00148 /****************************************************************/
00149 
00150 void printint(ctx,num,f,base, field1, field2)   /*print fixnum*/
00151 context *ctx;
00152 register eusinteger_t num;
00153 register pointer f;
00154 int base, field1, field2;
00155 { char work[65];        /*enough for 64 binary digits + sign*/
00156   register int i=65,digit,sign,j;
00157   int downcase;
00158 
00159   downcase= (Spevalof(PRCASE)==K_DOWNCASE);
00160   if (num<0) { sign= -1; num= -num;} else sign=0;
00161   do {
00162 #if (WORD_SIZE == 64)
00163     digit= (unsigned long)num % base;
00164     num=(unsigned long)num / base;
00165 #else
00166     digit= (unsigned)num % base;
00167     num=(unsigned)num / base;
00168 #endif
00169     if (base<=10 || digit<10) work[--i]='0'+digit;
00170     else if (downcase) work[--i]='a'+digit-10;
00171     else work[--i]='A'+digit-10;}
00172     while (num);
00173   if (sign) {
00174     if (field2> 65-i+1) j=field1-field2; else j=field1-(65-i+1);}
00175   else {
00176     if (field2> 65-i) j=field1-field2; else j=field1-(65-i);}
00177   while (j-- >0) writech(f,' ');
00178   if (sign) writech(f, '-');
00179   j=field2-(65-i);
00180   if (sign) j--;
00181   while (j-- >0) writech(f,'0');
00182   writestr(f,(byte *)&work[i],65-i);
00183   }
00184 
00185 static pointer printflt(num,f)
00186 double num;
00187 pointer f;
00188 { char work[20];
00189   double absnum,fraction;
00190   register int i,len,intpart;
00191   extern double fabs();
00192 
00193   if (num==0.0) writestr(f,(byte *)"0.0",3);
00194   else {
00195     absnum=fabs(num);
00196     if ((absnum<0.0001) || (absnum>1.0e+05)) {
00197       sprintf(work,"%1.6e",num); len=strlen(work);}
00198     else {
00199       intpart=absnum;   /*truncate*/
00200       fraction=absnum-intpart;
00201       if (intpart<1) i=6;
00202       else if (intpart<10) i=5;
00203       else if (intpart<100) i=4;
00204       else if (intpart<1000) i=3;
00205       else if (intpart<10000) i=2;
00206       else i=1;
00207       sprintf(work,"%1.*f",i,num);
00208       len=strlen(work);
00209       while (len>2 && work[len-1]=='0' && work[len-2]!='.') len--;} 
00210     writestr(f,(byte *)work,len); }}
00211 
00212 static void printhex(val,f)
00213 int val;
00214 pointer f;
00215 { char work[20];
00216   sprintf(work,"#x%x",val);
00217   writestr(f,(byte *)work,strlen(work));}
00218 
00219 static void printratio(ctx,rat,f, base)
00220 context *ctx;
00221 pointer rat,f;
00222 int base;
00223 { printnum(ctx,rat->c.ratio.numerator,f,base,0,0);
00224   writech(f,'/');
00225   printnum(ctx,rat->c.ratio.denominator,f,base,0,0);
00226   }
00227 
00228 extern pointer big_minus(), copy_big();
00229 
00230 static void printbig(ctx, big, f, base, field1,field2)
00231 context *ctx;
00232 pointer big,f;
00233 int base, field1,field2;
00234 { pointer bv,p;
00235   eusinteger_t *b, d, sign; long digits=0;
00236   int i, x;
00237   int downcase;
00238   extern eusinteger_t big_sign(), div_int_big();
00239 
00240   downcase=(Spevalof(PRCASE)==K_DOWNCASE);
00241   sign=big_sign(big);
00242   if (sign<0) big=big_minus(big);
00243   else big=copy_big(big);
00244   vpush(big);
00245 
00246   bv=big->c.bgnm.bv;  
00247   b=bv->c.ivec.iv;
00248 
00249   while (!big_zerop(big)) {
00250     d=div_int_big(base,big);
00251     p=makeint(d);
00252     ckpush(p);
00253     digits++;}
00254   
00255   if (field2<digits) i=field1-digits; else i=field1-field2;
00256   if (sign<0) i--;
00257   while (i-- > 0) writech(f, ' ');
00258   if (sign<0) writech(f, '-');
00259   i=field2-digits;
00260   if (sign<0) i--;
00261   while (i-- > 0) writech(f,'0');
00262 
00263   while (digits-- > 0) {
00264     p=vpop();
00265     x=intval(p);
00266     if (x>=10) {
00267       if (downcase) x=x+'a'-10;
00268       else x=x+'A'-10;}
00269     else x=x+'0';
00270     writech(f,x);}
00271   vpop();
00272   }
00273 
00274 void printnum(ctx, nump, strm, base, field1, field2)
00275 context *ctx;
00276 pointer nump, strm;
00277 int base;
00278 int field1, field2;
00279 { numunion nu;
00280 
00281   if (isint(nump)) printint(ctx,intval(nump), strm, base, field1, field2);
00282   else if (isflt(nump)) printflt(fltval(nump),strm);
00283   else if (pisbignum(nump)) printbig(ctx,nump, strm, base, field1, field2);
00284   else if (pisratio(nump)) printratio(ctx, nump, strm, base);
00285   else error(E_NONUMBER);}
00286 
00287 /****************************************************************/
00288 /* print object
00289 /****************************************************************/
00290 
00291 static void printobj(ctx,obj,f)
00292 register pointer obj,f;
00293 context *ctx;
00294 { pointer class;
00295   class=classtab[obj->cix].def;
00296   writestr(f,(byte *)"#<",2);
00297   printsym(ctx,class->c.cls.name,f);
00298   writech(f,' ');
00299   printhex(obj,f);
00300   writech(f,'>');}
00301 
00302 static void printpkg(p,f)
00303 register pointer p,f;
00304 { pointer nm;
00305   writestr(f,(byte *)"#<package ",10);
00306   nm=ccar(p->c.pkg.names);
00307   writestr(f,nm->c.str.chars,vecsize(nm));
00308   writech(f,'>');}
00309 
00310 static void printmark(ctx,p)
00311 register context *ctx;
00312 register pointer p;
00313 { register int i,s;
00314 
00315   if (isnum(p) || (pissymbol(p) && p->c.sym.homepkg != NIL) ) return;
00316   if (!p_marked(p)) {
00317     p_mark_on(p);
00318     if (pissymbol(p)) return;
00319     if (pisvector(p)) {
00320       if (elmtypeof(p)<ELM_POINTER) return;
00321       s=vecsize(p);
00322       for (i=0; i<s; i++) printmark(ctx,p->c.vec.v[i]); }
00323     else {
00324       s=objsize(p);
00325       for (i=0; i<s; i++) printmark(ctx,p->c.obj.iv[i]);}
00326     }
00327   else if (s_marked(p)) return;
00328   else {        /*already p_marked ->shared object*/
00329     s_mark_on(p);
00330     ckpush(p->c.obj.iv[0]);     /*save first element*/
00331     pointer_update(p->c.obj.iv[0],makeint(++ix));
00332     } }
00333   
00334 static int getprlength(ctx)
00335 context *ctx;
00336 { register pointer x;
00337   x=Spevalof(PRLENGTH);
00338   if (isint(x)) return(intval(x));
00339   else return(65536);}
00340 
00341 static pointer printvector(ctx,vec,f,leng,prlevel)
00342 register context *ctx;
00343 register pointer vec,f,leng;
00344 int prlevel;
00345 { register eusinteger_t n,i=0,eltype,x,prlength=getprlength(ctx);
00346   pointer sizesave;
00347 
00348   eltype=elmtypeof(vec);
00349   n=intval(leng);
00350   switch(eltype) {
00351     case ELM_BIT:
00352           writestr(f,(byte *)"#*",2);
00353           x=1;
00354           while (i<n) {
00355             writech(f,(vec->c.ivec.iv[i/WORD_SIZE] & x)?'1':'0');
00356             i++;
00357             x= x<<1;
00358             if (i % WORD_SIZE==0) x=1;}
00359           break;
00360     case ELM_BYTE:
00361           writestr(f,(byte *)"#<bytecode ",11);
00362           printhex(vec,f);
00363           writech(f,'>');
00364           break;
00365     case ELM_CHAR:
00366           printstr(ctx,n,vec->c.str.chars,f);  break;
00367     case ELM_INT:
00368           writestr(f,(byte *)"#i(",3);
00369           while (i<n && prlength>0) {
00370             printint(ctx,vec->c.ivec.iv[i++],f,intval(Spevalof(PRINTBASE)),
00371                         0,0);
00372             if(i<n) writech(f,' ');
00373             prlength--; }
00374           if (i<n) writestr(f,(byte *)"... ",4);
00375           writech(f,')');
00376           break;
00377     case ELM_FLOAT:
00378           writestr(f,(byte *)"#f(",3);
00379           while (i<n && prlength>0) {
00380             printflt(vec->c.fvec.fv[i++],f);
00381             if(i<n) writech(f,' ');
00382             prlength--; }
00383           if (i<n) writestr(f,(byte *)"... ",4);
00384           writech(f,')');
00385           break;
00386     case ELM_FOREIGN:
00387           writestr(f,(byte *)"#u",2);
00388           printstr(ctx,vecsize(vec),vec->c.ivec.iv[0],f);
00389           break;
00390     default:
00391           if (classof(vec)==C_VECTOR)  writestr(f,(byte *)"#(",2);
00392           else {
00393             writestr(f,(byte *)"#v(",3);
00394             printsym(ctx,classof(vec)->c.cls.name,f);
00395             writech(f,' ');
00396             printint(ctx,(eusinteger_t)vec->c.vec.size,f,intval(Spevalof(PRINTBASE)),0,0);
00397             writech(f,' ');}
00398           while (i<n && prlength>0) {
00399             prin1(ctx,vec->c.vec.v[i++],f,prlevel);
00400             if (i<n) writech(f,' '); }
00401           if (i<n) writestr(f,(byte *)"... ",4);
00402           writech(f,')');}
00403   return(vec);}
00404 
00405 static void prinelm(ctx,f,prlevel,vec,index)
00406 register context *ctx;
00407 register pointer f,vec;
00408 int prlevel,index;
00409 { switch(elmtypeof(vec)) {
00410     case ELM_BIT:
00411           { eusinteger_t bitmask;
00412 #if (WORD_SIZE == 64)
00413             bitmask=1L << (index % 64);
00414             writech(f,(vec->c.ivec.iv[index/64] & bitmask)?'1':'0');
00415 #else
00416             bitmask=1 << (index % 32);
00417             writech(f,(vec->c.str.chars[index/32] & bitmask)?'1':'0');
00418 #endif
00419           }
00420           break;
00421     case ELM_BYTE: case ELM_CHAR:
00422           printint(ctx,vec->c.str.chars[index],f,intval(Spevalof(PRINTBASE)),
00423                         0,0);
00424           break;
00425     case ELM_INT:
00426           printint(ctx,vec->c.ivec.iv[index],f,intval(Spevalof(PRINTBASE)),
00427                         0,0);
00428           break;
00429     case ELM_FLOAT:
00430           printflt(vec->c.fvec.fv[index],f); break;
00431     default:
00432           prin1(ctx,vec->c.vec.v[index],f,prlevel);
00433     }}
00434 
00435 static int prinary(ctx,f,prlevel,a,rank,axis,index)
00436 register context *ctx;
00437 register pointer f;     /*stream*/
00438 register pointer a;     /*array object*/
00439 int prlevel,rank,axis,index;
00440 { register int i,n,next;
00441   n=intval(a->c.ary.dim[axis]);
00442   writech(f,'(');
00443   if (axis<rank-1) {
00444     for (i=0; i<n; i++) {
00445       next=prinary(ctx,f,prlevel,a,rank,axis+1,index);
00446       if (i<n-1) writech(f,' ');
00447       index+=next;}
00448    n=next*n;}
00449   else {
00450     if (rank==1 && isint(a->c.ary.fillpointer)) n=intval(a->c.ary.fillpointer);
00451     for (i=0; i<n; i++) {
00452       prinelm(ctx,f,prlevel-1,a->c.ary.entity,index+i);
00453       if (i<n-1) writech(f,' ');} }
00454   writech(f,')');
00455   return(n);}
00456 
00457 static void printarray(ctx,a,f,prlevel)
00458 register context *ctx;
00459 register pointer a,f;
00460 register int prlevel;
00461 { char buf[16];
00462   register int i,j,rank,etype,size=1,index;
00463   register pointer p,v;
00464   rank=intval(a->c.ary.rank);
00465   etype=elmtypeof(a->c.ary.entity);
00466   sprintf(buf,"#%d%c",rank,(etype==ELM_FLOAT)?'f':
00467                            (etype==ELM_INT)?'i':'a');
00468   writestr(f,(byte *)buf,strlen(buf));
00469   if (isint(a->c.ary.offset)) index=intval(a->c.ary.offset); else index=0;
00470   prinary(ctx,f,prlevel,a,rank,0,index);
00471   }
00472 
00473 static void printlist(ctx,x,f,fobj,prlevel)
00474 register context *ctx;
00475 register pointer x,f;
00476 register pointer fobj;
00477 register int prlevel;
00478 { register pointer rest=ccdr(x);
00479   register int prlength=getprlength(ctx),shareix;
00480 
00481   if (fobj==QUOTE && islist(rest) && ccdr(rest)==NIL) {
00482     writech(f,'\'');
00483     prin1(ctx,ccar(rest),f,prlevel-1);
00484     return;}
00485   else if (fobj==FUNCTION && islist(rest) && ccdr(rest)==NIL) {
00486     writestr(f,(byte *)"#\'",2);
00487     prin1(ctx,ccar(rest),f,prlevel-1);
00488     return;}
00489   writech(f,'(');
00490   prin1(ctx,fobj,f,prlevel);
00491   x=rest;
00492   while (islist(x) && !s_marked(x)) {
00493     if (--prlength<=0) { 
00494       writestr(f,(byte *)" ...",4);
00495       x=NIL;   break;}
00496     else {
00497       writech(f,' ');
00498       prin1(ctx,ccar(x),f,prlevel);
00499       x=ccdr(x);} }
00500   if (x!=NIL) { writestr(f,(byte *)" . ",3); prin1(ctx,x,f,prlevel);}
00501   writech(f,')'); }
00502 
00503 static void printstructure(ctx,x,f,fobj,prlevel)
00504 register context *ctx;
00505 register pointer x,f;
00506 register pointer fobj;
00507 int prlevel;
00508 { pointer klass, *varvec;
00509   register int i=0,s;
00510   int prlength=getprlength(ctx);
00511   
00512   writestr(f,(byte *)"#s(",3);
00513   klass=classof(x);
00514   printsym(ctx,klass->c.cls.name,f);
00515   s=objsize(x); varvec=klass->c.cls.vars->c.vec.v;
00516   prlength--;
00517   while (i<s && prlength>0) {
00518     writech(f,' ');
00519     printsym(ctx,varvec[i],f);
00520     writech(f,' ');
00521     if (i==0) prin1(ctx,fobj,f,prlevel);
00522     else prin1(ctx,x->c.obj.iv[i],f,prlevel);
00523     i++; prlength-=2;}
00524   if (i<s) writestr(f,(byte *)" ...",4);
00525   writech(f,')');
00526   }
00527 
00528 static void prinxobj(ctx,x,f,fobj,prlevel)
00529 register context *ctx;
00530 register pointer x,f;
00531 pointer fobj;
00532 int prlevel;
00533 { pointer klass;
00534   register int i=0,s;
00535   int prlength=getprlength(ctx);
00536   writestr(f,(byte *)"#J(",3);
00537   klass=classof(x);
00538   printsym(ctx,klass->c.cls.name,f);
00539   s=objsize(x);
00540   while (i<s && prlength-->0) {
00541     writech(f,' ');
00542     if (i==0) prin1(ctx,fobj,f,prlevel);
00543     else prin1(ctx,x->c.obj.iv[i],f,prlevel);
00544     i++;}
00545   writech(f,')');
00546   }
00547 
00548 static void prin1(ctx,x,f,prlevel)
00549 register context *ctx;
00550 register pointer x;
00551 register pointer f;
00552 register int prlevel;
00553 { register pointer fobj;
00554   register int shareix=0;
00555   numunion nu;
00556 
00557   if (prlevel<=0) { writech(f,'#'); return;}
00558   if (isnum(x)) { printnum(ctx,x,f,intval(Spevalof(PRINTBASE)),0,0); return;}
00559   else if (x==UNBOUND) { writestr(f,(byte *)"***UNBOUND***",13); return;}
00560   /*pointed object*/
00561 #if vax || sun4 || news || mips || i386 || alpha || x86_64  || ARM
00562   if ((x<(pointer)(ctx->stack)) && ((pointer)(ctx->stacklimit)<x)){
00563         printint(ctx,(eusinteger_t)x,f,intval(Spevalof(PRINTBASE)),0,0); return;}
00564 #endif
00565   if (pisratio(x)) {
00566     printnum(ctx,x,f,intval(Spevalof(PRINTBASE)),0,0); return;}
00567   else if (pisbignum(x)) {
00568     printnum(ctx,x,f,intval(Spevalof(PRINTBASE)),0,0);
00569     return;}
00570   else {        /*use #n= and #n# for shared objects*/
00571     if (s_marked(x))
00572       if (p_marked (x)) {       /*first seen this shared obj. --> #n= */
00573         p_mark_off(x);
00574         shareix=intval(x->c.obj.iv[0]);
00575         sprintf(ixbuf,"#%d=",shareix);
00576         writestr(f,(byte *)ixbuf,strlen(ixbuf));
00577         fobj=ixvec[shareix]; }
00578       else {                    /*use #n# expression for labeled obj*/
00579         sprintf(ixbuf,"#%ld#",intval(x->c.obj.iv[0]));
00580         writestr(f,(byte *)ixbuf,strlen(ixbuf));
00581         return; }
00582     else fobj=x->c.obj.iv[0];
00583     if (classof(x)==C_CONS) printlist(ctx,x,f,fobj,prlevel-1);
00584     else if (pissymbol(x)) { printsym(ctx,x,f); return;}
00585     else if (pisvector(x))  printvector(ctx,x,f,fobj,prlevel-1);
00586     else if (Spevalof(PROBJECT)!=NIL)    prinxobj(ctx,x,f,fobj,prlevel-1);
00587     else if (pisarray(x) && (classof(x)==C_ARRAY))  printarray(ctx,x,f,prlevel-1);
00588     else if (Spevalof(PRSTRUCTURE)!=NIL) printstructure(ctx,x,f,fobj,prlevel-1);
00589     else csend(ctx,x,K_PRIN1,1,f);
00590     }    }
00591 
00592 static void printunmark(p)
00593 register pointer p;
00594 { register int i,s;
00595   if (isnum(p)) return;
00596   if (!s_marked(p) && !p_marked(p)) return;
00597   if (s_marked(p))
00598     if (p_marked(p)) fprintf(stderr,"smarked?\n");
00599     else pointer_update(p->c.obj.iv[0],ixvec[intval(p->c.obj.iv[0])]);
00600   s_mark_off(p); p_mark_off(p);
00601   if (pissymbol(p)) return;
00602   else if (pisvector(p)) {
00603     if (elmtypeof(p)<ELM_POINTER) return;
00604     s=vecsize(p);
00605     for (i=0; i<s; i++) printunmark(p->c.vec.v[i]); }
00606   else {
00607     s=objsize(p);
00608     for (i=0; i<s; i++) printunmark(p->c.obj.iv[i]); }
00609   }
00610 
00611 pointer prinx(ctx,obj,stream)
00612 register context *ctx;
00613 register pointer obj,stream;
00614 { pointer *spsave=ctx->vsp;
00615   pointer prlevel;
00616   int iprlevel;
00617 
00618   prlevel=Spevalof(PRLEVEL);
00619   if (isint(prlevel)) iprlevel=intval(prlevel); else iprlevel=65536;
00620   if (Spevalof(PRCIRCLE)!=NIL) {
00621     ixvec=ctx->vsp; ix=0; vpush(0);
00622 #if THREADED
00623     mutex_lock(&mark_lock);
00624     mark_locking="prinx";
00625 #endif
00626     printmark(ctx,obj);
00627     prin1(ctx,obj,stream,iprlevel);
00628     printunmark(obj);
00629 #if THREADED
00630     mutex_unlock(&mark_lock);
00631 #endif
00632     }
00633   else prin1(ctx,obj,stream,iprlevel);
00634   ctx->vsp=spsave;
00635   return(obj);}
00636 
00637 void terpri(f)
00638 register pointer f;
00639 { writech(f,'\n');  flushstream(f); }
00640 


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 18:05:53