/*
 *	aegis - project change supervisor
 *	Copyright (C) 2005-2008 Peter Miller
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program. If not, see
 *	<http://www.gnu.org/licenses/>.
 *
 * This report is primarily of use in debugging, but can also
 * demonstrate the shape of the internal data structures available to a
 * report author.  If you are expluring a specific sub-section of the
 * data tree, the best idea its to copy this report and then mangle the
 * thing first placed on the stack.
 */

title("Users List", "Verbose Recursive Debug");

columns
(
    { name = "Variable Name\n---------------"; right = 0; },
    { name = "Type\n------"; left = 16; width = 11; },
    { name = "Value\n------"; right = 0; }
);

auto stack, top;
top = 0;
stack[top++] = { name = "user"; value = user; };

while (top > 0)
{
    auto x, t, j, k, klen;

    x = stack[--top];
    t = typeof(x.value);
    if (t == "list")
    {
	print(x.name, t, "");
	klen = count(x.value);
	for (j = 0; j < klen; ++j)
	{
	    stack[top + klen - 1 - j] =
	       	{
		    name = x.name ## "[" ## j ## "]";
		    value = x.value[j];
	       	};
	}
	top += klen;
    }
    else if (t == "struct")
    {
	print(x.name, t, "");
	k = sort(keys(x.value));
	klen = count(k);
	for (j = 0; j < klen; ++j)
	{
	    if (typeof(k[j]) == "integer")
	    {
		stack[top + klen - 1 - j] =
		    {
			name = x.name ## "[" ## k[j] ## "]";
			value = x.value[k[j]];
		    };
	    }
	    else
	    {
		stack[top + klen - 1 - j] =
		    {
			name = x.name ## "." ## k[j];
			value = x.value[k[j]];
		    };
	    }
	}
	top += klen;
    }
    else if (t == "enumeration" || t == "time" || t == "integer")
	print(x.name, t, x.value);
    else if (t == "string")
	print(x.name, t, "\"" ## x.value ## "\"");
    else
	print(x.name, t, "???");
}
