View Raw SPL
#include
/* read table form URL */
webreadt(url="", argv)
{
local txt, tmpfile, cmd, j, s, isurl = 1;
if (not(isstring(url)) || strlen(url) == 0)
{
error(sprintf(_rdterr_iur, __FUNC__));
}
/* temp file for readt */
tmpfile = getmiscpath(1, 1) + "webtab.txt";
/* check URL syntax */
if (not(isvalidurl(url)))
{
/* check if file */
if (not(fileexists(url)))
{
error(sprintf(_rdterr_inu, __FUNC__, url));
}
else
{
/* file */
isurl = 0;
tmpfile = url;
}
}
if (isurl)
{
/* get URL table as string */
txt = geturl(url);
if (not(isstring(txt)) || strlen(txt) == 0)
{
error(sprintf(_rdterr_ntd, __FUNC__, url));
}
if (fileexists(tmpfile))
{
delfile(tmpfile);
}
/* save string to temp file */
if (not(fopen(tmpfile, "w") == 1))
{
error(sprintf(_rdterr_fer, __FUNC__));
}
fputs(txt, tmpfile);
fclose(tmpfile);
}
/* setup args for readt */
loop (j = 1..argc-1)
{
setlocalvar(sprintf("loc%d", j), getargv(j));
}
/* build command */
cmd = sprintf("readtable('%s'", tmpfile);
loop (j = 1..argc-1)
{
cmd += sprintf(", loc%d", j);
}
cmd += ")";
/* evaluate */
s = eval(cmd);
return(s);
}