Useful Little Hacks
Greetings!
A hacklet is, in my view, a dumb little script or utility that you could
probably have created yourself but someone else has already done it so why
bother spending an hour getting the nits correct, eh?
Here are a few small hacklets and utilities I hacked (or co-hacked) to make
life easier for myself:
- countWords.awk -- Wondering if your
latest paper fits under the 5000 word limit? Here's an awk script I
wrote in about 10 minutes that count the number of words in a Latex
file, ignoring document preambles, comments, and tokens beginning with
a backslash.
Usage: awk -f countWords.awk foo.tex
- countLOC.awk -- an awk script written in
1988 by Dan Kozak that counts lines of code but ignores comments and
blank lines. I hacked it slightly to ignore C++/Java-style comments
that begin with "//". This is very simple minded.
Usage: awk -f countLOC.awk *.[ch]
Vishal Goenka sent
me a
link to his little Unix scripts that are even more useful.
- colourizeSource.sh -- a (rather
trivial) shell script that creates colourized syntax highlighted HTML
versions of any file that the vim text
editor has syntax highlighting support for (you can also roll you own
for your favourite private notations, as I did for grok below). For
each file foo.ext, it creates foo.ext.html. There are a large number
of supported notations, including almost all programming languages of
note, shell scripts, HTML files, Xdefault files, ... It is kinda slow
tho. Requires gvim and that X windows be running.
Here's an example
of a C file that I ran this through. (Don't like the colour scheme? You
can change it.)
- grok.vim -- a syntax file for the grok
relational calculator for use with the vim text editor.
- make2acacia.awk -- a script that
generates a ksh script to run an
Acacia
(CCia) extraction on a system from a makefile. Typical use:
% ./configure (if appropriate)
% make -n > make.out (or make > make.out)
% awk -f make2acacia.awk make.out > make.acacia
% chmod 755 make.acacia
% ./make.acacia
The script make have to be hacked at still, but it's a good starting
point. This works for me out of the box for simple systems.
- make2cfx.awk -- a script that generates a
/bin/sh script to run an cfx/fbgen (PBS toolkit) extraction on a system
from a makefile, analogously to make2acacia.awk. Typical use:
% ./configure (if appropriate)
% make -n > make.out (or make > make.out)
% awk -f make2cfx.awk make.out > make.cfx
% chmod 755 make.cfx
% ./make.cfx
- taxform.tgz -- some scripts that allow you
to use the
Acacia
extractor "CCia" (as well as the older "cia" extractor that comes with
Acacia), as a drop-in replacement for cfx/fbgen with the PBS tool suite. Note that
while Acacia/CCia does handle C++ reasonably well, these scripts assume
your system is written in C. The advantage of using CCia over PBS's
cfx/fbgen is that the Acacia extractor seems to be a bit more robust
and slightly more accurate (plus there is more detail extracted if you
want to muck around). This is part of the TAXFORM
project. You must have the following software installed: Acacia,
ksh93 (comes with Acacia), PBS, grok 3.0 or better, gawk. It works for
me, but I make no promises. The README file gives gory details on use,
and the doc subdir outlines the data schemas used. A good example
system to try it all out on is
ctags-3.0.tgz.
Michael W. Godfrey PhD, Professor
School of Computer Science,
University of Waterloo
Waterloo, Ontario, N2L 3G1, CANADA
Office: DC2340
email:
URL: http://www.uwaterloo.ca/~migod
Last modification: Monday March 8, 2010 at 07:00:42 (EST)