Project 4 -- Interprocess Communication

Due Friday, December 5, 11:30 pm

(Note that due date is later than originally listed in the class schedule.)

NOTE: This assignment, like the other projects in this class, is due at particular time, as measured on the lab computers. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your homework ahead of time. Do this by submitting them electronically then giving the hard copy to me or the TA during office hours or by sliding it under my office door within twenty-four hours after the time it is due. Do not send assignments to me through email or leave them in my departmental mail box.

In UNIX systems it is typically very easy to print certain types of files, such as ordinary text files. For example, in most systems we can use the commands lpr (BSD systems) or lp (System V) followed by the file name to print to the printer. Moreover, if the printer is a PostScript printer (and many are), then we can also send PostScript files to the printer this way. For example,

    lpr myfile.ps
is all that is needed on a typical BSD system to send the PostScript file myfile.ps to the default printer.

Unfortunately, on most UNIX systems it is rather more involved to print an image files in formats such as jpeg and gif. Rather than a single, simple command, we typically need to open the file with a image viewer, then click around on the menus before the file is printed. This makes printing more time-consuming and makes it difficult to print from a remote location because a graphical display is required.

One application that people might find useful is one that assists them in printing their image files from the command line. One simple way to write this program would be to have it use available conversion software to convert the image file to PostScript, then send the PostScript file to the printer using the available printing command(s) such as lpr or lp.

Of course, making printing too easy with no easy way to see what a printout will look like is likely to result in many wasted printouts. A UNIX command-line utility for print previews of image files would also be useful. One simple way to write this program would be to have it use the same conversion software mentioned above but send the PostScript file to a PostScript previewer, rather than the printer.

For both the image print previewer and the image printer, we could put the PostScript in a temporary file, then erase the file when we are done. This approach has some shortcomings: (1) it requires us to have space available to store the temporary file and (2) it requires us to remove the temporary files when we are done which means that accidental exits can leave unneeded files laying around. A better approach from these standpoints is to simply use pipes to connect together the conversion and preview or printing functions.



The Assignment

Print Image Previewer

For this assignment, we'll implement a simple image printing previewer program that we'll call pip. Users will run pip as follows:

    pip [-paper <papersize>] [-orient <orientation>] <pathname>
where <pathname> is the path name (either absolute or relative) for the file that the user wishes to preview, <papersize> is the size of the paper on which the image would be printed, and <orientation> is the direction that the image would appear on the paper.

When run, pip will convert the file to PostScript using convert and display it to the user using ghostview.


Print Image

For this assignment, we'll also implement a simple image printing program that we'll call pi. Users will run pi as follows:

    pi [-paper <papersize>] [-orient <orientation>] <pathname>
where <pathname> is the path name (either absolute or relative) for the file that the user wishes to print, <papersize> is the size of the paper on which the image should be printed, and <orientation> is the direction that the image should appear on the paper.

When run, pi will convert the file to PostScript using convert and print it for the user using lpr, lp, or another available command-line printing utility. To determine which print command to use, pi will look in the environment variable PRINTUTIL. If PRINTUTIL is not defined, lpr should be used.


For both pi and pip, the command line arguments should be interpreted as follows:

For <papersize>, the user should be able to specify "Letter", "Legal", or "A4." If the user does not specify a paper size, the value in the environment variable PAPERSIZE should be used. If PAPERSIZE is not defined, "Letter" should be used.

For <orientation>, the user should be able to specify "Portrait" or "Landscape." If the user does not specify an orientation, the value in the environment variable PAPERORIENTATION should be used. If PAPERORIENTATION is not defined, "Portrait" should be used.




Notes on this assignment

You may NOT use system in this assignment.

Some parts of the assignment above may be vague or incomplete. This is intentional. This is to give you experience with the way software development is done in "the real world" (industry, academia outside the classroom, government labs, etc.). Often you will get problem descriptions that are vague or incomplete, even if they seem concrete and complete initially.

You should read through the assignment carefully, look for ambiguities or cases not covered, then ask about them, either in office hours or through email, as soon as you can. (Recall that those people who come to office hours get priority over those who call during office hours who, in turn, get priority over those who send email.) If you wait until the last minute to ask about ambiguities or missing cases, you may not get an answer before your project is due. If you don't get an answer in time (or at all, if you don't ask), then you will have to guess how to handle certain situations. If you guess wrong, you will lose points.



What to turn in.

You will turn in both a hard copy and an electronic copy of your assignment. Please follow the instructions on how to send electronic copies. Do not send them to my email address.

Both the hard copy and the electronic copy will contain a write-up and all source code you used in this project. The electronic copy will also contain the executable version of your code. The electronic copy of your write-up should not be in a proprietary format (such as MS Word); it should be either in plain ASCII text or in a portable format (such as Postscript or PDF). Your source code should be in two files called pip.c and pi.c and your executable code should be in two files called pip and pi.

Your source code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).

Your write-up will include 1/2 to 1 page (roughly 80 characters per line, 50 lines per page) explaining the data structures and algorithms used in your code. This page limitation does not include figures used in your explanation, which are encouraged and may take up any amount of space. (This explanation does not remove the requirement that your code be well commented.)



Other

You may write your program from scratch or may start from programs for which the source code is freely available on the web or through other sources (such as friends or student organizations). If you do not start from scratch, you must give a complete and accurate accounting of where all of your code came from and indicate which parts are original or changed, and which you got from which other source. Failure to give credit where credit is due is academic fraud and will be dealt with accordingly.

As noted in the syllabus, you are required to work on this programming assignment in a group of at least two people. It is your responsibility to find other group members and work with them. The group should turn in only one (1) hard copy and one (1) electronic copy of the assignment. Both the electronic and hard copies should contain the names and student ID numbers of all group members. If your group composition changes during the course of working on this assignment (for example, a group of five splits into a group of two and a separate group of three), this must be clearly indicated in your write-up, including the names and student ID numbers of everyone involved.

Each group member is required to contribute equally to each project, as far as is possible. You must thoroughly document which group members were involved in each part of the project. For example, if you have three functions in your program and one function was written by group member one, the second was written by group member two, and the third was written jointly and equally by group members three and four, both your write-up and the comments in your code must clearly indicate this division of labor.