The purpose of this assignment is to learn about laying out and drawing visualizations of data structures in a window. You will use a piece of software that will simulate monitoring a program and extracting information about its data structures. To begin your program, you must call the function DSReadIn defined in this software. (This function is inside the file dsd.o in the directory ~stasko/Public/7390/sun or sgi. Link that file into your executable. The header file for it is dsd.h.) This routine reads in a group of data structures and their values. The function takes a string parameter, which is the name of a file to read. It contains the data structure definitions. A sample of a file in the appropriate format can be found in dsd.data. Feel free to make up your own input files for program testing. If you have a real good one, send it to me, and I may use it as a tester.
Once your program has read all the data from a file, it is ready to begin processing user show and remove commands. You will receive a series of commands to either show a particular data object or to remove (hide) the view of the data structure. The format of those two commands is
S var-name /* show operation */ H var-name /* hide operation */Just scanf for those commands.
When you receive a show command with the variable to be shown, you must now query the program database to find out what type and value(s) the variable has. To do this, call the function DSInquire. It takes a string parameter (name of the variable) and it returns an InfoPtr (see below). If the string you gave to it is not a valid variable name, it returns NULL. Below is the file dsd.h.
typedef enum
{
CHAR,
SHORT,
INT,
FLOAT,
DOUBLE
} DSType;
typedef enum
{
SCALAR,
ARRAY1,
ARRAY2,
STRUCT,
PTR
} DSStructure;
typedef struct _InfoNode
{
char name[16];
DSStructure structure;
DSType type;
char *data;
int dim1;
int dim2;
struct _InfoNode *ptrnext;
struct _InfoNode *structnext;
} *InfoPtr, InfoNode;
void DSReadIn();
InfoPtr DSInquire();
void DSPrintOut();
A data structure in this assignment can be a scalar (char, short, int, float, double), a one-dimensional array, a two-dimensional array, a structure, or a pointer. Note that arrays are only of scalars, structures can have an arbitrary number of scalar fields, and pointers can be lists but they will always have the same item as a node throughout the list. An InfoPtr has a number of pertinent fields which describe the structure of a variable. The name, structure, and type fields should be self-explanatory. The data field is a pointer to the appropriate type of object (just cast it away from char* into whatever you expect it to be). For an array, data is a list of objects of the appropriate type (2-D arrays are listed sequentially, row-by-row). The field dim1 gives the size of a 1-D array, or the number of rows in a 2-D array (the number of columns is specified by dim2). If the InfoPtr describes a structure, then it begins with a logical header node. The field structnext points to the fields within the structure (this will be a NULL terminated list). For a pointer, again there is a blank header node, then each subsequent node in the ptrnext list describes a node in the linked list. For pointer lists, I will always make the nodes in the list the same type throughout.
I have also provided a debugging routine, DSPrintOut, which you can call and it will just print out what's in all the data structures that have been read in.
To display your data structures, build an 800x800 window using some graphics package such as Xlib, SRGP or GL. (A real good program will handle other sizes and resizing too.) The object of the program is to place the data structures in the window in an understandable, clear, and aesthetically appealing fashion. It's up to you to decide what they look like and where they go. Clearly, try to avoid overlaps. Some of the papers we've been reading have a few tips or ideas for both visual appearance and layout algorithms. Below appears a sample dsd.data file.
c char1 a h short1 3 i int1 34 f float1 3.4 f joe 3.2 f fred 6.5 d double1 -12.3 s struct1 i f1 12 i f2 6 c f3 b z p paul d val -191929292.2345 d val 0.0 d val 0.0 z p ptr1 i ggg 12 i ggg 13 i ggg 14 z 1 array11 i 4 1 2 3 4 2 array21 d 3 2 -1.0 -2.0 -3.0 -4.0 5.0 6.0 d double2 -9.0 i bob 3 i mary 12 z
and a sample input might be
S mary S struct1 S float1 S fred H float1 S array11 S array21 S paul S ptr1 H array21