GIF89a; EcchiShell v1.0
//proc/self/root/usr/share/ghostscript/ <#chars> -proc- <#refs> <#chars> % <#refs> <#chars> -proc- <#refs> <#chars> % This is required so that .writeobjects can also accumulate the actual % list of composite objects to write in the binary object sequence. /cntdict mark /integertype /pop load /realtype 1 index /marktype 1 index /nulltype 1 index /booleantype 1 index /nametype { length add } bind /stringtype 1 index /arraytype //null /dicttype //null .dicttomark def /.cntobj { % <> dup type //cntdict exch get exec } .bind def cntdict /arraytype { dup dup length 5 -1 roll add 4 2 roll { .cntobj } forall } bind put cntdict /dicttype { WRITEDICTS { dup dup length 2 mul 5 -1 roll add 4 2 roll { % We have to use .execn here, rather than simply rolling the % value under the top elements, because key might involve arrays % or dictionaries. cvlit {.cntobj} exch 2 .execn .cntobj } forall } { /writeobject .systemvar /typecheck signalerror } ifelse } bind put /w2dict mark /nametype { 2 copy .writecvs pop } bind /stringtype 1 index .dicttomark def /.bosheader { % .bosheader % dup 0 currentobjectformat 127 add put % object format => BOS tag 2 index 255 le 2 index 65531 le and { % Use the short header format: tag toplen(1) totlen(2) exch 4 add exch 0 4 getinterval dup 1 5 -1 roll put } { % Use the long header format: tag 0(1) toplen(2) totlen(4) exch 8 add exch 0 0 4 2 roll .bosobject exch pop exch pop % store with byte swapping } ifelse % Stack: shortlen str exch dup -8 bitshift exch 255 and % str hibyte lobyte currentobjectformat 1 and 0 eq { % lsb first exch } if 2 index 3 3 -1 roll put 1 index 2 3 -1 roll put } .bind def /.writeobjects { % .writeobjects - mark exch % Count the space required for refs and strings. dup length 0 3 -1 roll % Stack: file tag -mark- #refs #chars array dup 4 1 roll { .cntobj } forall % Write the header. % Stack: file tag -mark- array1 ... (array|dict)N #refs #chars counttomark 3 add -2 roll 4 1 roll % Stack: -mark- array1 ... (array|dict)N tag #refs #chars file dup counttomark 1 sub index length 4 index 3 bitshift 4 index add (xxxxxxxx) .bosheader writestring % Write the objects per se. 3 1 roll pop counttomark 1 sub index length 3 bitshift exch 3 bitshift % Stack: -mark- array1 ... (array|dict)N tag file ref# char# counttomark 4 sub { counttomark -1 roll dup 6 1 roll % Stack: ... objN tag file ref# char# objN dup type /dicttype eq { % can't be first object { 5 1 roll (x\000xxxxxx) .bosobject 3 index exch writestring 4 -1 roll (x\000xxxxxx) .bosobject 3 index exch writestring } forall } { { (x\000xxxxxx) .bosobject dup 1 6 index put 3 index exch writestring 4 -1 roll pop 0 4 1 roll % clear tag } forall } ifelse } repeat % Write the strings and names. pop pop exch pop % Stack: -mark- array1 ... array|dictN file counttomark 1 sub { counttomark -1 roll { % The counting pass ensured that the keys and values % of any dictionary must be writable objects. % Hence, we are processing a dictionary iff % the next-to-top stack element is not a file. 1 index type /filetype ne { exch 2 index exch dup type //w2dict exch .knownget { exec } { pop } ifelse pop } if dup type //w2dict exch .knownget { exec } { pop } ifelse } forall } repeat % Clean up. % Stack: -mark- file pop pop } .bind def /printobject { % printobject - currentobjectformat 0 eq { /printobject .systemvar /undefined signalerror } if (%stdout) (w) file 2 index 2 index .writeobject pop pop } odef /writeobject { % writeobject - currentobjectformat 0 eq { /writeobject .systemvar /undefined signalerror } if 2 .argindex pop % check # of args .writeobject } odef /.writeobject { 3 copy exch % We must allocate the array in local VM % to avoid a possible invalidaccess. .currentglobal //false .setglobal exch 1 array astore exch .setglobal .writeobjects pop pop pop } .bind def % Implement binary error message output. /.objectprinttest { % .objectprinttest - % This is a pseudo-operator so it will restore the stack % if it gets an error. mark 0 0 3 .argindex .cntobj cleartomark pop } bind odef /.printerror { $error /binary get .languagelevel 2 ge and { currentobjectformat 0 ne { [ /Error $error /errorname get $error /command get % Convert the object with cvs if it isn't printable. dup { .objectprinttest } .internalstopped { pop 100 string cvs } if //false ] 250 printobject } //.printerror % known to be a procedure ifelse } //.printerror % known to be a procedure ifelse } bind def currentdict /cntdict .undef currentdict /w2dict .undef % End of level2dict end .setlanguagelevel