Trim Space

Once in a while I get in a nit-picky mood and I want to write something that gets down to the nitty-gritty byte level. "Take this byte here and put it there, don't dribble, wipe your chin." Actually I do that fairly often trying to manipulate strings in C.

I've been using the Joe editor since maybe 1995 and I really like a lot about it. It's Wordstar-compatible, which doesn't mean much anymore, but it's also compatible with the Borland editors, QEdit, and the Semware Editor. It works almost like Delphi, or Turbo Pascal, or Turbo C.1 It's close enough so I don't have to think about it, it just works.

But it has one annoying, sloppy habit. It leaves trailing spaces scattered around at the ends of lines. It's been mentioned in the mailing list for Joe, but nobody has any great solutions. I think it happens when you move down over the ends of lines that are shorter than your current column positions in the lines you're moving from and to. Or maybe it's because it has a rectangle mode, which is a wonderful thing.

QEdit (I don't know if it's still around) might have had a similar tendancy, but the program authors built in this little switch in the configuration. If you turn it on, every time it saves it chops trailing spaces off all of its output lines as it saves them.

So I finally got around to write this one day when I was stumped on other things. It's called ts, which doesn't seem to conflict with anything on my machine, you can always rename it. If you run it with just "ts" it will prompt for a filename, if you run it as "ts filename" it trims trailing spaces on filename.

Actually it works from the input name you give into a file called ts_out.ts, then when it gets done it renames ts_out.ts to the original name. You probably didn't need to know that unless you find a ts_out.ts lying around and wonder where it came from. The original file is only opened for read access so if this crashes for some reason the original is still intact.

So anyway here it is all of 1200 bytes as a tar.gz. Unpack it, run make, copy it to /usr/local/bin or somewhere in your path until you need it. I ran it on its own source code for testing as I was writing it. There shouldn't be any upper limit on line lengths, but I haven't tested that. It starts by mallocing 1000 bytes for a line buffer and if it hits a longer line it does a realloc(). It is of course meant for pure text files, don't try it on Word files or PDFs or any of that junk. It was written under OpenBSD of course but it may work with other Unix-like operating systems.

1. Joe can also emulate several other editors like vi. If I remember how to get out of vi I'm doing well, usually it's pop another window and study the man page.

AB1JX / calcs