View Raw SPL
/*****************************************************************************
* *
* WRITECNF.SPL Copyright (C) 1997-2023 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Writes configuration table to an ASCII file *
* *
* Revisions: 2 Dec 1997 RRR Creation *
* 20 Jun 2000 RRR addversion *
* 5 May 2023 RRR verbosity *
* *
*****************************************************************************/
#include
#if @HELP_WRITECNF
WRITECNF
Purpose: Writes the configuration table to an ASCII file
Syntax: WRITECNF(fname, overwrite, verbose)
fname - Optional. A string specifying the filename, defaults
to "config.txt"
overwrite - Optional. An integer, the overwrite flag.
0: query user if file already exists (default)
1: overwrite existing file
verbose - Optional. An integer, the verbosity flag. If 1, adds
information about the application and system.
Defaults to 1.
Returns: 1 if successful
Example:
Writecnf();
Viewfile("config.txt")
Writes the current configuration table to "config.txt"
along with application and system information and displays
the table in a pop-up box.
See Also:
Fclose
Fopen
Fputs
#endif
/* write current configuration settings to text file */
writecnf(fname = getmiscpath(1,6)+"config.txt", overwrite = 0, verbose = 1, dwkcnf = 0)
{
local cnf, str;
if (fileexists(fname))
{
if (not(overwrite))
{
if (message(_fileexistsmes, sprintf(_replacefilemes, fname), 6) != 1)
{
return(0);
}
}
}
if (fopen(fname, "w") != TRUE)
{
error(sprintf("writecnf - cannot open %s", fname));
}
if (verbose)
{
str = strescape(sprintf("! Product: %s\n", version));
fputs(str, fname);
str = strescape(sprintf("! Serial Number: %s\n", version(7)));
fputs(str, fname);
str = strescape(sprintf("! OS Version: %s\n", getcomputer(1)));
fputs(str, fname);
str = strescape(sprintf("! OS Platform: %s\n", getcomputer(0)));
fputs(str, fname);
str = strescape(sprintf("! CPU Type: %s\n", getcomputer(-1)));
fputs(str, fname);
str = strescape(sprintf("! User Name: %s\n", gethostid(1)));
fputs(str, fname);
str = strescape(sprintf("! Buffer Size: %ld\n", setbufsize()));
fputs(str, fname);
str = strescape(sprintf("! Fit Memory: %d\n", getconfig("fit_memory")));
fputs(str, fname);
str = strescape(sprintf("! Time: %s\n", strtrim(gettime())));
fputs(str, fname);
str = strescape(sprintf("! Date: %s\n", strtrim(getdate())));
fputs(str, fname);
fputs(strescape("\n"), fname);
}
/* gets configuration table as string */
cnf = reserved(1001, dwkcnf);
/* sort */
cnf = strsort(cnf, strescape("\n"), strescape("\n"), 1, 1, 1);
/* append and close */
fputs(cnf, fname);
fclose(fname);
return(TRUE);
}
/* executes if we have an error */
writecnf_error(errnum)
{
/* close open files */
fcloseall();
}