Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #3230 > unrolled thread
| Started by | luser droog <luser.droog@gmail.com> |
|---|---|
| First post | 2018-01-25 15:41 -0800 |
| Last post | 2018-01-26 14:18 -0800 |
| Articles | 9 — 3 participants |
Back to article view | Back to comp.lang.postscript
Printing PS Data Structures luser droog <luser.droog@gmail.com> - 2018-01-25 15:41 -0800
Re: Printing PS Data Structures luser droog <luser.droog@gmail.com> - 2018-01-25 16:20 -0800
Re: Printing PS Data Structures luser droog <luser.droog@gmail.com> - 2018-01-25 16:54 -0800
Re: Printing PS Data Structures luser droog <luser.droog@gmail.com> - 2018-02-01 20:11 -0800
Re: Printing PS Data Structures Martin Leese <please@see.Web.for.e-mail.INVALID> - 2018-02-01 22:57 -0700
Re: Printing PS Data Structures luser droog <luser.droog@gmail.com> - 2018-02-02 18:24 -0800
Re: Printing PS Data Structures Martin Leese <please@see.Web.for.e-mail.INVALID> - 2018-02-03 13:54 -0700
Re: Printing PS Data Structures ken <ken@spamcop.net> - 2018-01-26 17:49 +0000
Re: Printing PS Data Structures luser droog <luser.droog@gmail.com> - 2018-01-26 14:18 -0800
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2018-01-25 15:41 -0800 |
| Subject | Printing PS Data Structures |
| Message-ID | <95a75c45-f12b-43d1-8d6e-f987f58dcddb@googlegroups.com> |
In a contemporaneous thread, Ken shared a program to
print the contents of a dictionary on multiple sheets
(if needed). And let me be very clear that I mean no
disrespect to Ken or his programming abilities when
I go on to say that I think the program can be redesigned
to be smaller, simpler, and more flexible.
The particular problem of dispatching code based on the
type of an object is something that I've worked on quite
a bit. And a great way to do it is to name several procs
with the desired typenames and then `type exec` or
`type DICT exch get exec` or similar.
/show-object {
dup type object-procs exch get exec
} def
/object-procs <<
[/integertype /realtype]
{ { =string cvs show } } forall
[/arraytype /packedarraytype]
{ { } } forall
/dicttype {
}
>> def
Of course this little snippet doesn't do a whole lot
just yet. How about naming this idiom and having it
call /default if there is no match.
/type-switch { % type dict-of-type-procs
exch
2 copy known not { pop /default } if
get exec
} def
/show-object {
dup type object-procs type-switch
} def
/object-procs <<
/default { =string cvs show }
/arraytype {
([ ) show
{ show-object } forall
(] ) show
}
/dicttype {
(<< ) show
{ exch show-object show-object } forall
(>> ) show
}
>>
That's a little better, I think. This version traverses
any compound data structure and prints it ... but all
on one long line.
So, all the places where I called `show` need to call
a new function which decides whether to start a new line
and if so, then it also figures out appropriate
indentation, and then calls show.
And let me do some thinking on this next step before
I blog all over myself.... more to follow.
[toc] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2018-01-25 16:20 -0800 |
| Message-ID | <d01ed8e3-7376-497b-be8f-8d3241cc0fe9@googlegroups.com> |
| In reply to | #3230 |
On Thursday, January 25, 2018 at 5:41:26 PM UTC-6, luser droog wrote:
[snip][...] I think the program can be redesigned
> to be smaller, simpler, and more flexible.
>
[snip]
> That's a little better, I think. This version traverses
> any compound data structure and prints it ... but all
> on one long line.
>
> So, all the places where I called `show` need to call
> a new function which decides whether to start a new line
> and if so, then it also figures out appropriate
> indentation, and then calls show.
>
> And let me do some thinking on this next step before
> I blog all over myself.... more to follow.
Ok this version minds line lengths and ghostscript shows
me the whole thing on one page. Still not quite achieving
the quality of output from the original, but I ain't done yet....
laptop ~
$ cat printdata.ps
%!
<<
/type-switch { 1 index type switch }
/switch { 2 copy known not { pop /default } if get exec }
/+= { dup load 3 2 roll add store }
/show-object { object-procs type-switch }
/show-simple { =string cvs show-it ( ) show-it }
/object-procs <<
/default { show-simple }
/nametype {
dup xcheck not { (/) show-and-update-position } if % ie. <nobr>
show-simple
}
/arraytype {
([ ) show-it { show-object } forall (] ) show-it
}
/dicttype {
(<< ) show-it { exch show-object show-object } forall (>> ) show-it
}
>>
/line-position 0
/max-line-length 80
/show-and-update-position {
dup length /line-position +=
show
}
/show-it {
show-and-update-position
line-position max-line-length gt {
next-line
} if
}
/next-line {
lead neg /Y +=
x Y moveto
/line-position 0 store
}
/x 30
/X {max-line-length}
/Y 600
/y 30
>> {def} forall
x Y moveto
/Palatino-Roman 10 selectfont /lead 12 def
<<
/currentpagedevice currentpagedevice
>> show-object
showpage
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2018-01-25 16:54 -0800 |
| Message-ID | <adc62d6f-2327-444b-b7e9-d8afef115508@googlegroups.com> |
| In reply to | #3231 |
On Thursday, January 25, 2018 at 6:20:51 PM UTC-6, luser droog wrote:
> On Thursday, January 25, 2018 at 5:41:26 PM UTC-6, luser droog wrote:
> [snip][...] I think the program can be redesigned
> > to be smaller, simpler, and more flexible.
> >
> [snip]
> > That's a little better, I think. This version traverses
> > any compound data structure and prints it ... but all
> > on one long line.
> >
> > So, all the places where I called `show` need to call
> > a new function which decides whether to start a new line
> > and if so, then it also figures out appropriate
> > indentation, and then calls show.
> >
> > And let me do some thinking on this next step before
> > I blog all over myself.... more to follow.
>
>
> Ok this version minds line lengths and ghostscript shows
> me the whole thing on one page. Still not quite achieving
> the quality of output from the original, but I ain't done yet....
>
Ok now there's all that, plus indentation and multiple pages.
Magic numbers at the bottom, near the 'script' portion.
laptop ~
$ cat printdata.ps
%!
<<
/type-switch { 1 index type switch }
/switch { 2 copy known not { pop /default } if get exec }
/+= { dup load 3 2 roll add store }
/is-simple { is-compound not }
/is-compound { compound-types exch type known }
/compound-types << [
/arraytype %/packedarraytype
/dicttype
]{null}forall >>
/map { 1 index xcheck 3 1 roll [ 3 1 roll forall ] exch { cvx } if }
/reduce { exch dup first exch rest 3 -1 roll forall }
/first { 0 get }
/rest { 1 1 index length 1 sub getinterval }
/all-simple { dup length 0 gt { {is-simple} map {and} reduce }{ pop true } ifelse }
/show-object { object-procs type-switch }
/show-simple { =string cvs show-it ( ) show-it }
/object-procs <<
/default { show-simple }
/nametype {
dup xcheck not { (/) show-and-update-position } if % ie. <nobr>
show-simple
}
/arraytype {
dup all-simple {
([ ) show-it { show-object } forall (] ) show-it
}{
([ ) show-it next-line
+20 /x += x Y moveto
{ show-object next-line } forall
-20 /x += x Y moveto
(] ) show-it next-line
} ifelse
}
/packedarraytype 1 index
/dicttype {
dup {}map all-simple {
(<< ) show-it { exch show-object show-object } forall (>> ) show-it
}{
(<< ) show-it next-line
+20 /x += x Y moveto
{ exch show-object show-object next-line } forall
-20 /x += x Y moveto
(>> ) show-it next-line
} ifelse
}
>>
/show-and-update-position {
dup length /line-position +=
show
/marks-on-page true store
}
/show-it {
show-and-update-position
line-position max-line-length gt {
next-line
} if
}
/next-line {
lead neg /Y +=
x Y moveto
/line-position 0 store
Y y lt { next-page } if
}
/next-page {
showpage
/marks-on-page false store
/Y max-page-height store
x Y moveto
}
/marks-on-page false
/line-position 0
/x 30
/X 100 /max-line-length 1 index
/Y 750 /max-page-height 1 index
/y 30
>> {def} forall
x Y moveto
/Palatino-Roman 10 selectfont /lead 12 def
<<
/currentpagedevice currentpagedevice
>> show-object
marks-on-page { showpage } if
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2018-02-01 20:11 -0800 |
| Message-ID | <e05ab00d-1c08-4341-a302-67240d0c242e@googlegroups.com> |
| In reply to | #3232 |
On Thursday, January 25, 2018 at 6:54:50 PM UTC-6, luser droog wrote: > x Y moveto > /Palatino-Roman 10 selectfont /lead 12 def What if /lead was negative and always added to the y position instead of subtracted? Somehow that seems nicer to have a vector instead of just a quantity. You could even define a shorthand notation /Palatino-Roman /10-12 selectleadfont
[toc] | [prev] | [next] | [standalone]
| From | Martin Leese <please@see.Web.for.e-mail.INVALID> |
|---|---|
| Date | 2018-02-01 22:57 -0700 |
| Message-ID | <p50ujs$5ad$1@dont-email.me> |
| In reply to | #3232 |
luser droog wrote: > Ok now there's all that, plus indentation and multiple pages. > Magic numbers at the bottom, near the 'script' portion. > > > laptop ~ > $ cat printdata.ps > %! ... Thanks for the program; I have squirreled it away for next time. If you are looking for bugs then I get some values of "--nostringval--". Perhaps these are nulls; they are with the keys /NumCopies, /ImagingBBox, and /PageDeviceName. -- Regards, Martin Leese E-mail: please@see.Web.for.e-mail.INVALID Web: http://members.tripod.com/martin_leese/
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2018-02-02 18:24 -0800 |
| Message-ID | <3e2f1ec9-5c0b-4e05-b11e-a46a73787112@googlegroups.com> |
| In reply to | #3237 |
On Thursday, February 1, 2018 at 11:57:18 PM UTC-6, Martin Leese wrote:
> luser droog wrote:
>
> > Ok now there's all that, plus indentation and multiple pages.
> > Magic numbers at the bottom, near the 'script' portion.
> >
> >
> > laptop ~
> > $ cat printdata.ps
> > %!
> ...
>
> Thanks for the program; I have squirreled it
> away for next time.
>
> If you are looking for bugs then I get some
> values of "--nostringval--". Perhaps these
> are nulls; they are with the keys /NumCopies,
> /ImagingBBox, and /PageDeviceName.
>
Yes, quite possible that they are nulls. You could
add a clause for those.
/nulltype { pop (null) show-it }
[toc] | [prev] | [next] | [standalone]
| From | Martin Leese <please@see.Web.for.e-mail.INVALID> |
|---|---|
| Date | 2018-02-03 13:54 -0700 |
| Message-ID | <p557hr$8nq$1@dont-email.me> |
| In reply to | #3238 |
luser droog wrote:
> On Thursday, February 1, 2018 at 11:57:18 PM UTC-6, Martin Leese wrote:
>> Thanks for the program; I have squirreled it
>> away for next time.
>>
>> If you are looking for bugs then I get some
>> values of "--nostringval--". Perhaps these
>> are nulls; they are with the keys /NumCopies,
>> /ImagingBBox, and /PageDeviceName.
>
> Yes, quite possible that they are nulls. You could
> add a clause for those.
>
> /nulltype { pop (null) show-it }
Yep, they were nulls.
Many thanks.
--
Martin Leese
E-mail: please@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/
[toc] | [prev] | [next] | [standalone]
| From | ken <ken@spamcop.net> |
|---|---|
| Date | 2018-01-26 17:49 +0000 |
| Message-ID | <MPG.34d57a65c64fc6e8989927@usenet.plus.net> |
| In reply to | #3230 |
In article <95a75c45-f12b-43d1-8d6e-f987f58dcddb@googlegroups.com>, luser.droog@gmail.com says... > (if needed). And let me be very clear that I mean no > disrespect to Ken or his programming abilities when > I go on to say that I think the program can be redesigned > to be smaller, simpler, and more flexible. LOL ! It was a real quick program knocked up to solve a specific problem, I can't (and wouldn't) claim its a good piece of programming..... In fact, as the original reporter pointed out, it has a bug in it as is.
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2018-01-26 14:18 -0800 |
| Message-ID | <b874157a-4a71-4104-8fe7-922f1539ddc7@googlegroups.com> |
| In reply to | #3233 |
On Friday, January 26, 2018 at 11:49:15 AM UTC-6, ken wrote: > In article <95a75c45-f12b-43d1-8d6e-f987f58dcddb@googlegroups.com>, > luser.droog@gmail.com says... > > > (if needed). And let me be very clear that I mean no > > disrespect to Ken or his programming abilities when > > I go on to say that I think the program can be redesigned > > to be smaller, simpler, and more flexible. > > LOL ! > > It was a real quick program knocked up to solve a specific problem, I > can't (and wouldn't) claim its a good piece of programming..... > > In fact, as the original reporter pointed out, it has a bug in it as is. I needed some kind of lead-in to explain why I was trying to solve an already-solved problem. But I think I failed on the 'smaller' and 'simpler' goals with my version. I'm pretty sure mine has bugs in it, too. For starters, the indentation handling is a real kluge. It moves the right edge, too, rather than narrowing the lines.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web