The trailing space trimmer and tab remover started as a 30 minute at home hack to save me time and sanity at work. I inherited some code that was filled with intermingled tabs and spaces. Many of the lines had random amounts of trailing space too. Things might have been reasonable if it weren't for the fact that the author's tabs stops were different than mine. Indentation seemed random and was more of a distraction than a benefit.
I decided that I needed a beautifier to make the code indentation something useful. After a few minutes of searching, I was unable to find a simple and free beautifier. I figured that it would take less than 30 minutes to write a hack to convert the tabs to spaces and that would be enough to preserve my sanity. It actually took 37 minutes.
A few more minutes were required to strip off the trailing spaces, and then a little more time to add command line options, comments, and the GPL stuff. This web page has taken more time than that code.
Trim compiles to a console program that is executed as follows:
Usage: trim <options>
-t : Tab size.
-k : Keep tabs. Do not convert them to spaces.
-i <filename> : Name of input file.
-o <filename> : Name of output file.
-h | ? : Print out command line options.
Default: trim -t4 -i stdin -o stdout
That's all there is.
I am releasing my trailing space trimmer and tab remover under the GPL. The source code repository is available on GitHub. I recommend that you checkout the latest revision of the master branch, unless you're looking for something specific.
All the source code that I have provided is written in strict ANSI C. I would expect it to build correctly on any machine with an ANSI C compiler. I have tested the code compiled with gcc on Linux and mingw on Windows XP.
If you have any further questions or comments, you may contact me by e-mail. My e-mail address is: firstname.lastname@example.org
Last updated on January 6, 2010