From: thor@arrakis.denver.co.us (Robert B. Hood)
Subject: Re: Pretty printer program.
Organization: Bob's Programming Paradise, Lakewood, CO, USA
Date: Sat, 12 Sep 1992 03:31:44 GMT

In article <gJ2wqB4w165w@vicuna.ocunix.on.ca> frampton@vicuna.ocunix.on.ca writes:
>Hi everyone:
>
>I was wondering -- is there a public domain or shareware program out 
>there that will print my C source to my line printer with functions 
>bolded, comments italicized, etc?
>
>I'm not necessarily looking for a formatter, I prefer my own "style" of 
>code and don't want anyone/thing messing with it.  But something to 
>output the program to the printer in an intuitive fashion would be great!
>
>Thanks in advance.  Please respond via e-mail as I do not have read 
>access to these groups, I'll be more than happy to follow-up with a 
>summary of replies received.
>

(At the risk of initiating more polite flames over posting source... ;-)

In an attempt to automate the re-formatting some of the most poorly
written xBASE stuff I've ever seen (over 300 source modules of it!),
I wrote a short (600+ lines) formatting program in C.

Now, I know you said that you didn't want a formatting program; fair
enough.  But my formatter will read a text file containing lines
of substitution.  Let me clarify with an example:

              PROCEDURE
              FUNCTION
              DO CASE
              CASE
              ENDCASE
              IF
              ENDIF
              .NOT.
              .AND.
...
              Len(
              Trim(
              EOF(
              IsColor(
...
              $~ $ 
              #~ # 
              <>~ <> 
              .AND.~ .AND. 
              .NOT.~ .NOT. 
              =<~ =< 
...

Etc.  The above is an excerpt from my .KEY file.  The first and
second portions are simply substitutions (i.e., if you find this
sequence of characters, regardless of their case, then substitute
what is in this file).  These allow me to highlight keywords with
upper-case, and initial-caps all the function calls that appear
in my .KEY file.

The last portion is a special type of keyword: a compound keyword.
The tilde (~) separates two keywords.  What it does is instruct the
program that, if it should locate the sequence of characters on the
left, to substitute all the characters on the right.  The IN operator
($), for example, would be replaced with " $ " to add clarity.  I
also use compound keywords to re-expand abbreviated xBASE commands.
For instance, one compound keyword line might read:

               CLOSE alte~CLOSE ALTERNATE

There are a bunch of abbreviations in the code I have to maintain,
and they simply drive me nuts!

It seems to me that it would be a fairly simple matter to re-work this
.KEY file (and the actual source code since it contains hard-coded
keywords for indenting purposes) to work with your keywords (or
comments), and imbed your printer codes either in the source, or
wrap them around the keywords:

                <italic-on code>/*
                */<italic-off code>
                <bold-on code>PROCEDURE<bold-off code>
                <bold-on code>FUNCTION<bold-off code>

Of course, since you would not get exact matches with the source
file character sequences because of the printer codes, you'd need
some means of recognizing -- and removing -- the printer codes
before comparisons took place (if you imbedded printer codes in
the .KEY file).

Anyway, it's just a thought.  It only took me an afternoon at
work to write the re-formatter, but you might be able to come up
with something similar to what I've outlined above sooner.

Bob
-- 
Bob Hood    thor@arrakis.denver.co.us     H: 303-980-8392  W: 303-632-2180
---------------------------------------------------------------------------
               The post office never loses you junk mail...
-- 
Bob Hood    thor@arrakis.denver.co.us     H: 303-980-8392  W: 303-632-2180
---------------------------------------------------------------------------
               The post office never loses you junk mail...
Newsgroups: comp.lang.c