Wednesday, March 21, 2012

atac - ASCII to ASCII Converter

atac source code repository.

When programming, it is not uncommon to want to make some sort of nice big separation between sections to make it easier to scroll through the source code and find what you're looking for.  This is usually done with big blocks of whatever the language's comment character happens to be (so in C it is done with long lines of /////////), but my father and I wanted to be able to create headers a little more meaningful than that.

ASCII art is where the monospaced font typically used in source code and on the terminal is used to draw diagrams, pictures, or larger version of symbols than in available from the font alone, using the ASCII character set commonly used in early (and even often modern) computers.  This was originally most useful when computer printers were little more than electric typewriters, so if you wanted any font other than the one in the printing dies, you had to get somewhat creative.  If you wanted headers to be a larger font, or even just bold, you were just out of luck*.

Building this enlarged "banner" text by hand can be tedious, so inevitably several programs were written that would convert requested text into a much larger version of itself.  Examples include the sys V banner and BSD FIGlet tools.

Both of these are perfectly good tools for the job, but my father and I wanted a simple and portable tool that did a little more than banner, but not anywhere near all FIGlet does (kerning in source code seems ridiculous).  The main thing we wanted was a single source file with no dependencies so it could be compiled in any of the several Unix environments we typically interact with nothing more than a standards-compliant cc, and have it be able to build the banner text with an optional comment prefix (such that banners in C would have each line start with //, bash scripts with #, etc).

So I wrote atac - the ASCII to ASCII Converter, which I'm finally releasing as open source after having it sitting around in my src and bin directories for several years now.  The public repo for it can be found on github, and can be checked out and installed from the command line by:

$ git clone https://github.com/PhirePhly/atac
$ cd atac; make install

This will compile it and copy it to your /home/user/bin/ directory, assuming you have one.  If you have root-like powers and would like to have this available system-wide, copy it to /usr/bin instead.  My father, always the pragmatist, renamed atac to the slightly more mnemonic BIG_WORD, and installed it through his company's unix systems, which I find highly amusing when I hear stories of other engineers finding this tool in their PATH and start using it in code that my father eventually sees.

The single feature currently separating this program from banner (other than a different font) is the -c prefix option, to have atac prefix each line with an arbitrary symbol or string to comment out the line in source code.

We most typically use atac by invoking it from within vim in a shell, and then have vim dump the result back into the file currently being edited (this is done by dropping into command mode (esc) and typing ":r!atac title" enter enter), but it has found several other uses, including breaking up long batch logs into each stage or flagging problems.

Several examples of atac's behavior can be seen in its README.

* - This wasn't really true.  Using tricks involving printing backspaces and printing over characters repeatedly allowed users to generate bold or underlined fonts at the expense of longer printing times.

2 comments:

  1. This does remind me of the old UNIX banner command. The last time I used that was probably about 15 years ago, and I was surprised to learn that 'banner' is nowhere to be found in Ubuntu, not even as an optional package!

    ReplyDelete
  2. Huh. Maybe I'm not going crazy. I originally wrote atac in 2007, but when I was putting together this article and went to show that banner wasn't in Ubuntu 10.04 yesterday, it came right up; it's in the bsdmainutils package. I recall finding only one utility that did anything like this in Ubuntu 07.04 when I looked, but it only printed sideways for tractor-feed line printers.

    Banner does have a prettier font, but atac gives you the -c flag, which is the only way I ever use it anyways.

    ReplyDelete