View Raw SPL
/*****************************************************************************
* *
* SPLREADALL.SPL Copyright (C) 2018 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Reads all SPL functions in a folder *
* *
* Revisions: 15 Nov 2018 RRR Creation *
* *
*****************************************************************************/
#if @HELP_SPLREADALL
SPLREADALL
Purpose: Reads one or more SPL functions without creating OPL files.
Syntax: SPLREADALL("filespec", recurse, overwrite, verbose)
"filespec" - String. The folder or file specification with
optional * or ? wildcard characters.
recurse - Optional. An integer, recurse into sub-directories.
0: do not recurse (default)
1: recurse
overwrite - Optional. An integer, macro overwrite.
0: do not replace macro of same name
1: replace macro if it exists (default)
verbose - Optional. An integer, display messages.
0: do not provide error messages
1: display compile errors (default)
Returns: An integer, the number of files read.
Example:
splreadall(".\spl\dsp\*.spl")
reads all .SPL files in the .\spl\dsp directory.
Example:
splreadall(".\spl\*.spl", 1)
reads all .SPL files in the .\spl directory and all
sub-directories.
Remarks:
SPLREADALL reads the functions into the Worksheet without
creating associated OPL files.
Any errors found during compile are written to the ASCII
text file, filename.err.
See Also:
Functions
Splcompile
Splcompileall
Splload
Splloadall
Splread
Splwrite
#endif
/* read all SPL functions in a folder as specified by filespec */
splreadall(filespec, recurse, ovr, expand, verbose)
{
local i, cnt = 0, filelist, dir, fname, mes;
if (argc < 4)
{
if (argc < 3)
{
if (argc < 2)
{
if (argc < 1) error(sprintf("%s - filename required", __FUNC__));
recurse = 0
}
ovr = 1;
}
verbose = 1;
}
/* check inputs */
if (strlen(filespec) == 0)
{
return(0);
}
/* get directory */
(dir, fname) = dirpath(filespec, 1);
/* get newline delimited filelist */
filelist = splreadall_filelist(filespec, recurse);
/* dir + splreadall.spl */
ourname = which("splreadall");
i = 1;
while (1)
{
file = strget(i, filelist, strescape("\n"));
if (strlen(file) > 0)
{
(filedir, fname) = dirpath(file, 0);
if (strlen(filedir) <= 0)
{
file = dir + file;
}
/* don't read ourself */
if (strcmp(ourname, file, 0) != 0)
{
splread(file, ovr, verbose);
cnt++;
}
i++;
}
else
{
break;
}
}
if (outargc > 0)
{
/* return successful count */
return(cnt);
}
else if (verbose)
{
/* display message */
mes = (cnt == 1) ? "%d SPL Function Loaded" : "%d SPL Functions Loaded";
return(sprintf(mes, cnt));
}
}
splreadall_filelist(spec, recurse)
{
local tempfile, cmd, options, s = "";
if (argc < 2)
{
if (argc < 1) spec = "*.*";
recurse = 0;
}
/* flag to recurse into sub-directories */
options = recurse ? "/S" : "";
/* build temporary file */
tempfile = getmiscpath(1, 1) + "templist.txt";
/* directory listing command */
cmd = sprintf('dir "%s" /b %s > "%s"', spec, options, tempfile);
/* run listing */
run(cmd, -1);
/* check tempfile existence */
if (fstat(tempfile) > 0)
{
/* return listing as a string */
s = strfile(tempfile, 0, 1, 0, 0);
delfile(tempfile);
}
return(s);
}