#ifndef STRUCTUREDIO
#define STRUCTUREDIO

#include "../MemoryManager.h"

int ParseStructure(FILE *file, char* DataDescription, int** FilledMask, MemoryManager* Memory, ...);
/*ParseStructure fills the optional parameters with values read from file.
Data types are described by the string DataDescription. If FilledMask is 
provided it will be filled with an integer array with one element for each of 
the optional parameters, to be set to 1 if that parameter is filled and 0
otherwise.

ParseStructure returns 1 if the file has more contents to be read and 0 if the 
file has been completely read or a "quit" keyword was encountered. In all but a
few instances (keywords echo, rem, and type string), ParseStructure reads in
single tokens separated by whitespace, not whole lines. Consequently,
the input can never use names that contain whitespace, and the choice of 
whitespace used in the input to separate tokens is irrelevant. Data can
be delimited by tabs, spaces, newlines, or any other whitespace characters.

ParseStructure has several predefined keywords:
done	Indicates that there is no more data for this structure but more data in
			the file. ParseStructure terminates and returns 1.
quit	Indicates that no more of the file should be parsed. ParseStructure
			terminates and returns 0.
echo	ParseStructure reads everything left on the line after the keyword up to 
			128 characters, trims	leading whitespace, and prints the rest to the 
			screen. This can be used for comments, problem numbers, and so forth.
rem		rem is like echo except that no text is printed to the screen. Used for
			comments.
help	Displays a help message by calling ShowHelp.

The syntax of DataDescription is as follows:
TYPE NAME[,TYPE NAME...]
The string can contain as many pairs of TYPE NAME pairs separated by commas
as necessary. 
NAME is a string corresponding to the name of the parameter; this will be used
in error messages and will be the keyword looked for in the input file. Each
parameter value is read from the file immediately after its keyword is
encountered.
TYPE is one of the following type keywords:
	matrix	The corresponding parameter from the optional parameters list is a
					pointer to a matrix. This will be read from the file by reading in a 
					pair of	integers corresponding to row and column count followed by 
					reading	in an integer for each element of the matrix.					
	int			The corresponding parameter is a pointer to an integer.
	double	The corresponding parameter is a pointer to a double.
	string	The corresponding parameter is a pointer to a pre-allocated
					character array of length greater than 128. The remains of the line
					following the keyword are read.
	arrayi	There are two corresponding parameters, one immediately after the
					other. The first is a pointer to a pointer to integers which
					is filled with all the integers read from the file. The second
					is a pointer to a single integer, filled with the length of the array.
					The length is read from the file first and then the array contents
					are read.
	arrayd	The same as arrayi except that the array contents are of type double 
					so the first associated parameter is a pointer to a pointer to double.
	indexarray
					Reading from the file, indexarray is identical to arrayi.
					See "DisplayStructure" for a special interpretation there.
Example Usage:
	ParseStructure(stdin, "matrix A, arrayi B, double C", &mask, &matrixA, &B, &LengthB, &C);
Would read the following keyboard input:
	C 5.921
	B 5
	1 2 3 4 5
	A 3 3
	1 2 3
	4 5 6
	7 8 9
	quit
When ParseStructure returned, matrixA would contain a 3x3 matrix with contents
[1, 2, 3; 4, 5, 6; 7, 8, 9], B would contain a 5-element array [1, 2, 3, 4, 5],
and C would contain 5.921. mask would be a 3-element integer array of ones.
LengthB would contain the number 5.
	*/	

void DisplayStructure(char* DataDescription, int* Mask, ...);
/*DisplayStructure prints the parameters passed in the optional parameter list
in a human-readable format. It takes an array of integers, Mask, which can
be used to suppress the printing of some of the parameters. This Mask is 
the same as the mask created by ParseStructure.

Data type is determined by the contents of the DataDescription string. The
string has the same syntax as that used in ParseStructure. The TYPE keywords
are the same but have slightly different intepretations:
	matrix	The corresponding parameter from the optional parameters list is a
					pointer to a matrix. This will be displayed by calling ShowMatrix 
					from MatrixMath.h.
	int			The corresponding parameter is an integer and is displayed in the form
					"NAME: value".
	double	The corresponding parameter is a double and is displayed in the form
					"NAME: value".
	string	The corresponding parameter is a pointer to C-style string and is 
					displayed in the form	"NAME: value".
	arrayi	There are two corresponding parameters, one immediately after the
					other. The first is to an integer array. The second is a single 
					integer containing the length of the array. Displayed in the form
					"NAME: value1 \t value2 \t value3 ..." where \t denotes a tab.
	arrayd	The same as arrayi except that the array is of type double.
	indexarray
					There are three associated parameters. The first is an array of
					integers corresponding to column indexes in a matrix. The second
					is the length of the array. The third is the number of columns
					in the matrix. The array is displayed as a single line of text
					with an X in every column (columns separated by tabs) the index
					of which is present in the array and a blank space in every other
					column, all followed by the name of the item.
					For example, if a 1x5 matrix [1, 2, 3, 4, 5] had just been displayed
					and an indexarray with array [0, 2, 3], length 3, and column count 5
					was encountered, the final display would look like this:
					Matrix matrixname (1 x 5):
					1	2	3	4	5
					X		X	X		IndexArrayName*/


#endif
