JC's Miscellaneous Tools

JC's Miscellaneous Tools

This directory (~jc/src/misc) contains an assortment of useful programs, Most of the tools here are designed to be linked to the V ("verbose") package, so you might want to make first.

Next, if you are a new visitor, you might want to check out a few of the tools, to get an idea of the sort of things found here.

takes input that should be in columns, and adds spaces so that the columns line up. Columns may be left- or right-aligned, or centered.

is a tool for generating arbitrary strings of characters based on their names or octal or hex values. It is designed to be used in scripts, to talk to other software that requires various sorts of untypable input.

draws several styles of boxes around its input.

is a general-purpose close of the Unix cp, ln, mv and rm commands, but much more programmer-friendly. They can be used in scripts without danger that the user will be harrassed by strange messages. Also, if called with a capitalized name, they will automatically back up target files that exist rather than overwriting them. It also implements the "lc" command, which attempts a link, and if that fails, does a copy instead.

accepts an integer on its command line and output its prime factors.

returns addresses of hosts and interfaces. The output has no extraneous noise, so this command can be easily used in shell scripts.

fixes email file-ownership problems that are common on many systems.

searches through directories and file lists looking for identical files, and replaces them with links to a single file. This can result in significant savings of disk space, as well as putting multiple source trees back into sync.

is like cat(1), but copies the data in N-byte chunks, with S-second pauses between. This can be used in communication tests to generate data at a controlled rate.

accepts dotted-decimal notation and sorts it into increasing numeric order.

synchronizes clocks among networked machines. You can give it a list of host names or addresses, and your clock will be set to the mean value of those that respond. There is a "forever" option to repeat at a given interval.

is a prototype TCP client program, which establishes a connection to a server, exchanges a few messages, and shows you the results.

is a prototype TCP server program, which listens on a port, accepts connections and messages, and generates a few simple kinds of replies.

accepts various sorts of dates and times on the command line or stdin, and outputs the corresponding Unix 32-bit timestamp.

reads two files and outputs their results xor-ed together. This is useful as an "unbreakable" encryption tool, as well as a way of demonstrating that any file is an encryption of any other (so every web page and email message is actually encrypted pornography ;-).

Most of the programs here were written by John Chambers on an assortment of projects, often with a bit of help from friends and colleagues. Some of these programs duplicate tools that are found on some (but not all) Unix systems; having them here makes it easy to install them on a system where they don't exist. Some are clones of the standard Unix library programs, but with "improved" functionality. For example, see the "rm" command, which is useful in scripts because it doesn't harass the user like /bin/rm usually does these days. There's also a Rm that renames the files rather than unlinking them.

There is a Makefile entry to build the $(BIN) directory and fill it with the programs here. You should note that there are a few programs (addr, ping) here that need to be setuid or setgid; to make or install them, you need to be root.

The tar kit for this directory is made relative to this directory, so to unpack it, you should do something like:

mkdir misc cd misc zcat ../misc.tar.gz | tar xf - make test make install


   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
   # First, before anything here will work, you need to create a #
   # local.h  file.  There are a number of *_local.h files here; #
   # pick one as a prototype and copy it to local.h;  then  edit #
   # local.h file to handle the system-dependent stuff.          #
   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
Most of the C code here has been "verbosized" in a way that may not be familiar to many C programmers. The main thing to note is that the "real" sources have .b as a suffix, not .c, and the Makefile builds the .c file from the .b file by running it through the b-c script. This is a rather trivial little script, really just a call of sed, but it's convenient to put it in a scrit. What it does is selects among the source lines with : in column 1. Such lines can be either included in the .c source or blanked out. This is a simpler and cleaner scheme than complex #ifdefs to make multiple versions from the same source. I mostly just use it to enable or disable the debug lines. This way, they take one line rather than three.

Most of the programs here use the V package. If you don't have it, go get it and build it, and then come back here. It should be found wherever you found the tar kit for the misc package. The best place to install it is in ../V/, i.e., next door to the misc package.

Next, edit the Makefile and make sure it's right for your system. Note in particular that it needs a pointer to wherever you have installed the V package.

To build the non-setuid programs, type: make make bin

To build the rest, become super-user and type: make install

There are also some test programs in the test subdirectory. You can run them all by typing make test Of course, you can just use this as the first make command.

Note that most of these use the ../V/libV.a library, which must be present or not much will link. Make sure that you have the V package compiled ...

There are some programs here that the "make all" entry doesn't build. They are typically the ones that are hopelessly system-dependent. You might look around after the make works, and see what odds and ends are of interest.