##

####

    A Tour of the ast Commands and Libraries
    Glenn Fowler

    AT&T Labs - Research

    Murray Hill, NJ 07974

### 1 Introduction

The ast commands and libraries were developed by the Software Engineering Research Department (aka the Advanced Software [Technology] Department) at AT&T Bell Laboratories, Murray Hill, NJ. The strength of ast is how its individual components combine to form a cohesive computing environment across UNIX® and non-UNIX platforms. Cohesiveness*Footnote test. is maintained by well-defined library interfaces for algorithms upon which the commands are built. In many cases a library implementation was the driving force behind command implementations.

### 2 Motivation

Why should you consider using the ast software? After all, many of the commands look like what's already in `/bin` and `/usr/local/gnu/bin`. Although there is some replication, there are also some commands you won't find anywhere else: the ksh93, nmake, the 3d filesystem, cia, and yeast.

### 3 Installation

The ast software installs in a single directory hierarchy, rooted at `$INSTALLROOT`, usually `/usr/local/ast` or `/usr/add-on/ast`. The top level `$INSTALLROOT` directories are:

                           bin      executable binaries and scripts
                           fun      ksh93 shell functions
                           lib      libraries
                   lib/command      related files for command
                   src/cmd/xxx      source for command xxx
                src/lib/libxxx      source for library xxx

To access the commands and related data files:

            export PATH=$INSTALLROOT/bin:$PATH

For each command that has a related data file file, file is found by searching `$PATH` for e.g., the magic file for the file command is `../lib/file/magic` on `$PATH`. If `$HOME/bin` is before `$INSTALLROOT/bin` in `$PATH` then you can selectively override standard ast related files by placing them in the directory This allows executables to be built without hard-coded pathnames and also requires only a change in `$PATH` when `$INSTALLROOT` changes. On systems with shared libraries one of

            export LD_LIBRARY_PATH=$INSTALLROOT/lib:$LD_LIBRARY_PATH
            export LIBPATH=$INSTALLROOT/lib:$LIBPATH
            export LPATH=$INSTALLROOT/lib:$LPATH

is required to locate the ast shared libraries.

### 4 Exploration

  tw

combines find and xargs. It provides C style expressions on path names and elements of `struct stat`. To find suspicious executables:

            tw -d / -e "uid=='root' && (mode&'u+s') && parent.uid!=uid"

to change the owner of all of bozo's files:

            tw -d / -e "uid=='bozo'" chown clown:circus

tw collects file pathname arguments up to the exec arg limit before it executes the command. For paranoid users:

            tw chmod go-rwx

which is equivalent to:

            chmod -R go-rwx

(Now you don't need to add a `-R` option to your favorite commands.) To find all source files that include `foo.h`:

            tw -e "name=='*.[chly]'" grep -l '^#.*include.*["<]foo.h[>"]'

libast handles the magic number matching for the file command. The magic file, `$INSTALLROOT/lib/file/magic`, is carefully constructed to give the same output across all architectures:

            cd $HOME/arch
            file */bin/cat

might produce:

            att.i386/bin/cat:   elf i386 executable, 32-bit, little-endian, ..
            bsd.i386/bin/cat:   bsd 386 executable, compact, paged, pure, no..
            hp.pa/bin/cat:      hp pa-risc executable, shared, dynamically l..
            sgi.mips2/bin/cat:  elf mips executable, 32-bit, dynamically lin..
            sol.sun4/bin/cat:   elf sparc executable, 32-bit, dynamically li..
            sun4/bin/cat:       sun sparc executable, paged, dynamically lin..

tw uses the same interface, making it easy to search for files based on type, name and content. The following searches for executable scripts:

            tw -e "(mode&'+x') && type!=DIR && magic!='*executable*'"

The tw algorithm efficiently detects file system loops, so following symbolic links is not a problem. The same algorithm is used by all ast commands that traverse directory hierarchies, and the following options to control pathname resolution:

            -L (logical)         follow symbolic links
            -P (physical)        don't follow symbolic links
            -H (metaphysical)    -L for command line files, -P otherwise

The ksh93 getconf builtin controls the default traversal mode:

            getconf PATH_RESOLVE - { logical, physical, metaphysical }

### 5 Configuration

### 6 Compression

### 7 Conclusion

April 18, 1997