View Raw SPL
#include 

static cbvarname = "";

/* insert series/object from clipboard file to row - called internally */
_cbinsertrow(vfile = "", vname = "", w = refwindow(w0), r = 0, c = 0, mode = 0)
{
        local s, nr, nc, local_s = "", pastewin, cmd, rstr;

        cbvarname = vname;

        /* return result if target is not a window */
        pastewin = iswindow(w);

        if (strlen(vname) > 0)
        {
                if (strlen(vfile) > 0 && fstat(vfile) > 0)
                {
                        if (pastewin)
                        {
                                printf(_cbrdstr_psing, getwnum(w));
                        }

                        /* load it */
                        loadvar(vfile);
                }

                /*
                 *  loadvar preserves storage info of the source file for
                 *  direct series reading so we need to make explicit
                 *  copies to avoid read locking the clipboard file
                 */

                if (eval(sprintf("isglobal('%s')", vname)))
                {
                        /* explict copy - handles all types */
                        eval(sprintf("local_s = copyobject(%s)", vname));

                        (nr, nc) = size(local_s);

                        if (nr > 0 && nc > 0 && r > 0)
                        {
                                cmd = sprintf("_cbinsertrow_insert(w%d, local_s, %lld, %lld, %d)", getwnum(w), r, c, mode);
                                
                                eval(cmd);
                        }

                        /* delete clipboard variable */
                        eval(sprintf("clear('%s')", vname));
                }
        }

        cbvarname = "";

        if (not(pastewin))
        {
                return(local_s);
        }
}


/* error handler */
_cbinsertrow_error(errnum, errmes)
{
        if (strlen(cbvarname) > 0)
        {
                eval(sprintf("clear('%s')", cbvarname));
                cbvarname = "";
        }

        error(errmes);
}