Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pretty printing the pretty print.

373 views
Skip to first unread message

Mike H

unread,
Sep 25, 2013, 6:36:52 AM9/25/13
to
For the first time ever, I have needed to print some code fragments. The
default print file command in the GNAT studio produced black and white
plain text. Is there something that will produce a more "illuminated"
output?

--
"Why," said Ford squatting down beside him and shivering, "are you lying face
down in the dust?" "It's a very effective way of being wretched," said Marvin.
Mike ;-(

Georg Bauhaus

unread,
Sep 25, 2013, 7:14:37 AM9/25/13
to
On 25.09.13 12:36, Mike H wrote:
> For the first time ever, I have needed to print some code fragments. The default print file command in the GNAT studio produced black and white plain text. Is there something that will produce a more "illuminated" output?
>

Emacs has customizable highlighting; buffers can be printed.

Thomas Wolf's AdaBrowse, if it helps in this case,
http://home.datacomm.ch/t_wolf/tw/ada95/adabrowse/index.html

And, shameless plug:
http://home.arcor.de/bauhaus/Tools/ASnip/

But the latter hasn't been updated for some time...

Britt

unread,
Sep 25, 2013, 10:27:03 AM9/25/13
to
On Wednesday, September 25, 2013 6:36:52 AM UTC-4, Mike H wrote:
> For the first time ever, I have needed to print some code fragments. The default print file command in the GNAT studio produced black and white plain text. Is there something that will produce a more "illuminated" output?

Which platform? On Linux GPS printes using a2ps. I use the a2ps "--prologue=color" switch to print the color syntax highlighting.

For example, I have the following in my GPS->Preferences->External Command->Print command string:

a2ps --prologue=color --rows=1 --columns=1 --sides=duplex --major=rows --chars-per-line=140 --line-numbers=5

Felix Krause

unread,
Sep 25, 2013, 10:47:08 AM9/25/13
to
On 2013-09-25 10:36:52 +0000, Mike H said:

> For the first time ever, I have needed to print some code fragments.
> The default print file command in the GNAT studio produced black and
> white plain text. Is there something that will produce a more
> "illuminated" output?

There's also GNU enscript which supports Ada syntax highlighting:

http://www.gnu.org/software/enscript/

--
Felix Krause
http://flyx.org/

Mike H

unread,
Sep 25, 2013, 10:48:04 AM9/25/13
to
In message <a0ec7acb-416a-4962...@googlegroups.com>,
Britt <britt.s...@gmail.com> writes
>Which platform?
Please don't laugh but it is MS Windows XP.

When I last wrote Ada for a living, Ada95 was still the very latest
thing! Now I am in my 9th decade and dabble for my own amusement.

--
Mike
"Homo sum, humani nihil a me alienum puto" =
"I am human, (so) I (should) judge nothing of humanity to be strange."
Publius Terentius (195/185–159 BC)

gautier...@hotmail.com

unread,
Sep 25, 2013, 11:16:35 AM9/25/13
to
Le mercredi 25 septembre 2013 16:48:04 UTC+2, Mike H a écrit :

> Please don't laugh but it is MS Windows XP.

Then consider: http://notepad-plus-plus.org/
It does a real pretty print - an not only to the printer, but to the clipboard too, so you can paste "pretty-printed" into Word, e-mails. etc.

XP is not a bad vintage at all, should not be laughed at...
_________________________
Gautier's Ada programming
http://sf.net/users/gdemont

Per Sandberg

unread,
Sep 26, 2013, 12:30:35 AM9/26/13
to
But there is cygwin !
And if you want all good stuff follow the recipe:
1) Have all your stuff including the compiler o the same "drive".
2) Make the following mounts:
Windows Cygwin
C:\(GNAT|GNATPRPO) /(GNAT/GNATPRO)
C:\mydevelroot /mydevelroot
3) Update ${PATH} to be
C:\(GNAT|GNATPRPO)\bin;C:\cygwin\bin;.........

And the tools are there.

/Per

Manuel Gomez

unread,
Sep 26, 2013, 2:38:32 PM9/26/13
to
El 25/09/13 12:36, Mike H escribi�:
> For the first time ever, I have needed to print some code fragments. The
> default print file command in the GNAT studio produced black and white
> plain text. Is there something that will produce a more "illuminated"
> output?
>

The Emacs editor has three printing outputs: plain text, rich format and
b/w rich format. Try using the menu entry File -> Postscript Print
Buffer, which invokes this Emacs command:

>
> ps-print-buffer-with-faces is an interactive compiled Lisp function in
> `ps-print.el'.
>
> It is bound to <menu-bar> <file> <ps-print-buffer-faces>.
>
> (ps-print-buffer-with-faces &optional FILENAME)
>
> Generate and print a PostScript image of the buffer.
> Like `ps-print-buffer', but includes font, color, and underline
information in
> the generated image. This command works only if you are using a
window system,
> so it has a way to determine color values.

--
Manuel

Mike H

unread,
Sep 27, 2013, 9:25:29 AM9/27/13
to
In message <da27e87a-7341-4b83...@googlegroups.com>,
gautier...@hotmail.com writes
>Then consider: http://notepad-plus-plus.org/
>It does a real pretty print
Agreed!

However, I was unable to persuade the site to download a copy onto my
PC. Not that it mattered because the on-line demonstration allowed me to
do all that I wanted to do for my immediate purposes. That purpose was
to print some code fragments in order to explain what is meant, in Ada,
by array slices, sliding and unbounded declarations.

A C++ man working for a blue-chip organisation, he was impressed and
also opined that Ada "seems to have a sweet syntax".

During the same conversation he asked me to write some Ada code to
perform an exercise question he routinely sets when interviewing
programmer candidates. Thinking on the hoof I wrote some code that in
hind-sight was not good Ada and certainly not what I would have written
if I had time to think the matter through. I seemed to fall straight
into the trap that he had set. But I say "seemed" because as soon as he
pointed out the error, and we discussed it, it became obvious that the
trap was a situation that, in Ada, would possibly not have compiled and
if it had would certainly have had potential for raising a constraint
error. I refrained from pointing out that it could be argued that it was
a specification error in that the specification did not admit that the
difference between two indices is not an index, it is an offset.

--
Knowledge is knowing a tomato is a fruit
Wisdom in knowing not to put it in the fruit salad.
Mike

Stephen Leake

unread,
Sep 29, 2013, 5:38:07 PM9/29/13
to
Mike H <postm...@ada-augusta.demon.co.uk> writes:

> In message <a0ec7acb-416a-4962...@googlegroups.com>,
> Britt <britt.s...@gmail.com> writes
>>Which platform?
> Please don't laugh but it is MS Windows XP.

Install Cygwin, use a2ps, then ps2pdf, then windows print.

--
-- Stephe

Stefan...@uni-weimar.de

unread,
Sep 30, 2013, 8:20:29 AM9/30/13
to
On Wed, 25 Sep 2013, Mike H wrote:

> For the first time ever, I have needed to print some code fragments. The
> default print file command in the GNAT studio produced black and white plain
> text. Is there something that will produce a more "illuminated" output?

If you really need syntax highlighting, rather than reformatting, then
highlight is a really good choice:

<http://www.andre-simon.de/doku/highlight/en/highlight.html>

The minor issue is that the Ada support of highlight is at the Ada 95
level -- since then, a few new keywords have been added, we have got the
precondition-postcondition-type_invariant aspects, ect. I have recently
revised the language definition to handle Ada 2012, see below.


<revised "ada.lang" from highlight>


Description="ADA2012"

Keywords={
{ Id=1,
List={"abort", "else", "new", "return", "abs", "elsif", "not",
"reverse", "abstract", "end", "null", "accept", "entry", "select",
"access", "exception", "", "separate", "", "aliased", "exit", "of", "",
"subtype", "", "all", "or", "", "and", "", "for", "", "others", "tagged",
"", "array", "function", "out", "task", "", "at", "terminate", "generic",
"package", "then", "", "begin", "goto", "pragma", "type", "", "body",
"private", "if", "procedure", "case", "in", "protected", "", "", "until",
"", "constant", "is", "", "use", "raise", "declare", "", "", "range",
"when", "", "delay", "limited", "record", "while", "", "delta", "loop",
"rem", "", "with", "digits", "renames", "do", "mod", "", "requeue", "xor",
"interface", "overriding", "synchronized",
"some"},
},
{ Id=2,
List={"pre", "post", "type_invariant",
"dynamic_predicate", "static_predicate"},
},
{ Id=4,
Regex=[[''']],
},
{ Id=4,
List={"true", "false"},
},
{ Id=4,
Regex=[[ [\w\)]+('\w+) ]],
}

}

-- Workaround: distinguish string delimiters and event markers
-- (same eymbol: ')

--workaround for special string '''

Strings={
Delimiter=[["|']],
Escape = [[ \\[^'] ]]
}

IgnoreCase=true

Comments={
{ Block=false,
Delimiter= { [[\-\-]] },
},
}

Operators=[[\(|\)|\[|\]|\{|\}|\,|\;|\:|\&|\<|\>|\!|\=|\/|\*|\%|\+|\-|\.]]

</revised "ada.lang" from highlight>



------ I love the taste of Cryptanalysis in the morning! ------
<http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
--Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universität Weimar, Germany--

Oliver Kleinke

unread,
Jan 4, 2014, 6:13:32 AM1/4/14
to
> A C++ man working for a blue-chip organisation, he was impressed and
> also opined that Ada "seems to have a sweet syntax".
>
> During the same conversation he asked me to write some Ada code to
> perform an exercise question he routinely sets when interviewing
> programmer candidates. Thinking on the hoof I wrote some code that in
> hind-sight was not good Ada and certainly not what I would have
> written if I had time to think the matter through. I seemed to fall
> straight into the trap that he had set. But I say "seemed" because as
> soon as he pointed out the error, and we discussed it, it became
> obvious that the trap was a situation that, in Ada, would possibly
> not have compiled and if it had would certainly have had potential
> for raising a constraint error. I refrained from pointing out that it
> could be argued that it was a specification error in that the
> specification did not admit that the difference between two indices
> is not an index, it is an offset.
>

Do you by chance remember the task?
I coded 4 solutions[1] to the fizzbuzz exercise that is supposedly used
by interviewers a lot.

--
[1] - https://github.com/oliver117/fizzbuzz

Mike H

unread,
Jan 6, 2014, 11:37:48 AM1/6/14
to
In message <20140104121332.22310cd2@vostro>, Oliver Kleinke
<oliver....@c-01a.de> writes
>Do you by chance remember the task?
As far as I remember the original "specification" was a requirement to
split an array at an arbitrary point and re-join the two parts (first
and last) in the reverse order (last then first). Spotting that what was
actually required was a circular shift changed the game somewhat. By
some odd coincidence, before Christmas I stumbled across the following
(see below). It seems to fit the bill. I also seem to remember that
turning it into a generic was not as sweet and clean as I expected.

function Shift_right_circular
(A : in Array_type;
Places : in Natural) return Array_type is

P : Natural := Places rem A'LENGTH;

-- Array will be split into two slices (I1 .. I2) & (I3 .. I4) and
-- re-made as (I3 .. I4) & (I1 .. I2). The values of I2 and I3 are
-- derived from their position numbers, P2 and P3.
P1 : Natural := Index_type'POS (A'FIRST); -- position number of
I1
P2 : Natural := P1 + P - 1; -- position
number of I2
P3 : Natural := P1 + P; -- position
number of I3
--
-- I1 is A'FIRST
I2 : Index_type := Index_type'VAL(P2);
I3 : Index_type := Index_type'VAL(P3);
-- I4 is A'LAST

begin

if Places = 0 then
-- no shifting to be done
return A;
else
return A (I3 .. A'LAST) & A (A'FIRST .. I2);
end if;

end Shift_right_circular;


--
Mike
Swim? Naturally at Severn Vale
<http://www.severnvalesc.org/>
0 new messages