CMPSC 311, General Instructions

Accessing Information -- How to get the source code from APUE

Here is how to get your own copy of the source code from APUE, to be used on a Unix system with the GNU tools installed (this includes Linux, Mac OS X, and Solaris at PSU CSE).  We assume you are using a Web browser where right-clicking on a link gets you a menu of choices; on Mac OS X, use control-click instead.  We also assume you have read and printed this page on some not-necessarily-Unix system, because we're going to start from the beginning.

Login, and open a terminal window.  You should be in your home directory.  Try these commands just to be sure.

When used as part of a command, the symbol ~ (tilde) is shorthand for the name of your home directory.  The environment variable HOME gives the same information.
  echo ~
  echo $HOME

Create a directory to hold all your projects for the course.  For example,
  mkdir ~/cmpsc311

Verify that the directory was created.

Create a subdirectory to hold the code from APUE.  For example,
  mkdir ~/cmpsc311/apue

The commands to follow will create a subdirectory of apue.

Open a Web browser.  For example,
  firefox &

Go to (right-click to open in a new tab or window, so you don't lose this one).

Click on Source Code in the left-side frame.  You should see
    The source code for the examples in the book is available
    for download here as a gzipped tar archive.

Right-click on the link (here, there) in the right-side frame, and select Save Link As ...

Browse to the directory you created earlier, and save the file as src.tar.gz which is its original name.

Now you need to unpack the source code files.  We will add some extra commands to see the effect of archiving and file compression.

First, change to your new directory.
  cd ~/cmpsc311/apue

The command gzip compresses a file, and gunzip uncompresses it.  The file name ends in .gz as a reminder.  The program names begin with g to indicate that they are from the GNU collection, but that isn't a foolproof or absolute rule.
  ls -l
  gunzip src.tar.gz
  ls -l

The file src.tar.gz has been replaced by the file src.tar, which is about 7 times larger.

This is the typical use of gzip and gunzip:
  gzip src.tar
  gunzip src.tar
Try this with interleaved ls -l commands to verify the file sizes and changes in the file name.

The command tar (which originally meant "tape archive") bundles files and directories into one file, called a tar file or tar archive for obvious reasons.  The filename ends in .tar as a reminder.  tar also unbundles a tar file.  It's usually a good idea to see what is in the tar file before un-tar'ing it.
  tar tvf src.tar

Note that tar does not use the modern convention for options, which would have been something like "tar -t -v -f src.tar".  The function letter t means "Table of Contents", so you get a listing.  The function modifier v means "Verbose" so you get a long listing (file size and original date, along with the name from the default listing).  The function modifier f means "File" so you can specify which tar file to read for its contents.

To extract the contents of the tar file,
  tar xvf src.tar

Now check to see what you have:
  ls -l

You can safely delete the file src.tar, since you know how to recover it from the web site, and since its contents are now available as individual files and subdirectories.
  rm src.tar

To see everything in the file tree,
  ls -lR

Now it's time to read the files.  Start with these,
  more apue.2e/README apue.2e/DISCLAIMER

Navigating through the apue.2e directory should be obvious once you see its subdirectories and file names.  Use the command
  cd subdir
to change to the subdirectory subdir, and the command
  cd ..
to change to the parent directory (one level upward in the file system), or the command
to change to your home directory.

Later we'll come back to the description of how to compile and run these programs.

Last revised, 28 Aug. 2008