home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13585 < prev    next >
Encoding:
Text File  |  1992-09-11  |  4.1 KB  |  110 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mnemosyne.cs.du.edu!arrakis!thor
  3. From: thor@arrakis.denver.co.us (Robert B. Hood)
  4. Subject: Re: Pretty printer program.
  5. Message-ID: <1992Sep12.033144.12262@arrakis.denver.co.us>
  6. Organization: Bob's Programming Paradise, Lakewood, CO, USA
  7. References: <gJ2wqB4w165w@vicuna.ocunix.on.ca>
  8. Date: Sat, 12 Sep 1992 03:31:44 GMT
  9. Lines: 99
  10.  
  11. In article <gJ2wqB4w165w@vicuna.ocunix.on.ca> frampton@vicuna.ocunix.on.ca writes:
  12. >Hi everyone:
  13. >
  14. >I was wondering -- is there a public domain or shareware program out 
  15. >there that will print my C source to my line printer with functions 
  16. >bolded, comments italicized, etc?
  17. >
  18. >I'm not necessarily looking for a formatter, I prefer my own "style" of 
  19. >code and don't want anyone/thing messing with it.  But something to 
  20. >output the program to the printer in an intuitive fashion would be great!
  21. >
  22. >Thanks in advance.  Please respond via e-mail as I do not have read 
  23. >access to these groups, I'll be more than happy to follow-up with a 
  24. >summary of replies received.
  25. >
  26.  
  27. (At the risk of initiating more polite flames over posting source... ;-)
  28.  
  29. In an attempt to automate the re-formatting some of the most poorly
  30. written xBASE stuff I've ever seen (over 300 source modules of it!),
  31. I wrote a short (600+ lines) formatting program in C.
  32.  
  33. Now, I know you said that you didn't want a formatting program; fair
  34. enough.  But my formatter will read a text file containing lines
  35. of substitution.  Let me clarify with an example:
  36.  
  37.               PROCEDURE
  38.               FUNCTION
  39.               DO CASE
  40.               CASE
  41.               ENDCASE
  42.               IF
  43.               ENDIF
  44.               .NOT.
  45.               .AND.
  46. ...
  47.               Len(
  48.               Trim(
  49.               EOF(
  50.               IsColor(
  51. ...
  52.               $~ $ 
  53.               #~ # 
  54.               <>~ <> 
  55.               .AND.~ .AND. 
  56.               .NOT.~ .NOT. 
  57.               =<~ =< 
  58. ...
  59.  
  60. Etc.  The above is an excerpt from my .KEY file.  The first and
  61. second portions are simply substitutions (i.e., if you find this
  62. sequence of characters, regardless of their case, then substitute
  63. what is in this file).  These allow me to highlight keywords with
  64. upper-case, and initial-caps all the function calls that appear
  65. in my .KEY file.
  66.  
  67. The last portion is a special type of keyword: a compound keyword.
  68. The tilde (~) separates two keywords.  What it does is instruct the
  69. program that, if it should locate the sequence of characters on the
  70. left, to substitute all the characters on the right.  The IN operator
  71. ($), for example, would be replaced with " $ " to add clarity.  I
  72. also use compound keywords to re-expand abbreviated xBASE commands.
  73. For instance, one compound keyword line might read:
  74.  
  75.                CLOSE alte~CLOSE ALTERNATE
  76.  
  77. There are a bunch of abbreviations in the code I have to maintain,
  78. and they simply drive me nuts!
  79.  
  80. It seems to me that it would be a fairly simple matter to re-work this
  81. .KEY file (and the actual source code since it contains hard-coded
  82. keywords for indenting purposes) to work with your keywords (or
  83. comments), and imbed your printer codes either in the source, or
  84. wrap them around the keywords:
  85.  
  86.                 <italic-on code>/*
  87.                 */<italic-off code>
  88.                 <bold-on code>PROCEDURE<bold-off code>
  89.                 <bold-on code>FUNCTION<bold-off code>
  90.  
  91. Of course, since you would not get exact matches with the source
  92. file character sequences because of the printer codes, you'd need
  93. some means of recognizing -- and removing -- the printer codes
  94. before comparisons took place (if you imbedded printer codes in
  95. the .KEY file).
  96.  
  97. Anyway, it's just a thought.  It only took me an afternoon at
  98. work to write the re-formatter, but you might be able to come up
  99. with something similar to what I've outlined above sooner.
  100.  
  101. Bob
  102. -- 
  103. Bob Hood    thor@arrakis.denver.co.us     H: 303-980-8392  W: 303-632-2180
  104. ---------------------------------------------------------------------------
  105.                The post office never loses you junk mail...
  106. -- 
  107. Bob Hood    thor@arrakis.denver.co.us     H: 303-980-8392  W: 303-632-2180
  108. ---------------------------------------------------------------------------
  109.                The post office never loses you junk mail...
  110.