Dana Vrajitoru
C151 Multi-User Operating Systems
Lab 4
Due date: Monday, February 6, 2012.
For this lab it's better to log on to the remote host with an X11
connection - either from a Linux machine (locally) or from a mac with
the optoin -XY for ssh, or from putty using Xming. If you work from
putty without Xming, remember F10 as the key that gives you access to
the menus.
Note. The Meta key is the Alt key under Linux or
Windows/putty. Under MacOs it should be the Command key. If the Meta
commands don't work properly, click on the X in the dashboard , go to
X11 -> Preferences, click on the Input tab, and unselect the Enable
key equivalents under X11.
Ex. 1 This exercise is about the Emacs editor. Connect to
one of the Linux computers using the ssh command with the option -X -Y
(or -XY). Open the emacs editor with the command emacs &. If you
do this from home using putty, to access the menu you have to use the
special key F10.
- Create a new buffer with the command Ctrl-x Ctrl-f (the same as
for opening an existing file). In the dialog at the bottom of the
window (in the minibuffer) enter the name "my_eq.cc". The minibuffer
should tell you it's a new file.
- In the browser click on the following link:
eq.cc
Copy the content of this file from your web browser into the new file
you have just created. For this, from a Mac, select the text in the
broswer, copy it with Cmd-C, then paste it by holding the option (alt)
key down, then clicking in the emacs window, or use Paste from the
Edit menu. If you are in a Linux environment, select the text in the
browser with the mouse (not the Ctrl-A), then paste it in the editor
with Ctrl-y. If you are in Windows using putty, select the text and
copy it (Ctrl-c), then right-click in the terminal to paste it.
- Save the file with Ctrl-x Ctrl-s.
- Indentation
Notice that the program is badly indented. Select the entire code if
your window interacts with the mouse (on any system but Windows with
Putty). If you're in a text-only terminal like putty, go to the
begining of the main and set the beginning of the selected region mark
on this point with Ctrl-space. Move down to the end of the program
(not including the comment). The entire code should be highlighted.
- From a Mac or Linux environment, from the C++ menu select Indent
line or region. If you work in a putty terminal, press the function
key F10, followed by a lowercase c to select the C++ menu, the
uppercase I to select the option Indent line or region. Your program
should now be correctly indented.
- Copy-Paste
Select the code from line 24 to line 33 (including 33) as you did for
the previous part. Copy this region with Meta-w. Paste it in the code
after line 33 (before return 0) with Ctrl-y twice.
- Undo one of the pasing operations with Ctrl-_ (Ctrl shift minus).
- In the new code that you added replace the variable a with b and
the other way around. This should compute the solution for
bx+a = 0
- Compilation
To compile the file run the command compile by typing Meta-x then
typing compile directly at the botton of the window (minibuffer) where
the M-x is displayed, and then pressing return. The editor will ask
for a compiling command. By default it will propose "make -k". Delete
this and type
g++ my_eq.cc
instead.
- The program will not compile because there are some compiling
errors. Hide the compilation result by typing Ctrl-x 1. Go to line 18
by pressing
Meta-g g
followed by return, and then the line
number. Replace the COUT symbol on this line with cout.
- Search - Replace
Note that there might be other occurences of COUT in the file. To make
sure you replace all of them, from the Edit menu, choose Replace, then
Replace String... (or Meta-%). The minibuffer should say "Query
replace: ". Enter the misspelled COUT and enter. It should now say
"Query replace COUT with: ". Enter cout. The editor will highlight
every entry of COUT one by one. To replace an entry you must type the
spacebar or 'y', and to skip an entry you should enter 'n'. After
replacing 2 of them, type '!' to replace all of the remaining
occurrences of COUT. Save this file.
- Compile the file again (the Compile command can also be found in
the Tools menu). This time there should be no error and the result
will be the file a.out. Verify in the terminal that this file was
created.
- Execution
Create a simple text file called "eqin". In this file write the two
numbers a and b, each on a line. Save the file and close it (Ctrl-x k
then return). Run the program by invoking the shell command execution
first (Tools menu -> Shell Command or Meta-!) and then
typing a.out < eqin
The editor should display the result
of the program execution. Close that window with Ctrl-x 1.
- In the file "my_eq.cc", delete the last comment containing the
output of the program. Replace the name at the top with your
name. Save this file.
- Spell checking.
Select (highlight) the entire comment at the beginning of the
program. From the menu Tools choose Spell Checking, then Spell Check
Region. Do not correct the name of the course or my name (space to
leave unchanged). Correct all of the other words that are
misspelled.
- Wrapping.
Place the cursor anywhere on the long line in the comment at the top
of the program. Wrap this line with Meta-q.
- Save this file. You will have to upload it to Oncourse.
- Create a new file called lab4.txt.
- Display the named colors available for Linux and copy them to the
file lab4.txt. For this, from the Edit menu follow with Text
properties, the Display colors. Choose two of them that you like, then
go back to the terminal (or hit Ctrl-z from putty) and run another
emacs editor, but this time with the options
emacs -bg color1 -fg color2
For example, if I chose the color1 to be RoyalBlue3 and the color2 to
be SlateGray1, I would run the command the following way:
emacs -bg RoyalBlue3 -fg SlateGray1
Note the difference between the two emacs windows. Open the file
"my_eq.cc" in the second window with the command Ctrl-x Ctrl-f to see
how the -fg option (foreground color) has affected the text
display. You can close this second window now (and if you stopped the
other emacs window with Ctrl-Z, go back to it with the command
fg)
- Copy the command that you have executed to open the second emacs
window in the file lab4.txt that should be the active buffer in the
first emacs window.
- From the Tool menu select Calendar. From the Holidays menu,
display the holidays for the window (which should be Aug-Oct), then
copy them to the file lab4.txt.
Submit. Upload the files lab4.txt and my_eq.cc to Oncourse,
Assignments 2, Lab 4. If you work remotely, then you may have to
transfer the file to your local computer first by sftp
(see How To SFTP)