Trailing Space Trimmer and Tab Remover
by Michael Dipperstein
About The Software
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.
Using The Software
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. All of my revisions of the code are listed below. As I add enhancements or fix bugs, I will post them here as newer versions. The larger the version number, the newer the version. I'm retaining the older versions for historical reasons. I recommend that most people download the newest version unless there is a compelling reason to do otherwise.
Each version is contained in its own zipped archive which includes the source files and brief instructions for building an executable. None of the archives contain executable programs. A copy of the archives may be obtained by clicking on the links below.
|Version 0.3||Writes output one character at a time instead of one line at a time. This requires less system memory.|
|Added a "Keep Tabs" mode, -k.|
|Version 0.2||Replaces getopt with my optlist library.|
|Explicitly license the library under GPL version 3.|
|Version 0.1||Initial release.|
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