diff options
| author | Joel Martin <github@martintribe.org> | 2014-03-29 15:56:20 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-03-29 15:56:20 -0500 |
| commit | 1b4a9012c540309ebe26b6ffff80ad44f15530d9 (patch) | |
| tree | da344787d4434ad5ebdae976958a5c5537ea601d /ps/types.ps | |
| parent | 60154d24a87ed9f3fa315870a32590a371e309d3 (diff) | |
| download | mal-1b4a9012c540309ebe26b6ffff80ad44f15530d9.tar.gz mal-1b4a9012c540309ebe26b6ffff80ad44f15530d9.zip | |
PS: minimal step1_read_print
Diffstat (limited to 'ps/types.ps')
| -rw-r--r-- | ps/types.ps | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ps/types.ps b/ps/types.ps new file mode 100644 index 0000000..a9d5023 --- /dev/null +++ b/ps/types.ps @@ -0,0 +1,63 @@ +(in types.ps\n) print + +/MAX_SYM_SIZE 256 + +% concatenate: concatenate two strings or two arrays +% From Thinking in PostScript 1990 Reid +% (string1) (string2) concatenate string3 +% array1 array2 concatenate array3 +/concatenate { %def + dup type 2 index type 2 copy ne { %if + pop pop + errordict begin (concatentate) typecheck end + }{ %else + /stringtype ne exch /arraytype ne and { + errordict begin (concatenate) typecheck end + } if + } ifelse + dup length 2 index length add 1 index type + /arraytype eq { array }{ string } ifelse + % stack: arg1 arg2 new + dup 0 4 index putinterval + % stack: arg1 arg2 new + dup 4 -1 roll length 4 -1 roll putinterval + % stack: new +} bind def + +/pr_str { + %(in pr_str\n) print + /obj exch def + /arraytype obj type eq { % if list + % accumulate an array of strings + (\() + obj length 0 gt { %if any elements + [ + obj { + pr_str + } forall + ] + { concatenate ( ) concatenate } forall + dup length 1 sub 0 exch getinterval % strip off final space + } if + (\)) concatenate + }{ /integertype obj type eq { % if number + /slen obj 10 idiv 1 add def + obj 10 slen string cvrs + }{ /stringtype obj type eq { % if string + (") obj (") concatenate concatenate + }{ null obj eq { % if nil + (nil) + }{ true obj eq { % if true + (true) + }{ false obj eq { % if false + (false) + }{ /nametype obj type eq { % if symbol + obj obj length string cvs + }{ + (<unknown>) + } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse + + %(pr_str2 stack vvv\n) print + %pstack + %(pr_str2 stack ^^^\n) print +} def |
