[CentOS] escape .c files to html code with bash how?

Mon Oct 18 16:52:12 UTC 2010
Bowie Bailey <Bowie_Bailey at BUC.com>

 On 10/18/2010 12:34 PM, Jozsef Vadkan wrote:
> i need to encode .c files to html, like on this website:
> http://centricle.com/tools/html-entities/
> i tried to write a bash script for it:
> http://pastebin.com/raw.php?i=mZKAw4c5
> but it's not working very well :D
> does anyone has a script, that does this?

That script is never going to work right as written.  Consider this:

Text to encode:  # 123

First, it will replace the space, resulting in:  # 123

Next, it will replace the two #s, resulting in: #&#32;123

Next, it will replace the three &s, resulting in:

I'm sure you can see where this is going...

If you want to replace almost every character in a file, you either have
to do it character by character to avoid this problem, or make more
complex regexes to avoid matching stuff that has already been replaced.

What is the eventual use of this program?  Do you really need to convert
every character to an entity, or could you leave most of the normal
characters alone and only convert the ones that cause problems?