home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!agate.berkeley.edu!dodd
- From: dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd)
- Newsgroups: comp.lang.fortran
- Subject: Re: Uglifier (was Re: Real Programmers)
- Date: 16 Dec 92 06:08:59
- Organization: Dept of Chemical Engineering, Polytechnic Univ, NY, USA
- Lines: 49
- Message-ID: <DODD.92Dec16060859@mycenae.cchem.berkeley.edu>
- References: <1992Dec15.170343.10342@craycos.com>
- <DODD.92Dec15142737@mycenae.cchem.berkeley.edu> <gay.724466320@sfu.ca>
- <1992Dec16.025109.24541@coe.montana.edu> <BzC6n8.J2G@news.cso.uiuc.edu>
- NNTP-Posting-Host: mycenae.cchem.berkeley.edu
- In-reply-to: ercolessi@uimrl3.mrl.uiuc.edu's message of Wed, 16 Dec 1992 05:16:19 GMT
-
- >>>>> "furio" == furio ercolessi <ercolessi@uimrl3.mrl.uiuc.edu> writes:
-
- furio> did any one ever made a source code uglifier, a filter removing
- furio> all comments, renaming all variables as A1,A2,... (*), removing all
- furio> extra spaces, replacing character constants with Holleriths, etc?
- furio> It could be a useful tool after all! Sometimes you do not want to
- furio> give away your sources, you would like to give only the binaries
- furio> but that's impractical ... this would be a brilliant intermediate
- furio> solution, give uglified code! :-)
-
- furio> Also, sounds like a good exercise for some CS course.
-
-
- Here is a SED script that does part of what you want.
-
- here is ugly.sh:
-
- ....
- #!/bin/csh
- # makes file $1 ugly
- sed -f ugly.sed $1 > $1.ugly
- ....
-
- where ugly.sed is:
-
- ....
- /^$/d
- /^[ ][ ]*$/d
- /^[cC]/d
- s/^ [0-9]/ \&/
- s/^[ ][ ]*//
- s/[ ]*\([-+\*\/=().]\)[ ]*/\1/g
- s/^\([^a-zA-Z]\)[ ][ ]*/\1/
- s/^\([0-9][0-9]*\)[ ][ ]*\(.*\)/\1\2/
- s/^\([0-9]\)\([^0-9]\)/\1 \2/
- s/^\([0-9][0-9]\)\([^0-9]\)/\1 \2/
- s/^\([0-9][0-9][0-9]\)\([^0-9]\)/\1 \2/
- s/^\([0-9][0-9][0-9][0-9]\)\([^0-9]\)/\1 \2/
- s/^\([0-9][0-9][0-9][0-9][0-9]\)\([^0-9]\)/\1 \2/
- s/^\([a-zA-Z]\)/ \1/
- s/^\([^ a-zA-Z0-9]\)/ \1/
- ...
-
-
- The tragic (?) thing is that often I see real code that looks like it has been
- uglyfied. A really good use for this script is to determine the number of line
- of non-comment code in a file.
-
- Larry
-