X-Windows
Welcome to X-Windows on Solaris. Today you will sit at a workstation, log in, and explore X-Windows as well as a number of UNIX commands.On the Suns you are presented with a login window which includes the ability to choose a desktop environment (as an option before you login). Try one of them---I often use the Java Desktop System (a little slow) or KDE (because they are similar to what I use under Linux), but other people use CDE (although it is a little old). XFce and fvwm are lightweight environments (read old) that some people like because they are fast. AfterStep is modeled after the NextStep environment, and is pretty classy and fast. Choose any for now, and you can choose a different one later. In fact, I encourage you to try additional environments (after completing the lab exercises).
Window Managers. Once you have logged in, explore the interface. Notice that each of these window managers treat application windows differently. Buttons to minimize, close, resize, etc. are all functions that can be mapped by the window manager. If your window manager didn't automatically open a shell console or terminal window, look for the tool that will do so and open it. You'll need it for the rest of this lab. Once you have one open, you can open additional ones the same way, or start additional shells by typing xterm from the one shell that is running.
Copying and Pasting. X-Windows provides a simple and intuitive way to copy and paste using a mouse. Whenever you highlight text (anywhere) using the left mouse button, that text is available for pasting. Pasting is performed by clicking on the middle mouse button (or both buttons together on a two-button mouse).
Web Browsers. While some window managers have icons and links to web browsers (e.g., Konquerer), most likely they are for old browsers. However, from your shell you can type firefox to run a reasonbly modern web browser.
Editors. Similarly, some window managers may have a link to editors, but probably not for vi or emacs. You can type them at the shell. If you run emacs, you'll get the X-windows interface automatically whenever it can run (unless you specify the -nw option to prevent it).
Office Applications. Some windowing environments will include menu items for office applications such as word processors and spreadsheets. An additional one that might be of interest is OpenOffice and Sun's version, called StarOffice. StarOffice is free for educational use, is available for many platforms, cincluding Solaris, Linux, and Windows, and can read and write Microsoft Office compatible files. To start it, just type soffice.
Document Viewers. The Suns include programs to view PDF and PostCript files. For PDF, you can use acroread (Acrobat Reader) or xpdf. For PostScript, try ggv. Try these out by viewing /home/brian/cse271/refcard.pdf and /home/brian/cse271/www04-abstract.ps.
Remote Execution. One thing that makes X-Windows great is the ability to log into a machine remotely, and then have a program use your local display. You can do this too -- just ssh from your machine to another (that is, type something similar to ssh -X <newhost>), and then run a program (that uses windows) on the other machine and see it show up on your screen. This separation of display and execution makes it easy to use high-powered, centralized servers, even though you might not be able to sit in front of them. Lehigh provides a number of such computational servers (such as vega.cc.lehigh.edu which has 32 processors and 128GB of RAM and runs Linux).
Printing
Often you will want to print a file. UNIX printing systems are typically configured to handle (print) plain text files and PostScript files. There are two major approaches to printing under UNIX: the System V and BSD command interfaces. Both work on our Sun installation.What printers are available?
What is the name of the default printer (used when no printer name is specified)? What are the names of printers not in this room?
- Use lpstat -v to see what printers are available
To print a file to printer pl122-ps (the black and white printer in here):
PostScript is the default printer language for UNIX printing; however, the printing subsystem will convert a text or postscript file to the appropriate printer language if necessary. For example, you can usually print a postscript file to a dot matrix printer.
- Using SysV-style: lp -d pl122-ps <filename>
- Using BSD-style: lpr -Ppl122-ps <filename>
To see what documents are currently queued for printer pl122-ps:
Removing a queued document 42:
- SysV: lpstat -o pl122-ps
- BSD: lpq -Ppl122-ps
- SysV: cancel 42 pl122-ps
- BSD: lprm -Ppl122-ps 42
While we can print a postscript file from the command line (e.g., lpr -Ppl122-ps file.ps), for other complex file types (like PDF) you'll need to run a viewer program that can generate PostScript instead.
UNIX includes other utilities to help manage PostScript files. One that is helpful to know and use to save trees when printing your programs is mpage. mpage takes text or postscript, and generates postscript placing multiple pages on each side of the piece of paper.
C Game Programming
Battleship is a popular two-player game for kids, and has a history going back to the 1930s.Typically, each player places five "ships" of known size and distribution on a 10x10 grid. Those ships occupy grid positions that can be blindly bombed by your opponent. The goal is to sink all of your opponent's ships to win the game.
You can play a modern version written in flash, or a more complex javascript version online.
Your goal for this task is to write a C program to print the screen containing the positions of a fleet of five ships of varying length (one ship of each type):
So, for example, a fleet might occupy grid positions as follows:
- Aircraft Carrier -- length 5 units
- Battleship -- length 4 units
- Frigate -- length 3 units
- Submarine -- length 3 units
- Minesweeper -- length 2 units
A (A,1) (B,1) (C,1) (D,1) (E,1) B (B,2) (C,2) (D,2) (E,2) F (C,3) (D,3) (E,3) S (D,4) (E,4) (F,4) M (E,5) (F,5)Note that in all cases, coordinates are row (letter) followed by number (column). So, when complete your program should print out the grid as:
1 2 3 4 5 6 7 8 9 0 A A . . . . . . . . . B A B . . . . . . . . C A B F S . . . . . . D A B F S M . . . . . E A B F S M . . . . . F . . . . . . . . . . G . . . . . . . . . . H . . . . . . . . . . I . . . . . . . . . . J . . . . . . . . . .Use mpage to generate a 2-up (two pages per side) document from your code that you wrote above. Redirect the output to a postscript file, and use a postscript viewer to examine it. Use ps2pdf (another useful postscript utility) to convert it to a PDF file, and then use a PDF viewer to see it. Finally, print the original 2-up postscript file using one of the command-line methods described earlier.
Okay, that's it. Now you can try out some of the other windowing systems.