View Raw SPL
/*****************************************************************************
*                                                                            *
*   READCNF.SPL  Copyright (C) 2023 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Reads a configuration file                                  *
*                                                                            *
*   Revisions:   30 Jul 2023  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_READCNF

    READCNF

    Purpose: Reads a configuration file.

    Syntax:  READCNF(fname, update)

              fname  - A string, the configuration settings filename or URL.

              update - Optional. An integer, redraw the application after
                       applying the new settings. 

                        0: Redraw entire screen.
 
                        1: Re-initialize graphics and redraw.
 
                        2: Re-initialize fonts, re-initialize graphics,
                           and redraw (default).
 
                        3: Re-initialize Windows, re-initialize graphics,
                           and redraw.
 
                        4: Re-initialize system colors, re-initialize graphics,
                           and redraw.
 
 

    Returns: An integer, the number of configuration parameters loaded 
             if successful.

    Example:
             writecnf("D:\temp\myconfig.cnf");
             setconfig("toolbar_font_height", -24);redrawall(2)
             readcnf("D:\temp\myconfig.cnf");

             Writes the current configuration table to "D:\temp\myconfig.cnf"
             and then sets the toolbar font height to 24 points (negative
             height implies points, positive height implies pixels).

             The original settings are reloaded from "D:\temp\myconfig.cnf"

   Example:
             writecnf("D:\temp\temp.cnf")
             readcnf("www.dadisp.com/files/test.cnf")
             readcnf("D:\temp\temp.cnf")

             Saves the current session settings, then reads a sample
             configuration file from the URL.

             The original settings are then restored.
             
    See Also:
             Writecnf
#endif


/* read configuration settings from text file */
readcnf(fname = "", update = 1, header = "")
{
        local cnt;

        if (fileexists(fname))
        {
                if ((cnt = readsession(fname)) >= 0)
                {
                        if (update)
                        {
                                /* update color settings */
                                readcnf_updateclr();

                                /* reinit worksheet graphic settings */
                                redrawall(0);
                        }
                }
        }
        else
        {
                if (isvalidurl(fname))
                {
                        cnt = webreadcnf(fname, update, header);
                }
                else
                {
                        error(sprintf("'%s' does not exist", fname));
                }
        }

        return(cnt);
}



/* update global color parameters */
readcnf_updateclr()
{
        setgcolor(5, castint(getconfig("series_color")));
        setgcolor(7, castint(getconfig("window_color")));

        setgcolor(17, castint(getconfig("window_background_color")));
        setgcolor(18, castint(getconfig("window_text_color")));
        setgcolor(19, castint(getconfig("window_grid_color")));

        setgcolor(20, castint(getconfig("window_hilite")));
        setgcolor(21, castint(getconfig("window_shadow")));

        setgcolor(31, castint(getconfig("window_label_color")));
        setgcolor(32, castint(getconfig("label_background")));
        setgcolor(35, castint(getconfig("inactive_label_bg")));
        setgcolor(36, castint(getconfig("inactive_text_color")));
        setgcolor(37, castint(getconfig("active_label_bg")));
        setgcolor(38, castint(getconfig("active_text_color")));

        setgcolor(41, castint(getconfig("error_color")));
        setgcolor(42, castint(getconfig("child_bg_color")));
        setgcolor(43, castint(getconfig("child_fg_color")));
        setgcolor(44, castint(getconfig("parent_bg_color")));
        setgcolor(45, castint(getconfig("parent_fg_color")));

        setgcolor(1, castint(getconfig("foreground")));
        setgcolor(2, castint(getconfig("background")));
        setgcolor(3, castint(getconfig("text_foreground")));
        setgcolor(4, castint(getconfig("text_background")));

        setgcolor(30, castint(getconfig("worksheet_bg")));
}