CPS 6 Summer 1999

Lab 1: Getting Started

8 pts


Introduction to Unix, C++ programming, Emacs, and Netscape

This document will show you how to:


This document has several parts. You'll login, reconfigure certain files to facilitate working in CPS 6, practice some unix commands, write a simple C++ program, and use netscape. If you look at this document using a web browser like netscape you'll be able to jump between sections by clicking on hyper-links. An explanation about how to use netscape is given below. The pieces of this document include:

Table of contents

[ login | X windows | Unix | Programming | Netscape | Submit ]

This is only a brief introduction to many tools. You'll need to spend some time on your own experimenting further. You should consult the duke.cs.cps006 newsgroup and the OIT online help page for more information. A summary of Unix commands (in postscript) is available.

In this document, commands that you type will be in a font that look like this , sometimes commands may be quoted --- "like this"! --- do NOT type the quotes, just type what is between them. When instructed to type something, press the return key after typing it.


Logging in

Log in to a workstation. If you have problems logging in ask a TA for help. (You may need to go to the OIT Help desk in 101 North Bldg, although engineering students may need to check with the engineering school office or the dean's office.)

back to table of contents

Managing Windows in X

The two rectangles labeled xterm are called windows. The row of small rectangles containing pictures in the top left position of the screen is a menubar which contains some icons. Icons represent windows that are temporarily hidden. Click the mouse (left button) on the picture of the calculator (also labeled xcalc) and wait until a calculator appears on the screen.

back to table of contents


Useful UNIX commands

[ Reconfigure environment | Create Directories ]

An operating system is a large program that coordinates all the resources for the execution of programs. Unix is the operating system on the SPARCstations. You'll need to learn lots of commands, a few important ones are introduced here. To enter a command, type after the prompt in one of the xterm windows. You should see a prompt that may look similar to

    [1] dr@teer8%
except dr should be replaced by your login-id and the number may be different. If you make a mistake when typing a Unix command, use the delete key and the arrow keys to correct it.

To make the font bigger and easier to read you can hold the control key down while pressing and holding the right mouse button while the cursor is in an xterm window. Choose large for an easier-to-read window.

Before executing commands, you need to reconfigure your environment. This is explained below. You'll then logout, log back in, and write a C++ program.

Skip the reconfigure step if you don't want to alter your .cshrc, or .login files. (You can always change back to your old version of these files.) However, if you don't run the set-up program ~dr/cps6/setup   you must still change your path so it includes ~dr/bin   in order to run the submission program used to submit assignments. You must also include /afs/acpub/project/cps/bin in your path to have access to the g++ compiler. If you don't run the setup script you must change your path, it's most likely set in your .cshrc file.

Reconfiguring

Creating and Traversing Directories

You'll create and move between several directories. Move the cursor to an xterm window (make the font larger if you want!).

You are now ready to begin typing and compiling a C++ program. The section below on Edit, Compile and Debug tells you how to do this.


Summary of Unix Commands

CommandMeaning
cd change back to home directory
cd name change to name directory
cd .. change back to directory this directory is in
pwd list the directory currently in
ls list files
fs setacl set access to files
fs listacl see currect access to files
mkdir name create a new directory called name
passwd change your password

back to table of contents


Programs: Edit, Compile, Debug

You'll edit, compile, and run a C++ program in this section.

Instructions for editing, compiling, and printing are given below. First you'll need to copy a Makefile to your lab1 directory. The copy command is cp so from within your lab1 directory type (don't forget the dot: "."):

cp ~dr/cps6/lab1/* .

Type ls to see that the file was copied. You should see a file called Makefile. We'll use the Makefile to compile programs in this course. This Makefile will automatically link to libraries that will be used in this course, including those used in CPS 6. You can use it for other C++ programs you write as long as the complete program is in one file. If you write a program in multiple files, you'll need to modify the Makefile.

A C++ Program (4 pts)

This program is very simple, but will provide some practice with editing, compiling, and debugging.

Creating your program using the editor xmacs

To type in your program you need to use an editor. To use the editor xemacs to create a file use the menubar if there is an xemacs icon or type in an xterm window:

       xemacs &

(Note: Typing the "&" after the word xemacs will allow you to continue to type commands in your xterm window.)

An xemacs window should appear (please be patient!). You can use the arrow keys and the mouse to move around in the xemacs window. You may be able to just type in the program without looking at descriptions of different xemacs commands below, but you'll need to know these commands at some point during the semester.

Many xemacs commands are written in the form C-x or M-x. The notation C-x is the same as CTRL-x, and means to press and hold down the control key (the key to the left of the A key) and press the x key at the same time, and then release both keys. The notation M-x is the same as ESC-x, and means to press the ESC key and release it, and then press and release the x key (The M is for meta, don't worry about this).

Note that for control characters you must hold down the control key and the other key at the same time, whereas for escape keys you press escape, let go, then press the other key!

Make sure you see the complete xemacs window on the screen. If you can't see the bottom of the window, then move the window until you can see the whole thing.

Loading, Editing, Saving Files

CommandMeaning
C-g cancel an xemacs command, even in ``mid-stream''
C-n down one line
C-p up one line
C-a beginning of current line
C-e end of current line
C-f move right one character
C-b move back one character
C-v scroll down one screen
M-v scroll up one screen
M-< move to the first line in the file
M-> move to the last line in the file
C-d erase character at cursor
delete key erase character to left of cursor
C-k yank (erase) a line (like cut)
C-y ``unyank'' previous yank (like paste)
C-s search forward (specify string)
C-x u undo last thing
C-x C-f find file
C-x C-s save buffer
C-x b switch to specified buffer
C-x C-b list all buffers
C-x C-c quit xemacs

Alternatively, you can also click on Edit and File at the top of the xemacs window to do some of these commands. You can use the mouse to position the cursor within xemacs and you can use the arrow-keys and the scroll-bar to move around too.

In general, you should always have an xemacs window open. Unless you are logging off, there is seldom a reason to quit xemacs. You can, however iconify (make small) the window by clicking the mouse on the dot-button in the upper-right of the window. This works for any window. Double-clicking on an icon opens that application.

Until you save your file, it is stored in a buffer (the region in xemacs in which you're typing). When you believe the C++ program is correct, save it by clicking the File button at the top of the xemacs window, and then selecting Save Buffer. A message that the buffer has been written should appear in the mini-buffer. (Alternatively, you can use the command C-x C-s).

Compiling a C++ program

A compiler transforms your C++ code into machine readable code the computer can understand. Programs can be compiled from within xemacs or from the shell (in an xterm window). Compiling from within xemacs will save LOTS of time in the long run.

If you don't have any errors with the first compile, you might want to modify the program so that there is an error so you can see what happens when you compile a program with an error. For example, remove a ";" and then compile the program. Once there are no errors, move on to the next section.

Execute your program

Show A Lab UTA (1 pt)

You should raise your hand and show one of the Lab UTAs the following:
  1. Show the files in your lab 1 directory.
  2. Show the path name for your lab 1 directory.
  3. Run the program feyneman.

Print a copy of your program

If you want to print out a copy of your program, just type print filename . Thus to print the file feyneman.cc, type print feyneman.cc (Printing is completely optional. You will not be asked to turn in a hardcopy of your programs.)

The print command sends your file to the printer in the room you are currently in. If several people try to print at the same time on the same printer, the print jobs are queued and printed one at a time. To see where in the queue your job is type lpq followed by -Pname where name name is replaced by the printer name. In Teer 106, the printers are at the front of the room.

If you want to specify a specific printer, use the lpr command. There are two printers in Teer 106, named teerlp1 (the last three symbols are lowercase L, p, and the number 1) and teerlp2. To print any text file use the lpr command, specify the printername (prefixing it with -P , specify the file is a text file by -Fl (with lowercase L here) and type the file name. To print your program words.cc on the printer teerlp1, type

     lpr -Pteerlp1 -Fl words.cc

back to table of contents


Surfing the Internet (3 pts)

Netscape is a web browser for surfing for information on the world-wide web. To start netscape, click on the icon at the top of your window, or type netscape & in your xterm window --- typing the & runs netscape in the background so that you can still type commands in the window from which netscape is invoked.

If you have never used Netscape before, you may need to click on accept, and then the Netscape window will appear. Click once anywhere in this window and the Duke homepage will appear. From here, you can click on any highlighted text to get more information on the item. Click on back to retrace your steps. From the Duke homepage you should be able to find your CPS 6 homepage or Dr. Ramm's homepage.

You can find the home pages by either navigating from the Duke page (to departments, people, or faculty) or by using the Open option at the top of the netscape title bar and entering the URL for the class web pages:

http://www.cs.duke.edu/~dr/6.97sm/syl.html &nbsp;

You can leave off the http:// or for Dr. Ramm's course you can type just www.cs.duke.edu/~dr/cps6.html   and then click on the link to the CPS6 web page.

Write answers to the following questions in a file called answers. You should create this file using xemacs. You'll need to submit the file at the end of the lab.

back to table of contents

Submitting Assignments

To submit assignments you'll run a program called submit6 The general format to run the program is:
    submit6 lab1 file1.cc file2.cc ... README 

where the first argument to the program (after submit6) is the assignment name. If you type an invalid assignment name a message will appear. After the assignment name comes all the files you need to submit as part of the assignment. You can enter the files in any order.

Every assignment must have a README file submitted with it (please use all capital letters). Include your name, the date, and an estimate of how long you worked on the assignment in the README file. You must also include a list of names of all those people with whom you collaborated on the assignment or lab. So for this lab, create a file named README using xemacs. Then submit electronically by typing

    submit6 lab1 feyneman.cc answers README

You'll get a message if the submit was successful. To see the files you submitted type submit6 lab1secN without any file names after the assignment name (e.g, type submit6 lab1. This should show you a list of the files you submitted.

Leaving

To exit xemacs, type the xemacs command C-x C-c or use the File menu.

If you have not saved all your files, you will be asked at the bottom of the window whether or not to save a particular file. Type y or n for each file. When you are asked ``Subprocesses are executing; kill them and exit?'' type yes and press Return. At this point, the xemacs window will disappear. Always exit xemacs before logging out!

To logout of your SUN workstation, click on the logout icon at the top left of the screen.

You will see all the windows and icons disappear and you will be logged off. Never turn off the workstation!

Remember this is only a brief summary of useful commands to get you started. You'll need to refer to the other documents mentioned on the first page to learn more.

back to table of contents