IUP Computer Science
COSC 300 Fall 1999

Project #6
(Due in class 9 December 1999)

This is a different kind of assignment. I have already written the program and it is provided in both source and executable form in the PROJECT directory. Your job is to make the program work by writing four macros that the program relies upon.

The file P6MACS.MAR in the PROJECT directory already contains three macros - to get you started. You need to add four macros to this file and use it to create a macro library. The program that relies on your macros is in a file named HEADTAIL.MAR in the PROJECT directory. HEADTAIL is designed to accept the name of any text file and display the first five and last five lines of that file. Your four macros must have the names and arguments as described below.

OPENIN  STREAM, FILEDES
This macro must open a file for input (using $OPEN) and make it ready for reading (using $CONNECT). You may assume that the file's records contain fewer than 100 bytes. The two arguments are:

STREAM Name to be associated with the FAB for the file, acts like a file stream object in C++ in that all actions on the file must use the stream name to refer to the file.

FILDES Fixed-length string descriptor for the file's name.

At the end of this macro, R0 must contain any error code that is produced while trying to open or connect the file. R0 is checked by the HEADTAIL program after using OPENIN.
GETLINE  STREAM, RECDES
This macro reads a record from the file associated with the STREAM and places the characters into a storage area described by RECDES.

STREAM Name associated with a FAB, like C++ file stream object.

RECDES Fixed-length string descriptor for the record storage area.

Because each record read can be of a different length, GETLINE must modify the part of the descriptor that specifies the string length so that the descriptor reflects the actual length of the record read. After placing a record where the descriptor specifies, GETLINE must change the length field of the descriptor to the appropriate value. If end-of-file occurs while reading, GETLINE must leave the error code in R0. If there is no error when reading, R0 should have an odd number put into it when the macro ends. HEADTAIL checks R0 after using GETLINE.
 
COLORSHOW  COLOR, STR, [LENGTH]
This macro is a much more flexible form of SHOWC that displays in color (on a black background). The [ ] surrounding LENGTH indicate that it is an optional argument.

COLOR Name of any standard color that can be displayed (or an abbreviation of the name) in uppercase or lowercase. The standard colors are red, green, yellow, blue, magenta, cyan, and white. Any of the following values for COLOR should cause the display to be in green: GREEN, green, gr, Gr, G

STR Some type of reference to the string which is to be displayed in color. May be any of three things: a fixed-length string descriptor, a label on a storage area holding the string (in this case the LENGTH argument is required), or a string constant in the form <"some words"> Only the specified string should be in the specified color; subsequent output should be in white.

LENGTH Some type of reference to the number of characters in the string to be displayed. This argument is used only for one of the STR values.

CHOOSE  HUE
Associate the HUE (color) with a number that you can use in making the appropriate escape sequence to change colors.

HUE A single character that can be used to determine which color was specified. The number to be associated with HUE should be 1 for red, 2 for green, ... and 7 for white.

This utility macro is meant to be used by COLORSHOW to "translate" the COLOR specification to a number, e.g. Green into 2, which COLORSHOW uses to construct/select an appropriate escape sequence to change color.

To make the macro library you need for this project, copy P6MACS.MAR into your own directory. This file contains the SHOWC macro ( works just as described in class), the GETSTR macro (which is similar to SHOWC but reads a string, rather than writes one), and the CLOSE macro (which closes a file). Add your version of the four macros to P6MACS.MAR and then make the library with the command:

	$ LIBRARY/CREATE/MACRO  P6MACS  P6MACS
The HEADTAIL program expects to use a macro library named P6MACS that is in your directory to do its job. Copy HEADTAIL.MAR to your directory, assemble it, link it, and run it.

Hand in a .LIS printout of HEADTAIL as it assembles with your library. HEADTAIL contains a .SHOW MEB directive so it will show the expanded macros in the .LIS file. Also, hand in a printout of P6MACS.MAR. Copy your executable HEADTAIL.EXE to the HANDIN directory and name it after yourself. If I were doing the assignment, I would give a command like this: $ COPY HEADTAIL.EXE HANDIN:WOLFE.EXE