View Raw SPL
/* viewobj.spl */

#include 


/* default height and width */
#define _VIEWOBJ_H 300
#define _VIEWOBJ_W 360

static pfile = "";

static viewobj_numitems();
static viewobj_object_header();
static viewobj_object_footer();
static viewobj_object_format_string();

static viewobj_cell_header();
static viewobj_cell_footer();
static viewobj_cell_format_string();



/* view any variable */
viewobj(obj = refwin(w0), objname = "", title = "Object Properties and Methods", h = -1, w = -1)
{
        local iscell;

        iscell = viewobj_iscell(obj);

        if (iscell)
        {
                viewobj_cell(obj, objname, title, h, w);
        }
        else
        {
                viewobj_object(obj, objname, title, h, w);
        }
}


/* display object properties and methods */
viewobj_object(obj = 0, objname = "", title = "Object Properties and Methods", h = -1, w = -1)
{
        local numprop, nummethod, i, j, k, vtype, val, valstr, name, curobj, nc, ni;

        /* temp file for html */
        pfile = getmiscpath(1, 1) + "vobject.htm";

        if (fopen(pfile, "w") > 0)
        {
                /* html header */
                viewobj_object_header(pfile);

                ni = viewobj_numitems(obj);

                loop (i = 1..ni)
                {
                        if (isstripchart(obj))
                        {
                                nc = 1;
                        }
                        else
                        {
                                nc = isarray(obj) ? numcols(refseries(obj, i)) : 1;
                        }

                loop (k = 1..nc)
                {
                        /* get type, get value and type as strings */
                        (type, valstr, vtype) = valuetype(obj, LOCAL_VARIABLE);

                        /* show value if it exists */
                        if (type != 105 && k == 1)
                        {
                                fputs('

Value

\n', pfile); /* html table */ fputs('\n', pfile); fputs('\n', pfile); /* format for HTML */ valstr = viewobj_object_format_string(valstr); /* html table row */ fputs(sprintf("", objname, vtype, valstr), pfile); /* close table */ fputs("
NameTypeValue
%s%s%s


\n", pfile); } curobj = isarray(obj) ? castobject(refseries(obj, i, k)) : obj; if (isobject(curobj)) { /* properties */ if ((numprop = getbasepropertyname(curobj, -1)) > 0) { if (nc > 1) { fputs(sprintf('

Series %d Properties

\n', k), pfile); } else { fputs('

Properties

\n', pfile); } /* html table */ fputs('\n', pfile); fputs('\n', pfile); loop (j = 1..numprop) { /* get property name, value and type as strings */ (name, valstr, vtype) = getbasepropertyname(curobj, j); /* format for HTML */ valstr = viewobj_object_format_string(valstr); /* html table row */ fputs(sprintf("", name, vtype, valstr), pfile); } /* close table */ fputs("
NameTypeValue
%s%s%s
\n", pfile); } if ((nummethod = getbasemethodname(curobj, -1)) > 0) { if (numprop > 0) { fputs('

\n', pfile); } fputs('

Methods

\n', pfile); /* html table */ fputs('\n', pfile); fputs('\n', pfile); loop (j = 1..nummethod) { /* get property name, value and type as strings */ (name, valstr, vtype) = getbasemethodname(curobj, j); /* format for HTML */ valstr = viewobj_object_format_string(valstr); /* html table row */ fputs(sprintf("", name, vtype, valstr), pfile); } /* close table */ fputs("
NameArgsValue
%s%s%s
\n", pfile); } if (nc > 1) { fputs('

\n', pfile); } } } if (ni > 1) { fputs('

\n', pfile); } } /* close html */ viewobj_object_footer(pfile); /* close file */ fclose(pfile); if (h <= 0) h = _VIEWOBJ_H; if (w <= 0) w = _VIEWOBJ_W; /* show it */ viewhtml(pfile, title, 0, h, w); pfile = ""; } } /* error handler */ viewobj_object_error(errnum, errmes) { if (strlen(pfile) > 0) { fclose(pfile); pfile = ""; } error(errmes); } /* html header */ static viewobj_object_header(pfile) { fputs('\n', pfile); fputs('\n', pfile); fputs('\n', pfile); fputs('Object\n', pfile); fputs('\n', pfile); fputs('\n', pfile); fputs('\n', pfile); fputs('
\n', pfile); } /* html footer */ static viewobj_object_footer(pfile) { fputs('
\n', pfile); } /* format string for html */ static viewobj_object_format_string(s) { s = strrep(s, "\", "\"); s = strrep(s, "<", "<"); s = strrep(s, ">", ">"); return(s); } /* display cells */ viewobj_cell(obj = 0, obname = "", title = "Cell Values", h = -1, w = -1) { local numprop, nummethod, j, vtype, val, valstr, name; if (isarray(obj) && itemtype(obj) == 15) { /* temp file for html */ pfile = getmiscpath(1, 1) + "vobject.htm"; if (fopen(pfile, "w") > 0) { /* html header */ viewobj_cell_header(pfile); (nr, nc) = size(obj); if (nc > 0) { fputs('

Cells

\n', pfile); /* html table */ fputs('\n', pfile); fputs('\n', pfile); loop (k = 1..nc) { loop (j = 1..nr) { try { clear(val); val = (nc > 1) ? obj[j, k] : obj[j]; (vtype, valstr) = viewobj_cell_typestr(val); /* format for HTML */ valstr = viewobj_cell_format_string(valstr); } catch { vtype = 'Unknown'; valstr = 'Unknown'; } /* index */ idxstr = (nc > 1) ? sprintf("[%d, %d]", j, k) : sprintf("[%d]", j); /* html table row */ fputs(sprintf("", idxstr, vtype, valstr), pfile); } } /* close table */ fputs("
IndexTypeValue
%s%s%s
\n", pfile); } /* close html */ viewobj_cell_footer(pfile); /* close file */ fclose(pfile); if (h <= 0) h = _VIEWOBJ_H; if (w <= 0) w = _VIEWOBJ_W; /* show it */ viewhtml(pfile, title, 0, h, w); pfile = ""; } } else { error("No Cells"); } } /* error handler */ viewobj_cell_error(errnum, errmes) { if (strlen(pfile) > 0) { fclose(pfile); pfile = ""; } error(errmes); } /* html header */ static viewobj_cell_header(pfile) { fputs('\n', pfile); fputs('\n', pfile); fputs('\n', pfile); fputs('Cell\n', pfile); fputs('\n', pfile); fputs('\n', pfile); fputs('
\n', pfile); } /* html footer */ static viewobj_cell_footer(pfile) { fputs('
\n', pfile); } /* format string for html */ static viewobj_cell_format_string(s) { s = strrep(s, "\", "\"); s = strrep(s, "<", "<"); s = strrep(s, ">", ">"); return(s); } viewobj_cell_typestr(val) { local vtype, valstr, typestr; (vtype, valstr, typestr) = valuetype(val, LOCAL_VARIABLE); return(typestr, valstr); } viewobj_iscell(obj) { local iscell; if (iswindow(obj)) { iscell = winstatus(obj, 4) ? itemtype(obj) == 15 : 0; } else { iscell = isarray(obj) ? itemtype(obj) == 15 : 0; } return(iscell); } static viewobj_numitems(obj) { local ni = 1; if (isarray(obj)) { ni = (length(obj) > 0) ? numitems(obj) : 0; } return(ni); }