CPS 100 Fall 1996, Getting Started

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 100, 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.cps100 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] rodger@teer8%
except rodger 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, .login, .emacs, or .Xdefaults files. (You can always change back to your old version of these files.) However, if you don't run the set-up program ~rodger/setup you must still change your path so it includes ~rodger/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 setup to start assignment 1. If you look at the instructions for assignment 1, you've already created the directory assign1. You might want to read the section below on Edit, Compile and Debug before attempting assignment 1.

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.

From your home directory (the directory that ends in your login name), create a directory called practice by typing cd to move to your home directory, type cd cps100 to move to your cps100 directory, type mkdir practice to create a directory named practice, and type cd practice to move into the new directory practice.

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

cp ~rodger/cps100/practice/* .

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

This program is very simple, but will provide some practice with editing, compiling, and debugging. Using the editing commands described below you are to type in the program shown, be sure to use your name and the current date . #include <iostream.h> // Author: YOUR NAME HERE // Date: TODAY'S DATE // Course: CPS 100 // Purpose: Practice C++ int main() { cout << "Nature uses only the longest threads" << endl; cout << "to weave her pattern, so each small piece" << endl; cout << "of the fabric reveals the organization" << endl; cout << "of the entire tapestry" << endl << endl; cout << " Richard Feyneman" << endl; return 0; }

Creating your program using the editor emacs

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

       emacs &

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

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

Many emacs 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!

If the print in your emacs window is not large enough, you can make it larger. (This will only work if you previously typed the setup command). Type the emacs command M-x big by first pressing and releasing the ESC key (press once quickly, do not hold down), and then typing x big and pressing the return key. (look in the minibuffer window at the bottom of the screen to see if it's working as you type).

Make sure you see the complete emacs 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 emacs 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 emacs

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

In general, you should always have an emacs window open. Unless you are logging off, there is seldom a reason to quit emacs. 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 emacs 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 emacs 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 emacs or from the shell (in an xterm window). Compiling from within emacs 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

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

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 in the back 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

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 the CPS 100 homepage or Prof. Rodger's homepage.

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

http://www.cs.duke.edu/~rodger/courses/cps100/intro.html

You can leave off the http:// and you can type just www.cs.duke.edu/~rodger and then click on the link to the CPS100 web page.

Try finding the answers to the following questions.

back to table of contents

Submitting Assignments

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

where the first argument to the program (after submit100) is the assignment name. If you type an invalid assignment name a message will appear. The N is assignN is the number of the assignment. 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.

When you submit you will get a message if the submit was successful. To see the files you submitted type submit100 assignN without any file names after the assignment name (e.g, type submit100 assign1 after submitting files for assignment 1. This should show you a list of the files you submitted.

Leaving

To exit emacs, type the emacs 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 emacs window will disappear. Always exit emacs 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