h46378 s 00188/00000/00000 d D 1.1 91/03/08 04:48:40 hopkins 1 0 c date and time created 91/03/08 04:48:40 by hopkins e u U f e 0 t T I 1 #include #include #define MAXLN 60 #define MAXCOL 50 dicttype dup_dict = growabledict; int dup_cnt = 0; extern void save_obj(filetype fp, any thing); void mark_obj_saved(any thing) { dup_dict[thing] = dup_cnt++; } boolean obj_saved_before(filetype fp, any thing) { if (known(dup_dict,thing)) { writeobject(fp,dup_dict[thing]); writestring(fp," #g"); return true; } else return false; } void save_shared_class(filetype fp, shared_class c) { if (!obj_saved_before(fp,c)) { mark_obj_saved(c); save_obj(fp,c.pdb_script); write(fp,' '); save_obj(fp,c.ps_script); write(fp,' '); save_obj(fp,c.superclass.classname); writestring(fp," SC"); } } void save_obj(filetype fp, any thing) { char *str; any *a, k, v; int col, n; fonttype fnt; dicttype d; object o; switch (truedicttype(thing)) { case /fixedtype: case /realtype: writeobject(fp,(cvi((float)thing) == thing) ? cvi((float)thing) : thing); break; case /integertype: case /booleantype: case /nulltype: writeobject(fp,thing); break; case /marktype: writestring(fp,"["); break; case /nametype: if (name_ok((name)thing)) writeobject(fp,thing); else { save_obj(fp,cvns((name)thing)); writestring(fp," cvn"); } break; case /stringtype: n = length(str = (char *)thing); if (n > MAXLN) { writestring(fp,"("); col = 0; forall(; n ; str) { str = lit_char(n); writestring(fp,str); if ((col += length(str)) > MAXCOL) { writestring(fp,"\\\n"); col = 0; } } writestring(fp,")"); } else if (n) writeobject(fp,str); else writestring(fp,"//nullstring"); break; case /packedarraytype: case /arraytype: n = length(a = (any *)thing); if (n) { if ((n == 6) && (a[0] == 1) && (a[1] == 0) && (a[2] == 0) && (a[3] == 1)) { save_obj(fp,a[4]); write(fp,' '); save_obj(fp,a[5]); writestring(fp," MX"); } else { writestring(fp,xcheck(a) ? "{" : "["); col = 0; forall (; v ; a) { save_obj(fp,v); if (col++ < 4) write(fp,' '); else { col = 0; writestring(fp,"\n"); } } writestring(fp,xcheck(a) ? "}\n" : "]\n"); } } else writestring(fp,xcheck(a) ? "{}" : "//nullarray"); break; case /operatortype: n = length(str = cvs((name)thing,string(64))); writestring(fp,getinterval(str,1,n-2)); break; case /colortype: a = colorrgb((colortype)thing); save_obj(fp,a[0]); write(fp,' '); save_obj(fp,a[1]); write(fp,' '); save_obj(fp,a[2]); writestring(fp," rgbcolor"); break; case /fonttype: a = (fnt = (fonttype)thing).FontMatrix; save_obj(fp,fnt.FontName); writestring(fp," findfont "); if ((a[0] == a[3]) && (a[1] == 0) && (a[2] == 0) && (a[4] == 0) && (a[5] == 0)) { save_obj(fp,a[0]); writestring(fp," scalefont "); } else { save_obj(fp,a); writestring(fp," makefont "); } save_obj(fp,fnt.PrinterMatched); writestring(fp," printermatchfont"); break; case /dicttype: if (!obj_saved_before(fp,thing)) { mark_obj_saved(thing); d = (dicttype)thing; writeobject(fp,maxlength(d)); writestring(fp," Bd\n"); forall (k ; v ; d) { save_obj(fp,k); write(fp,' '); save_obj(fp,v); writestring(fp," def\n"); } writestring(fp," Ed\n"); } break; case /hntype: if (!obj_saved_before(fp,thing)) { o = (object)thing; save_shared_class(fp,o.class()); writestring(fp," BO\n"); mark_obj_saved(o); forall(; k ; o.persistent()) if (known(o,k)) { save_obj(fp,k); write(fp,' '); save_obj(fp,o[k]); writestring(fp," def\n"); } writestring(fp,"EO"); } break; default: writestring(fp,"null"); break; } } void save_object(filetype fp, any thing) { writestring(fp,"% HyperNeWS window (c)1990 Turing Institute\n"); writestring(fp,"2.001 HNBegin\n"); dup_cnt = 0; save_obj(fp,thing); cleanoutdict(dup_dict); writestring(fp,"\nHNEnd\n"); } E 1