home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19930 < prev    next >
Encoding:
Internet Message Format  |  1993-01-27  |  4.0 KB

  1. Xref: sparky comp.lang.c++:19930 comp.sys.next.misc:24105
  2. Path: sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!mailgzrz.TU-Berlin.DE!math.fu-berlin.de!ira.uka.de!sol.ctr.columbia.edu!usc!news.cerf.net!nic.cerf.net!hlf
  3. From: hlf@nic.cerf.net (Howard Ferguson)
  4. Newsgroups: comp.lang.c++,comp.sys.next.misc
  5. Subject: Re: Looking for C++ Pretty-Printer/Formatter
  6. Date: 26 Jan 1993 16:48:22 GMT
  7. Organization: CERFnet Dial n' CERF Customer Group
  8. Lines: 95
  9. Message-ID: <1k3q0mINNcb1@news.cerf.net>
  10. References: <1993Jan26.022814.27915@netcom.com>
  11. NNTP-Posting-Host: nic.cerf.net
  12.  
  13. In article <1993Jan26.022814.27915@netcom.com> dx@netcom.com (dx) writes:
  14. >Can anyone point me to a C++ formatter?  What we're looking for should
  15. >simply rearrange the C++ code, rather than generate TeX or PostScript.
  16. >We'd like to find a formatter that is highly tailorable, as we'd like
  17. >to use it when checking code in and out of a central store, formating
  18. >the code to each programmer's liking on check-out, and reformating it
  19. >to a company-wide standard on check-in.
  20. >
  21.  
  22. I asked this exact question a few weeks ago and the best I got was the following script
  23. which hacks at the existing cb ( on most unix systems) which is desgned for C. 
  24.  
  25.  
  26. From: jdelsign@star-trek.bbn.com (John Delsignore)             \-(1)--(2)--[2]
  27. [2] Re: beautify for C++
  28. Date: Tue Jan 19 06:27:15 PST 1993
  29. Organization: Bolt Beranek and Newman Inc., Cambridge MA
  30. Lines: 30
  31. NNTP-Posting-Host: archive.bbn.com
  32.  
  33. In article <1jfhptINNg2g@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) writes:
  34. >
  35. >I am looking for a filter that I can run my C++ code through
  36. >that will apply some standard formatting rules to it.
  37. >
  38. >cb does this for C code, but is there a C++ specific version.
  39.  
  40. I pulled the following out of UnixWorld over a year ago, I forget who
  41. the original author was.  It uses sed to convert the '::' token into a
  42. string that's not likely to appear in your code, and '// comment'
  43. style comments into '/*C++ comment C++*/' comments.  It then pipes the
  44. result to cb and then through another sed filter to undo the
  45. conversion.
  46.  
  47. ====================cut here====================
  48. :
  49. # Use cb and sed to beautify C++ code
  50. #
  51. symbol=MAGIC_C_PLUS_PLUS_COLON_COLON_TOKEN
  52. sed -e 's,\(//.*\),/*C++ \1 C++*/,' \
  53.     -e "s,::,$symbol,g" $* |
  54. cb |
  55. sed -e 's,/\*C++ \(.*\) C++\*/,\1,' \
  56.     -e "s,$symbol,::,g"
  57. ----------------------------------------------------------------------
  58. John V. DelSignore, Jr.                 jdelsign@bbn.com
  59. BBN Systems and Technologies
  60. 10 Moulton Street                       Phone: (617) 873-2970
  61. Cambridge, MA 02138                     FAX:   (617) 873-3315
  62. ----------------------------------------------------------------------
  63.  
  64. Iplayed with this script and found indent ( again on most unix -- gnu copy on the net
  65. )
  66. was much more satisfactory. I also added a couple of lines to make class declarations
  67. a bit neater. 
  68.  
  69. However I refuse to believe that nobody has written a proper copy of a C++
  70. beautifier. I would still like to find one as this hack still has limitations
  71.  
  72. The following in my version of the above script. If you find any more improvements
  73. please let me know. In particular I would like to enforce the format
  74.  
  75. int*    x;
  76. instead of
  77. int    *x;
  78.  
  79. I managed to do this in standalone cases but it is more difficult to hack
  80. it when it is in the prototype of a function, or the top of a for loop :
  81. for (int *x; *x>10 .....
  82.  
  83.  
  84. # Use indent and sed to beautify C++ code
  85. #
  86. #options to indent are as follows
  87. # -bl   -- puts { on its own line
  88. #       -- following for, while class etc
  89. # -di4  -- lines up text following keyword
  90. #       -- 4 spaces after start of keyword
  91. # -nce  -- forces else keyeword onto a line
  92. #       -- on its own
  93. symbol=MAGIC_C_PLUS_PLUS_COLON_COLON_TOKEN
  94. sed -e 's,\(//.*\),/*C++ \1 C++*/,' \
  95.     -e "s,::,$symbol,g" $* > String.cb.tmp
  96. indent String.cb.tmp -bl -di4 -nce
  97. cat String.cb.tmp |
  98. sed -e 's,/\* C++ \(.*\) C++ \*/,\1,' \
  99.     -e "s,$symbol,::,g" \
  100.     -e "s/[\     ]*private:$/private:/" \
  101.     -e "s/[\     ]*public:$/private:/" \
  102.     -e "s/[\     ]*protected:$/private:/" \
  103.     -e "s/:public/: public/"
  104.  
  105.  
  106.     Have fun
  107.         hlf
  108.