View Raw SPL
#include
static cbvarname = "";
/* paste series/object from clipboard file to window selection - called internally */
_cbpastesel(vfile = "", vname = "", w = refwindow(w0), r = 0, c = 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 && c > 0)
{
if (r == 1 && nr >= length(w))
{
rstr = "..";
}
else
{
rstr = sprintf("%lld..%lld", r, r + nr - 1);
}
cmd = sprintf("w%d[%s, %lld..%lld] = local_s", getwnum(w), rstr, c, c + nc - 1);
eval(cmd);
}
/* delete clipboard variable */
eval(sprintf("clear('%s')", vname));
}
}
cbvarname = "";
if (not(pastewin))
{
return(local_s);
}
}
/* error handler */
_cbpastesel_error(errnum, errmes)
{
if (strlen(cbvarname) > 0)
{
eval(sprintf("clear('%s')", cbvarname));
cbvarname = "";
}
error(errmes);
}