Copyright (c) 2013 by Robert L. Bocchino Jr.
This is an implementation in C of the programs in the classic text Software Tools by Brian W. Kernighan and P.J. Plauger (Addison-Wesley 1976). So far I have implemented the programs from the first three chapters, except for the programs that drive line printers.
The code lives in two directories:
-
lib
contains code that is (or potentially could be) reused across different tools. -
tools
contains the tools themselves.
I used my judgment to decide which code to put where. I may change my mind as I work through more of the book.
Each of the directories lib
and tools
has a subdirectory tests
containing
tests.
The code is not idiomatic C; instead, it attempts to mimic the style of the programs in the book (written in a Fortran dialect called Rational Fortran, or Ratfor) as closely as possible, while writing in C. For example:
-
Arrays are indexed from 1, not 0.
-
Pointers are used only where necessary to mimic the behavior of global variables in the original code.
-
Control constructs are generally similar to C, but several (
repeat
,until
, etc.) are different.
I have used C macros to assist the translation process.
I find this coding style natural for programs that don't require pointer manipulation.
To build and run the code, you'll need to install the following software:
-
A UNIX command line and standard UNIX tools.
-
The fish shell.
-
The redo build tool.
If you are on a Mac and using MacPorts, you can get both by issuing the commands
sudo port install fish
sudo port install redo
on the command line.
The build system assumes you have clang installed on
your system. If you don't (or you'd rather use gcc), then edit params.fish
in
the top-level directory to replace clang
with gcc
.
To build everything, issue the command redo
from the top-level directory. You
can also issue redo
in the lib
or tools
directory to build just the
library or the tools. However, you have to build the library before building
the tools.
To remove the generated files, issue the command redo clean
.
To run the tests, issue the command redo test
from the top-level directory.
You can also issue redo test
in the lib
or tools
directory to run just
the library or tools tests.