home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / fortran / 4756 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  2.1 KB

  1. Path: sparky!uunet!spool.mu.edu!agate!agate.berkeley.edu!dodd
  2. From: dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Uglifier (was Re: Real Programmers)
  5. Date: 16 Dec 92 06:08:59
  6. Organization: Dept of Chemical Engineering, Polytechnic Univ, NY, USA
  7. Lines: 49
  8. Message-ID: <DODD.92Dec16060859@mycenae.cchem.berkeley.edu>
  9. References: <1992Dec15.170343.10342@craycos.com>
  10.     <DODD.92Dec15142737@mycenae.cchem.berkeley.edu> <gay.724466320@sfu.ca>
  11.     <1992Dec16.025109.24541@coe.montana.edu> <BzC6n8.J2G@news.cso.uiuc.edu>
  12. NNTP-Posting-Host: mycenae.cchem.berkeley.edu
  13. In-reply-to: ercolessi@uimrl3.mrl.uiuc.edu's message of Wed, 16 Dec 1992 05:16:19 GMT
  14.  
  15. >>>>> "furio" == furio ercolessi <ercolessi@uimrl3.mrl.uiuc.edu> writes:
  16.  
  17.   furio> did any one ever made a source code uglifier, a filter removing
  18.   furio> all comments, renaming all variables as A1,A2,... (*),  removing all
  19.   furio> extra spaces, replacing character constants with Holleriths, etc?
  20.   furio> It could be a useful tool after all!  Sometimes you do not want to
  21.   furio> give away your sources, you would like to give only the binaries
  22.   furio> but that's impractical ... this would be a brilliant intermediate 
  23.   furio> solution, give uglified code!  :-)
  24.  
  25.   furio> Also, sounds like a good exercise for some CS course.
  26.  
  27.  
  28. Here is a SED script that does part of what you want.
  29.  
  30. here is ugly.sh:
  31.  
  32. ....
  33. #!/bin/csh
  34. # makes file $1 ugly
  35. sed -f ugly.sed $1 > $1.ugly
  36. ....
  37.  
  38. where ugly.sed is:
  39.  
  40. ....
  41. /^$/d
  42. /^[     ][     ]*$/d
  43. /^[cC]/d
  44. s/^    [0-9]/     \&/
  45. s/^[     ][     ]*//
  46. s/[     ]*\([-+\*\/=().]\)[     ]*/\1/g
  47. s/^\([^a-zA-Z]\)[     ][     ]*/\1/
  48. s/^\([0-9][0-9]*\)[     ][     ]*\(.*\)/\1\2/
  49. s/^\([0-9]\)\([^0-9]\)/\1     \2/
  50. s/^\([0-9][0-9]\)\([^0-9]\)/\1    \2/
  51. s/^\([0-9][0-9][0-9]\)\([^0-9]\)/\1   \2/
  52. s/^\([0-9][0-9][0-9][0-9]\)\([^0-9]\)/\1  \2/
  53. s/^\([0-9][0-9][0-9][0-9][0-9]\)\([^0-9]\)/\1 \2/
  54. s/^\([a-zA-Z]\)/      \1/
  55. s/^\([^ a-zA-Z0-9]\)/     \1/
  56. ...
  57.  
  58.  
  59. The tragic (?) thing is that often I see real code that looks like it has been
  60. uglyfied. A really good use for this script is to determine the number of line
  61. of non-comment code in a file.
  62.  
  63. Larry
  64.